Source Code Cross Referenced for ComponentTestBeanInfoGenerator.java in  » J2EE » ICEfaces-1.6.1 » com » icesoft » metadata » generators » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » ICEfaces 1.6.1 » com.icesoft.metadata.generators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Version: MPL 1.1/GPL 2.0/LGPL 2.1
003:         *
004:         *  "The contents of this file are subject to the Mozilla Public License
005:         *  Version 1.1 (the "License"); you may not use this file except in
006:         *  compliance with the License. You may obtain a copy of the License at
007:         *  http://www.mozilla.org/MPL/
008:         *
009:         *  Software distributed under the License is distributed on an "AS IS"
010:         *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011:         *  License for the specific language governing rights and limitations under
012:         *  the License.
013:         *
014:         *  The Original Code is ICEfaces 1.5 open source software code, released
015:         *  November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016:         *  Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017:         *  2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018:         *
019:         *  Contributor(s): _____________________.
020:         *
021:         *  Alternatively, the contents of this file may be used under the terms of
022:         *  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023:         *  License), in which case the provisions of the LGPL License are
024:         *  applicable instead of those above. If you wish to allow use of your
025:         *  version of this file only under the terms of the LGPL License and not to
026:         *  allow others to use your version of this file under the MPL, indicate
027:         *  your decision by deleting the provisions above and replace them with
028:         *  the notice and other provisions required by the LGPL License. If you do
029:         *  not delete the provisions above, a recipient may use your version of
030:         *  this file under either the MPL or the LGPL License."
031:         *
032:         */
033:
034:        package com.icesoft.metadata.generators;
035:
036:        import com.icesoft.jsfmeta.util.AbstractGenerator;
037:        import com.icesoft.jsfmeta.util.InternalConfig;
038:        import com.icesoft.jsfmeta.util.JavaSourceWriter;
039:        import com.sun.rave.jsfmeta.beans.*;
040:        import java.io.*;
041:        import java.util.*;
042:
043:        public class ComponentTestBeanInfoGenerator extends AbstractGenerator {
044:
045:            private boolean base;
046:
047:            private String baseBI;
048:
049:            private String categoryDescriptors;
050:
051:            private String defaultMarkupSection;
052:
053:            protected HashMap bundleMaps;
054:
055:            private String defaultTaglibPrefix;
056:
057:            private String defaultTaglibURI;
058:
059:            private String implBD;
060:
061:            private String implPD;
062:
063:            protected boolean useComponentResourceBundles;
064:
065:            public ComponentTestBeanInfoGenerator(InternalConfig internalConfig) {
066:                super (internalConfig);
067:                base = false;
068:                categoryDescriptors = "com.icesoft.faces.ide.creator2.util.CategoryDescriptors";
069:                defaultMarkupSection = "FORM";
070:                bundleMaps = new HashMap();
071:                useComponentResourceBundles = false;
072:                baseBI = internalConfig.getProperty("project.base.beaninfo");
073:                implBD = internalConfig
074:                        .getProperty("project.impl.beanDescriptor");
075:                implPD = internalConfig
076:                        .getProperty("project.impl.propertyDescriptor");
077:            }
078:
079:            public boolean getBase() {
080:                return base;
081:            }
082:
083:            public void setBase(boolean base) {
084:                this .base = base;
085:            }
086:
087:            public String getBaseBI() {
088:                return baseBI;
089:            }
090:
091:            public void setBaseBI(String baseBI) {
092:                this .baseBI = baseBI;
093:            }
094:
095:            public String getCategoryDescriptors() {
096:                return categoryDescriptors;
097:            }
098:
099:            public void setCategoryDescriptors(String categoryDescriptors) {
100:                this .categoryDescriptors = categoryDescriptors;
101:            }
102:
103:            public String getDefaultMarkupSection() {
104:                return defaultMarkupSection;
105:            }
106:
107:            public void setDefaultMarkupSection(String defaultMarkupSection) {
108:                this .defaultMarkupSection = defaultMarkupSection;
109:            }
110:
111:            protected HashMap getBundleMap(String packageName,
112:                    String languageCode) {
113:
114:                HashMap packageMap = (HashMap) bundleMaps.get(packageName);
115:                if (packageMap == null) {
116:                    packageMap = new HashMap();
117:                    bundleMaps.put(packageName, packageMap);
118:                }
119:
120:                HashMap map = (HashMap) packageMap.get(languageCode);
121:                if (map == null) {
122:                    map = new HashMap();
123:                    packageMap.put(languageCode, map);
124:                }
125:                return map;
126:            }
127:
128:            protected HashMap getBundleMaps() {
129:                return bundleMaps;
130:            }
131:
132:            protected void putBundleMap(String packageName,
133:                    String languageCode, String key, String value) {
134:                HashMap map = getBundleMap(packageName, languageCode);
135:                map.put(key, value);
136:            }
137:
138:            public String getDefaultTaglibPrefix() {
139:                return defaultTaglibPrefix;
140:            }
141:
142:            public void setDefaultTaglibPrefix(String defaultTaglibPrefix) {
143:                this .defaultTaglibPrefix = defaultTaglibPrefix;
144:            }
145:
146:            public String getDefaultTaglibURI() {
147:                return defaultTaglibURI;
148:            }
149:
150:            public void setDefaultTaglibURI(String defaultTaglibURI) {
151:                this .defaultTaglibURI = defaultTaglibURI;
152:            }
153:
154:            public String getImplBD() {
155:                return implBD;
156:            }
157:
158:            public void setImplBD(String implBD) {
159:                this .implBD = implBD;
160:            }
161:
162:            public String getImplPD() {
163:                return implPD;
164:            }
165:
166:            public void setImplPD(String implPD) {
167:                this .implPD = implPD;
168:            }
169:
170:            public boolean getUseComponentResourceBundles() {
171:                return useComponentResourceBundles;
172:            }
173:
174:            public void setUseComponentResourceBundles(boolean flag) {
175:                useComponentResourceBundles = flag;
176:            }
177:
178:            public void generate() throws IOException {
179:
180:                ComponentBean cbs[] = getConfig().getComponents();
181:                for (int i = 0; i < cbs.length; i++) {
182:                    if (generated(cbs[i].getComponentClass())) {
183:                        generate(cbs[i]);
184:                    }
185:                }
186:            }
187:
188:            private void beanDescriptor(ComponentBean cb, RendererBean rb)
189:                    throws IOException {
190:                String implBD = this .implBD;
191:                int period = implBD.lastIndexOf(".");
192:                if (period >= 0)
193:                    implBD = implBD.substring(period + 1);
194:
195:                JavaSourceWriter writer = getWriter();
196:
197:                writer.startJavaDoc();
198:                writer
199:                        .emitJavaDoc("<p>Return the <code>BeanDescriptor</code> for this bean.</p>");
200:                writer.endJavaDoc();
201:                writer.startMethod("getBeanDescriptor", "BeanDescriptor", null,
202:                        null);
203:                writer.emitNewline();
204:                writer.emitExpression("if (beanDescriptor != null) {", true);
205:                writer.indent();
206:                writer.emitExpression("return beanDescriptor;", true);
207:                writer.outdent();
208:                writer.emitExpression("}", true);
209:                writer.emitNewline();
210:                writer.emitExpression("beanDescriptor = new " + implBD
211:                        + "(beanClass);", true);
212:                writer.emitNewline();
213:                writer.emitExpression("return beanDescriptor;", true);
214:                writer.emitNewline();
215:                writer.endMethod();
216:                writer.emitNewline();
217:            }
218:
219:            private void body(ComponentBean cb, RendererBean rb)
220:                    throws IOException {
221:                String baseBI = this .baseBI;
222:                int period = baseBI.lastIndexOf(".");
223:                if (period >= 0)
224:                    baseBI = baseBI.substring(period + 1);
225:                JavaSourceWriter writer = getWriter();
226:                String simple = simpleClassName(cb.getComponentClass());
227:                simple = simple + "BeanInfo";
228:                writer.startClass(simple, baseBI, null, !getBase(), getBase());
229:                writer.emitNewline();
230:
231:                constructor(cb, rb);
232:                instance(cb, rb);
233:                beanDescriptor(cb, rb);
234:                defaultPropertyIndex(cb, rb);
235:                propertyDescriptors(cb, rb);
236:                writer.endClass();
237:            }
238:
239:            private void constructor(ComponentBean cb, RendererBean rb)
240:                    throws IOException {
241:                JavaSourceWriter writer = getWriter();
242:                String simple = simpleClassName(cb.getComponentClass());
243:                writer.startJavaDoc();
244:                writer.emitJavaDoc("<p>Construct a new <code>"
245:                        + simpleClassName(cb) + "</code>.</p>");
246:                writer.endJavaDoc();
247:                writer.startMethod(simpleClassName(cb), null, null, null);
248:                writer.emitNewline();
249:                writer
250:                        .emitExpression("beanClass = " + simple + ".class;",
251:                                true);
252:                writer.emitNewline();
253:                writer.endMethod();
254:                writer.emitNewline();
255:            }
256:
257:            private void defaultPropertyIndex(ComponentBean cb, RendererBean rb)
258:                    throws IOException {
259:                JavaSourceWriter writer = getWriter();
260:                writer.startJavaDoc();
261:                writer
262:                        .emitJavaDoc("<p>Return the index of the default property, or");
263:                writer.emitJavaDoc("-1 if there is no default property.</p>");
264:                writer.endJavaDoc();
265:                writer
266:                        .startMethod("getDefaultPropertyIndex", "int", null,
267:                                null);
268:                writer.emitNewline();
269:                writer.indent();
270:                writer.emitExpression("defaultPropertyIndex = -1;", true);
271:                writer.emitExpression("return defaultPropertyIndex;", true);
272:                writer.endMethod();
273:                writer.outdent();
274:                writer.emitNewline();
275:                return;
276:
277:            }
278:
279:            private void generate(ComponentBean cb) throws IOException {
280:
281:                if (cb.getComponentClass().startsWith("javax.faces.component.")) {
282:                    return;
283:                }
284:                if (cb.isSuppressed())
285:                    return;
286:                RendererBean rb = renderer(cb);
287:                if (rb == null) {
288:                    rb = new RendererBean();
289:                }
290:                File outputFile = outputFile(cb.getComponentClass()
291:                        + "BeanInfo");
292:
293:                outputFile.mkdirs();
294:                outputFile.delete();
295:                try {
296:                    getWriter().setOutputWriter(
297:                            new BufferedWriter(new FileWriter(outputFile)));
298:                } catch (Exception e) {
299:                    e.printStackTrace();
300:                }
301:
302:                header(cb, rb);
303:                body(cb, rb);
304:
305:                getWriter().flush();
306:                getWriter().close();
307:            }
308:
309:            private void header(ComponentBean cb, RendererBean rb)
310:                    throws IOException {
311:                JavaSourceWriter writer = getWriter();
312:                writer.outdent();
313:                String packageName = packageName(cb);
314:                if (packageName.length() > 0) {
315:                    writer.emitPackage(packageName);
316:                    writer.emitNewline();
317:                }
318:                writer.emitImport("java.awt.Image");
319:                writer.emitImport("java.beans.BeanDescriptor");
320:                writer.emitImport("java.beans.BeanInfo");
321:                writer.emitImport("java.beans.IntrospectionException");
322:                writer.emitImport("java.beans.PropertyDescriptor");
323:                writer.emitImport("java.util.Locale");
324:                writer.emitImport("java.util.ResourceBundle");
325:                writer.emitNewline();
326:                writer.emitNewline();
327:                writer.emitImport(baseBI);
328:                if (!"java.beans.BeanDescriptor".equals(implBD)) {
329:                    writer.emitImport(implBD);
330:                }
331:                if (!"java.beans.PropertyDescriptor".equals(implPD)) {
332:                    writer.emitImport(implPD);
333:                }
334:                writer.emitNewline();
335:                writer.startJavaDoc();
336:                writer
337:                        .emitJavaDoc("<p>Auto-generated design time metadata class.");
338:                writer
339:                        .emitJavaDoc("Do <strong>NOT</strong> modify; all changes");
340:                writer.emitJavaDoc("<strong>will</strong> be lost!</p>");
341:                writer.endJavaDoc();
342:                writer.emitNewline();
343:            }
344:
345:            private void instance(ComponentBean cb, RendererBean rb)
346:                    throws IOException {
347:
348:                JavaSourceWriter writer = getWriter();
349:                writer.startJavaDoc();
350:                writer
351:                        .emitJavaDoc("<p>The bean class that this BeanInfo represents.");
352:                writer.endJavaDoc();
353:                writer.emitExpression("protected Class beanClass;", true);
354:                writer.emitNewline();
355:                writer.startJavaDoc();
356:                writer.emitJavaDoc("<p>The cached BeanDescriptor.</p>");
357:                writer.endJavaDoc();
358:                writer.emitExpression(
359:                        "protected BeanDescriptor beanDescriptor;", true);
360:                writer.emitNewline();
361:                writer.startJavaDoc();
362:                writer.emitJavaDoc("<p>The index of the default property.</p>");
363:                writer.endJavaDoc();
364:                writer.emitExpression(
365:                        "protected int defaultPropertyIndex = -1;", true);
366:                writer.emitNewline();
367:                writer.startJavaDoc();
368:                writer.emitJavaDoc("<p>The name of the default property.</p>");
369:                writer.endJavaDoc();
370:                writer.emitExpression("protected String defaultPropertyName;",
371:                        true);
372:                writer.emitNewline();
373:                writer.startJavaDoc();
374:                writer.emitJavaDoc("<p>The cached property descriptors.</p>");
375:                writer.endJavaDoc();
376:                writer
377:                        .emitExpression(
378:                                "protected PropertyDescriptor[] propDescriptors;",
379:                                true);
380:                writer.emitNewline();
381:                return;
382:
383:            }
384:
385:            private String packageName(ComponentBean cb) {
386:                String componentClass = cb.getComponentClass();
387:                int last = componentClass.lastIndexOf('.');
388:                if (last >= 0) {
389:                    return componentClass.substring(0, last);
390:                } else {
391:                    return "";
392:                }
393:            }
394:
395:            private void propertyDescriptor(ComponentBean cb, RendererBean rb,
396:                    PropertyBean pb, ComponentBean componentBeanBeingGenerated)
397:                    throws IOException {
398:                String implPD = this .implPD;
399:                int period = implPD.lastIndexOf(".");
400:                if (period >= 0) {
401:                    implPD = implPD.substring(period + 1);
402:                }
403:                JavaSourceWriter writer = getWriter();
404:                DescriptionBean description = pb.getShortDescription("");
405:                if (description == null) {
406:                    description = pb.getDescription("");
407:                }
408:                DescriptionBean descriptions[] = pb.getShortDescriptions();
409:                if (descriptions == null) {
410:                    descriptions = pb.getDescriptions();
411:                }
412:                String name = pb.getPropertyName();
413:                String readMethod = pb.getReadMethod();
414:                if (pb.isWriteOnly()) {
415:                    readMethod = null;
416:                } else if (readMethod == null) {
417:                    if ("boolean".equals(pb.getPropertyClass())) {
418:                        readMethod = "is"
419:                                + Character.toUpperCase(name.charAt(0))
420:                                + name.substring(1);
421:                    } else {
422:                        readMethod = "get"
423:                                + Character.toUpperCase(name.charAt(0))
424:                                + name.substring(1);
425:                    }
426:                }
427:                String writeMethod = pb.getWriteMethod();
428:                if (pb.isReadOnly()) {
429:                    writeMethod = null;
430:                } else if (writeMethod == null) {
431:                    writeMethod = "set" + Character.toUpperCase(name.charAt(0))
432:                            + name.substring(1);
433:                }
434:                StringBuffer psb = new StringBuffer("PropertyDescriptor prop_");
435:                psb.append(name);
436:                psb.append(" = new ");
437:                psb.append(implPD);
438:                psb.append("(");
439:                psb.append(JavaSourceWriter.toJavaString(name));
440:                psb.append(",beanClass,");
441:                psb.append(readMethod != null ? JavaSourceWriter
442:                        .toJavaString(readMethod) : "null");
443:                psb.append(",");
444:                psb.append(writeMethod != null ? JavaSourceWriter
445:                        .toJavaString(writeMethod) : "null");
446:                psb.append(");");
447:                writer.emitExpression(psb.toString(), true);
448:                writer.emitNewline();
449:            }
450:
451:            private void propertyDescriptors(ComponentBean cb, RendererBean rb)
452:                    throws IOException {
453:                JavaSourceWriter writer = getWriter();
454:                Map map = new TreeMap();
455:                writer.startJavaDoc();
456:                writer
457:                        .emitJavaDoc("<p>Return the <code>PropertyDescriptor</code>s for this bean.</p>");
458:                writer.endJavaDoc();
459:                writer.startMethod("getPropertyDescriptors",
460:                        "PropertyDescriptor[]", null, null);
461:                writer.emitNewline();
462:                writer.emitExpression("if (propDescriptors != null) {", true);
463:                writer.indent();
464:                writer.emitExpression("return propDescriptors;", true);
465:                writer.outdent();
466:                writer.emitExpression("}", true);
467:                writer.emitNewline();
468:                writer.emitExpression("try {", true);
469:                writer.emitNewline();
470:                writer.indent();
471:                propertyDescriptors(cb, rb, ((Map) (map)), cb);
472:                writer.emitExpression(
473:                        "propDescriptors = new PropertyDescriptor[] {", true);
474:                writer.indent();
475:                String prop;
476:                for (Iterator props = map.keySet().iterator(); props.hasNext(); writer
477:                        .emitExpression("prop_" + prop + ",", true)) {
478:                    prop = (String) props.next();
479:                }
480:
481:                writer.outdent();
482:                writer.emitExpression("};", true);
483:
484:                writer.emitExpression("return propDescriptors;", true);
485:                writer.emitNewline();
486:                writer.outdent();
487:                writer.emitExpression("} catch (IntrospectionException e) {",
488:                        true);
489:                writer.indent();
490:                writer.emitExpression("e.printStackTrace();", true);
491:                writer.emitExpression("return null;", true);
492:                writer.outdent();
493:                writer.emitExpression("}", true);
494:                writer.emitNewline();
495:                writer.endMethod();
496:                writer.emitNewline();
497:            }
498:
499:            private void propertyDescriptors(ComponentBean cb, RendererBean rb,
500:                    Map map, ComponentBean componentBeanBeingGenerated)
501:                    throws IOException {
502:
503:                PropertyBean pbs[] = cb.getProperties();
504:                for (int i = 0; i < pbs.length; i++) {
505:                    if (map.containsKey(pbs[i].getPropertyName())
506:                            || "valid".equals(pbs[i].getPropertyName())) {
507:                        continue;
508:                    }
509:
510:                    PropertyBean pb = merge(pbs[i], rb.getAttribute(pbs[i]
511:                            .getPropertyName()));
512:                    if (!pb.isSuppressed()) {
513:                        propertyDescriptor(cb, rb, pb,
514:                                componentBeanBeingGenerated);
515:                        map.put(pb.getPropertyName(), null);
516:                    }
517:                }
518:
519:                String baseComponentType = cb.getBaseComponentType();
520:                if (baseComponentType != null) {
521:                    ComponentBean bcb = getConfig().getComponent(
522:                            baseComponentType);
523:                    propertyDescriptors(bcb, rb, map,
524:                            componentBeanBeingGenerated);
525:                }
526:            }
527:
528:            private String simpleClassName(ComponentBean cb) {
529:                return simpleClassName(cb.getComponentClass()) + "BeanInfo";
530:            }
531:
532:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.