Source Code Cross Referenced for IDEComponentBeanInfoGenerator.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) 


0001:        /*
0002:         *  Version: MPL 1.1/GPL 2.0/LGPL 2.1
0003:         *
0004:         *  "The contents of this file are subject to the Mozilla Public License
0005:         *  Version 1.1 (the "License"); you may not use this file except in
0006:         *  compliance with the License. You may obtain a copy of the License at
0007:         *  http://www.mozilla.org/MPL/
0008:         *
0009:         *  Software distributed under the License is distributed on an "AS IS"
0010:         *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
0011:         *  License for the specific language governing rights and limitations under
0012:         *  the License.
0013:         *
0014:         *  The Original Code is ICEfaces 1.5 open source software code, released
0015:         *  November 5, 2006. The Initial Developer of the Original Code is ICEsoft
0016:         *  Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
0017:         *  2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
0018:         *
0019:         *  Contributor(s): _____________________.
0020:         *
0021:         *  Alternatively, the contents of this file may be used under the terms of
0022:         *  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
0023:         *  License), in which case the provisions of the LGPL License are
0024:         *  applicable instead of those above. If you wish to allow use of your
0025:         *  version of this file only under the terms of the LGPL License and not to
0026:         *  allow others to use your version of this file under the MPL, indicate
0027:         *  your decision by deleting the provisions above and replace them with
0028:         *  the notice and other provisions required by the LGPL License. If you do
0029:         *  not delete the provisions above, a recipient may use your version of
0030:         *  this file under either the MPL or the LGPL License."
0031:         *
0032:         */
0033:        package com.icesoft.metadata.generators;
0034:
0035:        import com.icesoft.jsfmeta.util.AbstractGenerator;
0036:        import com.icesoft.jsfmeta.util.FilterComponentBeanProperties;
0037:        import com.icesoft.jsfmeta.util.InternalConfig;
0038:        import com.icesoft.jsfmeta.util.JavaSourceWriter;
0039:        import com.sun.rave.jsfmeta.beans.*;
0040:        import java.io.*;
0041:        import java.util.*;
0042:
0043:        /*
0044:         * IDEComponentBeanInfoGenerator generates IDE specific beaninfo
0045:         *
0046:         */
0047:
0048:        public class IDEComponentBeanInfoGenerator extends AbstractGenerator {
0049:
0050:            protected static final String BUNDLE_VARIABLE_NAME = "resources";
0051:
0052:            protected static final String BUNDLE_GET_MESSAGE_START = "resources.getString(";
0053:
0054:            protected static final String BUNDLE_GET_MESSAGE_END = ")";
0055:
0056:            private boolean base;
0057:
0058:            private String baseBI;
0059:
0060:            private String categoryDescriptors;
0061:
0062:            private String defaultMarkupSection;
0063:
0064:            protected HashMap bundleMaps;
0065:
0066:            private String defaultTaglibPrefix;
0067:
0068:            private String defaultTaglibURI;
0069:
0070:            private String implBD;
0071:
0072:            private String implPD;
0073:
0074:            protected boolean useComponentResourceBundles;
0075:
0076:            public IDEComponentBeanInfoGenerator(InternalConfig internalConfig) {
0077:
0078:                super (internalConfig);
0079:                base = true;
0080:                baseBI = internalConfig.getProperty("project.base.beaninfo");
0081:                categoryDescriptors = internalConfig
0082:                        .getProperty("project.impl.categoryDescriptors");
0083:                defaultMarkupSection = "FORM";
0084:                bundleMaps = new HashMap();
0085:                defaultTaglibPrefix = internalConfig
0086:                        .getProperty("project.taglib.prefix");
0087:                defaultTaglibURI = internalConfig
0088:                        .getProperty("project.taglib.uri");
0089:                implBD = internalConfig
0090:                        .getProperty("project.impl.beanDescriptor");
0091:                implPD = internalConfig
0092:                        .getProperty("project.impl.propertyDescriptor");
0093:                useComponentResourceBundles = true;
0094:            }
0095:
0096:            public boolean getBase() {
0097:                return base;
0098:            }
0099:
0100:            public void setBase(boolean base) {
0101:                this .base = base;
0102:            }
0103:
0104:            public String getBaseBI() {
0105:                return baseBI;
0106:            }
0107:
0108:            public void setBaseBI(String baseBI) {
0109:                this .baseBI = baseBI;
0110:            }
0111:
0112:            public String getCategoryDescriptors() {
0113:                return categoryDescriptors;
0114:            }
0115:
0116:            public void setCategoryDescriptors(String categoryDescriptors) {
0117:                this .categoryDescriptors = categoryDescriptors;
0118:            }
0119:
0120:            public String getDefaultMarkupSection() {
0121:                return defaultMarkupSection;
0122:            }
0123:
0124:            public void setDefaultMarkupSection(String defaultMarkupSection) {
0125:                this .defaultMarkupSection = defaultMarkupSection;
0126:            }
0127:
0128:            protected HashMap getBundleMap(String packageName,
0129:                    String languageCode) {
0130:                HashMap packageMap = (HashMap) bundleMaps.get(packageName);
0131:                if (packageMap == null) {
0132:                    packageMap = new HashMap();
0133:                    bundleMaps.put(packageName, packageMap);
0134:                }
0135:                HashMap map = (HashMap) packageMap.get(languageCode);
0136:                if (map == null) {
0137:                    map = new HashMap();
0138:                    packageMap.put(languageCode, map);
0139:                }
0140:                return map;
0141:            }
0142:
0143:            protected HashMap getBundleMaps() {
0144:                return bundleMaps;
0145:            }
0146:
0147:            protected void putBundleMap(String packageName,
0148:                    String languageCode, String key, String value) {
0149:                HashMap map = getBundleMap(packageName, languageCode);
0150:                map.put(key, value);
0151:            }
0152:
0153:            public String getDefaultTaglibPrefix() {
0154:                return defaultTaglibPrefix;
0155:            }
0156:
0157:            public void setDefaultTaglibPrefix(String defaultTaglibPrefix) {
0158:                this .defaultTaglibPrefix = defaultTaglibPrefix;
0159:            }
0160:
0161:            public String getDefaultTaglibURI() {
0162:                return defaultTaglibURI;
0163:            }
0164:
0165:            public void setDefaultTaglibURI(String defaultTaglibURI) {
0166:                this .defaultTaglibURI = defaultTaglibURI;
0167:            }
0168:
0169:            public String getImplBD() {
0170:                return implBD;
0171:            }
0172:
0173:            public void setImplBD(String implBD) {
0174:                this .implBD = implBD;
0175:            }
0176:
0177:            public String getImplPD() {
0178:                return implPD;
0179:            }
0180:
0181:            public void setImplPD(String implPD) {
0182:                this .implPD = implPD;
0183:            }
0184:
0185:            public boolean getUseComponentResourceBundles() {
0186:                return useComponentResourceBundles;
0187:            }
0188:
0189:            public void setUseComponentResourceBundles(boolean flag) {
0190:                useComponentResourceBundles = flag;
0191:            }
0192:
0193:            public void generate() throws IOException {
0194:                ComponentBean cbs[] = getConfig().getComponents();
0195:                for (int i = 0; i < cbs.length; i++)
0196:                    if (generated(cbs[i].getComponentClass()))
0197:                        generate(cbs[i]);
0198:
0199:                generateComponentResourceBundlesIfNecessary();
0200:            }
0201:
0202:            protected void generateComponentResourceBundlesIfNecessary()
0203:                    throws IOException {
0204:                if (!getUseComponentResourceBundles())
0205:                    return;
0206:                for (Iterator packageKeyIterator = getBundleMaps().keySet()
0207:                        .iterator(); packageKeyIterator.hasNext();) {
0208:                    String packageKey = (String) packageKeyIterator.next();
0209:                    HashMap byLangMap = (HashMap) getBundleMaps().get(
0210:                            packageKey);
0211:                    Iterator langKeyIterator = byLangMap.keySet().iterator();
0212:                    while (langKeyIterator.hasNext()) {
0213:                        String langKey = (String) langKeyIterator.next();
0214:                        HashMap stringsByKey = (HashMap) byLangMap.get(langKey);
0215:                        componentResourceBundle(packageKey, langKey,
0216:                                stringsByKey);
0217:                    }
0218:                }
0219:            }
0220:
0221:            private void beanDescriptor(ComponentBean cb, RendererBean rb)
0222:                    throws IOException {
0223:
0224:                String implBD = this .implBD;
0225:                int period = implBD.lastIndexOf(".");
0226:                if (period >= 0) {
0227:                    implBD = implBD.substring(period + 1);
0228:                }
0229:
0230:                String packageName = packageName(cb);
0231:                String simpleClassName = simpleClassName(cb.getComponentClass());
0232:                JavaSourceWriter writer = getWriter();
0233:                DisplayNameBean displayName = cb.getDisplayName("");
0234:                DisplayNameBean displayNames[] = cb.getDisplayNames();
0235:                DescriptionBean description = cb.getDescription("");
0236:                DescriptionBean descriptions[] = cb.getDescriptions();
0237:                writer.startJavaDoc();
0238:                writer
0239:                        .emitJavaDoc("<p>Return the <code>BeanDescriptor</code> for this bean.</p>");
0240:                writer.endJavaDoc();
0241:                writer.startMethod("getBeanDescriptor", "BeanDescriptor", null,
0242:                        null);
0243:                writer.emitNewline();
0244:                writer.emitExpression("if (beanDescriptor != null) {", true);
0245:                writer.indent();
0246:                writer.emitExpression("return beanDescriptor;", true);
0247:                writer.outdent();
0248:                writer.emitExpression("}", true);
0249:                writer.emitNewline();
0250:                if (cb.getCustomizerClass() != null) {
0251:
0252:                    writer.emitExpression("Class clazz = null;", true);
0253:                    writer.emitExpression("try {", true);
0254:                    writer.indent();
0255:                    writer.emitExpression(
0256:                            "clazz = this.getClass().getClassLoader().loadClass(\""
0257:                                    + cb.getCustomizerClass() + "\");", true);
0258:                    writer.outdent();
0259:                    writer.emitExpression("} catch (Exception e) {", true);
0260:                    writer.indent();
0261:                    writer.emitExpression(
0262:                            "throw new IllegalArgumentException(\""
0263:                                    + cb.getCustomizerClass() + "\");", true);
0264:                    writer.outdent();
0265:                    writer.emitExpression("}", true);
0266:                    writer.emitExpression("beanDescriptor = new " + implBD
0267:                            + "(beanClass, clazz);", true);
0268:                } else {
0269:                    writer.emitExpression("beanDescriptor = new " + implBD
0270:                            + "(beanClass);", true);
0271:                }
0272:                displayName(displayName, displayNames, writer,
0273:                        "beanDescriptor", packageName, simpleClassName, null);
0274:                shortDescription(description, descriptions, writer,
0275:                        "beanDescriptor", packageName, simpleClassName, null);
0276:                writer.emitExpression("beanDescriptor.setExpert("
0277:                        + cb.isExpert() + ");", true);
0278:                writer.emitExpression("beanDescriptor.setHidden("
0279:                        + cb.isHidden() + ");", true);
0280:                writer.emitExpression("beanDescriptor.setPreferred("
0281:                        + cb.isPreferred() + ");", true);
0282:                writer
0283:                        .emitExpression(
0284:                                "beanDescriptor.setValue(Constants.BeanDescriptor.FACET_DESCRIPTORS,getFacetDescriptors());",
0285:                                true);
0286:                if (rb.getComponentHelpKey() != null)
0287:                    writer.emitExpression(
0288:                            "beanDescriptor.setValue(Constants.BeanDescriptor.HELP_KEY,"
0289:                                    + writer.toJavaString(rb
0290:                                            .getComponentHelpKey().trim())
0291:                                    + ");", true);
0292:                String instanceName = rb.getInstanceName();
0293:
0294:                if (instanceName == null) {
0295:                    instanceName = simpleInstanceName(cb, rb);
0296:                }
0297:
0298:                if (instanceName != null) {
0299:                    writer.emitExpression(
0300:                            "beanDescriptor.setValue(Constants.BeanDescriptor.INSTANCE_NAME,"
0301:                                    + writer.toJavaString(instanceName.trim())
0302:                                    + ");", true);
0303:                }
0304:                writer.emitExpression(
0305:                        "beanDescriptor.setValue(Constants.BeanDescriptor.IS_CONTAINER,"
0306:                                + (rb.isContainer() ? "Boolean.TRUE"
0307:                                        : "Boolean.FALSE") + ");", true);
0308:
0309:                String markupSection = rb.getMarkupSection();
0310:                if (markupSection == null) {
0311:                    markupSection = getDefaultMarkupSection();
0312:                }
0313:                if (markupSection != null) {
0314:                    writer
0315:                            .emitExpression(
0316:                                    "beanDescriptor.setValue(Constants.BeanDescriptor.MARKUP_SECTION,"
0317:                                            + writer.toJavaString(markupSection
0318:                                                    .toLowerCase().trim())
0319:                                            + ");", true);
0320:                }
0321:                if (rb.getPropertiesHelpKey() != null) {
0322:                    writer.emitExpression(
0323:                            "beanDescriptor.setValue(Constants.BeanDescriptor.PROPERTIES_HELP_KEY,"
0324:                                    + writer.toJavaString(rb
0325:                                            .getPropertiesHelpKey().trim())
0326:                                    + ");", true);
0327:                }
0328:
0329:                writer
0330:                        .emitExpression(
0331:                                "beanDescriptor.setValue(Constants.BeanDescriptor.PROPERTY_CATEGORIES,getCategoryDescriptors());",
0332:                                true);
0333:
0334:                if (rb.getResizeConstraints() != null) {
0335:                    writer
0336:                            .emitExpression(
0337:                                    "beanDescriptor.setValue(Constants.BeanDescriptor.RESIZE_CONSTRAINTS,new Integer(Constants.ResizeConstraints."
0338:                                            + rb.getResizeConstraints()
0339:                                                    .toUpperCase().trim()
0340:                                            + "));", true);
0341:                }
0342:                String tagName = rb.getTagName();
0343:                if (tagName == null && !cb.isNonVisual()) {
0344:                    tagName = simpleTagName(cb, rb);
0345:                }
0346:                if (tagName != null) {
0347:                    writer.emitExpression(
0348:                            "beanDescriptor.setValue(Constants.BeanDescriptor.TAG_NAME,"
0349:                                    + writer.toJavaString(tagName.trim())
0350:                                    + ");", true);
0351:                }
0352:                String taglibPrefix = rb.getTaglibPrefix();
0353:                if (taglibPrefix == null) {
0354:                    taglibPrefix = getDefaultTaglibPrefix();
0355:                }
0356:                if (taglibPrefix != null) {
0357:                    writer.emitExpression(
0358:                            "beanDescriptor.setValue(Constants.BeanDescriptor.TAGLIB_PREFIX,"
0359:                                    + writer.toJavaString(taglibPrefix.trim())
0360:                                    + ");", true);
0361:                }
0362:                String taglibURI = rb.getTaglibURI();
0363:                if (taglibURI == null) {
0364:                    taglibURI = getDefaultTaglibURI();
0365:                }
0366:                if (taglibURI != null) {
0367:                    writer.emitExpression(
0368:                            "beanDescriptor.setValue(Constants.BeanDescriptor.TAGLIB_URI,"
0369:                                    + writer.toJavaString(taglibURI.trim())
0370:                                    + ");", true);
0371:                }
0372:                if (cb.isNonVisual() || rb.isNonVisual()) {
0373:                    writer
0374:                            .emitExpression(
0375:                                    "beanDescriptor.setValue(Constants.BeanDescriptor.TRAY_COMPONENT,Boolean.TRUE);",
0376:                                    true);
0377:                }
0378:                Map namedValues = rb.getNamedValues();
0379:                String key;
0380:                String expression;
0381:                String value;
0382:                for (Iterator keys = namedValues.keySet().iterator(); keys
0383:                        .hasNext(); writer.emitExpression(
0384:                        "beanDescriptor.setValue("
0385:                                + writer.toJavaString(key.trim())
0386:                                + ","
0387:                                + (expression == null ? writer
0388:                                        .toJavaString(value.trim())
0389:                                        : expression.trim()) + ");", true)) {
0390:                    key = (String) keys.next();
0391:                    NamedValueBean nvb = (NamedValueBean) namedValues.get(key);
0392:                    expression = nvb.getExpression();
0393:                    value = nvb.getValue();
0394:                }
0395:
0396:                writer.emitNewline();
0397:                if (raveBaseBI()) {
0398:                    writer.emitExpression(
0399:                            "annotateBeanDescriptor(beanDescriptor);", true);
0400:                }
0401:                writer.emitExpression("return beanDescriptor;", true);
0402:                writer.emitNewline();
0403:                writer.endMethod();
0404:                writer.emitNewline();
0405:            }
0406:
0407:            private void body(ComponentBean cb, RendererBean rb)
0408:                    throws IOException {
0409:
0410:                String baseBI = this .baseBI;
0411:                int period = baseBI.lastIndexOf(".");
0412:                if (period >= 0) {
0413:                    baseBI = baseBI.substring(period + 1);
0414:                }
0415:                JavaSourceWriter writer = getWriter();
0416:                String simple = simpleClassName(cb.getComponentClass());
0417:                simple = simple + (getBase() ? "BeanInfoBase" : "BeanInfo");
0418:                writer.startClass(simple, baseBI, null, !getBase(), getBase());
0419:                writer.emitNewline();
0420:                if (getUseComponentResourceBundles()) {
0421:                    writer.emitExpression(
0422:                            "protected static ResourceBundle resources = ResourceBundle.getBundle(\""
0423:                                    + packageName(cb) + ".Bundle-JSF\""
0424:                                    + ", Locale.getDefault(), " + simple
0425:                                    + ".class.getClassLoader());", true);
0426:                    writer.emitNewline();
0427:                }
0428:
0429:                constructor(cb, rb);
0430:                instance(cb, rb);
0431:                beanDescriptor(cb, rb);
0432:                categoryDescriptors(cb, rb);
0433:                defaultPropertyIndex(cb, rb);
0434:                facetDescriptors(cb, rb);
0435:                icon(cb, rb);
0436:                loadClass(cb);
0437:
0438:                FilterComponentBeanProperties filter = new FilterComponentBeanProperties();
0439:
0440:                String baseComponentType = cb.getBaseComponentType();
0441:                if (baseComponentType != null) {
0442:                    ComponentBean bcb = getConfig().getComponent(
0443:                            baseComponentType);
0444:                    filter.filter(bcb);
0445:                }
0446:                propertyDescriptors(cb, rb);
0447:                writer.endClass();
0448:            }
0449:
0450:            private void loadClass(ComponentBean cb) throws IOException {
0451:                JavaSourceWriter writer = getWriter();
0452:                writer.startJavaDoc();
0453:                writer
0454:                        .emitJavaDoc("<p>Return a class loaded by name via the class loader that loaded this class.</p>");
0455:                writer.endJavaDoc();
0456:                writer.startMethod("loadClass", "java.lang.Class",
0457:                        new String[] { "java.lang.String" },
0458:                        new String[] { "name" }, "private");
0459:                writer.emitNewline();
0460:                writer.emitExpression("try {", true);
0461:                writer.indent();
0462:                writer.emitExpression("return Class.forName(name);", true);
0463:                writer.outdent();
0464:                writer.emitExpression("} catch (ClassNotFoundException e) {",
0465:                        true);
0466:                writer.indent();
0467:                writer.emitExpression("throw new RuntimeException(e);", true);
0468:                writer.outdent();
0469:                writer.emitExpression("}", true);
0470:                writer.emitNewline();
0471:                writer.endMethod();
0472:                writer.emitNewline();
0473:            }
0474:
0475:            private void categoryDescriptors(ComponentBean cb, RendererBean rb)
0476:                    throws IOException {
0477:                JavaSourceWriter writer = getWriter();
0478:                writer.startJavaDoc();
0479:                writer
0480:                        .emitJavaDoc("<p>Return the <code>CategoryDescriptor</code> array for the property categories of this component.</p>");
0481:                writer.endJavaDoc();
0482:                writer.startMethod("getCategoryDescriptors",
0483:                        "CategoryDescriptor[]", null, null, "private");
0484:                writer.emitNewline();
0485:                if (rb.getPropertyCategories() != null) {
0486:                    writer
0487:                            .emitExpression(
0488:                                    "CategoryDescriptor cds[] = new CategoryDescriptor[] {",
0489:                                    true);
0490:                    writer.indent();
0491:                    String temp = rb.getPropertyCategories().trim();
0492:                    do {
0493:                        int comma = temp.indexOf(',');
0494:                        if (comma < 0)
0495:                            break;
0496:                        writer.emitExpression(getCategoryDescriptors() + "."
0497:                                + temp.substring(0, comma).trim().toUpperCase()
0498:                                + ",", true);
0499:                        temp = temp.substring(comma + 1);
0500:                    } while (true);
0501:                    writer.emitExpression(getCategoryDescriptors() + "."
0502:                            + temp.trim().toUpperCase(), true);
0503:                    writer.outdent();
0504:                    writer.emitExpression("};", true);
0505:                    writer.emitExpression("return cds;", true);
0506:                } else {
0507:                    writer.emitExpression("return " + getCategoryDescriptors()
0508:                            + ".getDefaultCategoryDescriptors();", true);
0509:                }
0510:                writer.emitNewline();
0511:                writer.endMethod();
0512:                writer.emitNewline();
0513:            }
0514:
0515:            protected void componentResourceBundle(String packageName,
0516:                    String lang, HashMap map) throws IOException {
0517:                if (map.size() == 0)
0518:                    return;
0519:                String filename = packageName;
0520:                if (filename.length() > 0) {
0521:                    filename = filename.replace('.', File.separatorChar);
0522:                    filename = filename + File.separatorChar;
0523:                }
0524:                filename = filename + "Bundle-JSF";
0525:                if (lang.length() > 0)
0526:                    filename = filename + "_" + lang;
0527:                filename = filename + ".properties";
0528:                File file = new File(getDest(), filename);
0529:                file.mkdirs();
0530:                file.delete();
0531:                PrintWriter writer = new PrintWriter(new BufferedWriter(
0532:                        new FileWriter(file)));
0533:                char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7',
0534:                        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
0535:                String specialSaveChars = "=: \t\r\n\f#!";
0536:                Object keys[] = map.keySet().toArray();
0537:                Arrays.sort(keys);
0538:                String lastKeyGroup = null;
0539:                for (int i = 0; i < keys.length; i++) {
0540:                    String key = (String) keys[i];
0541:                    String value = (String) map.get(key);
0542:                    value = trimWhitespace(value);
0543:                    int index = key.indexOf('_');
0544:                    if (index != -1) {
0545:                        String keyGroup = key.substring(0, index);
0546:                        if (lastKeyGroup == null
0547:                                || !lastKeyGroup.equals(keyGroup)) {
0548:                            if (lastKeyGroup != null)
0549:                                writer.write(10);
0550:                            writer.write("# ");
0551:                            writer.write(keyGroup);
0552:                            writer.write(10);
0553:                            lastKeyGroup = keyGroup;
0554:                        }
0555:                    }
0556:                    writer.write(key);
0557:                    writer.write(61);
0558:                    int len = value.length();
0559:                    for (int x = 0; x < len; x++) {
0560:                        char aChar = value.charAt(x);
0561:                        switch (aChar) {
0562:                        case 32: // ' '
0563:                            writer.write(32);
0564:                            break;
0565:
0566:                        case 92: // '\\'
0567:                            writer.write(92);
0568:                            writer.write(92);
0569:                            break;
0570:
0571:                        case 9: // '\t'
0572:                            writer.write(92);
0573:                            writer.write(116);
0574:                            break;
0575:
0576:                        case 10: // '\n'
0577:                            writer.write(92);
0578:                            writer.write(110);
0579:                            break;
0580:
0581:                        case 13: // '\r'
0582:                            writer.write(92);
0583:                            writer.write(114);
0584:                            break;
0585:
0586:                        case 12: // '\f'
0587:                            writer.write(92);
0588:                            writer.write(102);
0589:                            break;
0590:
0591:                        default:
0592:                            if (aChar < ' ' || aChar > '~') {
0593:                                writer.write(92);
0594:                                writer.write(117);
0595:                                writer.write(hexDigit[aChar >> 12 & 0xf]);
0596:                                writer.write(hexDigit[aChar >> 8 & 0xf]);
0597:                                writer.write(hexDigit[aChar >> 4 & 0xf]);
0598:                                writer.write(hexDigit[aChar & 0xf]);
0599:                                break;
0600:                            }
0601:                            if ("=: \t\r\n\f#!".indexOf(aChar) != -1)
0602:                                writer.write(92);
0603:                            writer.write(aChar);
0604:                            break;
0605:                        }
0606:                    }
0607:
0608:                    writer.write(10);
0609:                }
0610:
0611:                writer.flush();
0612:                writer.close();
0613:            }
0614:
0615:            private void constructor(ComponentBean cb, RendererBean rb)
0616:                    throws IOException {
0617:                JavaSourceWriter writer = getWriter();
0618:                String simple = simpleClassName(cb.getComponentClass());
0619:                writer.startJavaDoc();
0620:                writer.emitJavaDoc("<p>Construct a new <code>"
0621:                        + simpleClassName(cb) + "</code>.</p>");
0622:                writer.endJavaDoc();
0623:                writer.startMethod(simpleClassName(cb), null, null, null);
0624:                writer.emitNewline();
0625:                writer
0626:                        .emitExpression("beanClass = " + simple + ".class;",
0627:                                true);
0628:                if (rb.getDefaultPropertyName() != null)
0629:                    writer.emitExpression("defaultPropertyName = "
0630:                            + JavaSourceWriter.toJavaString(rb
0631:                                    .getDefaultPropertyName()) + ";", true);
0632:                writer.emitExpression("iconFileName_C16 = \"" + simple
0633:                        + "_C16\";", true);
0634:                writer.emitExpression("iconFileName_C32 = \"" + simple
0635:                        + "_C32\";", true);
0636:                writer.emitExpression("iconFileName_M16 = \"" + simple
0637:                        + "_M16\";", true);
0638:                writer.emitExpression("iconFileName_M32 = \"" + simple
0639:                        + "_M32\";", true);
0640:                writer.emitNewline();
0641:                writer.endMethod();
0642:                writer.emitNewline();
0643:            }
0644:
0645:            private void defaultPropertyIndex(ComponentBean cb, RendererBean rb)
0646:                    throws IOException {
0647:                if (raveBaseBI()) {
0648:                    return;
0649:                } else {
0650:                    JavaSourceWriter writer = getWriter();
0651:                    writer.startJavaDoc();
0652:                    writer
0653:                            .emitJavaDoc("<p>Return the index of the default property, or");
0654:                    writer
0655:                            .emitJavaDoc("-1 if there is no default property.</p>");
0656:                    writer.endJavaDoc();
0657:                    writer.startMethod("getDefaultPropertyIndex", "int", null,
0658:                            null);
0659:                    writer.emitNewline();
0660:                    writer.emitExpression("if (defaultPropertyIndex > -2) {",
0661:                            true);
0662:                    writer.indent();
0663:                    writer.emitExpression("return defaultPropertyIndex;", true);
0664:                    writer.outdent();
0665:                    writer.emitExpression("} else {", true);
0666:                    writer.indent();
0667:                    writer.emitExpression("if (defaultPropertyName == null) {",
0668:                            true);
0669:                    writer.indent();
0670:                    writer.emitExpression("defaultPropertyIndex = -1;", true);
0671:                    writer.outdent();
0672:                    writer.emitExpression("} else {", true);
0673:                    writer.indent();
0674:                    writer
0675:                            .emitExpression(
0676:                                    "PropertyDescriptor pd[] = getPropertyDescriptors();",
0677:                                    true);
0678:                    writer.emitExpression(
0679:                            "for (int i = 0; i < pd.length; i++) {", true);
0680:                    writer.indent();
0681:                    writer
0682:                            .emitExpression(
0683:                                    "if (defaultPropertyName.equals(pd[i].getName())) {",
0684:                                    true);
0685:                    writer.indent();
0686:                    writer.emitExpression("defaultPropertyIndex = i;", true);
0687:                    writer.emitExpression("break;", true);
0688:                    writer.outdent();
0689:                    writer.emitExpression("}", true);
0690:                    writer.outdent();
0691:                    writer.emitExpression("}", true);
0692:                    writer.outdent();
0693:                    writer.emitExpression("}", true);
0694:                    writer.outdent();
0695:                    writer.emitExpression("}", true);
0696:                    writer.emitExpression("return defaultPropertyIndex;", true);
0697:                    writer.endMethod();
0698:                    writer.emitNewline();
0699:                    return;
0700:                }
0701:            }
0702:
0703:            protected void displayName(DisplayNameBean displayName,
0704:                    DisplayNameBean displayNames[], JavaSourceWriter writer,
0705:                    String variableName, String packageName,
0706:                    String simpleClassName, String propertyName)
0707:                    throws IOException {
0708:                String key = simpleClassName;
0709:                if (propertyName != null)
0710:                    key = key + "_" + propertyName;
0711:                key = key + "_DisplayName";
0712:                if (displayName != null || getUseComponentResourceBundles())
0713:                    writer.emitExpression(variableName + ".setDisplayName(",
0714:                            false);
0715:                String displayNameString = displayName != null ? displayName
0716:                        .getDisplayName().trim() : "";
0717:                if (getUseComponentResourceBundles()) {
0718:                    writer.emitExpressionPart("resources.getString(");
0719:                    putBundleMap(packageName, "", key, displayNameString);
0720:                    writer.emitJavaString(key);
0721:                    writer.emitExpressionPart(")");
0722:                } else if (displayName != null)
0723:                    writer.emitJavaString(displayNameString);
0724:                if (displayName != null || getUseComponentResourceBundles()) {
0725:                    writer.emitExpressionPart(");");
0726:                    writer.emitNewline();
0727:                }
0728:                for (int i = 0; i < displayNames.length; i++) {
0729:                    String lang = displayNames[i].getLang();
0730:                    if ("".equals(lang))
0731:                        continue;
0732:                    displayNameString = displayNames[i].getDisplayName().trim();
0733:                    if (getUseComponentResourceBundles())
0734:                        putBundleMap(packageName, lang, key, displayNameString);
0735:                    else
0736:                        writer.emitExpression(variableName + ".setValue("
0737:                                + writer.toJavaString("displayName." + lang)
0738:                                + "," + writer.toJavaString(displayNameString)
0739:                                + ");", true);
0740:                }
0741:
0742:            }
0743:
0744:            private void facetDescriptor(ComponentBean cb, RendererBean rb,
0745:                    FacetBean fb) throws IOException {
0746:                JavaSourceWriter writer = getWriter();
0747:                DisplayNameBean displayName = fb.getDisplayName("");
0748:                DisplayNameBean displayNames[] = fb.getDisplayNames();
0749:                DescriptionBean description = fb.getDescription("");
0750:                DescriptionBean descriptions[] = fb.getDescriptions();
0751:                String name = fb.getFacetName();
0752:                StringBuffer fsb = new StringBuffer("FacetDescriptor facet_");
0753:                fsb.append(name);
0754:                fsb.append(" = new FacetDescriptor(");
0755:                fsb.append(writer.toJavaString(name));
0756:                fsb.append(");");
0757:                writer.emitExpression(fsb.toString(), true);
0758:                String packageName = packageName(cb);
0759:                String simpleClassName = simpleClassName(cb.getComponentClass());
0760:                displayName(displayName, displayNames, writer, "facet_" + name,
0761:                        packageName, simpleClassName, name);
0762:                shortDescription(description, descriptions, writer, "facet_"
0763:                        + name, packageName, simpleClassName, name);
0764:                Map namedValues = fb.getNamedValues();
0765:                String key;
0766:                String expression;
0767:                String value;
0768:                for (Iterator keys = namedValues.keySet().iterator(); keys
0769:                        .hasNext(); genericNamedValue(key, value, expression,
0770:                        writer, "facet_" + name, packageName, simpleClassName,
0771:                        name)) {
0772:                    key = (String) keys.next();
0773:                    NamedValueBean nvb = (NamedValueBean) namedValues.get(key);
0774:                    expression = nvb.getExpression();
0775:                    value = nvb.getValue();
0776:                }
0777:
0778:                writer.emitNewline();
0779:            }
0780:
0781:            private void facetDescriptors(ComponentBean cb, RendererBean rb)
0782:                    throws IOException {
0783:                JavaSourceWriter writer = getWriter();
0784:                TreeMap map = new TreeMap();
0785:                writer.startJavaDoc();
0786:                writer.emitJavaDoc("<p>The cached facet descriptors.</p>");
0787:                writer.endJavaDoc();
0788:                writer.emitExpression(
0789:                        "protected FacetDescriptor[] facetDescriptors;", true);
0790:                writer.emitNewline();
0791:                writer.startJavaDoc();
0792:                writer
0793:                        .emitJavaDoc("<p>Return the <code>FacetDescriptor</code>s for this bean.</p>");
0794:                writer.endJavaDoc();
0795:                writer.startMethod("getFacetDescriptors", "FacetDescriptor[]",
0796:                        null, null);
0797:                writer.emitNewline();
0798:                writer.emitExpression("if (facetDescriptors != null) {", true);
0799:                writer.indent();
0800:                writer.emitExpression("return facetDescriptors;", true);
0801:                writer.outdent();
0802:                writer.emitExpression("}", true);
0803:                FacetBean facets[] = facets(cb, rb);
0804:                if (facets.length > 0) {
0805:                    writer.emitExpression("try {", true);
0806:                    writer.emitNewline();
0807:                    writer.indent();
0808:                }
0809:                for (int i = 0; i < facets.length; i++) {
0810:                    FacetBean facet = facets[i];
0811:                    facetDescriptor(cb, rb, facet);
0812:                    map.put(facet.getFacetName(), facet);
0813:                }
0814:
0815:                writer.emitExpression(
0816:                        "facetDescriptors = new FacetDescriptor[] {", true);
0817:                writer.indent();
0818:                String facetName;
0819:                for (Iterator facetNames = map.keySet().iterator(); facetNames
0820:                        .hasNext(); writer.emitExpression("facet_" + facetName
0821:                        + ",", true))
0822:                    facetName = (String) facetNames.next();
0823:
0824:                writer.outdent();
0825:                writer.emitExpression("};", true);
0826:                writer.emitExpression("return facetDescriptors;", true);
0827:                writer.emitNewline();
0828:                if (facets.length > 0) {
0829:                    writer.outdent();
0830:                    writer.emitExpression("} catch (RuntimeException e) {",
0831:                            true);
0832:                    writer.indent();
0833:                    writer.emitExpression(
0834:                            "System.out.println(e.getMessage());", true);
0835:                    writer.emitExpression("e.printStackTrace(System.out);",
0836:                            true);
0837:                    writer.emitExpression("throw e;", true);
0838:                    writer.outdent();
0839:                    writer.emitExpression("}", true);
0840:                    writer.emitNewline();
0841:                }
0842:                writer.endMethod();
0843:                writer.emitNewline();
0844:            }
0845:
0846:            private void generate(ComponentBean cb) throws IOException {
0847:
0848:                if (cb.getComponentClass().startsWith("javax.faces.component.")) {
0849:                    return;
0850:                }
0851:                if (cb.isSuppressed())
0852:                    return;
0853:                RendererBean rb = renderer(cb);
0854:                if (rb == null)
0855:                    rb = new RendererBean();
0856:                File outputFile = outputFile(cb.getComponentClass()
0857:                        + (getBase() ? "BeanInfoBase" : "BeanInfo"));
0858:                outputFile.mkdirs();
0859:                outputFile.delete();
0860:                try {
0861:                    getWriter().setOutputWriter(
0862:                            new BufferedWriter(new FileWriter(outputFile)));
0863:                } catch (Exception e) {
0864:                    e.printStackTrace();
0865:                }
0866:                license(cb, rb);
0867:                header(cb, rb);
0868:                body(cb, rb);
0869:                getWriter().flush();
0870:                getWriter().close();
0871:            }
0872:
0873:            private void header(ComponentBean cb, RendererBean rb)
0874:                    throws IOException {
0875:                JavaSourceWriter writer = getWriter();
0876:                String packageName = packageName(cb);
0877:                if (packageName.length() > 0) {
0878:                    writer.emitPackage(packageName);
0879:                    writer.emitNewline();
0880:                }
0881:                writer.emitImport("java.awt.Image");
0882:                writer.emitImport("java.beans.BeanDescriptor");
0883:                writer.emitImport("java.beans.BeanInfo");
0884:                writer.emitImport("java.beans.IntrospectionException");
0885:                writer.emitImport("java.beans.PropertyDescriptor");
0886:                writer.emitImport("java.util.Locale");
0887:                writer.emitImport("java.util.ResourceBundle");
0888:                writer.emitNewline();
0889:                writer.emitImport("com.sun.rave.designtime.CategoryDescriptor");
0890:                writer.emitImport("com.sun.rave.designtime.Constants");
0891:                writer
0892:                        .emitImport("com.sun.rave.designtime.faces.FacetDescriptor");
0893:                writer
0894:                        .emitImport("com.sun.rave.designtime.markup.AttributeDescriptor");
0895:                writer.emitNewline();
0896:                writer.emitImport(baseBI);
0897:                if (!"java.beans.BeanDescriptor".equals(implBD))
0898:                    writer.emitImport(implBD);
0899:                if (!"java.beans.PropertyDescriptor".equals(implPD))
0900:                    writer.emitImport(implPD);
0901:                writer.emitNewline();
0902:                writer.startJavaDoc();
0903:                writer
0904:                        .emitJavaDoc("<p>Auto-generated design time metadata class.");
0905:                writer
0906:                        .emitJavaDoc("Do <strong>NOT</strong> modify; all changes");
0907:                writer.emitJavaDoc("<strong>will</strong> be lost!</p>");
0908:                writer.endJavaDoc();
0909:                writer.emitNewline();
0910:            }
0911:
0912:            protected void genericNamedValue(String valueName, String value,
0913:                    String expression, JavaSourceWriter writer,
0914:                    String variableName, String packageName,
0915:                    String simpleClassName, String propertyName)
0916:                    throws IOException {
0917:                boolean inBundle = false;
0918:                if (getUseComponentResourceBundles() && value != null
0919:                        && expression == null
0920:                        && "instructions".equals(valueName))
0921:                    inBundle = true;
0922:                writer.emitExpression(variableName, false);
0923:                valueName = valueName.trim();
0924:                writer.emitExpressionPart(".setValue(");
0925:                writer.emitJavaString(valueName);
0926:                writer.emitExpressionPart(", ");
0927:                if (inBundle) {
0928:                    String key = simpleClassName;
0929:                    if (propertyName != null)
0930:                        key = key + "_" + propertyName;
0931:                    key = key + "_" + valueName;
0932:                    putBundleMap(packageName, "", key, value);
0933:                    writer.emitExpressionPart("resources.getString(");
0934:                    writer.emitJavaString(key);
0935:                    writer.emitExpressionPart(")");
0936:                } else if (expression == null)
0937:                    writer.emitJavaString(value.trim());
0938:                else
0939:                    writer.emitExpressionPart(expression.trim());
0940:                writer.emitExpressionPart(");");
0941:                writer.emitNewline();
0942:            }
0943:
0944:            private void icon(ComponentBean cb, RendererBean rb)
0945:                    throws IOException {
0946:                if (raveBaseBI()) {
0947:                    return;
0948:                } else {
0949:                    JavaSourceWriter writer = getWriter();
0950:                    writer.startJavaDoc();
0951:                    writer
0952:                            .emitJavaDoc("<p>Return the specified image (if any)");
0953:                    writer.emitJavaDoc("for this component class.</p>");
0954:                    writer.endJavaDoc();
0955:                    writer.startMethod("getIcon", "Image",
0956:                            new String[] { "int" }, new String[] { "kind" });
0957:                    writer.emitNewline();
0958:                    writer.emitExpression("String name;", true);
0959:                    writer.emitExpression("switch (kind) {", true);
0960:                    writer.indent();
0961:                    writer.emitExpression("case ICON_COLOR_16x16:", true);
0962:                    writer.indent();
0963:                    writer.emitExpression("name = iconFileName_C16;", true);
0964:                    writer.emitExpression("break;", true);
0965:                    writer.outdent();
0966:                    writer.emitExpression("case ICON_COLOR_32x32:", true);
0967:                    writer.indent();
0968:                    writer.emitExpression("name = iconFileName_C32;", true);
0969:                    writer.emitExpression("break;", true);
0970:                    writer.outdent();
0971:                    writer.emitExpression("case ICON_MONO_16x16:", true);
0972:                    writer.indent();
0973:                    writer.emitExpression("name = iconFileName_M16;", true);
0974:                    writer.emitExpression("break;", true);
0975:                    writer.outdent();
0976:                    writer.emitExpression("case ICON_MONO_32x32:", true);
0977:                    writer.indent();
0978:                    writer.emitExpression("name = iconFileName_M32;", true);
0979:                    writer.emitExpression("break;", true);
0980:                    writer.outdent();
0981:                    writer.emitExpression("default:", true);
0982:                    writer.indent();
0983:                    writer.emitExpression("name = null;", true);
0984:                    writer.emitExpression("break;", true);
0985:                    writer.outdent();
0986:                    writer.outdent();
0987:                    writer.emitExpression("}", true);
0988:                    writer.emitExpression("if (name == null) {", true);
0989:                    writer.indent();
0990:                    writer.emitExpression("return null;", true);
0991:                    writer.outdent();
0992:                    writer.emitExpression("}", true);
0993:                    writer.emitNewline();
0994:                    writer.emitExpression(
0995:                            "Image image = loadImage(name + \".png\");", true);
0996:                    writer.emitExpression("if (image == null) {", true);
0997:                    writer.indent();
0998:                    writer.emitExpression(
0999:                            "image = loadImage(name + \".gif\");", true);
1000:                    writer.outdent();
1001:                    writer.emitExpression("}", true);
1002:                    writer.emitExpression("return image;", true);
1003:                    writer.emitNewline();
1004:                    writer.endMethod();
1005:                    writer.emitNewline();
1006:                    return;
1007:                }
1008:            }
1009:
1010:            private void instance(ComponentBean cb, RendererBean rb)
1011:                    throws IOException {
1012:                if (raveBaseBI()) {
1013:                    return;
1014:                } else {
1015:                    JavaSourceWriter writer = getWriter();
1016:                    writer.startJavaDoc();
1017:                    writer
1018:                            .emitJavaDoc("<p>The bean class that this BeanInfo represents.");
1019:                    writer.endJavaDoc();
1020:                    writer.emitExpression("protected Class beanClass;", true);
1021:                    writer.emitNewline();
1022:                    writer.startJavaDoc();
1023:                    writer.emitJavaDoc("<p>The cached BeanDescriptor.</p>");
1024:                    writer.endJavaDoc();
1025:                    writer.emitExpression(
1026:                            "protected BeanDescriptor beanDescriptor;", true);
1027:                    writer.emitNewline();
1028:                    writer.startJavaDoc();
1029:                    writer
1030:                            .emitJavaDoc("<p>The index of the default property.</p>");
1031:                    writer.endJavaDoc();
1032:                    writer.emitExpression(
1033:                            "protected int defaultPropertyIndex = -2;", true);
1034:                    writer.emitNewline();
1035:                    writer.startJavaDoc();
1036:                    writer
1037:                            .emitJavaDoc("<p>The name of the default property.</p>");
1038:                    writer.endJavaDoc();
1039:                    writer.emitExpression(
1040:                            "protected String defaultPropertyName;", true);
1041:                    writer.emitNewline();
1042:                    writer.startJavaDoc();
1043:                    writer.emitJavaDoc("<p>The 16x16 color icon.</p>");
1044:                    writer.endJavaDoc();
1045:                    writer.emitExpression("protected String iconFileName_C16;",
1046:                            true);
1047:                    writer.emitNewline();
1048:                    writer.startJavaDoc();
1049:                    writer.emitJavaDoc("<p>The 32x32 color icon.</p>");
1050:                    writer.endJavaDoc();
1051:                    writer.emitExpression("protected String iconFileName_C32;",
1052:                            true);
1053:                    writer.emitNewline();
1054:                    writer.startJavaDoc();
1055:                    writer.emitJavaDoc("<p>The 16x16 monochrome icon.</p>");
1056:                    writer.endJavaDoc();
1057:                    writer.emitExpression("protected String iconFileName_M16;",
1058:                            true);
1059:                    writer.emitNewline();
1060:                    writer.startJavaDoc();
1061:                    writer.emitJavaDoc("<p>The 32x32 monochrome icon.</p>");
1062:                    writer.endJavaDoc();
1063:                    writer.emitExpression("protected String iconFileName_M32;",
1064:                            true);
1065:                    writer.emitNewline();
1066:                    writer.startJavaDoc();
1067:                    writer
1068:                            .emitJavaDoc("<p>The cached property descriptors.</p>");
1069:                    writer.endJavaDoc();
1070:                    writer.emitExpression(
1071:                            "protected PropertyDescriptor[] propDescriptors;",
1072:                            true);
1073:                    writer.emitNewline();
1074:                    return;
1075:                }
1076:            }
1077:
1078:            private void license(ComponentBean componentbean,
1079:                    RendererBean rendererbean) throws IOException {
1080:            }
1081:
1082:            private String packageName(ComponentBean cb) {
1083:                String componentClass = cb.getComponentClass();
1084:                int last = componentClass.lastIndexOf('.');
1085:                if (last >= 0)
1086:                    return componentClass.substring(0, last);
1087:                else
1088:                    return "";
1089:            }
1090:
1091:            private void propertyDescriptor(ComponentBean cb, RendererBean rb,
1092:                    PropertyBean pb, ComponentBean componentBeanBeingGenerated)
1093:                    throws IOException {
1094:                String implPD = this .implPD;
1095:                int period = implPD.lastIndexOf(".");
1096:                if (period >= 0)
1097:                    implPD = implPD.substring(period + 1);
1098:                JavaSourceWriter writer = getWriter();
1099:                DisplayNameBean displayName = pb.getDisplayName("");
1100:                DisplayNameBean displayNames[] = pb.getDisplayNames();
1101:                DescriptionBean description = pb.getShortDescription("");
1102:                if (description == null)
1103:                    description = pb.getDescription("");
1104:                DescriptionBean descriptions[] = pb.getShortDescriptions();
1105:                if (descriptions == null)
1106:                    descriptions = pb.getDescriptions();
1107:                String name = pb.getPropertyName();
1108:                String readMethod = pb.getReadMethod();
1109:                if (pb.isWriteOnly())
1110:                    readMethod = null;
1111:                else if (readMethod == null)
1112:                    if ("boolean".equals(pb.getPropertyClass()))
1113:                        readMethod = "is"
1114:                                + Character.toUpperCase(name.charAt(0))
1115:                                + name.substring(1);
1116:                    else
1117:                        readMethod = "get"
1118:                                + Character.toUpperCase(name.charAt(0))
1119:                                + name.substring(1);
1120:                String writeMethod = pb.getWriteMethod();
1121:                if (pb.isReadOnly())
1122:                    writeMethod = null;
1123:                else if (writeMethod == null)
1124:                    writeMethod = "set" + Character.toUpperCase(name.charAt(0))
1125:                            + name.substring(1);
1126:                StringBuffer psb = new StringBuffer("PropertyDescriptor prop_");
1127:                psb.append(name);
1128:                psb.append(" = new ");
1129:                psb.append(implPD);
1130:                psb.append("(");
1131:                psb.append(writer.toJavaString(name));
1132:                psb.append(",beanClass,");
1133:                psb.append(readMethod != null ? writer.toJavaString(readMethod)
1134:                        : "null");
1135:                psb.append(",");
1136:                psb.append(writeMethod != null ? writer
1137:                        .toJavaString(writeMethod) : "null");
1138:                psb.append(");");
1139:                writer.emitExpression(psb.toString(), true);
1140:                String packageName = packageName(componentBeanBeingGenerated);
1141:                String simpleClassName = simpleClassName(componentBeanBeingGenerated
1142:                        .getComponentClass());
1143:                displayName(displayName, displayNames, writer, "prop_" + name,
1144:                        packageName, simpleClassName, name);
1145:                shortDescription(description, descriptions, writer, "prop_"
1146:                        + name, packageName, simpleClassName, name);
1147:                if (pb.getEditorClass() != null)
1148:                    writer.emitExpression("prop_" + name
1149:                            + ".setPropertyEditorClass(" + "loadClass(\""
1150:                            + pb.getEditorClass().trim() + "\"));", true);
1151:                writer.emitExpression("prop_" + name + ".setExpert("
1152:                        + pb.isExpert() + ");", true);
1153:                writer.emitExpression("prop_" + name + ".setHidden("
1154:                        + pb.isHidden() + ");", true);
1155:                writer.emitExpression("prop_" + name + ".setPreferred("
1156:                        + pb.isPreferred() + ");", true);
1157:                if (pb.isTagAttribute()) {
1158:                    StringBuffer asb = new StringBuffer(
1159:                            "attrib = new AttributeDescriptor(");
1160:                    String attributeName = pb.getAttributeAlias();
1161:                    if (attributeName == null)
1162:                        attributeName = name;
1163:                    asb.append(writer.toJavaString(attributeName));
1164:                    asb.append(",");
1165:                    asb.append(pb.isRequired());
1166:                    asb.append(",");
1167:                    if (pb.getDefaultValue() != null)
1168:                        asb.append(writer.toJavaString(pb.getDefaultValue()));
1169:                    else
1170:                        asb.append("null");
1171:                    asb.append(",");
1172:                    asb.append(pb.isBindable());
1173:                    asb.append(");");
1174:                    writer.emitExpression(asb.toString(), true);
1175:                    writer
1176:                            .emitExpression(
1177:                                    "prop_"
1178:                                            + name
1179:                                            + ".setValue("
1180:                                            + "Constants.PropertyDescriptor.ATTRIBUTE_DESCRIPTOR,"
1181:                                            + "attrib);", true);
1182:                }
1183:                String category = pb.getCategory();
1184:                if (category == null)
1185:                    category = "GENERAL";
1186:                writer.emitExpression("prop_" + name + ".setValue("
1187:                        + "Constants.PropertyDescriptor.CATEGORY,"
1188:                        + getCategoryDescriptors() + "."
1189:                        + category.toUpperCase().trim() + ");", true);
1190:                if (pb.getHelpKey() != null)
1191:                    writer.emitExpression("prop_" + name + ".setValue("
1192:                            + "Constants.PropertyDescriptor.HELP_KEY,"
1193:                            + writer.toJavaString(pb.getHelpKey().trim())
1194:                            + ");", true);
1195:                Map namedValues = pb.getNamedValues();
1196:                String key;
1197:                String expression;
1198:                String value;
1199:                for (Iterator keys = namedValues.keySet().iterator(); keys
1200:                        .hasNext(); genericNamedValue(key, value, expression,
1201:                        writer, "prop_" + name, packageName, simpleClassName,
1202:                        name)) {
1203:                    key = (String) keys.next();
1204:                    NamedValueBean nvb = (NamedValueBean) namedValues.get(key);
1205:                    expression = nvb.getExpression();
1206:                    value = nvb.getValue();
1207:                }
1208:
1209:                writer.emitNewline();
1210:            }
1211:
1212:            private void propertyDescriptors(ComponentBean cb, RendererBean rb)
1213:                    throws IOException {
1214:                JavaSourceWriter writer = getWriter();
1215:                TreeMap map = new TreeMap();
1216:                writer.startJavaDoc();
1217:                writer
1218:                        .emitJavaDoc("<p>Return the <code>PropertyDescriptor</code>s for this bean.</p>");
1219:                writer.endJavaDoc();
1220:                writer.startMethod("getPropertyDescriptors",
1221:                        "PropertyDescriptor[]", null, null);
1222:                writer.emitNewline();
1223:                writer.emitExpression("if (propDescriptors != null) {", true);
1224:                writer.indent();
1225:                writer.emitExpression("return propDescriptors;", true);
1226:                writer.outdent();
1227:                writer.emitExpression("}", true);
1228:                writer.emitExpression("AttributeDescriptor attrib = null;",
1229:                        true);
1230:                writer.emitNewline();
1231:                writer.emitExpression("try {", true);
1232:                writer.emitNewline();
1233:                writer.indent();
1234:                propertyDescriptors(cb, rb, ((Map) (map)), cb);
1235:                writer.emitExpression(
1236:                        "propDescriptors = new PropertyDescriptor[] {", true);
1237:                writer.indent();
1238:                String prop;
1239:                for (Iterator props = map.keySet().iterator(); props.hasNext(); writer
1240:                        .emitExpression("prop_" + prop + ",", true))
1241:                    prop = (String) props.next();
1242:
1243:                writer.outdent();
1244:                writer.emitExpression("};", true);
1245:                if (raveBaseBI())
1246:                    writer.emitExpression(
1247:                            "annotatePropertyDescriptors(propDescriptors);",
1248:                            true);
1249:                writer.emitExpression("return propDescriptors;", true);
1250:                writer.emitNewline();
1251:                writer.outdent();
1252:                writer.emitExpression("} catch (IntrospectionException e) {",
1253:                        true);
1254:                writer.indent();
1255:                writer.emitExpression("e.printStackTrace();", true);
1256:                writer.emitExpression("return null;", true);
1257:                writer.outdent();
1258:                writer.emitExpression("}", true);
1259:                writer.emitNewline();
1260:                writer.endMethod();
1261:                writer.emitNewline();
1262:            }
1263:
1264:            private void propertyDescriptors(ComponentBean cb, RendererBean rb,
1265:                    Map map, ComponentBean componentBeanBeingGenerated)
1266:                    throws IOException {
1267:                PropertyBean pbs[] = cb.getProperties();
1268:                for (int i = 0; i < pbs.length; i++) {
1269:                    if (map.containsKey(pbs[i].getPropertyName())
1270:                            || "valid".equals(pbs[i].getPropertyName()))
1271:                        continue;
1272:                    PropertyBean pb = merge(pbs[i], rb.getAttribute(pbs[i]
1273:                            .getPropertyName()));
1274:                    if (!pb.isSuppressed()) {
1275:                        propertyDescriptor(cb, rb, pb,
1276:                                componentBeanBeingGenerated);
1277:                        map.put(pb.getPropertyName(), null);
1278:                    }
1279:                }
1280:
1281:                String baseComponentType = cb.getBaseComponentType();
1282:                if (baseComponentType != null) {
1283:                    ComponentBean bcb = getConfig().getComponent(
1284:                            baseComponentType);
1285:                    propertyDescriptors(bcb, rb, map,
1286:                            componentBeanBeingGenerated);
1287:                }
1288:            }
1289:
1290:            protected boolean raveBaseBI() {
1291:                return "com.sun.jsfcl.std.HtmlBeanInfoBase".equals(baseBI);
1292:            }
1293:
1294:            protected void shortDescription(DescriptionBean description,
1295:                    DescriptionBean descriptions[], JavaSourceWriter writer,
1296:                    String variableName, String packageName,
1297:                    String simpleClassName, String propertyName)
1298:                    throws IOException {
1299:                String key = simpleClassName;
1300:                if (propertyName != null)
1301:                    key = key + "_" + propertyName;
1302:                key = key + "_Description";
1303:                if (description != null || getUseComponentResourceBundles()) {
1304:                    writer.emitExpression(variableName, false);
1305:                    writer.emitExpressionPart(".setShortDescription(");
1306:                }
1307:                String descriptionString = description != null ? description
1308:                        .getDescription().trim() : "";
1309:                if (getUseComponentResourceBundles()) {
1310:                    putBundleMap(packageName, "", key, descriptionString);
1311:                    writer.emitExpressionPart("resources.getString(");
1312:                    writer.emitJavaString(key);
1313:                    writer.emitExpressionPart(")");
1314:                } else if (description != null)
1315:                    writer.emitJavaString(descriptionString);
1316:                if (description != null || getUseComponentResourceBundles()) {
1317:                    writer.emitExpressionPart(");");
1318:                    writer.emitNewline();
1319:                }
1320:                for (int i = 0; i < descriptions.length; i++) {
1321:                    String lang = descriptions[i].getLang();
1322:                    if ("".equals(lang))
1323:                        continue;
1324:                    descriptionString = descriptions[i].getDescription();
1325:                    if (getUseComponentResourceBundles())
1326:                        putBundleMap(packageName, lang, key, descriptionString);
1327:                    else
1328:                        writer.emitExpression(variableName + ".setValue("
1329:                                + writer.toJavaString("description." + lang)
1330:                                + "," + writer.toJavaString(descriptionString)
1331:                                + ");", true);
1332:                }
1333:
1334:            }
1335:
1336:            private String simpleClassName(ComponentBean cb) {
1337:                return simpleClassName(cb.getComponentClass())
1338:                        + (getBase() ? "BeanInfoBase" : "BeanInfo");
1339:            }
1340:
1341:            private String simpleInstanceName(ComponentBean cb, RendererBean rb) {
1342:                String cname = cb.getComponentType();
1343:                int period = cname.lastIndexOf('.');
1344:                if (period >= 0)
1345:                    cname = cname.substring(period + 1);
1346:                String rname = rb.getRendererType();
1347:                if (rname == null) {
1348:                    rname = "";
1349:                }
1350:                period = rname.lastIndexOf('.');
1351:                if (period >= 0)
1352:                    rname = rname.substring(period + 1);
1353:                if (cname.equalsIgnoreCase(rname) || rname.length() < 1) {
1354:                    return Character.toLowerCase(cname.charAt(0))
1355:                            + cname.substring(1);
1356:                } else {
1357:                    return Character.toLowerCase(cname.charAt(0))
1358:                            + cname.substring(1)
1359:                            + Character.toUpperCase(rname.charAt(0))
1360:                            + rname.substring(1);
1361:                }
1362:            }
1363:
1364:            private String simpleTagName(ComponentBean cb, RendererBean rb) {
1365:                String cname = cb.getComponentType();
1366:                int period = cname.lastIndexOf('.');
1367:                if (period >= 0)
1368:                    cname = cname.substring(period + 1);
1369:                String rname = rb.getRendererType();
1370:                if (rname == null)
1371:                    rname = "";
1372:                period = rname.lastIndexOf('.');
1373:                if (period >= 0)
1374:                    rname = rname.substring(period + 1);
1375:                if (cname.equalsIgnoreCase(rname) || rname.length() < 1) {
1376:                    return Character.toLowerCase(cname.charAt(0))
1377:                            + cname.substring(1);
1378:                } else {
1379:                    return Character.toLowerCase(cname.charAt(0))
1380:                            + cname.substring(1)
1381:                            + Character.toUpperCase(rname.charAt(0))
1382:                            + rname.substring(1);
1383:                }
1384:            }
1385:
1386:            protected String trimWhitespace(String string) {
1387:
1388:                StringBuffer buffer = new StringBuffer(string.length());
1389:                boolean eatingWhite = true;
1390:                for (int i = 0; i < string.length(); i++) {
1391:                    char c = string.charAt(i);
1392:                    if (eatingWhite) {
1393:                        if (Character.isWhitespace(c))
1394:                            continue;
1395:                        eatingWhite = false;
1396:                    }
1397:                    if (Character.isWhitespace(c)) {
1398:                        buffer.append(" ");
1399:                        eatingWhite = true;
1400:                    } else {
1401:                        buffer.append(c);
1402:                    }
1403:                }
1404:
1405:                return buffer.toString();
1406:            }
1407:
1408:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.