KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > metadata > generators > MetadataGenerator


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.metadata.generators;
35
36 import com.icesoft.jsfmeta.util.GeneratorUtil;
37 import java.io.File JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.net.MalformedURLException JavaDoc;
40 import java.net.URL JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.List JavaDoc;
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 JavaDoc;
52 import java.util.Properties JavaDoc;
53 import java.util.logging.Logger JavaDoc;
54 import org.xml.sax.SAXException JavaDoc;
55
56 public final class MetadataGenerator {
57     
58     private static Logger JavaDoc logger = Logger.getLogger("com.icesoft.metadata.generators.MetadataGenerator");
59     
60     private FacesConfigBean config;
61     
62     private List JavaDoc excludes;
63     
64     private List JavaDoc includes;
65     
66     private List JavaDoc listeners;
67     
68     private MetadataXmlParser parser;
69     
70     private List JavaDoc validators;
71     
72     private InternalConfig internalConfig;
73     
74     public MetadataGenerator() {
75         
76         parser = new MetadataXmlParser();
77         config = new FacesConfigBean();
78         excludes = new ArrayList JavaDoc();
79         includes = new ArrayList JavaDoc();
80         listeners = new ArrayList JavaDoc();
81         validators = new ArrayList JavaDoc();
82     }
83     
84     
85     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
86         
87         MetadataGenerator main = new MetadataGenerator();
88         main.loadProps();
89         main.execute(args);
90     }
91     
92     private void parseXML(String JavaDoc[] urlList){
93         
94         for(int i=0; i< urlList.length; i++){
95             String JavaDoc url = urlList[i];
96             try {
97                 parser.parse(new URL JavaDoc(url), config);
98             } catch (MalformedURLException JavaDoc ex) {
99                 System.out.println("Please check following: url="+url);
100                 ex.printStackTrace();
101                 System.exit(1);
102             } catch (IOException JavaDoc ex) {
103                 System.out.println("Please check following: url="+url);
104                 ex.printStackTrace();
105                 System.exit(1);
106             } catch (SAXException JavaDoc ex) {
107                 System.out.println("Please check following: url="+url);
108                 ex.printStackTrace();
109                 System.exit(1);
110             }
111         }
112     }
113     
114     //TODO: filter version from ICEfaces core
115
private void loadProps(){
116         
117         init();
118         String JavaDoc fileName = GeneratorUtil.getWorkingFolder()+"conf/config.properties";
119         Properties JavaDoc props = ConfigStorage.getInstance(fileName).loadProperties();
120         internalConfig = new InternalConfig(props);
121     }
122     
123     //TODO: move to catalog
124
private void init(){
125         
126         String JavaDoc standard_html_renderkit = "jar:file:"+GeneratorUtil.getWorkingFolder()+"jsfmeta-resources.jar!/com/sun/faces/standard-html-renderkit.xml";
127         String JavaDoc standard_html_renderkit_overlay = "jar:file:"+GeneratorUtil.getWorkingFolder()+"jsfmeta-resources.jar!/com/sun/rave/jsfmeta/standard-html-renderkit-overlay.xml";
128         String JavaDoc standard_html_renderkit_fixup = "jar:file:"+GeneratorUtil.getWorkingFolder()+"jsfmeta-resources.jar!/META-INF/standard-html-renderkit-fixups.xml";
129         
130         String JavaDoc[] baseUrlList = new String JavaDoc[]{standard_html_renderkit, standard_html_renderkit_overlay, standard_html_renderkit_fixup};
131         parseXML(baseUrlList);
132         
133         exclude();
134         
135         String JavaDoc component_faces_config = "file:"+GeneratorUtil.getWorkingFolder()+"../../../component/conf/META-INF/faces-config.xml";
136         String JavaDoc extended_faces_config = "file:"+GeneratorUtil.getWorkingFolder()+"conf/extended-faces-config.xml";
137         String JavaDoc[] urlList = new String JavaDoc[]{component_faces_config, extended_faces_config};
138         parseXML(urlList);
139         
140     }
141     
142     
143     private void execute(String JavaDoc args[]) throws Exception JavaDoc {
144         
145         for (int i = 0; i < args.length; i++) {
146             String JavaDoc 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 JavaDoc(arg);
173             }
174         }
175     }
176     
177     private void tagLibrary() throws Exception JavaDoc {
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 JavaDoc ex) {
184             ex.printStackTrace();
185             System.exit(1);
186         }
187     }
188     
189     private void component() throws Exception JavaDoc {
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 JavaDoc ex) {
197             ex.printStackTrace();
198             System.exit(1);
199         }
200     }
201     
202         
203     private void componentCreatorBeanInfo() throws Exception JavaDoc {
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 JavaDoc ex) {
211             ex.printStackTrace();
212             System.exit(1);
213         }
214     }
215     
216     private void componentBeanInfo() throws Exception JavaDoc {
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 JavaDoc ex) {
224             ex.printStackTrace();
225             System.exit(1);
226         }
227     }
228     
229     private void componentTestBeanInfo() throws Exception JavaDoc {
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 JavaDoc ex) {
236             ex.printStackTrace();
237             System.exit(1);
238         }
239     }
240     
241     private void descriptor() throws Exception JavaDoc {
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 JavaDoc 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     //TODO:
281
private void usage() {
282         String JavaDoc info = "TODO";
283         logger.info(info);
284     }
285     
286 }
287
Popular Tags