1 16 17 package org.apache.catalina.storeconfig; 18 19 import java.io.PrintWriter ; 20 21 import org.apache.catalina.util.StringManager; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 33 public class StoreFactoryBase implements IStoreFactory { 34 private static Log log = LogFactory.getLog(StoreFactoryBase.class); 35 36 private StoreRegistry registry; 37 38 private StoreAppender storeAppender = new StoreAppender(); 39 40 43 protected static final StringManager sm = StringManager 44 .getManager(Constants.Package); 45 46 49 private static final String info = "org.apache.catalina.config.StoreFactoryBase/1.0"; 50 51 56 public String getInfo() { 57 58 return (info); 59 60 } 61 62 65 public StoreAppender getStoreAppender() { 66 return storeAppender; 67 } 68 69 73 public void setStoreAppender(StoreAppender storeAppender) { 74 this.storeAppender = storeAppender; 75 } 76 77 82 public void setRegistry(StoreRegistry aRegistry) { 83 registry = aRegistry; 84 85 } 86 87 92 public StoreRegistry getRegistry() { 93 94 return registry; 95 } 96 97 public void storeXMLHead(PrintWriter aWriter) { 98 aWriter.print("<?xml version=\"1.0\" encoding=\""); 100 aWriter.print(getRegistry().getEncoding()); 101 aWriter.println("\"?>"); 102 } 103 104 110 public void store(PrintWriter aWriter, int indent, Object aElement) 111 throws Exception { 112 113 StoreDescription elementDesc = getRegistry().findDescription( 114 aElement.getClass()); 115 116 if (elementDesc != null) { 117 if (log.isDebugEnabled()) 118 log.debug(sm.getString("factory.storeTag", 119 elementDesc.getTag(), aElement)); 120 getStoreAppender().printIndent(aWriter, indent + 2); 121 if (!elementDesc.isChilds()) { 122 getStoreAppender().printTag(aWriter, indent, aElement, 123 elementDesc); 124 } else { 125 getStoreAppender().printOpenTag(aWriter, indent + 2, aElement, 126 elementDesc); 127 storeChilds(aWriter, indent + 2, aElement, elementDesc); 128 getStoreAppender().printIndent(aWriter, indent + 2); 129 getStoreAppender().printCloseTag(aWriter, elementDesc); 130 } 131 } else 132 log.warn(sm.getString("factory.storeNoDescriptor", aElement 133 .getClass())); 134 } 135 136 144 public void storeChilds(PrintWriter aWriter, int indent, Object aElement, 145 StoreDescription elementDesc) throws Exception { 146 } 147 148 157 protected void storeElement(PrintWriter aWriter, int indent, 158 Object aTagElement) throws Exception { 159 if (aTagElement != null) { 160 IStoreFactory elementFactory = getRegistry().findStoreFactory( 161 aTagElement.getClass()); 162 163 if (elementFactory != null) { 164 StoreDescription desc = getRegistry().findDescription( 165 aTagElement.getClass()); 166 if (!desc.isTransientChild(aTagElement.getClass().getName())) 167 elementFactory.store(aWriter, indent, aTagElement); 168 } else { 169 log.warn(sm.getString("factory.storeNoDescriptor", aTagElement 170 .getClass())); 171 } 172 } 173 } 174 175 178 protected void storeElementArray(PrintWriter aWriter, int indent, 179 Object [] elements) throws Exception { 180 if (elements != null) { 181 for (int i = 0; i < elements.length; i++) { 182 storeElement(aWriter, indent, elements[i]); 183 } 184 } 185 } 186 } | Popular Tags |