KickJava   Java API By Example, From Geeks To Geeks.

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


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

33 package com.icesoft.metadata.generators;
34
35 import com.icesoft.jsfmeta.util.AbstractGenerator;
36 import com.icesoft.jsfmeta.util.FilterComponentBeanProperties;
37 import com.icesoft.jsfmeta.util.InternalConfig;
38 import com.icesoft.jsfmeta.util.JavaSourceWriter;
39 import com.sun.rave.jsfmeta.beans.*;
40 import java.io.*;
41 import java.util.*;
42
43 /*
44  * IDEComponentBeanInfoGenerator generates IDE specific beaninfo
45  *
46  */

47
48 public class IDEComponentBeanInfoGenerator extends AbstractGenerator {
49     
50     
51     protected static final String JavaDoc BUNDLE_VARIABLE_NAME = "resources";
52     
53     protected static final String JavaDoc BUNDLE_GET_MESSAGE_START = "resources.getString(";
54     
55     protected static final String JavaDoc BUNDLE_GET_MESSAGE_END = ")";
56     
57     private boolean base;
58     
59     private String JavaDoc baseBI;
60     
61     private String JavaDoc categoryDescriptors;
62     
63     private String JavaDoc defaultMarkupSection;
64     
65     protected HashMap bundleMaps;
66     
67     private String JavaDoc defaultTaglibPrefix;
68     
69     private String JavaDoc defaultTaglibURI;
70     
71     private String JavaDoc implBD;
72     
73     private String JavaDoc implPD;
74     
75     protected boolean useComponentResourceBundles;
76     
77     public IDEComponentBeanInfoGenerator(InternalConfig internalConfig) {
78         
79         super(internalConfig);
80         base = true;
81         baseBI = internalConfig.getProperty("project.base.beaninfo");
82         categoryDescriptors = internalConfig.getProperty("project.impl.categoryDescriptors");
83         defaultMarkupSection = "FORM";
84         bundleMaps = new HashMap();
85         defaultTaglibPrefix = internalConfig.getProperty("project.taglib.prefix");
86         defaultTaglibURI = internalConfig.getProperty("project.taglib.uri");
87         implBD = internalConfig.getProperty("project.impl.beanDescriptor");
88         implPD = internalConfig.getProperty("project.impl.propertyDescriptor");
89         useComponentResourceBundles = true;
90     }
91     
92     
93     public boolean getBase() {
94         return base;
95     }
96     
97     public void setBase(boolean base) {
98         this.base = base;
99     }
100     
101     public String JavaDoc getBaseBI() {
102         return baseBI;
103     }
104     
105     public void setBaseBI(String JavaDoc baseBI) {
106         this.baseBI = baseBI;
107     }
108     
109     public String JavaDoc getCategoryDescriptors() {
110         return categoryDescriptors;
111     }
112     
113     public void setCategoryDescriptors(String JavaDoc categoryDescriptors) {
114         this.categoryDescriptors = categoryDescriptors;
115     }
116     
117     public String JavaDoc getDefaultMarkupSection() {
118         return defaultMarkupSection;
119     }
120     
121     public void setDefaultMarkupSection(String JavaDoc defaultMarkupSection) {
122         this.defaultMarkupSection = defaultMarkupSection;
123     }
124     
125     protected HashMap getBundleMap(String JavaDoc packageName, String JavaDoc languageCode) {
126         HashMap packageMap = (HashMap) bundleMaps.get(packageName);
127         if (packageMap == null) {
128             packageMap = new HashMap();
129             bundleMaps.put(packageName, packageMap);
130         }
131         HashMap map = (HashMap) packageMap.get(languageCode);
132         if (map == null) {
133             map = new HashMap();
134             packageMap.put(languageCode, map);
135         }
136         return map;
137     }
138     
139     protected HashMap getBundleMaps() {
140         return bundleMaps;
141     }
142     
143     protected void putBundleMap(String JavaDoc packageName, String JavaDoc languageCode,
144             String JavaDoc key, String JavaDoc value) {
145         HashMap map = getBundleMap(packageName, languageCode);
146         map.put(key, value);
147     }
148     
149     public String JavaDoc getDefaultTaglibPrefix() {
150         return defaultTaglibPrefix;
151     }
152     
153     public void setDefaultTaglibPrefix(String JavaDoc defaultTaglibPrefix) {
154         this.defaultTaglibPrefix = defaultTaglibPrefix;
155     }
156     
157     public String JavaDoc getDefaultTaglibURI() {
158         return defaultTaglibURI;
159     }
160     
161     public void setDefaultTaglibURI(String JavaDoc defaultTaglibURI) {
162         this.defaultTaglibURI = defaultTaglibURI;
163     }
164     
165     public String JavaDoc getImplBD() {
166         return implBD;
167     }
168     
169     public void setImplBD(String JavaDoc implBD) {
170         this.implBD = implBD;
171     }
172     
173     public String JavaDoc getImplPD() {
174         return implPD;
175     }
176     
177     public void setImplPD(String JavaDoc implPD) {
178         this.implPD = implPD;
179     }
180     
181     public boolean getUseComponentResourceBundles() {
182         return useComponentResourceBundles;
183     }
184     
185     public void setUseComponentResourceBundles(boolean flag) {
186         useComponentResourceBundles = flag;
187     }
188     
189     public void generate() throws IOException {
190         ComponentBean cbs[] = getConfig().getComponents();
191         for (int i = 0; i < cbs.length; i++)
192             if (generated(cbs[i].getComponentClass()))
193                 generate(cbs[i]);
194         
195         generateComponentResourceBundlesIfNecessary();
196     }
197     
198     protected void generateComponentResourceBundlesIfNecessary()
199     throws IOException {
200         if (!getUseComponentResourceBundles())
201             return;
202         for (Iterator packageKeyIterator = getBundleMaps().keySet().iterator(); packageKeyIterator
203                 .hasNext();) {
204             String JavaDoc packageKey = (String JavaDoc) packageKeyIterator.next();
205             HashMap byLangMap = (HashMap) getBundleMaps().get(packageKey);
206             Iterator langKeyIterator = byLangMap.keySet().iterator();
207             while (langKeyIterator.hasNext()) {
208                 String JavaDoc langKey = (String JavaDoc) langKeyIterator.next();
209                 HashMap stringsByKey = (HashMap) byLangMap.get(langKey);
210                 componentResourceBundle(packageKey, langKey, stringsByKey);
211             }
212         }
213     }
214     
215     private void beanDescriptor(ComponentBean cb, RendererBean rb)
216     throws IOException {
217         
218         String JavaDoc implBD = this.implBD;
219         int period = implBD.lastIndexOf(".");
220         if (period >= 0){
221             implBD = implBD.substring(period + 1);
222         }
223         
224         String JavaDoc packageName = packageName(cb);
225         String JavaDoc simpleClassName = simpleClassName(cb.getComponentClass());
226         JavaSourceWriter writer = getWriter();
227         DisplayNameBean displayName = cb.getDisplayName("");
228         DisplayNameBean displayNames[] = cb.getDisplayNames();
229         DescriptionBean description = cb.getDescription("");
230         DescriptionBean descriptions[] = cb.getDescriptions();
231         writer.startJavaDoc();
232         writer.emitJavaDoc("<p>Return the <code>BeanDescriptor</code> for this bean.</p>");
233         writer.endJavaDoc();
234         writer.startMethod("getBeanDescriptor", "BeanDescriptor", null, null);
235         writer.emitNewline();
236         writer.emitExpression("if (beanDescriptor != null) {", true);
237         writer.indent();
238         writer.emitExpression("return beanDescriptor;", true);
239         writer.outdent();
240         writer.emitExpression("}", true);
241         writer.emitNewline();
242         if (cb.getCustomizerClass() != null) {
243             
244             writer.emitExpression("Class clazz = null;", true);
245             writer.emitExpression("try {", true);
246             writer.indent();
247             writer.emitExpression(
248                     "clazz = this.getClass().getClassLoader().loadClass(\""
249                     + cb.getCustomizerClass() + "\");", true);
250             writer.outdent();
251             writer.emitExpression("} catch (Exception e) {", true);
252             writer.indent();
253             writer.emitExpression("throw new IllegalArgumentException(\""
254                     + cb.getCustomizerClass() + "\");", true);
255             writer.outdent();
256             writer.emitExpression("}", true);
257             writer.emitExpression("beanDescriptor = new " + implBD
258                     + "(beanClass, clazz);", true);
259         } else {
260             writer.emitExpression("beanDescriptor = new " + implBD
261                     + "(beanClass);", true);
262         }
263         displayName(displayName, displayNames, writer, "beanDescriptor",
264                 packageName, simpleClassName, null);
265         shortDescription(description, descriptions, writer, "beanDescriptor",
266                 packageName, simpleClassName, null);
267         writer.emitExpression("beanDescriptor.setExpert(" + cb.isExpert()
268         + ");", true);
269         writer.emitExpression("beanDescriptor.setHidden(" + cb.isHidden()
270         + ");", true);
271         writer.emitExpression("beanDescriptor.setPreferred(" + cb.isPreferred()
272         + ");", true);
273         writer.emitExpression(
274                 "beanDescriptor.setValue(Constants.BeanDescriptor.FACET_DESCRIPTORS,getFacetDescriptors());",
275                 true);
276         if (rb.getComponentHelpKey() != null)
277             writer.emitExpression(
278                     "beanDescriptor.setValue(Constants.BeanDescriptor.HELP_KEY,"
279                     + writer.toJavaString(rb.getComponentHelpKey()
280                     .trim()) + ");", true);
281         String JavaDoc instanceName = rb.getInstanceName();
282         
283         if (instanceName == null){
284             instanceName = simpleInstanceName(cb, rb);
285         }
286         
287         if (instanceName != null){
288             writer.emitExpression(
289                     "beanDescriptor.setValue(Constants.BeanDescriptor.INSTANCE_NAME,"
290                     + writer.toJavaString(instanceName.trim()) + ");",
291                     true);
292         }
293         writer.emitExpression(
294                 "beanDescriptor.setValue(Constants.BeanDescriptor.IS_CONTAINER,"
295                 + (rb.isContainer() ? "Boolean.TRUE" : "Boolean.FALSE")
296                 + ");", true);
297         
298         String JavaDoc markupSection = rb.getMarkupSection();
299         if (markupSection == null){
300             markupSection = getDefaultMarkupSection();
301         }
302         if (markupSection != null){
303             writer.emitExpression(
304                     "beanDescriptor.setValue(Constants.BeanDescriptor.MARKUP_SECTION,"
305                     + writer.toJavaString(markupSection.toLowerCase()
306                     .trim()) + ");", true);
307         }
308         if (rb.getPropertiesHelpKey() != null){
309             writer.emitExpression(
310                     "beanDescriptor.setValue(Constants.BeanDescriptor.PROPERTIES_HELP_KEY,"
311                     + writer.toJavaString(rb.getPropertiesHelpKey()
312                     .trim()) + ");", true);
313         }
314         
315         writer
316                 .emitExpression(
317                 "beanDescriptor.setValue(Constants.BeanDescriptor.PROPERTY_CATEGORIES,getCategoryDescriptors());",
318                 true);
319         
320         if (rb.getResizeConstraints() != null){
321             writer
322                     .emitExpression(
323                     "beanDescriptor.setValue(Constants.BeanDescriptor.RESIZE_CONSTRAINTS,new Integer(Constants.ResizeConstraints."
324                     + rb.getResizeConstraints().toUpperCase()
325                     .trim() + "));", true);
326         }
327         String JavaDoc tagName = rb.getTagName();
328         if (tagName == null && !cb.isNonVisual()){
329             tagName = simpleTagName(cb, rb);
330         }
331         if (tagName != null){
332             writer.emitExpression(
333                     "beanDescriptor.setValue(Constants.BeanDescriptor.TAG_NAME,"
334                     + writer.toJavaString(tagName.trim()) + ");", true);
335         }
336         String JavaDoc taglibPrefix = rb.getTaglibPrefix();
337         if (taglibPrefix == null){
338             taglibPrefix = getDefaultTaglibPrefix();
339         }
340         if (taglibPrefix != null){
341             writer.emitExpression(
342                     "beanDescriptor.setValue(Constants.BeanDescriptor.TAGLIB_PREFIX,"
343                     + writer.toJavaString(taglibPrefix.trim()) + ");",
344                     true);
345         }
346         String JavaDoc taglibURI = rb.getTaglibURI();
347         if (taglibURI == null){
348             taglibURI = getDefaultTaglibURI();
349         }
350         if (taglibURI != null){
351             writer.emitExpression(
352                     "beanDescriptor.setValue(Constants.BeanDescriptor.TAGLIB_URI,"
353                     + writer.toJavaString(taglibURI.trim()) + ");",
354                     true);
355         }
356         if (cb.isNonVisual() || rb.isNonVisual()){
357             writer
358                     .emitExpression(
359                     "beanDescriptor.setValue(Constants.BeanDescriptor.TRAY_COMPONENT,Boolean.TRUE);",
360                     true);
361         }
362         Map namedValues = rb.getNamedValues();
363         String JavaDoc key;
364         String JavaDoc expression;
365         String JavaDoc value;
366         for (Iterator keys = namedValues.keySet().iterator(); keys.hasNext(); writer
367                 .emitExpression("beanDescriptor.setValue("
368                 + writer.toJavaString(key.trim())
369                 + ","
370                 + (expression == null ? writer.toJavaString(value
371                 .trim()) : expression.trim()) + ");", true)) {
372             key = (String JavaDoc) keys.next();
373             NamedValueBean nvb = (NamedValueBean) namedValues.get(key);
374             expression = nvb.getExpression();
375             value = nvb.getValue();
376         }
377         
378         writer.emitNewline();
379         if (raveBaseBI()){
380             writer.emitExpression("annotateBeanDescriptor(beanDescriptor);",
381                     true);
382         }
383         writer.emitExpression("return beanDescriptor;", true);
384         writer.emitNewline();
385         writer.endMethod();
386         writer.emitNewline();
387     }
388     
389     private void body(ComponentBean cb, RendererBean rb) throws IOException {
390         
391         String JavaDoc baseBI = this.baseBI;
392         int period = baseBI.lastIndexOf(".");
393         if (period >= 0){
394             baseBI = baseBI.substring(period + 1);
395         }
396         JavaSourceWriter writer = getWriter();
397         String JavaDoc simple = simpleClassName(cb.getComponentClass());
398         simple = simple + (getBase() ? "BeanInfoBase" : "BeanInfo");
399         writer.startClass(simple, baseBI, null, !getBase(), getBase());
400         writer.emitNewline();
401         if (getUseComponentResourceBundles()) {
402             writer.emitExpression(
403                     "protected static ResourceBundle resources = ResourceBundle.getBundle(\""
404                     + packageName(cb) + ".Bundle-JSF\""
405                     + ", Locale.getDefault(), " + simple
406                     + ".class.getClassLoader());", true);
407             writer.emitNewline();
408         }
409         
410         constructor(cb, rb);
411         instance(cb, rb);
412         beanDescriptor(cb, rb);
413         categoryDescriptors(cb, rb);
414         defaultPropertyIndex(cb, rb);
415         facetDescriptors(cb, rb);
416         icon(cb, rb);
417         loadClass(cb);
418         
419         FilterComponentBeanProperties filter = new FilterComponentBeanProperties();
420         
421         String JavaDoc baseComponentType = cb.getBaseComponentType();
422         if (baseComponentType != null) {
423             ComponentBean bcb = getConfig().getComponent(baseComponentType);
424             filter.filter(bcb);
425         }
426         propertyDescriptors(cb, rb);
427         writer.endClass();
428     }
429     
430     private void loadClass(ComponentBean cb) throws IOException {
431         JavaSourceWriter writer = getWriter();
432         writer.startJavaDoc();
433         writer
434                 .emitJavaDoc("<p>Return a class loaded by name via the class loader that loaded this class.</p>");
435         writer.endJavaDoc();
436         writer.startMethod("loadClass", "java.lang.Class",
437                 new String JavaDoc[] { "java.lang.String" }, new String JavaDoc[] { "name" },
438                 "private");
439         writer.emitNewline();
440         writer.emitExpression("try {", true);
441         writer.indent();
442         writer.emitExpression("return Class.forName(name);", true);
443         writer.outdent();
444         writer.emitExpression("} catch (ClassNotFoundException e) {", true);
445         writer.indent();
446         writer.emitExpression("throw new RuntimeException(e);", true);
447         writer.outdent();
448         writer.emitExpression("}", true);
449         writer.emitNewline();
450         writer.endMethod();
451         writer.emitNewline();
452     }
453     
454     private void categoryDescriptors(ComponentBean cb, RendererBean rb)
455     throws IOException {
456         JavaSourceWriter writer = getWriter();
457         writer.startJavaDoc();
458         writer
459                 .emitJavaDoc("<p>Return the <code>CategoryDescriptor</code> array for the property categories of this component.</p>");
460         writer.endJavaDoc();
461         writer.startMethod("getCategoryDescriptors", "CategoryDescriptor[]",
462                 null, null, "private");
463         writer.emitNewline();
464         if (rb.getPropertyCategories() != null) {
465             writer.emitExpression(
466                     "CategoryDescriptor cds[] = new CategoryDescriptor[] {",
467                     true);
468             writer.indent();
469             String JavaDoc temp = rb.getPropertyCategories().trim();
470             do {
471                 int comma = temp.indexOf(',');
472                 if (comma < 0)
473                     break;
474                 writer.emitExpression(getCategoryDescriptors() + "."
475                         + temp.substring(0, comma).trim().toUpperCase() + ",",
476                         true);
477                 temp = temp.substring(comma + 1);
478             } while (true);
479             writer.emitExpression(getCategoryDescriptors() + "."
480                     + temp.trim().toUpperCase(), true);
481             writer.outdent();
482             writer.emitExpression("};", true);
483             writer.emitExpression("return cds;", true);
484         } else {
485             writer.emitExpression("return " + getCategoryDescriptors()
486             + ".getDefaultCategoryDescriptors();", true);
487         }
488         writer.emitNewline();
489         writer.endMethod();
490         writer.emitNewline();
491     }
492     
493     protected void componentResourceBundle(String JavaDoc packageName, String JavaDoc lang,
494             HashMap map) throws IOException {
495         if (map.size() == 0)
496             return;
497         String JavaDoc filename = packageName;
498         if (filename.length() > 0) {
499             filename = filename.replace('.', File.separatorChar);
500             filename = filename + File.separatorChar;
501         }
502         filename = filename + "Bundle-JSF";
503         if (lang.length() > 0)
504             filename = filename + "_" + lang;
505         filename = filename + ".properties";
506         File file = new File(getDest(), filename);
507         file.mkdirs();
508         file.delete();
509         PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(
510                 file)));
511         char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
512         'A', 'B', 'C', 'D', 'E', 'F' };
513         String JavaDoc specialSaveChars = "=: \t\r\n\f#!";
514         Object JavaDoc keys[] = map.keySet().toArray();
515         Arrays.sort(keys);
516         String JavaDoc lastKeyGroup = null;
517         for (int i = 0; i < keys.length; i++) {
518             String JavaDoc key = (String JavaDoc) keys[i];
519             String JavaDoc value = (String JavaDoc) map.get(key);
520             value = trimWhitespace(value);
521             int index = key.indexOf('_');
522             if (index != -1) {
523                 String JavaDoc keyGroup = key.substring(0, index);
524                 if (lastKeyGroup == null || !lastKeyGroup.equals(keyGroup)) {
525                     if (lastKeyGroup != null)
526                         writer.write(10);
527                     writer.write("# ");
528                     writer.write(keyGroup);
529                     writer.write(10);
530                     lastKeyGroup = keyGroup;
531                 }
532             }
533             writer.write(key);
534             writer.write(61);
535             int len = value.length();
536             for (int x = 0; x < len; x++) {
537                 char aChar = value.charAt(x);
538                 switch (aChar) {
539                     case 32: // ' '
540
writer.write(32);
541                         break;
542                         
543                     case 92: // '\\'
544
writer.write(92);
545                         writer.write(92);
546                         break;
547                         
548                     case 9: // '\t'
549
writer.write(92);
550                         writer.write(116);
551                         break;
552                         
553                     case 10: // '\n'
554
writer.write(92);
555                         writer.write(110);
556                         break;
557                         
558                     case 13: // '\r'
559
writer.write(92);
560                         writer.write(114);
561                         break;
562                         
563                     case 12: // '\f'
564
writer.write(92);
565                         writer.write(102);
566                         break;
567                         
568                     default:
569                         if (aChar < ' ' || aChar > '~') {
570                             writer.write(92);
571                             writer.write(117);
572                             writer.write(hexDigit[aChar >> 12 & 0xf]);
573                             writer.write(hexDigit[aChar >> 8 & 0xf]);
574                             writer.write(hexDigit[aChar >> 4 & 0xf]);
575                             writer.write(hexDigit[aChar & 0xf]);
576                             break;
577                         }
578                         if ("=: \t\r\n\f#!".indexOf(aChar) != -1)
579                             writer.write(92);
580                         writer.write(aChar);
581                         break;
582                 }
583             }
584             
585             writer.write(10);
586         }
587         
588         writer.flush();
589         writer.close();
590     }
591     
592     private void constructor(ComponentBean cb, RendererBean rb)
593     throws IOException {
594         JavaSourceWriter writer = getWriter();
595         String JavaDoc simple = simpleClassName(cb.getComponentClass());
596         writer.startJavaDoc();
597         writer.emitJavaDoc("<p>Construct a new <code>" + simpleClassName(cb)
598         + "</code>.</p>");
599         writer.endJavaDoc();
600         writer.startMethod(simpleClassName(cb), null, null, null);
601         writer.emitNewline();
602         writer.emitExpression("beanClass = " + simple + ".class;", true);
603         if (rb.getDefaultPropertyName() != null)
604             writer.emitExpression("defaultPropertyName = "
605                     + JavaSourceWriter
606                     .toJavaString(rb.getDefaultPropertyName()) + ";",
607                     true);
608         writer.emitExpression("iconFileName_C16 = \"" + simple + "_C16\";",
609                 true);
610         writer.emitExpression("iconFileName_C32 = \"" + simple + "_C32\";",
611                 true);
612         writer.emitExpression("iconFileName_M16 = \"" + simple + "_M16\";",
613                 true);
614         writer.emitExpression("iconFileName_M32 = \"" + simple + "_M32\";",
615                 true);
616         writer.emitNewline();
617         writer.endMethod();
618         writer.emitNewline();
619     }
620     
621     private void defaultPropertyIndex(ComponentBean cb, RendererBean rb)
622     throws IOException {
623         if (raveBaseBI()) {
624             return;
625         } else {
626             JavaSourceWriter writer = getWriter();
627             writer.startJavaDoc();
628             writer
629                     .emitJavaDoc("<p>Return the index of the default property, or");
630             writer.emitJavaDoc("-1 if there is no default property.</p>");
631             writer.endJavaDoc();
632             writer.startMethod("getDefaultPropertyIndex", "int", null, null);
633             writer.emitNewline();
634             writer.emitExpression("if (defaultPropertyIndex > -2) {", true);
635             writer.indent();
636             writer.emitExpression("return defaultPropertyIndex;", true);
637             writer.outdent();
638             writer.emitExpression("} else {", true);
639             writer.indent();
640             writer.emitExpression("if (defaultPropertyName == null) {", true);
641             writer.indent();
642             writer.emitExpression("defaultPropertyIndex = -1;", true);
643             writer.outdent();
644             writer.emitExpression("} else {", true);
645             writer.indent();
646             writer
647                     .emitExpression(
648                     "PropertyDescriptor pd[] = getPropertyDescriptors();",
649                     true);
650             writer
651                     .emitExpression("for (int i = 0; i < pd.length; i++) {",
652                     true);
653             writer.indent();
654             writer.emitExpression(
655                     "if (defaultPropertyName.equals(pd[i].getName())) {", true);
656             writer.indent();
657             writer.emitExpression("defaultPropertyIndex = i;", true);
658             writer.emitExpression("break;", true);
659             writer.outdent();
660             writer.emitExpression("}", true);
661             writer.outdent();
662             writer.emitExpression("}", true);
663             writer.outdent();
664             writer.emitExpression("}", true);
665             writer.outdent();
666             writer.emitExpression("}", true);
667             writer.emitExpression("return defaultPropertyIndex;", true);
668             writer.endMethod();
669             writer.emitNewline();
670             return;
671         }
672     }
673     
674     protected void displayName(DisplayNameBean displayName,
675             DisplayNameBean displayNames[], JavaSourceWriter writer,
676             String JavaDoc variableName, String JavaDoc packageName, String JavaDoc simpleClassName,
677             String JavaDoc propertyName) throws IOException {
678         String JavaDoc key = simpleClassName;
679         if (propertyName != null)
680             key = key + "_" + propertyName;
681         key = key + "_DisplayName";
682         if (displayName != null || getUseComponentResourceBundles())
683             writer.emitExpression(variableName + ".setDisplayName(", false);
684         String JavaDoc displayNameString = displayName != null ? displayName
685                 .getDisplayName().trim() : "";
686         if (getUseComponentResourceBundles()) {
687             writer.emitExpressionPart("resources.getString(");
688             putBundleMap(packageName, "", key, displayNameString);
689             writer.emitJavaString(key);
690             writer.emitExpressionPart(")");
691         } else if (displayName != null)
692             writer.emitJavaString(displayNameString);
693         if (displayName != null || getUseComponentResourceBundles()) {
694             writer.emitExpressionPart(");");
695             writer.emitNewline();
696         }
697         for (int i = 0; i < displayNames.length; i++) {
698             String JavaDoc lang = displayNames[i].getLang();
699             if ("".equals(lang))
700                 continue;
701             displayNameString = displayNames[i].getDisplayName().trim();
702             if (getUseComponentResourceBundles())
703                 putBundleMap(packageName, lang, key, displayNameString);
704             else
705                 writer.emitExpression(variableName + ".setValue("
706                         + writer.toJavaString("displayName." + lang) + ","
707                         + writer.toJavaString(displayNameString) + ");", true);
708         }
709         
710     }
711     
712     private void facetDescriptor(ComponentBean cb, RendererBean rb, FacetBean fb)
713     throws IOException {
714         JavaSourceWriter writer = getWriter();
715         DisplayNameBean displayName = fb.getDisplayName("");
716         DisplayNameBean displayNames[] = fb.getDisplayNames();
717         DescriptionBean description = fb.getDescription("");
718         DescriptionBean descriptions[] = fb.getDescriptions();
719         String JavaDoc name = fb.getFacetName();
720         StringBuffer JavaDoc fsb = new StringBuffer JavaDoc("FacetDescriptor facet_");
721         fsb.append(name);
722         fsb.append(" = new FacetDescriptor(");
723         fsb.append(writer.toJavaString(name));
724         fsb.append(");");
725         writer.emitExpression(fsb.toString(), true);
726         String JavaDoc packageName = packageName(cb);
727         String JavaDoc simpleClassName = simpleClassName(cb.getComponentClass());
728         displayName(displayName, displayNames, writer, "facet_" + name,
729                 packageName, simpleClassName, name);
730         shortDescription(description, descriptions, writer, "facet_" + name,
731                 packageName, simpleClassName, name);
732         Map namedValues = fb.getNamedValues();
733         String JavaDoc key;
734         String JavaDoc expression;
735         String JavaDoc value;
736         for (Iterator keys = namedValues.keySet().iterator(); keys.hasNext(); genericNamedValue(
737                 key, value, expression, writer, "facet_" + name, packageName,
738                 simpleClassName, name)) {
739             key = (String JavaDoc) keys.next();
740             NamedValueBean nvb = (NamedValueBean) namedValues.get(key);
741             expression = nvb.getExpression();
742             value = nvb.getValue();
743         }
744         
745         writer.emitNewline();
746     }
747     
748     private void facetDescriptors(ComponentBean cb, RendererBean rb)
749     throws IOException {
750         JavaSourceWriter writer = getWriter();
751         TreeMap map = new TreeMap();
752         writer.startJavaDoc();
753         writer.emitJavaDoc("<p>The cached facet descriptors.</p>");
754         writer.endJavaDoc();
755         writer.emitExpression("protected FacetDescriptor[] facetDescriptors;",
756                 true);
757         writer.emitNewline();
758         writer.startJavaDoc();
759         writer
760                 .emitJavaDoc("<p>Return the <code>FacetDescriptor</code>s for this bean.</p>");
761         writer.endJavaDoc();
762         writer.startMethod("getFacetDescriptors", "FacetDescriptor[]", null,
763                 null);
764         writer.emitNewline();
765         writer.emitExpression("if (facetDescriptors != null) {", true);
766         writer.indent();
767         writer.emitExpression("return facetDescriptors;", true);
768         writer.outdent();
769         writer.emitExpression("}", true);
770         FacetBean facets[] = facets(cb, rb);
771         if (facets.length > 0) {
772             writer.emitExpression("try {", true);
773             writer.emitNewline();
774             writer.indent();
775         }
776         for (int i = 0; i < facets.length; i++) {
777             FacetBean facet = facets[i];
778             facetDescriptor(cb, rb, facet);
779             map.put(facet.getFacetName(), facet);
780         }
781         
782         writer.emitExpression("facetDescriptors = new FacetDescriptor[] {",
783                 true);
784         writer.indent();
785         String JavaDoc facetName;
786         for (Iterator facetNames = map.keySet().iterator(); facetNames
787                 .hasNext(); writer.emitExpression("facet_" + facetName + ",",
788                 true))
789             facetName = (String JavaDoc) facetNames.next();
790         
791         writer.outdent();
792         writer.emitExpression("};", true);
793         writer.emitExpression("return facetDescriptors;", true);
794         writer.emitNewline();
795         if (facets.length > 0) {
796             writer.outdent();
797             writer.emitExpression("} catch (RuntimeException e) {", true);
798             writer.indent();
799             writer.emitExpression("System.out.println(e.getMessage());", true);
800             writer.emitExpression("e.printStackTrace(System.out);", true);
801             writer.emitExpression("throw e;", true);
802             writer.outdent();
803             writer.emitExpression("}", true);
804             writer.emitNewline();
805         }
806         writer.endMethod();
807         writer.emitNewline();
808     }
809     
810     private void generate(ComponentBean cb) throws IOException {
811
812         if(cb.getComponentClass().startsWith("javax.faces.component.")){
813             return;
814         }
815         if (cb.isSuppressed())
816             return;
817         RendererBean rb = renderer(cb);
818         if (rb == null)
819             rb = new RendererBean();
820         File outputFile = outputFile(cb.getComponentClass()
821         + (getBase() ? "BeanInfoBase" : "BeanInfo"));
822         outputFile.mkdirs();
823         outputFile.delete();
824         try{
825             getWriter().setOutputWriter(
826                     new BufferedWriter(new FileWriter(outputFile)));
827         }catch(Exception JavaDoc e){
828             e.printStackTrace();
829         }
830         license(cb, rb);
831         header(cb, rb);
832         body(cb, rb);
833         getWriter().flush();
834         getWriter().close();
835     }
836     
837     private void header(ComponentBean cb, RendererBean rb) throws IOException {
838         JavaSourceWriter writer = getWriter();
839         String JavaDoc packageName = packageName(cb);
840         if (packageName.length() > 0) {
841             writer.emitPackage(packageName);
842             writer.emitNewline();
843         }
844         writer.emitImport("java.awt.Image");
845         writer.emitImport("java.beans.BeanDescriptor");
846         writer.emitImport("java.beans.BeanInfo");
847         writer.emitImport("java.beans.IntrospectionException");
848         writer.emitImport("java.beans.PropertyDescriptor");
849         writer.emitImport("java.util.Locale");
850         writer.emitImport("java.util.ResourceBundle");
851         writer.emitNewline();
852         writer.emitImport("com.sun.rave.designtime.CategoryDescriptor");
853         writer.emitImport("com.sun.rave.designtime.Constants");
854         writer.emitImport("com.sun.rave.designtime.faces.FacetDescriptor");
855         writer.emitImport("com.sun.rave.designtime.markup.AttributeDescriptor");
856         writer.emitNewline();
857         writer.emitImport(baseBI);
858         if (!"java.beans.BeanDescriptor".equals(implBD))
859             writer.emitImport(implBD);
860         if (!"java.beans.PropertyDescriptor".equals(implPD))
861             writer.emitImport(implPD);
862         writer.emitNewline();
863         writer.startJavaDoc();
864         writer.emitJavaDoc("<p>Auto-generated design time metadata class.");
865         writer.emitJavaDoc("Do <strong>NOT</strong> modify; all changes");
866         writer.emitJavaDoc("<strong>will</strong> be lost!</p>");
867         writer.endJavaDoc();
868         writer.emitNewline();
869     }
870     
871     protected void genericNamedValue(String JavaDoc valueName, String JavaDoc value,
872             String JavaDoc expression, JavaSourceWriter writer, String JavaDoc variableName,
873             String JavaDoc packageName, String JavaDoc simpleClassName, String JavaDoc propertyName)
874             throws IOException {
875         boolean inBundle = false;
876         if (getUseComponentResourceBundles() && value != null
877                 && expression == null && "instructions".equals(valueName))
878             inBundle = true;
879         writer.emitExpression(variableName, false);
880         valueName = valueName.trim();
881         writer.emitExpressionPart(".setValue(");
882         writer.emitJavaString(valueName);
883         writer.emitExpressionPart(", ");
884         if (inBundle) {
885             String JavaDoc key = simpleClassName;
886             if (propertyName != null)
887                 key = key + "_" + propertyName;
888             key = key + "_" + valueName;
889             putBundleMap(packageName, "", key, value);
890             writer.emitExpressionPart("resources.getString(");
891             writer.emitJavaString(key);
892             writer.emitExpressionPart(")");
893         } else if (expression == null)
894             writer.emitJavaString(value.trim());
895         else
896             writer.emitExpressionPart(expression.trim());
897         writer.emitExpressionPart(");");
898         writer.emitNewline();
899     }
900     
901     private void icon(ComponentBean cb, RendererBean rb) throws IOException {
902         if (raveBaseBI()) {
903             return;
904         } else {
905             JavaSourceWriter writer = getWriter();
906             writer.startJavaDoc();
907             writer.emitJavaDoc("<p>Return the specified image (if any)");
908             writer.emitJavaDoc("for this component class.</p>");
909             writer.endJavaDoc();
910             writer.startMethod("getIcon", "Image", new String JavaDoc[] { "int" },
911                     new String JavaDoc[] { "kind" });
912             writer.emitNewline();
913             writer.emitExpression("String name;", true);
914             writer.emitExpression("switch (kind) {", true);
915             writer.indent();
916             writer.emitExpression("case ICON_COLOR_16x16:", true);
917             writer.indent();
918             writer.emitExpression("name = iconFileName_C16;", true);
919             writer.emitExpression("break;", true);
920             writer.outdent();
921             writer.emitExpression("case ICON_COLOR_32x32:", true);
922             writer.indent();
923             writer.emitExpression("name = iconFileName_C32;", true);
924             writer.emitExpression("break;", true);
925             writer.outdent();
926             writer.emitExpression("case ICON_MONO_16x16:", true);
927             writer.indent();
928             writer.emitExpression("name = iconFileName_M16;", true);
929             writer.emitExpression("break;", true);
930             writer.outdent();
931             writer.emitExpression("case ICON_MONO_32x32:", true);
932             writer.indent();
933             writer.emitExpression("name = iconFileName_M32;", true);
934             writer.emitExpression("break;", true);
935             writer.outdent();
936             writer.emitExpression("default:", true);
937             writer.indent();
938             writer.emitExpression("name = null;", true);
939             writer.emitExpression("break;", true);
940             writer.outdent();
941             writer.outdent();
942             writer.emitExpression("}", true);
943             writer.emitExpression("if (name == null) {", true);
944             writer.indent();
945             writer.emitExpression("return null;", true);
946             writer.outdent();
947             writer.emitExpression("}", true);
948             writer.emitNewline();
949             writer.emitExpression("Image image = loadImage(name + \".png\");",
950                     true);
951             writer.emitExpression("if (image == null) {", true);
952             writer.indent();
953             writer.emitExpression("image = loadImage(name + \".gif\");", true);
954             writer.outdent();
955             writer.emitExpression("}", true);
956             writer.emitExpression("return image;", true);
957             writer.emitNewline();
958             writer.endMethod();
959             writer.emitNewline();
960             return;
961         }
962     }
963     
964     private void instance(ComponentBean cb, RendererBean rb) throws IOException {
965         if (raveBaseBI()) {
966             return;
967         } else {
968             JavaSourceWriter writer = getWriter();
969             writer.startJavaDoc();
970             writer
971                     .emitJavaDoc("<p>The bean class that this BeanInfo represents.");
972             writer.endJavaDoc();
973             writer.emitExpression("protected Class beanClass;", true);
974             writer.emitNewline();
975             writer.startJavaDoc();
976             writer.emitJavaDoc("<p>The cached BeanDescriptor.</p>");
977             writer.endJavaDoc();
978             writer.emitExpression("protected BeanDescriptor beanDescriptor;",
979                     true);
980             writer.emitNewline();
981             writer.startJavaDoc();
982             writer.emitJavaDoc("<p>The index of the default property.</p>");
983             writer.endJavaDoc();
984             writer.emitExpression("protected int defaultPropertyIndex = -2;",
985                     true);
986             writer.emitNewline();
987             writer.startJavaDoc();
988             writer.emitJavaDoc("<p>The name of the default property.</p>");
989             writer.endJavaDoc();
990             writer
991                     .emitExpression("protected String defaultPropertyName;",
992                     true);
993             writer.emitNewline();
994             writer.startJavaDoc();
995             writer.emitJavaDoc("<p>The 16x16 color icon.</p>");
996             writer.endJavaDoc();
997             writer.emitExpression("protected String iconFileName_C16;", true);
998             writer.emitNewline();
999             writer.startJavaDoc();
1000            writer.emitJavaDoc("<p>The 32x32 color icon.</p>");
1001            writer.endJavaDoc();
1002            writer.emitExpression("protected String iconFileName_C32;", true);
1003            writer.emitNewline();
1004            writer.startJavaDoc();
1005            writer.emitJavaDoc("<p>The 16x16 monochrome icon.</p>");
1006            writer.endJavaDoc();
1007            writer.emitExpression("protected String iconFileName_M16;", true);
1008            writer.emitNewline();
1009            writer.startJavaDoc();
1010            writer.emitJavaDoc("<p>The 32x32 monochrome icon.</p>");
1011            writer.endJavaDoc();
1012            writer.emitExpression("protected String iconFileName_M32;", true);
1013            writer.emitNewline();
1014            writer.startJavaDoc();
1015            writer.emitJavaDoc("<p>The cached property descriptors.</p>");
1016            writer.endJavaDoc();
1017            writer.emitExpression(
1018                    "protected PropertyDescriptor[] propDescriptors;", true);
1019            writer.emitNewline();
1020            return;
1021        }
1022    }
1023    
1024    private void license(ComponentBean componentbean, RendererBean rendererbean)
1025    throws IOException {
1026    }
1027    
1028    private String JavaDoc packageName(ComponentBean cb) {
1029        String JavaDoc componentClass = cb.getComponentClass();
1030        int last = componentClass.lastIndexOf('.');
1031        if (last >= 0)
1032            return componentClass.substring(0, last);
1033        else
1034            return "";
1035    }
1036    
1037    private void propertyDescriptor(ComponentBean cb, RendererBean rb,
1038            PropertyBean pb, ComponentBean componentBeanBeingGenerated)
1039            throws IOException {
1040        String JavaDoc implPD = this.implPD;
1041        int period = implPD.lastIndexOf(".");
1042        if (period >= 0)
1043            implPD = implPD.substring(period + 1);
1044        JavaSourceWriter writer = getWriter();
1045        DisplayNameBean displayName = pb.getDisplayName("");
1046        DisplayNameBean displayNames[] = pb.getDisplayNames();
1047        DescriptionBean description = pb.getShortDescription("");
1048        if (description == null)
1049            description = pb.getDescription("");
1050        DescriptionBean descriptions[] = pb.getShortDescriptions();
1051        if (descriptions == null)
1052            descriptions = pb.getDescriptions();
1053        String JavaDoc name = pb.getPropertyName();
1054        String JavaDoc readMethod = pb.getReadMethod();
1055        if (pb.isWriteOnly())
1056            readMethod = null;
1057        else if (readMethod == null)
1058            if ("boolean".equals(pb.getPropertyClass()))
1059                readMethod = "is" + Character.toUpperCase(name.charAt(0))
1060                + name.substring(1);
1061            else
1062                readMethod = "get" + Character.toUpperCase(name.charAt(0))
1063                + name.substring(1);
1064        String JavaDoc writeMethod = pb.getWriteMethod();
1065        if (pb.isReadOnly())
1066            writeMethod = null;
1067        else if (writeMethod == null)
1068            writeMethod = "set" + Character.toUpperCase(name.charAt(0))
1069            + name.substring(1);
1070        StringBuffer JavaDoc psb = new StringBuffer JavaDoc("PropertyDescriptor prop_");
1071        psb.append(name);
1072        psb.append(" = new ");
1073        psb.append(implPD);
1074        psb.append("(");
1075        psb.append(writer.toJavaString(name));
1076        psb.append(",beanClass,");
1077        psb.append(readMethod != null ? writer.toJavaString(readMethod)
1078        : "null");
1079        psb.append(",");
1080        psb.append(writeMethod != null ? writer.toJavaString(writeMethod)
1081        : "null");
1082        psb.append(");");
1083        writer.emitExpression(psb.toString(), true);
1084        String JavaDoc packageName = packageName(componentBeanBeingGenerated);
1085        String JavaDoc simpleClassName = simpleClassName(componentBeanBeingGenerated
1086                .getComponentClass());
1087        displayName(displayName, displayNames, writer, "prop_" + name,
1088                packageName, simpleClassName, name);
1089        shortDescription(description, descriptions, writer, "prop_" + name,
1090                packageName, simpleClassName, name);
1091        if (pb.getEditorClass() != null)
1092            writer.emitExpression("prop_" + name + ".setPropertyEditorClass("
1093                    + "loadClass(\"" + pb.getEditorClass().trim() + "\"));",
1094                    true);
1095        writer.emitExpression("prop_" + name + ".setExpert(" + pb.isExpert()
1096        + ");", true);
1097        writer.emitExpression("prop_" + name + ".setHidden(" + pb.isHidden()
1098        + ");", true);
1099        writer.emitExpression("prop_" + name + ".setPreferred("
1100                + pb.isPreferred() + ");", true);
1101        if (pb.isTagAttribute()) {
1102            StringBuffer JavaDoc asb = new StringBuffer JavaDoc(
1103                    "attrib = new AttributeDescriptor(");
1104            String JavaDoc attributeName = pb.getAttributeAlias();
1105            if (attributeName == null)
1106                attributeName = name;
1107            asb.append(writer.toJavaString(attributeName));
1108            asb.append(",");
1109            asb.append(pb.isRequired());
1110            asb.append(",");
1111            if (pb.getDefaultValue() != null)
1112                asb.append(writer.toJavaString(pb.getDefaultValue()));
1113            else
1114                asb.append("null");
1115            asb.append(",");
1116            asb.append(pb.isBindable());
1117            asb.append(");");
1118            writer.emitExpression(asb.toString(), true);
1119            writer.emitExpression("prop_" + name + ".setValue("
1120                    + "Constants.PropertyDescriptor.ATTRIBUTE_DESCRIPTOR,"
1121                    + "attrib);", true);
1122        }
1123        String JavaDoc category = pb.getCategory();
1124        if (category == null)
1125            category = "GENERAL";
1126        writer.emitExpression("prop_" + name + ".setValue("
1127                + "Constants.PropertyDescriptor.CATEGORY,"
1128                + getCategoryDescriptors() + "."
1129                + category.toUpperCase().trim() + ");", true);
1130        if (pb.getHelpKey() != null)
1131            writer.emitExpression("prop_" + name + ".setValue("
1132                    + "Constants.PropertyDescriptor.HELP_KEY,"
1133                    + writer.toJavaString(pb.getHelpKey().trim()) + ");", true);
1134        Map namedValues = pb.getNamedValues();
1135        String JavaDoc key;
1136        String JavaDoc expression;
1137        String JavaDoc value;
1138        for (Iterator keys = namedValues.keySet().iterator(); keys.hasNext(); genericNamedValue(
1139                key, value, expression, writer, "prop_" + name, packageName,
1140                simpleClassName, name)) {
1141            key = (String JavaDoc) keys.next();
1142            NamedValueBean nvb = (NamedValueBean) namedValues.get(key);
1143            expression = nvb.getExpression();
1144            value = nvb.getValue();
1145        }
1146        
1147        writer.emitNewline();
1148    }
1149    
1150    private void propertyDescriptors(ComponentBean cb, RendererBean rb)
1151    throws IOException {
1152        JavaSourceWriter writer = getWriter();
1153        TreeMap map = new TreeMap();
1154        writer.startJavaDoc();
1155        writer
1156                .emitJavaDoc("<p>Return the <code>PropertyDescriptor</code>s for this bean.</p>");
1157        writer.endJavaDoc();
1158        writer.startMethod("getPropertyDescriptors", "PropertyDescriptor[]",
1159                null, null);
1160        writer.emitNewline();
1161        writer.emitExpression("if (propDescriptors != null) {", true);
1162        writer.indent();
1163        writer.emitExpression("return propDescriptors;", true);
1164        writer.outdent();
1165        writer.emitExpression("}", true);
1166        writer.emitExpression("AttributeDescriptor attrib = null;", true);
1167        writer.emitNewline();
1168        writer.emitExpression("try {", true);
1169        writer.emitNewline();
1170        writer.indent();
1171        propertyDescriptors(cb, rb, ((Map) (map)), cb);
1172        writer.emitExpression("propDescriptors = new PropertyDescriptor[] {",
1173                true);
1174        writer.indent();
1175        String JavaDoc prop;
1176        for (Iterator props = map.keySet().iterator(); props.hasNext(); writer
1177                .emitExpression("prop_" + prop + ",", true))
1178            prop = (String JavaDoc) props.next();
1179        
1180        writer.outdent();
1181        writer.emitExpression("};", true);
1182        if (raveBaseBI())
1183            writer.emitExpression(
1184                    "annotatePropertyDescriptors(propDescriptors);", true);
1185        writer.emitExpression("return propDescriptors;", true);
1186        writer.emitNewline();
1187        writer.outdent();
1188        writer.emitExpression("} catch (IntrospectionException e) {", true);
1189        writer.indent();
1190        writer.emitExpression("e.printStackTrace();", true);
1191        writer.emitExpression("return null;", true);
1192        writer.outdent();
1193        writer.emitExpression("}", true);
1194        writer.emitNewline();
1195        writer.endMethod();
1196        writer.emitNewline();
1197    }
1198    
1199    private void propertyDescriptors(ComponentBean cb, RendererBean rb,
1200            Map map, ComponentBean componentBeanBeingGenerated)
1201            throws IOException {
1202        PropertyBean pbs[] = cb.getProperties();
1203        for (int i = 0; i < pbs.length; i++) {
1204            if (map.containsKey(pbs[i].getPropertyName())
1205            || "valid".equals(pbs[i].getPropertyName()))
1206                continue;
1207            PropertyBean pb = merge(pbs[i], rb.getAttribute(pbs[i]
1208                    .getPropertyName()));
1209            if (!pb.isSuppressed()) {
1210                propertyDescriptor(cb, rb, pb, componentBeanBeingGenerated);
1211                map.put(pb.getPropertyName(), null);
1212            }
1213        }
1214        
1215        String JavaDoc baseComponentType = cb.getBaseComponentType();
1216        if (baseComponentType != null) {
1217            ComponentBean bcb = getConfig().getComponent(baseComponentType);
1218            propertyDescriptors(bcb, rb, map, componentBeanBeingGenerated);
1219        }
1220    }
1221    
1222    protected boolean raveBaseBI() {
1223        return "com.sun.jsfcl.std.HtmlBeanInfoBase".equals(baseBI);
1224    }
1225    
1226    protected void shortDescription(DescriptionBean description,
1227            DescriptionBean descriptions[], JavaSourceWriter writer,
1228            String JavaDoc variableName, String JavaDoc packageName, String JavaDoc simpleClassName,
1229            String JavaDoc propertyName) throws IOException {
1230        String JavaDoc key = simpleClassName;
1231        if (propertyName != null)
1232            key = key + "_" + propertyName;
1233        key = key + "_Description";
1234        if (description != null || getUseComponentResourceBundles()) {
1235            writer.emitExpression(variableName, false);
1236            writer.emitExpressionPart(".setShortDescription(");
1237        }
1238        String JavaDoc descriptionString = description != null ? description
1239                .getDescription().trim() : "";
1240        if (getUseComponentResourceBundles()) {
1241            putBundleMap(packageName, "", key, descriptionString);
1242            writer.emitExpressionPart("resources.getString(");
1243            writer.emitJavaString(key);
1244            writer.emitExpressionPart(")");
1245        } else if (description != null)
1246            writer.emitJavaString(descriptionString);
1247        if (description != null || getUseComponentResourceBundles()) {
1248            writer.emitExpressionPart(");");
1249            writer.emitNewline();
1250        }
1251        for (int i = 0; i < descriptions.length; i++) {
1252            String JavaDoc lang = descriptions[i].getLang();
1253            if ("".equals(lang))
1254                continue;
1255            descriptionString = descriptions[i].getDescription();
1256            if (getUseComponentResourceBundles())
1257                putBundleMap(packageName, lang, key, descriptionString);
1258            else
1259                writer.emitExpression(variableName + ".setValue("
1260                        + writer.toJavaString("description." + lang) + ","
1261                        + writer.toJavaString(descriptionString) + ");", true);
1262        }
1263        
1264    }
1265    
1266    private String JavaDoc simpleClassName(ComponentBean cb) {
1267        return simpleClassName(cb.getComponentClass())
1268        + (getBase() ? "BeanInfoBase" : "BeanInfo");
1269    }
1270    
1271    private String JavaDoc simpleInstanceName(ComponentBean cb, RendererBean rb) {
1272        String JavaDoc cname = cb.getComponentType();
1273        int period = cname.lastIndexOf('.');
1274        if (period >= 0)
1275            cname = cname.substring(period + 1);
1276        String JavaDoc rname = rb.getRendererType();
1277        if (rname == null){
1278            rname = "";
1279        }
1280        period = rname.lastIndexOf('.');
1281        if (period >= 0)
1282            rname = rname.substring(period + 1);
1283        if (cname.equalsIgnoreCase(rname) || rname.length() < 1){
1284            return Character.toLowerCase(cname.charAt(0)) + cname.substring(1);
1285        }else{
1286            return Character.toLowerCase(cname.charAt(0)) + cname.substring(1)
1287            + Character.toUpperCase(rname.charAt(0))
1288            + rname.substring(1);
1289        }
1290    }
1291    
1292    private String JavaDoc simpleTagName(ComponentBean cb, RendererBean rb) {
1293        String JavaDoc cname = cb.getComponentType();
1294        int period = cname.lastIndexOf('.');
1295        if (period >= 0)
1296            cname = cname.substring(period + 1);
1297        String JavaDoc rname = rb.getRendererType();
1298        if (rname == null)
1299            rname = "";
1300        period = rname.lastIndexOf('.');
1301        if (period >= 0)
1302            rname = rname.substring(period + 1);
1303        if (cname.equalsIgnoreCase(rname) || rname.length() < 1){
1304            return Character.toLowerCase(cname.charAt(0)) + cname.substring(1);
1305        }else{
1306            return Character.toLowerCase(cname.charAt(0)) + cname.substring(1)
1307            + Character.toUpperCase(rname.charAt(0))
1308            + rname.substring(1);
1309        }
1310    }
1311    
1312    protected String JavaDoc trimWhitespace(String JavaDoc string) {
1313        
1314        StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(string.length());
1315        boolean eatingWhite = true;
1316        for (int i = 0; i < string.length(); i++) {
1317            char c = string.charAt(i);
1318            if (eatingWhite) {
1319                if (Character.isWhitespace(c))
1320                    continue;
1321                eatingWhite = false;
1322            }
1323            if (Character.isWhitespace(c)) {
1324                buffer.append(" ");
1325                eatingWhite = true;
1326            } else {
1327                buffer.append(c);
1328            }
1329        }
1330        
1331        return buffer.toString();
1332    }
1333    
1334}
1335
Popular Tags