1 33 34 package com.icesoft.metadata.generators; 35 36 import com.icesoft.jsfmeta.util.GeneratorUtil; 37 import java.io.File ; 38 import java.io.IOException ; 39 import java.net.MalformedURLException ; 40 import java.net.URL ; 41 import java.util.ArrayList ; 42 import java.util.List ; 43 import com.icesoft.jsfmeta.MetadataXmlParser; 44 import com.icesoft.jsfmeta.util.ConfigStorage; 45 import com.icesoft.jsfmeta.util.InternalConfig; 46 import com.sun.rave.jsfmeta.beans.ComponentBean; 47 import com.sun.rave.jsfmeta.beans.ConverterBean; 48 import com.sun.rave.jsfmeta.beans.FacesConfigBean; 49 import com.sun.rave.jsfmeta.beans.RendererBean; 50 import com.sun.rave.jsfmeta.beans.ValidatorBean; 51 import java.util.Enumeration ; 52 import java.util.Properties ; 53 import java.util.logging.Logger ; 54 import org.xml.sax.SAXException ; 55 56 public final class MetadataGenerator { 57 58 private static Logger logger = Logger.getLogger("com.icesoft.metadata.generators.MetadataGenerator"); 59 60 private FacesConfigBean config; 61 62 private List excludes; 63 64 private List includes; 65 66 private List listeners; 67 68 private MetadataXmlParser parser; 69 70 private List validators; 71 72 private InternalConfig internalConfig; 73 74 public MetadataGenerator() { 75 76 parser = new MetadataXmlParser(); 77 config = new FacesConfigBean(); 78 excludes = new ArrayList (); 79 includes = new ArrayList (); 80 listeners = new ArrayList (); 81 validators = new ArrayList (); 82 } 83 84 85 public static void main(String args[]) throws Exception { 86 87 MetadataGenerator main = new MetadataGenerator(); 88 main.loadProps(); 89 main.execute(args); 90 } 91 92 private void parseXML(String [] urlList){ 93 94 for(int i=0; i< urlList.length; i++){ 95 String url = urlList[i]; 96 try { 97 parser.parse(new URL (url), config); 98 } catch (MalformedURLException ex) { 99 System.out.println("Please check following: url="+url); 100 ex.printStackTrace(); 101 System.exit(1); 102 } catch (IOException ex) { 103 System.out.println("Please check following: url="+url); 104 ex.printStackTrace(); 105 System.exit(1); 106 } catch (SAXException ex) { 107 System.out.println("Please check following: url="+url); 108 ex.printStackTrace(); 109 System.exit(1); 110 } 111 } 112 } 113 114 private void loadProps(){ 116 117 init(); 118 String fileName = GeneratorUtil.getWorkingFolder()+"conf/config.properties"; 119 Properties props = ConfigStorage.getInstance(fileName).loadProperties(); 120 internalConfig = new InternalConfig(props); 121 } 122 123 private void init(){ 125 126 String standard_html_renderkit = "jar:file:"+GeneratorUtil.getWorkingFolder()+"jsfmeta-resources.jar!/com/sun/faces/standard-html-renderkit.xml"; 127 String standard_html_renderkit_overlay = "jar:file:"+GeneratorUtil.getWorkingFolder()+"jsfmeta-resources.jar!/com/sun/rave/jsfmeta/standard-html-renderkit-overlay.xml"; 128 String standard_html_renderkit_fixup = "jar:file:"+GeneratorUtil.getWorkingFolder()+"jsfmeta-resources.jar!/META-INF/standard-html-renderkit-fixups.xml"; 129 130 String [] baseUrlList = new String []{standard_html_renderkit, standard_html_renderkit_overlay, standard_html_renderkit_fixup}; 131 parseXML(baseUrlList); 132 133 exclude(); 134 135 String component_faces_config = "file:"+GeneratorUtil.getWorkingFolder()+"../../../component/conf/META-INF/faces-config.xml"; 136 String extended_faces_config = "file:"+GeneratorUtil.getWorkingFolder()+"conf/extended-faces-config.xml"; 137 String [] urlList = new String []{component_faces_config, extended_faces_config}; 138 parseXML(urlList); 139 140 } 141 142 143 private void execute(String args[]) throws Exception { 144 145 for (int i = 0; i < args.length; i++) { 146 String arg = args[i]; 147 148 if (arg.equals("--cpBeanInfoBase")) { 149 componentBeanInfo(); 150 continue; 151 } 152 if (arg.equals("--cpTestBeanInfo")) { 153 componentTestBeanInfo(); 154 continue; 155 } 156 if (arg.equals("--cpClassBase")) { 157 component(); 158 continue; 159 } 160 if (arg.equals("--tlClass")) { 161 tagLibrary(); 162 continue; 163 } 164 if (arg.equals("--cpCreatorBeanInfoBase")) { 165 componentBeanInfo(); 166 continue; 167 } 168 if (arg.equals("--tlDescriptor")) { 169 descriptor(); 170 } else { 171 usage(); 172 throw new IllegalArgumentException (arg); 173 } 174 } 175 } 176 177 private void tagLibrary() throws Exception { 178 try { 179 TagLibraryGenerator generator = new TagLibraryGenerator(internalConfig); 180 generator.setDest(GeneratorUtil.getDestFolder(GeneratorUtil.getWorkingFolder()+"../generated-sources/taglib/main/java")); 181 generator.setConfig(config); 182 generator.generate(); 183 } catch (Exception ex) { 184 ex.printStackTrace(); 185 System.exit(1); 186 } 187 } 188 189 private void component() throws Exception { 190 191 try { 192 BaseComponentGenerator generator = new BaseComponentGenerator(internalConfig); 193 generator.setDest(GeneratorUtil.getDestFolder(GeneratorUtil.getWorkingFolder()+"../generated-sources/component/main/java")); 194 generator.setConfig(config); 195 generator.generate(); 196 } catch (Exception ex) { 197 ex.printStackTrace(); 198 System.exit(1); 199 } 200 } 201 202 203 private void componentCreatorBeanInfo() throws Exception { 204 205 try { 206 IDEComponentBeanInfoGenerator generator = new IDEComponentBeanInfoGenerator(internalConfig); 207 generator.setDest(GeneratorUtil.getDestFolder(GeneratorUtil.getWorkingFolder()+"../generated-sources/beaninfo/main/java")); 208 generator.setConfig(config); 209 generator.generate(); 210 } catch (Exception ex) { 211 ex.printStackTrace(); 212 System.exit(1); 213 } 214 } 215 216 private void componentBeanInfo() throws Exception { 217 218 try { 219 IDEComponentBeanInfoGenerator generator = new IDEComponentBeanInfoGenerator(internalConfig); 220 generator.setDest(GeneratorUtil.getDestFolder(GeneratorUtil.getWorkingFolder()+"../generated-sources/beaninfo/main/java")); 221 generator.setConfig(config); 222 generator.generate(); 223 } catch (Exception ex) { 224 ex.printStackTrace(); 225 System.exit(1); 226 } 227 } 228 229 private void componentTestBeanInfo() throws Exception { 230 try { 231 ComponentTestBeanInfoGenerator generator = new ComponentTestBeanInfoGenerator(internalConfig); 232 generator.setDest(GeneratorUtil.getDestFolder(GeneratorUtil.getWorkingFolder()+"../generated-sources/testbeaninfo/main/java")); 233 generator.setConfig(config); 234 generator.generate(); 235 } catch (Exception ex) { 236 ex.printStackTrace(); 237 System.exit(1); 238 } 239 } 240 241 private void descriptor() throws Exception { 242 try { 243 TLDGenerator generator = new TLDGenerator(internalConfig); 244 generator.setDest(GeneratorUtil.getDestFolder(GeneratorUtil.getWorkingFolder()+"../generated-sources/tld")); 245 generator.setConfig(config); 246 generator.setVerbose(true); 247 generator.generate(); 248 } catch (Exception ex) { 249 ex.printStackTrace(); 250 System.exit(1); 251 } 252 } 253 254 255 private void exclude() { 256 257 ComponentBean cpb[] = config.getComponents(); 258 for (int i = 0; i < cpb.length; i++) 259 excludes.add(cpb[i].getComponentClass()); 260 261 ConverterBean cvb1[] = config.getConvertersByClass(); 262 for (int i = 0; i < cvb1.length; i++) 263 excludes.add(cvb1[i].getConverterClass()); 264 265 ConverterBean cvb2[] = config.getConvertersById(); 266 for (int i = 0; i < cvb2.length; i++) 267 excludes.add(cvb2[i].getConverterClass()); 268 269 RendererBean rb[] = config.getRenderKit("HTML_BASIC").getRenderers(); 270 for (int i = 0; i < rb.length; i++){ 271 excludes.add(rb[i].getRendererClass()); 272 } 273 274 ValidatorBean vb[] = config.getValidators(); 275 for (int i = 0; i < vb.length; i++){ 276 excludes.add(vb[i].getValidatorClass()); 277 } 278 } 279 280 private void usage() { 282 String info = "TODO"; 283 logger.info(info); 284 } 285 286 } 287 | Popular Tags |