1 package org.ozoneDB.tools.OPP; 7 8 import org.ozoneDB.tools.OPP.srcgen.ClassBuilder; 9 import org.ozoneDB.tools.OPP.srcgen.ClassDirector; 10 import org.ozoneDB.tools.OPP.srcgen.builder.*; 11 import org.ozoneDB.tools.OPP.srcgen.builder.CompositeBuilder; 12 import org.ozoneDB.tools.OPP.srcgen.builder.FactoryBuilder; 13 import org.ozoneDB.tools.OPP.srcgen.builder.MethodNameUpgradingClassBuilderDecorator; 14 import org.ozoneDB.tools.OPP.srcgen.builder.OcdBuilder; 15 import org.ozoneDB.tools.OPP.srcgen.query.ReflectionClassQuery; 16 import org.ozoneDB.tools.OPP.srcgen.streamfactory.InputStreamFactory; 17 import org.ozoneDB.tools.OPP.srcgen.streamfactory.FileInputStreamFactory; 18 import org.ozoneDB.tools.OPP.srcgen.streamfactory.OutputStreamFactory; 19 import org.ozoneDB.tools.OPP.srcgen.streamfactory.FileOutputStreamFactory; 20 import org.ozoneDB.tools.OPP.srcgen.direct.ReflectionClassDirector; 21 import org.ozoneDB.tools.OPP.srcgen.resolve.ClassDescriptorUpdateMethodResolver; 22 import org.ozoneDB.tools.OPP.srcgen.resolve.CompositeMethodResolver; 23 import org.ozoneDB.tools.OPP.srcgen.resolve.SourceUpdateMethodResolver; 24 import org.ozoneDB.tools.OPP.message.CompositeOPPMessageListener; 25 import org.ozoneDB.tools.OPP.message.MessageWriter; 26 import org.ozoneDB.tools.OPP.message.SummaryMessageWriterDecorator; 27 28 import java.io.*; 29 30 46 public class OPPBean { 47 private boolean printStackTrace = false; 48 private String updateExpression = ".*_update"; 49 private boolean cache = true; 50 private CompositeOPPMessageListener compListener = new CompositeOPPMessageListener(); 51 private SummaryMessageWriterDecorator summaryListenerDecorator; 52 private boolean useOcd = true; 53 private boolean useSource = true; 54 private boolean generateFactory = true; 55 private boolean generateProxy = true; 56 private boolean generateOcd = false; 57 58 public OPPBean() { 59 summaryListenerDecorator = new SummaryMessageWriterDecorator(compListener); 60 } 61 62 public boolean isUseOcd() { 63 return useOcd; 64 } 65 66 public void setUseOcd(boolean useOcd) { 67 this.useOcd = useOcd; 68 } 69 70 public boolean isUseSource() { 71 return useSource; 72 } 73 74 public void setUseSource(boolean useSource) { 75 this.useSource = useSource; 76 } 77 78 public boolean isGenerateFactory() { 79 return generateFactory; 80 } 81 82 public void setGenerateFactory(boolean generateFactory) { 83 this.generateFactory = generateFactory; 84 } 85 86 public boolean isGenerateProxy() { 87 return generateProxy; 88 } 89 90 public void setGenerateProxy(boolean generateProxy) { 91 this.generateProxy = generateProxy; 92 } 93 94 public boolean isGenerateOcd() { 95 return generateOcd; 96 } 97 98 public void setGenerateOcd(boolean generateOcd) { 99 this.generateOcd = generateOcd; 100 } 101 102 private MessageWriter getSummaryListener() { 103 return summaryListenerDecorator; 104 } 105 106 public void setCache(boolean cache) { 107 this.cache = cache; 108 } 109 110 public void setUpdateExpression(String updateExpression) { 111 this.updateExpression = updateExpression; 112 } 113 114 public void setPrintStackTrace(boolean printStackTrace) { 115 this.printStackTrace = printStackTrace; 116 } 117 118 public ClassDirector createDirector(InputStreamFactory source, InputStreamFactory ocdsource) { 119 CompositeMethodResolver resolver = new CompositeMethodResolver(); 120 if (source != null) { 121 resolver.addResolver(new SourceUpdateMethodResolver(source, getSummaryListener(), new ReflectionClassQuery())); 122 } 123 if (ocdsource != null) { 124 resolver.addResolver(new ClassDescriptorUpdateMethodResolver(ocdsource, getSummaryListener())); 125 } 126 return new ReflectionClassDirector(getSummaryListener(), resolver); 127 } 128 129 133 public ClassDirector createDirector(File sourceDir) { 134 InputStreamFactory ocdFactory = null; 135 InputStreamFactory sourceFactory = null; 136 if (useOcd) { 137 ocdFactory = new FileInputStreamFactory(sourceDir, "ocd"); 138 } 139 if (useSource) { 140 sourceFactory = new FileInputStreamFactory(sourceDir, "java"); 141 } 142 return createDirector(sourceFactory, ocdFactory); 143 } 144 145 public ClassBuilder createBuilder(OutputStreamFactory factory, String factoryPost, OutputStreamFactory proxy, String proxyPost, OutputStreamFactory ocd) { 146 CompositeBuilder builder = new CompositeBuilder(); 147 if (factory != null) { 148 builder.addBuilder(new FactoryBuilder(factory, factoryPost)); 149 } 150 if (proxy != null) { 151 ClassBuilder proxyBuilder = new ProxyBuilder(proxy, proxyPost, printStackTrace, cache, getSummaryListener()); 152 MethodNameUpgradingClassBuilderDecorator decorator = 154 new MethodNameUpgradingClassBuilderDecorator(proxyBuilder, updateExpression); 155 builder.addBuilder(decorator); 156 } 157 if (ocd != null) { 158 builder.addBuilder(new OcdBuilder(ocd)); 159 } 160 return builder; 161 } 162 163 public ClassBuilder createBuilder(File outputDir, String factoryPost, String proxyPost) { 164 OutputStreamFactory factoryOsFactory = null; 165 OutputStreamFactory proxyOsFactory = null; 166 OutputStreamFactory ocdOsFactory = null; 167 if (generateFactory) { 168 factoryOsFactory = new FileOutputStreamFactory(outputDir, "java"); 169 } 170 if (generateProxy) { 171 proxyOsFactory = new FileOutputStreamFactory(outputDir, "java"); 172 } 173 if (generateOcd) { 174 ocdOsFactory = new FileOutputStreamFactory(outputDir, "ocd"); 175 } 176 return createBuilder(factoryOsFactory, factoryPost, proxyOsFactory, proxyPost, ocdOsFactory); 177 } 178 179 public void addGenrationEventListener(MessageWriter listener) { 180 compListener.addListener(listener); 181 } 182 183 public void removeGenrationEventListener(MessageWriter listener) { 184 compListener.removeListener(listener); 185 } 186 } 187 | Popular Tags |