KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > schema2beansdev > BeanClass


1 /*
2  * Sun Public License Notice
3  *
4  * The contents of this file are subject to the Sun Public License
5  * Version 1.0 (the "License"). You may not use this file except in
6  * compliance with the License. A copy of the License is available at
7  * http://www.sun.com/
8  *
9  * The Original Code is NetBeans. The Initial Developer of the Original
10  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11  * Microsystems, Inc. All Rights Reserved.
12  */

13
14 package org.netbeans.modules.schema2beansdev;
15
16 import java.util.*;
17 import java.io.*;
18
19 import org.netbeans.modules.schema2beans.*;
20 import org.netbeans.modules.schema2beansdev.metadd.*;
21 import org.netbeans.modules.schema2beansdev.gen.*;
22
23 //******************************************************************************
24
// BEGIN_NOI18N
25
//******************************************************************************
26

27 /**
28  * This class generates the bean classes code. There is one instance of
29  * this class per bean to generate.
30  *
31  * The BeanBuilder creates one instance of the BeanClass class for every
32  * bean class to generate, and for each of these instances,
33  * the BeanBuilder calls the addPropertyMethod() in order to populate the
34  * list of properties contained by the bean. Then it calls the process()
35  * method, which makes the class to generate its java output into
36  * the output stream specified in the process parameter.
37  *
38  * The BeanBuilder might give an optional MetaDD bean graph which contains
39  * extra information that didn't exist in the dtd. The content of this graph
40  * is used to generate extra information about the properties of the bean
41  * (for example the default values, well known values, wrapper class)
42  */

43 public class BeanClass extends AbstractCodeGeneratorClass implements CodeGeneratorClass {
44     private boolean isVetoable;
45     private boolean genVetoListeners;
46     private boolean genGenericVetoListeners;
47     static HashMap listOfTags = new HashMap(); // SRIDATTA
48

49     protected int GET_DEFAULT_ATTR_GENERIC_SECTION = BODY_SECTION;
50     protected int GET_DEFAULT_ATTR_SECTION = ACCESS_SECTION;
51  
52     //NOTE_SRIDATTA
53
//1. the list of pks
54
//2. servertags
55
//3. package name changes
56
//END NOTE
57
//SRIDATTA
58
//which tag file
59
static String JavaDoc stags = null;
60         static Properties listOfPKs = new Properties();
61         //static Properties s2bInfo = new Properties();
62
static {
63         try {
64         // System.out.println("Loding s2bInfo");
65
// FileInputStream is = new FileInputStream(System.getProperty("s2binfo"));
66
// s2bInfo.load(is);
67
// System.out.println("Loding s2bInfo" + s2bInfo) ;
68
System.out.println("listofpks dir=" + System.getProperty("listofpks"));
69         FileInputStream is2 = new FileInputStream(System.getProperty("listofpks"));
70         listOfPKs.load(is2);
71         System.out.println("Loading listofPks" + listOfPKs);
72         } catch(Exception JavaDoc e){}
73         stags = System.getProperty("servertagname");
74         if(stags == null) stags = "ServerTags";
75     }
76
77     private String JavaDoc tagFile = stags + ".";
78     
79     BeanClass(BeanBuilder.BeanElement be, GenBeans.Config config) {
80         init(be, config);
81         addExtraMethods();
82     }
83     
84     void setBeanName(String JavaDoc n) {
85         this.className = n;
86     }
87     
88     private void genVetoBegin() {
89         gencr("try"); begin();
90     }
91     
92     private void genVetoEnd() {
93         end();
94         gencr("catch(BaseProperty.VetoException ve)");
95         begin();
96         gen("throw ve.getPropertyVetoException()"); eol();
97         end();
98     }
99     
100     // SRIDATTA
101
String JavaDoc getPK(String JavaDoc ss){
102         //System.out.println("PK for" + ss + " " + Common.convertName(ss));
103
//for (int i=0; i<this.primaryKeys.length; i++){
104
// System.out.println("=================================");
105
// System.out.println("listofpks=" + listOfPKs);
106
// System.out.println("=================================");
107
//String p = listOfPKs.getProperty(ss);
108
String JavaDoc p = null;
109              
110              for(Enumeration e = listOfPKs.propertyNames(); e.hasMoreElements();){
111                  String JavaDoc s = (String JavaDoc) e.nextElement();
112                  if(ss.equalsIgnoreCase(Common.convertName(s))) {
113                      p = listOfPKs.getProperty(s);
114                      break;
115                  }
116              }
117           // if (ss.equalsIgnoreCase(Common.convertName(p)))
118
// return primaryKeys[i][1];
119

120         //}
121

122              System.out.println("PK for " + ss + "is " + p);
123         if("".equals(p)) return null;
124         return p;
125     }
126     
127     static final String JavaDoc VCL_FULL_CLASS_NAME = "java.beans.VetoableChangeListener";
128     static final String JavaDoc VCL = "VetoableChangeListener";
129     static final String JavaDoc PCL_FULL_CLASS_NAME = "java.beans.PropertyChangeListener";
130     static final String JavaDoc PCL = "PropertyChangeListener";
131     
132     /**
133      * Generate the different parts of the class
134      */

135     void genHeader(int out) {
136     select(out);
137     gencr("/*");
138     gencr(" * The contents of this file are subject to the terms ");
139     gencr(" * of the Common Development and Distribution License ");
140     gencr(" * (the License). You may not use this file except in");
141     gencr(" * compliance with the License.");
142     gencr(" * ");
143     gencr(" * You can obtain a copy of the license at ");
144     gencr(" * https://glassfish.dev.java.net/public/CDDLv1.0.html or");
145     gencr(" * glassfish/bootstrap/legal/CDDLv1.0.txt.");
146     gencr(" * See the License for the specific language governing ");
147     gencr(" * permissions and limitations under the License.");
148     gencr(" * ");
149     gencr(" * When distributing Covered Code, include this CDDL ");
150     gencr(" * Header Notice in each file and include the License file ");
151     gencr(" * at glassfish/bootstrap/legal/CDDLv1.0.txt. ");
152     gencr(" * If applicable, add the following below the CDDL Header, ");
153     gencr(" * with the fields enclosed by brackets [] replaced by");
154     gencr(" * you own identifying information: ");
155     gencr(" * \"Portions Copyrighted [year] [name of copyright owner]\"");
156     gencr(" * ");
157     gencr(" * Copyright 2006 Sun Microsystems, Inc. All rights reserved.");
158     gencr(" */");
159     gencr(" ");
160  
161     gencr("/**");
162     gencr(" * This generated bean class " + this.className +
163     " matches the DTD element " + this.beanElement.node.getName());
164     gencr(" *");
165     gencr(" */"); cr();
166     }
167     void genPackage(int out) {
168         select(out);
169         if (this.packageName != null) {
170             gen(PACKAGE, this.packageName);
171             eol();
172             cr();
173         }
174     }
175     
176     void genImports(int out) {
177     select(out);
178     gen(IMPORT, "org.w3c.dom.*"); eol();
179     gen(IMPORT, "org.netbeans.modules.schema2beans.*"); eol();
180     gen(IMPORT, "java.beans.*"); eol();
181     gen(IMPORT, "java.util.*"); eol();
182     //if (!this.config.isStandalone()) {
183
// gen(IMPORT, "org.openide.util.NbBundle"); eol();
184
//}
185
if (this.beanElement.isRoot) {
186         gen(IMPORT, "java.io.*"); eol();
187     }
188     
189     //SRIDATTA-RI
190
gencr("import java.io.Serializable;");
191     //gencr("import com.iplanet.ias.config.ConfigBean;");
192
//gencr("import com.iplanet.ias.config.ConfigException;");
193
//gencr("import com.iplanet.ias.config.StaleWriteConfigException;");
194

195     gencr("import com.sun.enterprise.config.ConfigBean;");
196     gencr("import com.sun.enterprise.config.ConfigException;");
197     gencr("import com.sun.enterprise.config.StaleWriteConfigException;");
198     gencr("import com.sun.enterprise.util.i18n.StringManager;");
199     
200     String JavaDoc[] imps = null;
201     if (this.mdd != null) {
202         if (this.metaElement != null)
203         imps = this.metaElement.getImport();
204         
205         if (imps == null || imps.length==0)
206         imps = this.mdd.getImport();
207     }
208     if (imps != null) {
209         for (int i=0; i<imps.length; i++) {
210         String JavaDoc imp = imps[i];
211         imp = imp.trim();
212         if (imp.startsWith("import"))
213             gen(imp);
214         else
215             gen(IMPORT, " ", imp);
216         if (!imp.endsWith(";"))
217             eol();
218         else
219             cr();
220         }
221     }
222     
223     }
224     
225     void genClassName(int out) {
226     String JavaDoc name = null;
227     String JavaDoc impName = null;
228     
229     select(out);
230     gen(PUBLIC, CLASS, this.className);
231     
232     if (this.mdd != null) {
233         if (this.metaElement != null) {
234         name = this.metaElement.getExtends();
235         impName = this.metaElement.getImplements();
236         }
237         if (name == null) {
238         name = this.mdd.getExtends();
239         }
240         if (impName == null) {
241         impName = this.mdd.getImplements();
242         }
243     }
244     
245     gen(" extends ");
246     if (name != null)
247         gencr(name);
248     else
249         gencr("ConfigBean implements Serializable"); //SRIDATTA-040102
250

251     if (impName != null) {
252         gentab(1); gencr(" implements ", impName);
253     }
254     
255     begin();
256     }
257     
258     
259     void genConstructor(int out) throws IOException {
260         select(out);
261         String JavaDoc thrownExceptions = null;
262         if (this.beanElement.isRoot && shouldThrowException()) {
263             thrownExceptions = "org.netbeans.modules.schema2beans.Schema2BeansException";
264         }
265         jw.beginConstructor(className, "", thrownExceptions, jw.PUBLIC);
266     gen("this(");
267     if (this.beanElement.isRoot)
268         gen("null, ");
269     gen("Common.USE_DEFAULT_VALUES)");
270     eol();
271     end(); cr();
272     
273     if (this.beanElement.isRoot) {
274         jw.beginConstructor(className, "org.w3c.dom.Node doc, int options",
275                             thrownExceptions, jw.PUBLIC);
276         //
277
// This call should never pass anything but NO_DEFAULT_VALUES, since
278
// initFromNode will get the options that are specified.
279
//
280
jw.writeEol("this(Common.NO_DEFAULT_VALUES)");
281         if (!shouldThrowException()) {
282             gen("try ");
283             begin();
284         }
285         gen("initFromNode(doc, options)"); eol();
286         if (!shouldThrowException()) {
287             end();
288             gen("catch (Schema2BeansException e) ");
289             begin();
290             gen("throw new RuntimeException(e)");
291             eol();
292             end();
293         }
294         end();
295         // Make it so that initFromNode can be called from other
296
// methods in this class (like ones used for deserializing
297
// from a DOM tree).
298
gen(PROTECTED, VOID, "initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException"); cr();
299         begin();
300         gencr("if (doc == null)");
301         begin();
302         gen("doc = GraphManager.createRootElementNode(\"",
303         this.beanElement.node.getName(), "\")");
304         eolNoI18N();
305         gencr("if (doc == null)");
306         
307         if (this.config.isStandalone()) {
308             tabIn();
309             gencrNoI18N("throw new Schema2BeansException(\"Cannot create DOM root\");");
310         } else {
311             tabIn();
312             gencr("throw new Schema2BeansException(Common.getMessage(");
313             tabIn(); tabIn();
314             gencr("\"CantCreateDOMRoot_msg\", \""+beanElement.node.getName()+"\"));");
315         }
316         end();
317         
318         gen("Node n = GraphManager.getElementNode(\"");
319         gen(this.beanElement.node.getName(), "\", doc)");
320         eolNoI18N();
321         gencr("if (n == null)");
322         if (this.config.isStandalone()) {
323             tabIn();
324             gen("throw new Schema2BeansException(\"Doc root not in the DOM graph\")");
325             eolNoI18N();
326         } else {
327             tabIn();
328             gencr("throw new Schema2BeansException(Common.getMessage(");
329             tabIn(); tabIn();
330             gen("\"DocRootNotInDOMGraph_msg\", \""+beanElement.node.getName()+"\", doc.getFirstChild().getNodeName()))");
331         }
332         eol();
333         
334         cr();
335         gen("this.graphManager.setXmlDocument(doc)"); eol(); cr();
336         comment("Entry point of the createBeans() recursive calls");
337         gen("this.createBean(n, this.graphManager())"); eol();
338         gen("this.initialize(options)"); eol();
339         end();
340     }
341     
342     gen(PUBLIC, this.className+"(int options)");
343     /*
344     if (this.beanElement.isRoot && shouldThrowException()) {
345         gen(" throws Schema2BeansException ");
346     }
347     */

348     cr();
349     begin();
350     //gen("super(", this.className, ".comparators");
351
jw.writeEol("super(comparators, runtimeVersion)");
352     if (this.beanElement.isRoot) {
353         gen("initOptions(options)"); eol();
354         end();
355         
356         gen(PROTECTED, VOID, "initOptions(int options)"); cr();
357         begin();
358         comment("The graph manager is allocated in the bean root");
359         gen("this.graphManager = new GraphManager(this)"); eol();
360         gen("this.createRoot(\"", this.beanElement.node.getName(), "\", \"");
361         gen(this.className, "\",");
362         noI18N(); tabIn();
363         gen("Common.TYPE_1 | Common.TYPE_BEAN, ");
364         gen(this.className, ".class)"); eol(); cr();
365     }
366     }
367
368     /**
369      * This method needs to be run after genAccessors is run, so that
370      * all of the a.isIndexed values are correct (for attributes).
371      */

372     void genInitializer() throws IOException {
373         select(INITIALIZE_SECTION);
374         comment("Setting the default values of the properties");
375         jw.beginMethod("initialize", "int options", null, "void", jw.PACKAGE_LEVEL);
376         if (beanElement.isRoot) {
377             if (getDefaultNamespace() != null) {
378                 jw.write("setDefaultNamespace(");
379                 jw.write(JavaUtil.instanceFrom("java.lang.String",
380                                                getDefaultNamespace()));
381                 jw.writeEol(")");
382             }
383             if (mdd.getSchemaLocation() != null) {
384                 jw.beginIf("(options & Common.USE_DEFAULT_VALUES) == Common.USE_DEFAULT_VALUES");
385                 jw.write("_setSchemaLocation(");
386                 jw.write(JavaUtil.instanceFrom("java.lang.String",
387                                                mdd.getSchemaLocation()));
388                 jw.writeEol(")");
389                 jw.end();
390             }
391         }
392
393         int size = attrList.size();
394         for (int i = 0; i < size; i++) {
395             Property a = (Property)attrList.get(i);
396             boolean indexed = a.isIndexed();
397             String JavaDoc type = a.getType();
398             String JavaDoc constName = a.constName;
399             // Generate the initializer (default & well known property values)
400
String JavaDoc values[] = null;
401             String JavaDoc wrapperClass = null;
402         
403             MetaElement me = getMetaElement(a);
404             MetaProperty mp = getMetaProperty(a);
405            // no default value for a bean element (only for final property)
406
if (me != null && !a.isBean) {
407                 select(INITIALIZE_SECTION);
408                 //
409
// Generate the default values
410
//
411
int elts = 0;
412         
413                 // Get the current property default values first
414
if (mp != null)
415                     values = mp.getDefaultValue();
416         
417                 if (values != null)
418                     elts = values.length;
419         
420                 // If no default value, try to get the generic ones
421
if (elts == 0)
422                     values = me.getDefaultValue();
423         
424                 if (values != null ) {
425                     if (values.length > 0)
426                         gencr("if ((options & Common.USE_DEFAULT_VALUES) ",
427                               "== Common.USE_DEFAULT_VALUES)");
428                     if (values.length > 1)
429                         begin();
430                     for (int j=0; j<values.length; j++) {
431                         if (indexed) {
432                             gen("this.addValue(", constName, ", ");
433                             gen(JavaUtil.instanceFrom(JavaUtil.toObjectType(type), values[j]));
434                             gen(")");
435                             eol();
436                         }
437                         else {
438                             gen("this.setValue(", constName, ", ");
439                             gen(JavaUtil.instanceFrom(JavaUtil.toObjectType(type), values[j]));
440                             gen(")");
441                             eol();
442                             break;
443                         }
444                     }
445                     if (values.length > 1)
446                         end();
447                 }
448         
449                 //
450
// Generate the well-known values
451
//
452
elts = 0;
453                 values = null;
454         
455                 // Get the current property default values first
456
if (mp != null)
457                     values = mp.getKnownValue();
458         
459                 if (values != null)
460                     elts = values.length;
461         
462                 // If no default value, try to get the generic ones
463
if (elts == 0)
464                     values = me.getKnownValue();
465
466                 if (values != null) {
467                     for (int j = 0; j < values.length; j++) {
468                         jw.writeEol("addKnownValue("+constName+", ", JavaUtil.instanceFrom(JavaUtil.toObjectType(type), values[j]), ")");
469                     }
470                 }
471             }
472         }
473
474         boolean first = true;
475         for (int i = 0; i < size; i++) {
476             Property a = (Property)attrList.get(i);
477             boolean indexed = a.isIndexed();
478             String JavaDoc type = a.getType();
479             if (!indexed && a.getDefaultValue() != null && (a.elementInstance == Common.TYPE_1 || a.elementInstance == Common.TYPE_1_N)) {
480                 if (!JavaUtil.checkValueToType(type, a.getDefaultValue())) {
481                     config.messageOut.println(Common.getMessage("MSG_NotAGoodValue", a.getDefaultValue(), type));
482                 }
483                 if (first) {
484                     first = false;
485                     jw.beginIf("(options & Common.USE_DEFAULT_VALUES) == Common.USE_DEFAULT_VALUES");
486                 }
487                 jw.write(a.getWriteMethod(), "(");
488                 jw.write(JavaUtil.instanceFrom(type, a.getDefaultValue()));
489                 jw.writeEol(")");
490             }
491         }
492         if (!first)
493             jw.end();
494     }
495     
496     
497     void genDeclarations(int out) {
498         select(out);
499         cr();
500         gen("static Vector comparators = new Vector()"); eol();
501         if (this.metaElement != null) {
502             int size = this.metaElement.sizeComparatorClass();
503         
504             if (size >0) {
505                 gen(STATIC);
506                 begin();
507                 for (int i=0; i<size; i++) {
508                     gen(this.className, ".addComparator(new ");
509                     gen(this.metaElement.getComparatorClass(i), "())");
510                     eol();
511                 }
512                 end();
513             }
514         }
515         gen("private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(" + Version.MAJVER);
516         gen(", " + Version.MINVER);
517         gen(", " + Version.PTCVER, ")");
518         eol();
519     }
520     
521     /**
522      */

523     void genAccessors(int out) throws IOException {
524     int size = this.attrList.size();
525     boolean defaultKey = true;
526     ArrayList attrNames = new ArrayList();
527     
528
529     //SRIDATTA-040402
530
select(BODY_SECTION);
531     gencr("/**");
532     gencr("* get the xpath representation for this element");
533     gencr("* returns something like abc[@name='value'] or abc");
534     gencr("* depending on the type of the bean");
535     gencr("*/");
536     gencr("protected String getRelativeXPath() {");
537     gencr(" String ret = null;");
538     String JavaDoc thisPK = getPK(Common.convertName(this.beanElement.node.getName()));
539     if(thisPK != null) {
540         gencr(" ret = \"" + this.beanElement.node.getName() + "\" + (canHaveSiblings() ? \"[@" + thisPK + "='\" + getAttributeValue(\"" + thisPK + "\") +\"']\" : \"\") ;");
541     } else {
542         gencr(" ret = \"" + this.beanElement.node.getName() + "\";");
543     }
544
545     gencr(" return (null != ret ? ret.trim() : null);");
546     gencr("}");
547         
548         
549         
550     // Generate the verify() method
551
// select(OUT_BODY);
552
// comment("This method verifies that the mandatory properties are set");
553
// gen(PUBLIC, BOOLEAN, "verify"); PO(); PC(); cr();
554
// begin();
555
// int n = 1;
556

557     select(TRAILER_SECTION);
558     if (this.beanElement.isRoot) {
559         //
560
// Put in some writeObject/readObject serializer/deserializer
561
// methods, so that this object can implement java.io.Serializable
562
// correctly.
563
//
564
comment("Special serializer: output XML as serialization");
565         gen(PRIVATE, VOID, "writeObject(java.io.ObjectOutputStream out) throws java.io.IOException");
566         begin();
567         gen("ByteArrayOutputStream baos = new ByteArrayOutputStream()"); eol();
568         /*
569         gen("try ");
570         begin();
571         */

572         gen("write(baos)"); eol();
573         /*
574         end();
575         gen("catch (Schema2BeansException e) ");
576         begin();
577         gen("throw new RuntimeException(e)"); eol();
578         end();
579         */

580         gen("String str = baos.toString();"); eol();
581         comment("System.out.println(\"str='\"+str+\"'\");");
582         gen("out.writeUTF(str)"); eol();
583         end();
584         
585         comment("Special deserializer: read XML as deserialization");
586         gen(PRIVATE, VOID, "readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException");
587         begin();
588         gen("try");
589         begin();
590         gen("init(comparators, runtimeVersion)");
591         eol();
592         gen("String strDocument = in.readUTF()"); eol();
593         comment("System.out.println(\"strDocument='\"+strDocument+\"'\");");
594         gen("ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes())"); eol();
595         gen("Document doc = GraphManager.createXmlDocument(bais, false)"); eol();
596         if (config.isSetDefaults()) {
597             gen("initOptions(Common.USE_DEFAULT_VALUES)"); eol();
598             gen("initFromNode(doc, Common.USE_DEFAULT_VALUES)"); eol();
599         } else {
600             gen("initOptions(Common.NO_DEFAULT_VALUES)"); eol();
601             gen("initFromNode(doc, Common.NO_DEFAULT_VALUES)"); eol();
602         }
603         end();
604         gen("catch (Schema2BeansException e) ");
605         begin();
606         gen("throw new RuntimeException(e)"); eol();
607         end();
608         end(); cr();
609
610         jw.beginMethod("_setSchemaLocation", "String location", null, "void", jw.PUBLIC);
611         jw.beginIf("beanProp().getAttrProp(\"xsi:schemaLocation\", true) == null");
612         jw.writeEol("createAttribute(\"xmlns:xsi\", \"xmlns:xsi\", AttrProp.CDATA | AttrProp.IMPLIED, null, \"http://www.w3.org/2001/XMLSchema-instance\")");
613         jw.writeEol("setAttributeValue(\"xmlns:xsi\", \"http://www.w3.org/2001/XMLSchema-instance\")");
614         jw.writeEol("createAttribute(\"xsi:schemaLocation\", \"xsi:schemaLocation\", AttrProp.CDATA | AttrProp.IMPLIED, null, location)");
615         jw.end();
616         jw.writeEol("setAttributeValue(\"xsi:schemaLocation\", location)");
617         jw.end();
618         jw.cr();
619
620         jw.beginMethod("_getSchemaLocation", "", null, "String", jw.PUBLIC);
621         jw.beginIf("beanProp().getAttrProp(\"xsi:schemaLocation\", true) == null");
622         jw.writeEol("createAttribute(\"xmlns:xsi\", \"xmlns:xsi\", AttrProp.CDATA | AttrProp.IMPLIED, null, \"http://www.w3.org/2001/XMLSchema-instance\")");
623         jw.writeEol("setAttributeValue(\"xmlns:xsi\", \"http://www.w3.org/2001/XMLSchema-instance\")");
624         jw.writeEol("createAttribute(\"xsi:schemaLocation\", \"xsi:schemaLocation\", AttrProp.CDATA | AttrProp.IMPLIED, null, null)");
625         jw.end();
626         jw.writeEol("return getAttributeValue(\"xsi:schemaLocation\")");
627         jw.end();
628         jw.cr();
629     }
630     
631     select(TRAILER_SECTION);
632     comment("Dump the content of this bean returning it as a String");
633     gen(PUBLIC, VOID, "dump(StringBuffer str, String indent)");
634     begin();
635     gen("String s"); eol();
636     gen("Object o"); eol();
637     gen("org.netbeans.modules.schema2beans.BaseBean n"); eol();
638     
639     select(CONSTRUCTOR_SECTION);
640     comment("Properties (see root bean comments for the bean graph)");
641
642     int propertyCount = 0;
643     for (int i = 0; i < size; i++) {
644         Property a = (Property) attrList.get(i);
645         if (!a.isAttribute()) {
646             ++propertyCount;
647         }
648     }
649     jw.writeEol("initPropertyTables("+propertyCount, ")");
650     
651     select(DECL_SECTION); cr();
652     
653     //
654
// Assume that there is no property interested in veto events.
655
// We'll adjust later on in the above properties loop.
656
//
657
this.genVetoListeners = false;
658     
659     // Find out if any element has a key
660
if (this.metaElement != null) {
661         MetaProperty[] mp = this.metaElement.getMetaProperty();
662         for (int i=0; i<mp.length; i++) {
663         if (mp[i].isKey()) {
664             // At least one key is defined - default to false
665
defaultKey = false;
666             break;
667         }
668         }
669     }
670     
671     for(int i=0; i<size; i++) {
672         boolean indexed = false;
673         Property a = (Property)this.attrList.get(i);
674         String JavaDoc constName = a.constName;
675         boolean keyedElement = defaultKey;
676         boolean isWrapper = false;
677         MetaElement me;
678         String JavaDoc scalarType = a.getScalarType();
679         boolean genVetoable = this.isVetoable;
680         Signatures sigs = getSignatures(a);
681         boolean isScalar = a.isScalar();
682         
683         
684         //
685
// Information about this property defined in the mdd file
686
// (extra information provided on top of the dtd informations)
687
//
688
MetaProperty mp = getMetaProperty(a);
689         
690         if (mp != null) {
691         keyedElement = (mp.isKey())?true:defaultKey;
692         genVetoable = (mp.isVetoable())?true:genVetoable;
693         }
694         
695         // Change the class type with the Wrapper info
696
me = getMetaElement(a);
697         if (me != null) {
698             /*
699             String tmp = me.getWrapperClass();
700             if (tmp != null && !tmp.equals("") &&
701                 !tmp.equals("String") && !tmp.equals("java.lang.String")) {
702                 int t = Common.wrapperToType(tmp);
703                 if (t != Common.NONE)
704                     a.type = t;
705                 else {
706                     a.classType = tmp;
707                     isWrapper = true;
708                 }
709             }
710             */

711             /*
712             if (me.getBeanName() != null) {
713                 if (config.isTraceGen() && !a.name.equals(me.getBeanName()))
714                     config.messageOut.println("Reseting a.name from "+a.name+" to "+me.getBeanName());
715                 a.name = me.getBeanName();
716             }
717             */

718             
719             genVetoable = (me.isVetoable())?true:genVetoable;
720         }
721         if (!isScalar && !a.isBean) {
722             if (!JavaUtil.isPrimitiveType(a.classType))
723                 isWrapper = true;
724         }
725         
726         //System.out.println("a.name="+a.name+" a.type="+a.type+" a.dtdName="+a.dtdName+" isWrapper="+isWrapper+" a.classType="+a.classType+" me="+me+" constName="+constName);
727

728         if (genVetoable) {
729         // At least prop is handling veto events - we'll need to
730
// generate the listener methods.
731
this.genVetoListeners = true;
732         }
733         
734         // Only final prop can be vetoable
735
if (a.isBean)
736             genVetoable = false;
737         
738         // Generate the constants
739
select(DECL_SECTION);
740         gen(STATIC, PUBLIC, FINAL, STRING, (String JavaDoc)constName);
741         gen(" = \"");
742         gen(a.name);
743         gen("\"");
744 eol();
745 // eolNoI18N();
746

747         // Keep track of the constant name for this property
748
select(CONSTRUCTOR_SECTION);
749         if (!a.isAttribute()) {
750             // FIXME SRIDATTA: instead of dtd Name change to property.
751
String JavaDoc dtdName = a.dtdName;
752                 if(a.dtdName.equals("element-property"))
753                     dtdName = "property";
754                 gen("this.createProperty(\"", dtdName, "\", ");
755             // END FIX
756
// gen("this.createProperty(\"", a.dtdName, "\", ");
757

758 //krav
759
//noI18N();
760
//tabIn();
761
gen(constName, ", ");
762             if (a.ored)
763                 gen("Common.SEQUENCE_OR | ");
764             
765             if (genVetoable)
766                 gen("Common.TYPE_VETOABLE |");
767             
768             cr(); tabIn();
769         
770             select(BODY_SECTION);
771             if (a.elementInstance == Common.TYPE_1) {
772                 //
773
// The property is mandatory. Check it is properly set.
774
//
775
if (!Common.isBoolean(a.type)) {
776                     select(CONSTRUCTOR_SECTION);
777                     gen("Common.TYPE_1");
778                 }
779                 else {
780                     //
781
// A boolean type cannot be mandatory because the
782
// value of the tag depends on the existance of the
783
// empty tag in the document (a mandatory DTD empty
784
// element doesn't make sense since it would always
785
// be true).
786
//
787
select(CONSTRUCTOR_SECTION);
788                     gen("Common.TYPE_0_1");
789                 }
790             }
791             else
792                 if (a.elementInstance == Common.TYPE_0_1) {
793                     select(CONSTRUCTOR_SECTION);
794                     gen("Common.TYPE_0_1");
795                 }
796                 else
797                     if (a.elementInstance == Common.TYPE_1_N) {
798                         //
799
// Check out that the first element is set and check
800
// that every element set is valid.
801
//
802
indexed = true;
803                         select(CONSTRUCTOR_SECTION);
804                         gen("Common.TYPE_1_N");
805                     }
806                     else
807                         if (a.elementInstance == Common.TYPE_0_N) {
808                             //
809
// The property is optional. However if
810
// the property is set and is a bean,
811
// its content has to be valid.
812
//
813
indexed = true;
814                             select(CONSTRUCTOR_SECTION);
815                             gen("Common.TYPE_0_N");
816                         }
817         }
818         select(out);
819         
820         //SRIDATTA
821
String JavaDoc thetype = a.name;
822         boolean isPCDATA = a.getBeanElement().isPCDATA();;
823         if(!indexed) { //SRIDATTA-0207
824
// isPCDATA = a.be.isPCDATA(); //SRIDATTA-0207
825
// System.out.println("**********" + a.name+isPCDATA);
826
if (isPCDATA)
827                 thetype = "String";
828         } //SRIDATTA-0207
829
// System.out.println(a.name+isPCDATA);
830

831         Property attributeOwner = null;
832         if (a.isAttribute()) {
833             attributeOwner = a.getAttributeOwner();
834             indexed = attributeOwner.isIndexed();
835         }
836         String JavaDoc type;
837         if (isScalar)
838             type = scalarType;
839         else
840             type = a.classType;
841         String JavaDoc thrownExceptions = null;
842         if (genVetoable) {
843             thrownExceptions = "java.beans.PropertyVetoException";
844         }
845
846         String JavaDoc setParameters = "";
847         if (!isPCDATA) //krav: bypass generic set/get for PCDATA element
848
{
849             /*
850              * Set method
851              */

852             comment("This attribute is ", Common.instanceToString(a.elementInstance));
853             // Set - signature
854
if (indexed)
855                 setParameters = "int index, ";
856             if (a.getPropertyInterface() == null) {
857                 setParameters += type + " value";
858             } else {
859                 setParameters += a.getPropertyInterface() + " valueInterface";
860             }
861             if (genVetoable) {
862                 thrownExceptions = "java.beans.PropertyVetoException";
863             }
864     
865             jw.beginMethod(a.getWriteMethod(), setParameters, thrownExceptions,
866                            "void", jw.PUBLIC | jw.BEANINFO);
867             if (a.getPropertyInterface() != null) {
868                 jw.writeEol(type+" value = ("+type+") valueInterface");
869             }
870             if (genVetoable)
871                 genVetoBegin();
872             
873             SchemaRep.WhiteSpace ws = (SchemaRep.WhiteSpace) a.searchExtraData(SchemaRep.WhiteSpace.class);
874             if (ws != null)
875                 genWhiteSpaceRestriction(ws, "value", type);
876             if (a.isAttribute()) {
877                 AttrProp attrProp = a.getAttrProp();
878                 if (attributeOwner != a) {
879                     jw.comment("Make sure we've got a place to put this attribute.");
880                     jw.beginIf("size("+attributeOwner.constName+") == 0");
881                     String JavaDoc valueToSetTo = "\"\""; // The empty string.
882
if (Common.isBoolean(attributeOwner.type) && attributeOwner.getCanBeEmpty())
883                         valueToSetTo = "java.lang.Boolean.TRUE";
884                     if (attributeOwner.isIndexed()) {
885                         jw.writeEol("addValue("+attributeOwner.constName+", ",
886                                     valueToSetTo, ")");
887                     } else {
888                         jw.writeEol("setValue("+attributeOwner.constName+", ",
889                                     valueToSetTo, ")");
890                     }
891                     jw.end();
892                     if (Common.isBoolean(attributeOwner.type) && attributeOwner.getCanBeEmpty() && attributeOwner.isIndexed()) {
893                         jw.write("setValue(", attributeOwner.constName);
894                         jw.write(", index");
895                         jw.writeEol(", java.lang.Boolean.TRUE)");
896                     }
897                     jw.write("setAttributeValue(");
898                     jw.write(attributeOwner.constName+", ");
899                     if (attributeOwner.isIndexed())
900                         gen("index, ");
901                     jw.write("\""+attrProp.getName()+"\"");
902                 } else {
903                     gen("setAttributeValue(");
904                     gen(a.constName);
905                 }
906                 gen(", ");
907                 if (isScalar)
908                     gen("\"\"+value");
909                 else
910                     gen(JavaUtil.typeToString(a.getType(), "value"));
911                 geneol(")");
912             } else {
913                 gen("this.setValue(", constName, ", ");
914                 
915                 if (indexed) gen("index, ");
916                 
917                 genSetValue(isScalar, a.getType());
918             
919                 eol();
920             }
921             
922             if (genVetoable)
923                 genVetoEnd();
924     
925             if (!indexed)
926                 genResetMutuallyExclusive(a, true);
927             end(); cr();
928             
929             /*
930              * Get method
931              */

932             comment("Get Method");
933             // Signature
934
String JavaDoc getParameters = "";
935             if (indexed)
936                 getParameters = "int index";
937             jw.beginMethod(a.getReadMethod(indexed), getParameters, null,
938                            a.getPropertyInterface() == null ? type :a.getPropertyInterface(),
939                            jw.PUBLIC|jw.BEANINFO);
940             
941             // Body
942
if (a.isAttribute()) {
943                 List exceps = JavaUtil.exceptionsFromParsingText(a.getType());
944                 if (!exceps.isEmpty()) {
945                     gen("try ");
946                     begin();
947                 }
948                 if (attributeOwner != a) {
949                     AttrProp attrProp = a.getAttrProp();
950                     jw.comment("If our element does not exist, then the attribute does not exist.");
951                     jw.beginIf("size("+attributeOwner.constName+") == 0");
952                     jw.writeEol("return null");
953                     jw.endElseBegin();
954                     jw.write("return ");
955                     jw.writeEol(JavaUtil.genParseText(a.getType(), "getAttributeValue("+attributeOwner.constName+ ((attributeOwner.isIndexed()) ? ", index" : "") +", \""+attrProp.getName()+"\")", config.isForME()));
956                     jw.end();
957                 } else {
958                     String JavaDoc nullValue = JavaUtil.nullValueForType(a.getType());
959                     gen("return ");
960                     if (!"null".equals(nullValue))
961                         gen("(getAttributeValue("+a.constName+") == null) ? "+nullValue+" : ");
962                     gen(JavaUtil.genParseText(a.getType(), "getAttributeValue("+a.constName+")", config.isForME()));
963                     eol();
964                 }
965                 if (!exceps.isEmpty()) {
966                     end();
967                     genRethrowExceptions(exceps);
968                 }
969             } else if (isScalar) {
970                 gen(a.classType, " ret = ");
971                 gen("(", a.classType, ")");
972                 gen("this.getValue(", constName);
973                 if (indexed) gen(", index");
974                 PC(); eol();
975                 gencr("if (ret == null)");
976                 if (this.config.isScalarException() && !Common.isBoolean(a.type)) {
977                     if (this.config.isStandalone()) {
978                         tabIn();
979                         gen("throw new NoSuchElementException(\"The element ",
980                             a.name, " of type ");
981                         gen(scalarType, " has no value.\")"); eol();
982                     } else {
983                         tabIn();
984                         gencr("throw new RuntimeException(Common.getMessage(");
985                         tabIn(); tabIn();
986                         gencr("\"NoValueForElt_msg\",");
987                         tabIn(); tabIn();
988                         gen("new Object[] {\"");
989                         gen(constName);
990                         gen("\", ");
991                         gen("\"", scalarType);
992                         gen("\"}));");
993                         cr();
994                     }
995                 }
996                 else {
997                     tabIn();
998                     gen("ret = ");
999                     gen("(", a.classType, ")");
1000                    gen("Common.defaultScalarValue(Common.");
1001                    gen(Common.typeToString(a.type), ")"); eol();
1002                }
1003                gen("return "+JavaUtil.fromObject(a.getType(), "ret"));
1004                eol();
1005            } else {
1006                gen("return (", a.classType, ")");
1007                gen("this.getValue(", constName);
1008                if (indexed) gen(", index"); PC();
1009                eol();
1010            }
1011            end(); cr();
1012        } // krav: exclude PCDATA
1013

1014        //
1015
// If we are an indexed property, we have to generate another
1016
// kind of setter and getter method for the whole array.
1017
//
1018
if (indexed) {
1019            if (!a.isAttribute()) {
1020                // Setter method
1021
comment("This attribute is ", Common.instanceToString(a.elementInstance));
1022                // Set - signature
1023
if (a.getPropertyInterface() == null) {
1024                    setParameters = type + "[] value";
1025                } else {
1026                    setParameters = a.getPropertyInterface() +"[] value";
1027                }
1028                jw.beginMethod(a.getWriteMethod(), setParameters, thrownExceptions, "void", jw.PUBLIC|jw.BEANINFO);
1029        
1030                // Body
1031
if (isScalar) {
1032                    gen(a.classType, "[] values = null"); eol();
1033                    gencr("if (value != null)");
1034                    begin();
1035                    gen("values = new ", a.classType, "[value.length]"); eol();
1036                    gencr("for (int i=0; i<value.length; i++)");
1037                    gentab(1);
1038                    if (!config.isForME() && Common.isBoolean(a.type))
1039                        gen("values[i] = (value[i] ? Boolean.TRUE : Boolean.FALSE)");
1040                    else
1041                        gen("values[i] = new ", a.classType, "(value[i])");
1042                    eol();
1043                    end();
1044                }
1045        
1046                if (genVetoable)
1047                    genVetoBegin();
1048        
1049                gen("this.setValue(", constName, ", ");
1050            
1051                if (isScalar)
1052                    gen("values)");
1053                else
1054                    gen("value)");
1055            
1056                eol();
1057                if (genVetoable)
1058                    genVetoEnd();
1059
1060                genResetMutuallyExclusive(a, true);
1061                end(); cr();
1062        
1063                // Getter method
1064
comment("Getter Method");
1065                // Signature
1066
jw.beginMethod(a.getReadMethod(false), "", null,
1067                               (a.getPropertyInterface() == null ? type : a.getPropertyInterface())+"[]",
1068                               jw.PUBLIC|jw.BEANINFO);
1069
1070                // Body
1071
if (isScalar) {
1072                    gen(scalarType, "[] ret = null"); eol();
1073                    gen(a.classType, "[] values = (", a.classType);
1074                    gen("[])this.getValues(", constName, ")"); eol();
1075                    gencr("if (values != null)");
1076                    begin();
1077                    gen("ret = new ", scalarType, "[values.length]"); eol();
1078                    gencr("for (int i=0; i<values.length; i++)");
1079                    gentab(1);
1080                    gen("ret[i] = values[i].",
1081                        Common.wrapperGetMethod(a.type), "()"); eol();
1082                    end();
1083                    geneol("return ret");
1084                } else {
1085                    gen("return (", a.classType, "[])");
1086                    gen("this.getValues(", constName, ")");
1087                    eol();
1088                }
1089                end(); cr();
1090
1091                jw.comment("Return the number of properties");
1092                // Signature
1093
gen(sigs.findSignature(SIZE));
1094                sp();
1095                begin();
1096                // Body
1097
if (!a.isAttribute())
1098                    gen("return this.size(", constName, ")");
1099                else
1100                    gen("return this.size(", attributeOwner.constName, ")");
1101                eol(); end(); cr();
1102
1103                /*
1104                 * Remove and Add methods
1105                 */

1106                comment("Add a new element returning its index in the list");
1107/*
1108                // Signature
1109                gen(sigs.findSignature(ADD));
1110                sp();
1111                if (genVetoable) {
1112                    gencr("throws PropertyVetoException ");
1113                }
1114                begin();
1115                // Body
1116                if (a.getPropertyInterface() != null) {
1117                    jw.writeEol(a.getType()+" value = ("+a.getType()+") valueInterface");
1118                }
1119                if (genVetoable)
1120                    genVetoBegin();
1121                jw.write("int positionOfNewItem = this.addValue(", constName, ", ");
1122                genSetValue(isScalar, a.getType());
1123                jw.eol();
1124                if (isMutuallyExclusive(a)) {
1125                    jw.beginIf("positionOfNewItem == 0");
1126                    genResetMutuallyExclusive(a, false);
1127                    jw.end();
1128                }
1129                jw.writeEol("return positionOfNewItem");
1130*/

1131                //SRIDATTA-041502-SRART
1132
gen(PUBLIC, INT, "add", a.name); // SRIDATTA REMOVED THIS
1133
//SRIDATTA
1134
//gencr("public int add" + a.name + "() throws ConfigException ");
1135

1136        PO(); genSetValP(isScalar, scalarType, a.classType);
1137        PC(); cr();
1138        if (genVetoable)
1139            gencr("\t\tthrows PropertyVetoException");
1140                //SRIDATTa
1141
gen("\t\tthrows ConfigException");
1142                begin();
1143                gencr("return add"+a.name+"(value, true);");
1144                end(); cr();
1145                //SRIDATTA-041502-END
1146

1147                
1148        comment("Add a new element returning its index in the list with a boolean flag");
1149
1150                
1151        // Signature
1152
gen(PUBLIC, INT, "add", a.name); // SRIDATTA REMOVED THIS
1153
//SRIDATTA
1154
//gencr("public int add" + a.name + "() throws ConfigException ");
1155

1156        PO(); genSetValP(isScalar, scalarType, a.classType);
1157                gen(", boolean overwrite"); //SRIDATTA-041502
1158
PC(); cr();
1159        if (genVetoable)
1160            gencr("\t\tthrows PropertyVetoException");
1161                //SRIDATTa
1162
gen("\t\tthrows ConfigException");
1163        begin();
1164                
1165        // Body
1166
if (genVetoable)
1167            genVetoBegin();
1168                // SRIDATTA added this
1169

1170            if(!isPCDATA) { //SRIDATTA-0207
1171
String JavaDoc pk = getPK(a.name);
1172                if (null == pk) {
1173                    throw new NullPointerException JavaDoc("primary key for " + a.name);
1174                }
1175                
1176                pk = Common.convertName(pk);
1177                
1178        gencr(a.name + " old = get" + a.name + "By" + pk + "(value.get" + pk + "());");
1179                gencr("if(old != null) {");
1180        
1181// gencr("\tthrow new ConfigException(\"" + a.name + " Already Exists: cannot add duplicate\");");
1182
gencr("\tthrow new ConfigException(StringManager.getManager(" +
1183                      this.className +
1184                      ".class).getString(\"cannotAddDuplicate\", \"" +
1185                      a.name +
1186                      "\"));");
1187                gencr("}");
1188            } //SRIDATTA-0207
1189
// SRIDATTA till here.
1190
gen("return this.addValue(", constName, ", value, overwrite)");
1191        // genSetValue(isScalar, a.classType); //SRIDATTA-041402
1192
//SRIDATTA-041502
1193
eol();
1194
1195                
1196                if (genVetoable)
1197                    genVetoEnd();
1198                end(); cr();
1199        
1200                comment();
1201                comment("Remove an element using its reference");
1202                comment("Returns the index the element had in the list");
1203                comment();
1204                // Signature
1205
//krav
1206
/* gen(sigs.findSignature(REMOVE));
1207                sp();
1208 */

1209                gen(PUBLIC, INT, "remove", a.name);
1210                PO(); genSetValP(isScalar, scalarType, a.classType);
1211                PC(); //cr();
1212
//krav
1213

1214                if (genVetoable) {
1215                    gencr("throws PropertyVetoException ");
1216                }
1217                begin();
1218                // Body
1219
if (a.getPropertyInterface() != null) {
1220                    jw.writeEol(a.getType()+" value = ("+a.getType()+") valueInterface");
1221                }
1222                if (genVetoable)
1223                    genVetoBegin();
1224                gen("return this.removeValue(", constName, ", ");
1225                genSetValue(isScalar, a.getType());
1226                eol();
1227                if (genVetoable)
1228                    genVetoEnd();
1229                end(); cr();
1230                //SRIDATTA_S
1231
comment();
1232                comment("Remove an element using its reference");
1233                comment("Returns the index the element had in the list");
1234                comment("with boolean overwrite");
1235                comment();
1236                // Signature
1237
gen(PUBLIC, INT, "remove", a.name);
1238                PO(); genSetValP(isScalar, scalarType, a.classType);
1239                gen(", boolean overwrite");
1240                PC(); cr();
1241                if (genVetoable)
1242                    gencr("\t\tthrows PropertyVetoException");
1243                gen("\t\tthrows StaleWriteConfigException");
1244
1245                begin();
1246                // Body
1247
if (genVetoable)
1248                    genVetoBegin();
1249                gen("return this.removeValue(", constName, ", value, overwrite)");
1250                //genSetValue(isScalar, a.classType);
1251
eol();
1252                if (genVetoable)
1253                    genVetoEnd();
1254                end(); cr();
1255                //SRIDATTA_E
1256

1257
1258                if (isScalar && !"int".equals(a.getType())) {
1259                    // Don't do "int" because we already have a method
1260
// with that signature.
1261
comment();
1262                    comment("Remove an element using its index");
1263                    comment();
1264                    // Signature
1265
jw.beginMethod(a.getRemoveMethod(), "int index",
1266                                   thrownExceptions, "void",
1267                                   jw.PUBLIC|jw.BEANINFO);
1268                    // Body
1269
if (genVetoable)
1270                        genVetoBegin();
1271                    gen("this.removeValue(", constName, ", index)");
1272                    eol();
1273                    if (genVetoable)
1274                        genVetoEnd();
1275                    end(); cr();
1276                }
1277            }
1278
1279       }
1280        
1281
1282            // SRIDATTA ADDED
1283
String JavaDoc plural = a.name+"s";
1284            String JavaDoc tagName = Common.constName(a.dtdName);
1285            
1286            if(indexed && !isPCDATA) { //SRIDATTA-0207
1287

1288                
1289                String JavaDoc pk = getPK(a.name);
1290        pk = Common.convertName(pk);
1291        String JavaDoc pkTag = Common.constName(getPK(a.name));
1292                
1293            gencr("public "+a.name +" get"+a.name +"By"+pk+"(String id) {");
1294            gencr(" if (null != id) { id = id.trim(); }");
1295            gencr(a.name + "[] o = get" + a.name + "();");
1296            gencr(" if (o == null) return null;");
1297            gencr("");
1298            gencr(" for (int i=0; i < o.length; i++) {");
1299            gencr(" if(o[i].getAttributeValue(Common.convertName(" + tagFile + pkTag + ")).equals(id)) {");
1300            gencr(" return o[i];");
1301            gencr(" }");
1302            gencr(" }");
1303            gencr("");
1304
1305            gencr(" return null;");
1306            gencr(" ");
1307            gencr("}");
1308
1309               /* //SRIDATTA-040402 --remove this fixme
1310                gencr("/**");
1311                gencr("* get the xpath representation for this element");
1312                gencr("* returns something like abc[@name='value'] or abc");
1313                gencr("* depending on the type of the bean");
1314                gencr("* /");
1315                gencr("protected String getRelativeXPath() {");
1316                gencr(" String ret = null;");
1317                String thisPK = getPK(this.beanElement.node.getName());
1318                if(indexed && thisPK != null) {
1319                    gencr(" ret = \"" + this.beanElement.node.getName() + "[@" + thisPK + "='\" + getAttributeValue(" + a.name + ") +']\";");
1320                } else {
1321                    //never generated
1322                    gencr("// no valid primary key return null" + thisPK + ":" + this.beanElement.node.getName());
1323                }
1324
1325                gencr(" return ret;");
1326                gencr("}");
1327                */

1328        }
1329            
1330            
1331        ///SRIDATTA for description types
1332
if(!indexed && isPCDATA) { // FIXME SOON isPCDATA && false //SRIDATTA-0207
1333
// get
1334
gencr("/**");
1335        gencr("* Return the "+a.name +" of the Element "+this.beanElement.node.getName());
1336        gencr("*/");
1337                        gencr("public String"+" get"+ a.name +"() {");
1338                        gencr("\treturn (String) getValue(" + tagFile +tagName +");");
1339        gencr("}");
1340                    // set
1341
gencr("/**");
1342        gencr("* Modify the "+a.name +" of the Element "+this.beanElement.node.getName());
1343        gencr("* @param v the new value");
1344        gencr("*/");
1345                        gencr("public void set"+ a.name +"(String v){");
1346        gencr("\tsetValue(" + tagFile + tagName + ", (null != v ? v.trim() : null));");
1347                        gencr("\t}");
1348
1349              /* not completed implementation
1350                        int once = 0;
1351                        if(once == 0) {
1352                        //SRIDATTA-041902
1353                        gencr("/**");
1354        gencr("* Overide getAttribute to for class that has pcdata like description "+this.beanElement.node.getName());
1355               */

1356        // gencr("*/");
1357
/* gencr("public String getAttrubuteValue(String value) {");
1358                        once++;
1359                        }
1360                        if(once >0) {
1361                            gencr("if(" + tagFile + tagName + ".equals(value))");
1362                            gencr(" return (String) getValue("+tagFile + tagName + ");");
1363                        }
1364
1365                        if(once == 1) {
1366                            gencr("\treturn (String) getAttributeValue(" + tagFile +tagName +");");
1367                            gencr("}");
1368                    // set
1369                        gencr("/**");
1370        gencr("* Modify the "+a.name +" of the Element "+this.beanElement.node.getName());
1371        gencr("* @param v the new value");
1372                 */

1373        // gencr("*/");
1374
/*
1375                        gencr("public void set"+ a.name +"(String v){");
1376        gencr("\tsetValue(" + tagFile + tagName + ", v);");
1377                        gencr("\t}");
1378                      }
1379                 */

1380
1381
1382                }
1383                //SRIDATTA
1384
//
1385
//-----------------
1386

1387        {
1388            // The metaDD might define the class name of the bean
1389
MetaElement e = getMetaElement(a);
1390            String JavaDoc cls = null;
1391            if (e != null)
1392                cls = e.getBeanClass();
1393            if (cls == null)
1394                cls = a.classType;
1395            //System.out.println("cls="+cls);
1396

1397            if (!a.isAttribute()) {
1398                select(CONSTRUCTOR_SECTION);
1399                gen(" | Common.");
1400                if (isScalar && (a.type != Common.TYPE_BOOLEAN)) {
1401                    gen(Common.typeToString(Common.TYPE_STRING));
1402                } else {
1403                    gen(Common.typeToString(a.type));
1404                    if (a.type == Common.TYPE_BOOLEAN && !a.getCanBeEmpty()) {
1405                        gen(" | Common.TYPE_SHOULD_NOT_BE_EMPTY");
1406                    }
1407                }
1408                if (keyedElement)
1409                    gen(" | Common.TYPE_KEY");
1410                gen(", "); cr(); tabIn();
1411                gen( cls, ".class)"); eol();
1412            }
1413        }
1414        
1415        // dump()
1416
if (!a.isAttribute()) {
1417            select(TRAILER_SECTION);
1418            if (isScalar && config.isScalarException() && !Common.isBoolean(a.type)) {
1419                gen("if (this.getValue(");
1420                gen(constName);
1421                gen(") != null) ");
1422                begin();
1423            }
1424            gen("str.append(indent)"); eol();
1425            gen("str.append(\"",a.name);
1426            if (indexed) {
1427                gen("[\"+this.size", a.name, "()+\"]");
1428            }
1429            gen("\")" );
1430            eolNoI18N();
1431            if (indexed) {
1432                gen("for(int i=0; i<this.size", a.name, "(); i++)");
1433                cr();
1434                begin();
1435                gen("str.append(indent+\"\\t\")"); eol();
1436                gen("str.append(\"#\"+i+\":\")"); eol();
1437            }
1438        
1439            boolean isCharArray = a.classType.equals("char[]");
1440            if (Common.isBoolean(a.type)) {
1441                gen("str.append(indent+\"\\t\")"); eolNoI18N();
1442                gen("str.append((");
1443                gen("this.is", a.name, "(");
1444                if (indexed)
1445                    gen("i");
1446                gen(")?\"true\":\"false\"))"); eol();
1447            } else if (Common.isString(a.type) || isScalar || isCharArray) {
1448                gen("str.append(indent+\"\\t\")"); eolNoI18N();
1449                gen("str.append(\"<\")"); eolNoI18N();
1450            
1451                if (isWrapper && !isCharArray)
1452                    gen("o = ");
1453                else
1454                    gen("s = ");
1455            
1456                if (isScalar || isCharArray) gen("String.valueOf(");
1457                //krav
1458
if(indexed)
1459                {
1460                    gen("this.getValue(", constName, ", i)");
1461                }
1462                else
1463                {
1464                    gen("this.get", a.name, "()");
1465                }
1466                if (isScalar || isCharArray) gen(")");
1467                eol();
1468            
1469                if (isWrapper && !isCharArray)
1470                    gen("str.append((o==null?\"null\":o.toString()");
1471                else
1472                    gen("str.append((s==null?\"null\":s");
1473            
1474                gen(".trim()))");
1475                eolNoI18N();
1476                gen("str.append(\">\\n\")"); eolNoI18N();
1477            } else if (a.isBean) {
1478                gen("n = (org.netbeans.modules.schema2beans.BaseBean) this.get", a.name, "(");
1479                if (indexed) gen("i");
1480                gencr(");");
1481                gencr("if (n != null)");
1482                gen("\tn.dump(str, indent + \"\\t\")"); eolNoI18N();
1483                gencr("else");
1484                gen("\tstr.append(indent+\"\\tnull\")"); eolNoI18N();
1485            }
1486            if (!a.isAttribute()) {
1487                gen("this.dumpAttributes(", constName, ", ");
1488                if (indexed)
1489                    gen("i");
1490                else
1491                    gen("0");
1492                gen(", str, indent)"); eol();
1493            }
1494        
1495            if (isScalar && config.isScalarException() && !Common.isBoolean(a.type)) {
1496                end();
1497            }
1498        
1499            if (indexed) {
1500                //gen("str.append(indent+\"\\t\")"); eol();
1501
//gen("str.append(\"---\")"); eol();
1502
end();
1503            }
1504            cr();
1505        }
1506        
1507
1508        genAttributes(CONSTRUCTOR_SECTION, a.attributes, constName);
1509        select(ACCESS_SECTION);
1510        genDefaultsAccessable(a);
1511
1512        if (a.isBean) {
1513            genNewMethod(a.getPropertyInterface(), a.getType());
1514        }
1515        else
1516        {
1517            String JavaDoc ss = transformTo_(a.getBeanElement().getDTDName().toUpperCase());
1518            if (listOfTags.containsKey(ss))
1519                serverTagsStream.println("\t//static public final String " + ss + " = \""+ a.getBeanElement().getDTDName()+"\";");
1520            else
1521                serverTagsStream.println("\tstatic public final String " + ss + " = \""+ a.getBeanElement().getDTDName()+"\";");
1522            listOfTags.put(ss,ss );
1523        }
1524    }
1525    
1526    // The root might have attributes
1527
if (this.beanElement.isRoot)
1528        genAttributes(CONSTRUCTOR_SECTION,
1529        this.beanElement.node.getAttributes(), null);
1530    
1531    select(DECL_SECTION); cr();
1532    
1533    select(TRAILER_SECTION);
1534    end(false); cr();
1535    
1536        
1537        ////////////////////////////////////////////////
1538
//SRIDATTA
1539

1540        //SRIDATTA-031402
1541
select(GET_DEFAULT_ATTR_GENERIC_SECTION);
1542        gencr("");
1543        gencr("/*");
1544        gencr("* generic method to get default value from dtd");
1545        gencr("*/");
1546         gencr("public static String getDefaultAttributeValue(String attr) {");
1547         gencr("\tif(attr == null) return null;");
1548         gencr("\tattr = attr.trim();");
1549        
1550                ///REAL ATTRIBUTES HERE!!!!!!
1551

1552
1553        GraphNode node = beanElement.getGraphNode();
1554        AttrProp attrs[] = node.getAttributes();
1555        select(out);
1556        
1557        for(int i=0; i<attrs.length ; i++) {
1558            select(out);
1559            // System.out.println(attrs[i].getDtdName() );
1560
// System.out.println(attrs[i].getName() );
1561
// System.out.println(attrs[i].getDefaultValue() );
1562

1563            boolean isBoolean = false;
1564            
1565            if (attrs[i].getDefaultValue()==null){
1566            }
1567            else
1568                if (attrs[i].getDefaultValue().equals("'true'") || attrs[i].getDefaultValue().equals("true")) {
1569                    isBoolean =true;
1570                }
1571                else
1572                    if (attrs[i].getDefaultValue().equals("'false'") || attrs[i].getDefaultValue().equals("false")){
1573                        isBoolean =true;
1574                    }
1575            //System.out.println(attrs[i].getDefaultValue()+isBoolean);
1576

1577            String JavaDoc constantTagName = transformTo_(attrs[i].getDtdName().toUpperCase());
1578            if (listOfTags.containsKey(constantTagName))
1579                serverTagsStream.println("\t//static public final String "+constantTagName+" = \""+ attrs[i].getDtdName()+"\";");
1580            else
1581                serverTagsStream.println("\tstatic public final String "+constantTagName+" = \""+ attrs[i].getDtdName()+"\";");
1582            listOfTags.put(constantTagName, constantTagName );
1583            String JavaDoc thetype ="String";
1584            
1585            if (isBoolean)
1586                thetype ="boolean";
1587            
1588            
1589            gencr("/**");
1590            gencr("* Getter for "+attrs[i].getName() +" of the Element "+this.beanElement.node.getName());
1591            // gencr("* @throws ConfigException if there is a Config error."); //SRIDATTA031802
1592
gencr("* @return the "+attrs[i].getName() +" of the Element "+this.beanElement.node.getName());
1593            gencr("*/");
1594            if(isBoolean){
1595                // gencr("public "+thetype+" is"+attrs[i].getName() +"() throws ConfigException {");//SRIDATTA-031802
1596
gencr("public "+thetype+" is"+attrs[i].getName() +"() {");
1597                gencr("\treturn toBoolean(getAttributeValue(" + tagFile + constantTagName+"));");
1598            }
1599            else{
1600                if (attrs[i].getOption()==BaseAttribute.OPTION_IMPLIED){
1601                // gencr("public "+thetype+" get"+ attrs[i].getName() +"() throws ConfigException{");
1602
gencr("public "+thetype+" get"+ attrs[i].getName() +"() {"); //SRIDATTA-031802
1603
// gencr("\ttry{");
1604
gencr("\t\treturn getAttributeValue(" + tagFile + constantTagName+");");
1605            // gencr("\t}");
1606
// gencr("\tcatch (ConfigException ex){");
1607
// gencr("\t\treturn null;");
1608
// gencr("\t}");
1609
}
1610                else{
1611                // gencr("public "+thetype+" get"+ attrs[i].getName() +"() throws ConfigException{");
1612
gencr("public "+thetype+" get"+ attrs[i].getName() +"() {"); //SRIDATTA-031802
1613
gencr("\treturn getAttributeValue(" + tagFile + constantTagName+");");
1614                }
1615            }
1616            gencr("}");
1617
1618                        //SRIDATTA-041502-START
1619
gencr("/**");
1620            gencr("* Modify the "+attrs[i].getName() +" of the Element "+this.beanElement.node.getName());
1621            gencr("* @param v the new value");
1622                        gencr("* @throws StaleWriteConfigException if overwrite is false and file changed on disk");
1623            //gencr("* @throws ConfigException if there is a config error"); //SRIDATTA-031802
1624
gencr("*/");
1625            gencr("public void set"+ attrs[i].getName() +"("+thetype +" v, boolean overwrite) throws StaleWriteConfigException {");
1626            if(isBoolean){
1627                gencr("\tsetAttributeValue("+ tagFile + constantTagName+", \"\"+(v==true), overwrite);");
1628            }
1629            else{
1630                gencr("\tsetAttributeValue(" + tagFile + constantTagName+", v, overwrite);");
1631            }
1632            //gencr("\tthis.changed();"); //SRIDATTA-042502
1633
gencr("}");
1634                        //SRIDATTA-041502-END
1635

1636            gencr("/**");
1637            gencr("* Modify the "+attrs[i].getName() +" of the Element "+this.beanElement.node.getName());
1638            gencr("* @param v the new value");
1639            //gencr("* @throws ConfigException if there is a config error"); //SRIDATTA-031802
1640
gencr("*/");
1641            gencr("public void set"+ attrs[i].getName() +"("+thetype +" v) {");
1642            if(isBoolean){
1643                gencr("\tsetAttributeValue("+ tagFile + constantTagName+", \"\"+(v==true));");
1644            }
1645            else{
1646                gencr("\tsetAttributeValue(" + tagFile + constantTagName+", v);");
1647            }
1648            
1649            // gencr("\tthis.changed();"); //SRIDATTA-042502
1650
gencr("}");
1651            
1652                        //SRIDATTA-031402
1653
select(GET_DEFAULT_ATTR_SECTION);
1654                        
1655                        if(attrs[i].getDefaultValue() != null) {
1656                            gencr("/**");
1657                            gencr("* Get the default value of "+attrs[i].getName() +" from dtd");
1658                            gencr("*/");
1659                            gencr("public static String getDefault" + attrs[i].getName() + "() {");
1660                            gencr("\treturn \"" + attrs[i].getDefaultValue()+ "\".trim();");
1661                            gencr("}");
1662                        }
1663                        
1664                        select(GET_DEFAULT_ATTR_GENERIC_SECTION);
1665                        if(attrs[i].getDefaultValue() != null) {
1666                            gencr("\tif(attr.equals(" + tagFile + constantTagName + ")) return \"" + attrs[i].getDefaultValue() + "\".trim();");
1667                        }
1668                        
1669/* select(OUT_GETATTR);
1670            gencr("\t\tif (key.equals(ServerTags."+ constantTagName+"))");
1671            if(isBoolean){
1672                gencr("\t\t\treturn \"\"+is"+ attrs[i].getName() +"();");
1673            }
1674            else{
1675
1676                gencr("\t\t\treturn get"+ attrs[i].getName() +"();");
1677            }
1678            select(OUT_SETATTR);
1679            if(isBoolean){
1680                gencr("\t\tif (key.equals(ServerTags."+ constantTagName+"))");
1681                gencr("\t\t\tset"+ attrs[i].getName() +"(toBoolean(value));");
1682            }
1683            else{
1684                gencr("\t\tif (key.equals(ServerTags."+ constantTagName+"))");
1685                gencr("\t\t\tset"+ attrs[i].getName() +"(value);");
1686            }
1687 */

1688                        
1689                        
1690        }
1691// select(OUT_GETATTR);
1692
// gencr("\treturn null;");
1693
// gencr("}");
1694

1695select(GET_DEFAULT_ATTR_GENERIC_SECTION);
1696                gencr("return null;");
1697        gencr("}");
1698       
1699        
1700        /////////////////////////////////////////////////
1701

1702                
1703     
1704           
1705    }
1706
1707    ////////////////////////////////////
1708
static String JavaDoc transformTo_(String JavaDoc in){
1709    return in.replace('-', '_').toUpperCase();
1710    }
1711    
1712    ////////////////////////////////////
1713

1714    // Generate the createAttribute() code
1715
void genAttributes(int out, AttrProp[] attributes, String JavaDoc name) {
1716        select(out);
1717        if (attributes == null)
1718            return;
1719        for (int j=0; j<attributes.length; j++) {
1720            AttrProp attr = attributes[j];
1721            genAttribute(name, attr);
1722        }
1723    }
1724
1725    void genAttribute(String JavaDoc name, AttrProp attr) {
1726        String JavaDoc constName = Common.constName(attr.getDtdName());
1727        gen("this.createAttribute(");
1728        if (name != null)
1729            gen(name, ", ");
1730        gen("\"", attr.getDtdName(), "\", ");
1731        gen("\"", attr.getName(), "\", "); cr(); gentab(4);
1732        gencr(attr.typeAsString(), ","); gentab(4);
1733        String JavaDoc[] values = attr.getValues();
1734        if (values.length > 0) {
1735            gencr("new String[] {");
1736            for (int k=0; k<values.length; k++) {
1737                if (k>0) gencr(",");
1738                gentab(5);
1739                gen("\"", values[k], "\"");
1740            }
1741            cr(); gentab(4); gen("}, ");
1742        }
1743        else
1744            gen("null, ");
1745        
1746        String JavaDoc value = attr.getDefaultValue();
1747        
1748        if (value != null)
1749            gen("\"", value, "\")");
1750        else
1751            gen("null)");
1752        eol();
1753    }
1754    
1755    void genBody(int out) throws IOException {
1756    select(out);
1757    
1758    //
1759
// add/remove comparators
1760
//
1761
comment();
1762    jw.beginMethod("addComparator", "org.netbeans.modules.schema2beans.BeanComparator c", null, "void", jw.PUBLIC | jw.STATIC);
1763    gen("comparators.add(c)"); eol();
1764    end(); cr();
1765    
1766    comment();
1767    jw.beginMethod("removeComparator", "org.netbeans.modules.schema2beans.BeanComparator c", null, "void", jw.PUBLIC | jw.STATIC);
1768    gen("comparators.remove(c)"); eol();
1769    end();
1770    
1771    //
1772
// Event registration methods
1773
//
1774

1775    //
1776
// the generation of addPropertyChange are in BaseBean.
1777
//
1778

1779    if (this.genGenericVetoListeners) {
1780        comment();
1781        jw.beginMethod("add"+VCL, VCL_FULL_CLASS_NAME+" l", null, "void", jw.PUBLIC);
1782        gengetprop();
1783        gen("\tp.addVCListener(l)"); eol();
1784        end(); cr();
1785        
1786        comment();
1787        jw.beginMethod("remove"+VCL, VCL_FULL_CLASS_NAME+" l", null, "void", jw.PUBLIC);
1788        gengetprop();
1789        gen("\tp.removeVCListener(l)"); eol();
1790        end(); cr();
1791    }
1792    
1793    //
1794
// Per property event registration method
1795
//
1796

1797    //
1798
// the generation of addPropertyChange are now in BaseBean.
1799
//
1800
if (this.genVetoListeners) {
1801        comment();
1802        jw.beginMethod("add"+VCL, "String n, "+VCL_FULL_CLASS_NAME+" l", null, "void", jw.PUBLIC);
1803        gengetpropbyname();
1804        gen("\tp.addVCListener(l)"); eol();
1805        end(); cr();
1806        
1807        comment();
1808        jw.beginMethod("remove"+VCL, "String n, "+VCL_FULL_CLASS_NAME+" l", null, "void", jw.PUBLIC);
1809        gengetpropbyname();
1810        gen("\tp.removeVCListener(l)"); eol();
1811        end(); cr();
1812    }
1813    
1814    if (this.beanElement.isRoot) {
1815        // public void createBean(Node doc)
1816
comment();
1817        comment("This method returns the root of the bean graph");
1818        comment("Each call creates a new bean graph from the specified DOM graph");
1819        comment();
1820
1821        String JavaDoc thrownExceptions = null;
1822        if (shouldThrowException()) {
1823            thrownExceptions = "org.netbeans.modules.schema2beans.Schema2BeansException";
1824        }
1825        jw.beginMethod("createGraph", "org.w3c.dom.Node doc", thrownExceptions, className, jw.PUBLIC | jw.STATIC);
1826        if (config.isSetDefaults())
1827            gen("return new ", this.className, "(doc, Common.USE_DEFAULT_VALUES)");
1828        else
1829            gen("return new ", this.className, "(doc, Common.NO_DEFAULT_VALUES)");
1830        eol();
1831        end(); cr();
1832        
1833        jw.beginMethod("createGraph", "java.io.File f",
1834                       (thrownExceptions == null) ? "java.io.IOException" :
1835                         thrownExceptions + ", " + "java.io.IOException",
1836                       className, jw.PUBLIC | jw.STATIC);
1837        jw.writeEol("java.io.InputStream in = new java.io.FileInputStream(f)");
1838        jw.beginTry();
1839        gen("return createGraph(in, false)"); eol();
1840        jw.endFinallyBegin();
1841        jw.writeEol("in.close()");
1842        jw.end();
1843        jw.endMethod();
1844
1845        // public void createGraph(InputStream in)
1846
jw.beginMethod("createGraph", "java.io.InputStream in", thrownExceptions, className, jw.PUBLIC | jw.STATIC);
1847        gen("return createGraph(in, false)"); eol();
1848        jw.endMethod();
1849        
1850        // public void createGraph(InputStream in)
1851
jw.beginMethod("createGraph", "java.io.InputStream in, boolean validate", thrownExceptions, className, jw.PUBLIC | jw.STATIC);
1852        if (!shouldThrowException()) {
1853            gen("try ");
1854            begin();
1855        }
1856        gen("Document doc = GraphManager.createXmlDocument(in, validate)");
1857        eol();
1858        gen("return createGraph(doc)"); eol();
1859        if (!shouldThrowException()) {
1860            end();
1861            gen("catch (Exception t) ");
1862            begin();
1863            if (this.config.isStandalone()) {
1864                gencrNoI18N("throw new RuntimeException(\"DOM graph creation failed\", t);");
1865            } else {
1866                gencr("throw new RuntimeException(Common.getMessage(");
1867                tabIn();
1868                gencr("\"DOMGraphCreateFailed_msg\",");
1869                tabIn();
1870                gen("t))"); eol();
1871            }
1872            end();
1873        }
1874        end(); cr();
1875        
1876        
1877        // public void createBean()
1878
comment();
1879        comment("This method returns the root for a new empty bean graph");
1880        comment();
1881        
1882        jw.beginMethod("createGraph", "", null, className, jw.PUBLIC | jw.STATIC);
1883        if (shouldThrowException()) {
1884            gen("try ");
1885            begin();
1886        }
1887        gen("return new ", this.className, "()"); eol();
1888        if (shouldThrowException()) {
1889            end();
1890            gen("catch (Schema2BeansException e) ");
1891            begin();
1892            gen("throw new RuntimeException(e)"); eol();
1893            end();
1894        }
1895        end(); cr();
1896    }
1897    
1898    MetaElement me = getMetaElement(beanElement);
1899    if (me != null && me.getUserCode() != null) {
1900        String JavaDoc userCode = me.getUserCode();
1901        cr(); gencr(userCode);
1902    }
1903    }
1904
1905    boolean shouldThrowException() {
1906        return (config.isThrowErrors() || (mdd != null && mdd.isThrowExceptions()));
1907    }
1908    
1909    void genValidate() throws IOException {
1910        select(BODY_SECTION);
1911        jw.beginMethod("validate", "", "org.netbeans.modules.schema2beans.ValidateException", "void", jw.PUBLIC);
1912        if (config.isGenerateValidate()) {
1913            genValidateProperties();
1914        }
1915        end();
1916        cr();
1917    }
1918
1919    protected void genValidateFail(String JavaDoc detail, String JavaDoc name,
1920                                   boolean quoteDetail,
1921                                   ValidateException.FailureType ft,
1922                                   JavaWriter out) throws IOException {
1923        out.write("throw new org.netbeans.modules.schema2beans.ValidateException(");
1924        if (quoteDetail)
1925            out.write('"');
1926        out.write(detail);
1927        if (quoteDetail)
1928            out.write('"');
1929        out.write(", org.netbeans.modules.schema2beans.ValidateException.FailureType.",
1930                 ft.toString());
1931        out.writeEolNoI18N(", \""+name+"\", this)");
1932    }
1933
1934    void genTrailer(int out) {
1935    select(out);
1936    gen(PUBLIC, STRING, "dumpBeanNode()");
1937    begin();
1938    gen("StringBuffer str = new StringBuffer()"); eol();
1939    gen("str.append(\"", this.className, "\\n\")"); eolNoI18N();
1940    gen("this.dump(str, \"\\n \")"); eolNoI18N();
1941    gen("return str.toString()"); eol();
1942    end(false);
1943    
1944    if (this.config.isDumpToString()) {
1945        cr();
1946        gencr(PUBLIC, STRING, "toString()");
1947        begin();
1948        gen("return this.dumpBeanNode()"); eol();
1949        end();
1950    }
1951    }
1952        
1953      // SRIDATTA
1954
static PrintStream serverTagsStream = null;
1955    
1956    /**
1957     * Generate the java code in the out stream, using the optional
1958     * metaDD bean graph.
1959     */

1960    public void generate(OutputStream out, MetaDD mdd) throws IOException {
1961    this.mdd = mdd;
1962    this.metaElement = getMetaElement(beanElement);
1963
1964    
1965    if (this.metaElement != null && this.metaElement.isSkipGeneration()) {
1966        config.messageOut.println("Skipping generation of class "
1967        + " (as specified in the mdd file)"); // NOI18N
1968
return;
1969    }
1970    
1971    ////////////////////////////////////////SRIDATTA
1972
if (serverTagsStream==null){
1973        String JavaDoc genDir = System.getProperty("gendir");
1974        if(genDir==null)
1975        {
1976            genDir = config.getRootDir()+ "/" +this.packageName.replace('.','/');
1977        }
1978        serverTagsStream = new PrintStream(new FileOutputStream(genDir + "/" + stags + ".java"));
1979
1980        serverTagsStream.println("/*");
1981        serverTagsStream.println(" * The contents of this file are subject to the terms ");
1982        serverTagsStream.println(" * of the Common Development and Distribution License ");
1983        serverTagsStream.println(" * (the License). You may not use this file except in");
1984        serverTagsStream.println(" * compliance with the License.");
1985        serverTagsStream.println(" * ");
1986        serverTagsStream.println(" * You can obtain a copy of the license at ");
1987        serverTagsStream.println(" * https://glassfish.dev.java.net/public/CDDLv1.0.html or");
1988        serverTagsStream.println(" * glassfish/bootstrap/legal/CDDLv1.0.txt.");
1989        serverTagsStream.println(" * See the License for the specific language governing ");
1990        serverTagsStream.println(" * permissions and limitations under the License.");
1991        serverTagsStream.println(" * ");
1992        serverTagsStream.println(" * When distributing Covered Code, include this CDDL ");
1993        serverTagsStream.println(" * Header Notice in each file and include the License file ");
1994        serverTagsStream.println(" * at glassfish/bootstrap/legal/CDDLv1.0.txt. ");
1995        serverTagsStream.println(" * If applicable, add the following below the CDDL Header, ");
1996        serverTagsStream.println(" * with the fields enclosed by brackets [] replaced by");
1997        serverTagsStream.println(" * you own identifying information: ");
1998        serverTagsStream.println(" * \"Portions Copyrighted [year] [name of copyright owner]\"");
1999        serverTagsStream.println(" * ");
2000        serverTagsStream.println(" * Copyright 2006 Sun Microsystems, Inc. All rights reserved.");
2001        serverTagsStream.println(" */");
2002        serverTagsStream.println(" ");
2003
2004        serverTagsStream.println("package " + this.packageName + ";");
2005        serverTagsStream.println("public class " + stags + "{ ");
2006    }
2007
2008    serverTagsStream.println("// Tags for Element "+beanElement.getDTDName());
2009    String JavaDoc ss = transformTo_(beanElement.getDTDName().toUpperCase());
2010    if (listOfTags.containsKey(ss))
2011        serverTagsStream.println("//static public final String "+ss+" = \""+ beanElement.getDTDName()+"\";");
2012    else
2013        serverTagsStream.println("static public final String "+transformTo_(beanElement.getDTDName().toUpperCase())+" = \""+ beanElement.getDTDName()+"\";");
2014    listOfTags.put(ss,ss );
2015    ////////////////////////////////////////////////SRIDATTA this.mdd = mdd;
2016

2017    findAttributeOwners();
2018
2019    this.isVetoable = this.config.isVetoable();
2020    
2021    // Find out if there is any veto specified in the mdd
2022
if (this.mdd != null) {
2023        //if (this.mdd.findPropertyValue("vetoable", Boolean.TRUE).length != 0) {
2024
org.netbeans.modules.schema2beansdev.metadd.CommonBean[] beans = mdd.childBeans(true);
2025        for (int beanPos = 0; beanPos < beans.length; ++beanPos) {
2026            try {
2027                if (((Boolean JavaDoc)beans[beanPos].fetchPropertyByName("vetoable")).booleanValue()) {
2028                    // Override information from the mdd file
2029
this.isVetoable = this.mdd.isVetoable();
2030                    this.genGenericVetoListeners = true;
2031                    break;
2032                }
2033            } catch (IllegalArgumentException JavaDoc e) {
2034                // This bean does not have that property
2035
}
2036        }
2037    }
2038    
2039    
2040    this.genHeader(HEADER_SECTION);
2041    this.genPackage(HEADER_SECTION);
2042    this.genImports(HEADER_SECTION);
2043    select(HEADER_SECTION);
2044    cr(); beginNoI18N(); cr();
2045    this.genClassName(HEADER_SECTION);
2046    
2047    this.genDeclarations(DECL_SECTION);
2048    this.genConstructor(CONSTRUCTOR_SECTION);
2049    
2050    this.genAccessors(ACCESS_SECTION);
2051    
2052    this.genBody(BODY_SECTION);
2053    
2054    this.genInitializer();
2055
2056    genValidate();
2057    
2058    this.genTrailer(TRAILER_SECTION);
2059    
2060    select(CONSTRUCTOR_SECTION);
2061    gen("this.initialize(options)"); eol();
2062    end(); cr();
2063    
2064    select(INITIALIZE_SECTION);
2065    cr(); end(); cr();
2066    
2067    select(TRAILER_SECTION);
2068    end(); cr();
2069    endNoI18N(); cr();
2070/* krav
2071    try {
2072        printSchema();
2073    } catch (IOException ioe) {
2074        // Do not generate the schema comment
2075    }
2076*/

2077    printGenBuffers(out);
2078    }
2079
2080    protected void addExtraMethods() {
2081        // Most of these are taken from the public methods of BaseBean
2082
jw.addToMethodStore("addComparator", "org.netbeans.modules.schema2beans.BeanComparator c", null, "void", jw.PUBLIC | jw.STATIC);
2083        jw.addToMethodStore("removeComparator", "org.netbeans.modules.schema2beans.BeanComparator c", null, "void", jw.PUBLIC | jw.STATIC);
2084        if (beanElement.isRoot) {
2085        }
2086        jw.addToMethodStore("getValue", "String name", null, "Object");
2087        jw.addToMethodStore("getValue", "String name, int index", null, "Object");
2088        jw.addToMethodStore("isNull", "String name", null, "boolean");
2089        jw.addToMethodStore("isNull", "String name, int index", null, "boolean");
2090        jw.addToMethodStore("getValues", "String name", null, "Object[]");
2091        jw.addToMethodStore("setValue", "String name, Object value", null, "void");
2092        jw.addToMethodStore("setValue", "String name, int index, Object value", null, "void");
2093        jw.addToMethodStore("setValue", "String name, Object[] value", null, "void");
2094        jw.addToMethodStore("addValue", "String name, Object value", null, "int");
2095        jw.addToMethodStore("removeValue", "String name, Object value", null, "int");
2096        jw.addToMethodStore("removeValue", "String name, int index", null, "void");
2097        jw.addToMethodStore("indexOf", "String name, Object value", null, "int");
2098        jw.addToMethodStore("size", "String name", null, "int");
2099        jw.addToMethodStore("isChoiceProperty", "String name", null, "boolean");
2100        jw.addToMethodStore("isChoiceProperty", "", null, "boolean");
2101        jw.addToMethodStore("getAttributeValue", "String name", null, "String");
2102        jw.addToMethodStore("getAttributeValue", "String propName, String name", null, "String");
2103        jw.addToMethodStore("setAttributeValue", "String propName, int index, String name, String value", null, "void");
2104        jw.addToMethodStore("getAttributeValue", "String propName, int index, String name", null, "String");
2105        jw.addToMethodStore("getAttributeNames", "String propName", null, "String[]");
2106        jw.addToMethodStore("getAttributeNames", "", null, "String[]");
2107        jw.addToMethodStore("write", "java.io.OutputStream out", "java.io.IOException, org.netbeans.modules.schema2beans.Schema2BeansRuntimeException", "void");
2108        jw.addToMethodStore("write", "java.io.OutputStream out, String encoding", "java.io.IOException, org.netbeans.modules.schema2beans.Schema2BeansException", "void");
2109        jw.addToMethodStore("write", "java.io.Writer w", "java.io.IOException, org.netbeans.modules.schema2beans.Schema2BeansException", "void");
2110        jw.addToMethodStore("write", "java.io.Writer w, String encoding", "java.io.IOException, org.netbeans.modules.schema2beans.Schema2BeansException", "void");
2111        jw.addToMethodStore("writeNoReindent", "java.io.OutputStream out", "java.io.IOException, org.netbeans.modules.schema2beans.Schema2BeansException", "void");
2112        jw.addToMethodStore("reindent", "", null, "void");
2113        jw.addToMethodStore("clone", "", null, "Object");
2114        jw.addToMethodStore("merge", "org.netbeans.modules.schema2beans.BaseBean bean, int mode", null, "void");
2115        jw.addToMethodStore("merge", "org.netbeans.modules.schema2beans.BaseBean bean", null, "void");
2116        jw.addToMethodStore("equals", "Object obj", null, "boolean");
2117        jw.addToMethodStore("parent", "", null, "org.netbeans.modules.schema2beans.BaseBean");
2118        jw.addToMethodStore("fullName", "", null, "String");
2119        jw.addToMethodStore("isRoot", "", null, "boolean");
2120        jw.addToMethodStore("name", "", null, "String");
2121        jw.addToMethodStore("dtdName", "", null, "String");
2122        jw.addToMethodStore("dump", "StringBuffer str, String indent", null, "void");
2123        jw.addToMethodStore("createGraph", "Class clazz, java.io.InputStream in", "org.netbeans.modules.schema2beans.Schema2BeansException", "org.netbeans.modules.schema2beans.BaseBean", jw.PUBLIC | jw.STATIC);
2124        jw.addToMethodStore("createGraph", "Class clazz, java.io.InputStream in, boolean validate", "org.netbeans.modules.schema2beans.Schema2BeansException", "org.netbeans.modules.schema2beans.BaseBean", jw.PUBLIC | jw.STATIC);
2125        jw.addToMethodStore("createGraph", "Class clazz, java.io.InputStream in, boolean validate, org.xml.sax.EntityResolver er", "org.netbeans.modules.schema2beans.Schema2BeansException", "org.netbeans.modules.schema2beans.BaseBean", jw.PUBLIC | jw.STATIC);
2126        jw.addToMethodStore("createGraph", "Class clazz, java.io.InputStream in, boolean validate, org.xml.sax.EntityResolver er, org.xml.sax.ErrorHandler eh", "org.netbeans.modules.schema2beans.Schema2BeansException", "org.netbeans.modules.schema2beans.BaseBean", jw.PUBLIC | jw.STATIC);
2127        jw.addToMethodStore("addPropertyChangeListener", "java.beans.PropertyChangeListener l", null, "void");
2128        jw.addToMethodStore("removePropertyChangeListener", "java.beans.PropertyChangeListener l", null, "void");
2129        jw.addToMethodStore("addPropertyChangeListener", "String n, java.beans.PropertyChangeListener l", null, "void");
2130        jw.addToMethodStore("removePropertyChangeListener", "String n, java.beans.PropertyChangeListener l", null, "void");
2131        jw.addToMethodStore("comments", "", null, "org.w3c.dom.Comment[]");
2132        jw.addToMethodStore("addComment", "String comment", null, "org.w3c.dom.Comment");
2133        jw.addToMethodStore("removeComment", "org.w3c.dom.Comment comment", null, "void");
2134        jw.addToMethodStore("childBeans", "boolean recursive", null, "org.netbeans.modules.schema2beans.BaseBean[]");
2135        jw.addToMethodStore("childBeans", "boolean recursive, java.util.List beans", null, "void");
2136        jw.addToMethodStore("setDefaultNamespace", "String namespace", null, "void");
2137        jw.addToMethodStore("getDefaultNamespace", "", null, "String");
2138        jw.addToMethodStore("toString", "", null, "String");
2139        //jw.addToMethodStore("copyProperties", "org.netbeans.modules.schema2beans.BaseBean destBean, java.util.Map nameMapping", null, "void");
2140
}
2141
2142    /*
2143    protected Signatures getSystemSignatures() {
2144        Signatures result = new Signatures();
2145        Signature sig;
2146        if (config.isGenerateValidate()) {
2147            result.add(new Signature("void", "validate"));
2148        }
2149        sig = new Signature("void", "addComparator");
2150        sig.addParameter("org.netbeans.modules.schema2beans.BeanComparator", "c");
2151        sig.setStatic();
2152        result.add(sig);
2153        sig = new Signature("void", "removeComparator");
2154        sig.addParameter("org.netbeans.modules.schema2beans.BeanComparator", "c");
2155        sig.setStatic();
2156        result.add(sig);
2157        if (beanElement.isRoot) {
2158            sig = new Signature(className, "createGraph");
2159            sig.addParameter("org.w3c.dom.Node", "doc");
2160            sig.setStatic();
2161            result.add(sig);
2162            sig = new Signature(className, "createGraph");
2163            sig.addParameter("java.io.InputStream", "in");
2164            sig.setStatic();
2165            result.add(sig);
2166            sig = new Signature(className, "createGraph");
2167            sig.addParameter("java.io.InputStream", "in");
2168            sig.addParameter("boolean", "validate");
2169            sig.setStatic();
2170            result.add(sig);
2171            sig = new Signature(className, "createGraph");
2172            sig.setStatic();
2173            result.add(sig);
2174        }
2175        sig = new Signature("void", "write");
2176        sig.addParameter("java.io.OutputStream", "out");
2177        sig.addThrows("java.io.IOException");
2178        sig.addThrows("org.netbeans.modules.schema2beans.Schema2BeansRuntimeException");
2179        result.add(sig);
2180        sig = new Signature("void", "write");
2181        sig.addParameter("java.io.OutputStream", "out");
2182        sig.addParameter("String", "encoding");
2183        sig.addThrows("java.io.IOException");
2184        sig.addThrows("org.netbeans.modules.schema2beans.Schema2BeansException");
2185        result.add(sig);
2186        sig = new Signature("void", "write");
2187        sig.addParameter("java.io.Writer", "w");
2188        sig.addThrows("java.io.IOException");
2189        sig.addThrows("org.netbeans.modules.schema2beans.Schema2BeansException");
2190        result.add(sig);
2191        sig = new Signature("void", "write");
2192        sig.addParameter("java.io.Writer", "w");
2193        sig.addParameter("String", "encoding");
2194        sig.addThrows("java.io.IOException");
2195        sig.addThrows("org.netbeans.modules.schema2beans.Schema2BeansException");
2196        result.add(sig);
2197        sig = new Signature("void", "merge");
2198        sig.addParameter("org.netbeans.modules.schema2beans.BaseBean", "bean");
2199        result.add(sig);
2200        sig = new Signature("boolean", "equals", OTHER);
2201        sig.addParameter("Object", "obj");
2202        result.add(sig);
2203        result.add(new Signature("String", "toString"));
2204        return result;
2205    }
2206    */

2207
2208    public void setInvalidPropertyNames(Map invalidNames) {
2209        invalidNames.put("Class", null);
2210        invalidNames.put("Property", null);
2211        invalidNames.put("AttributeNames", null);
2212    }
2213
2214    protected String JavaDoc testIfPropertySet(Property prop) {
2215        if (!prop.isAttribute() && prop.isScalar() &&
2216            !Common.isBoolean(prop.type))
2217            return "getValue("+prop.constName+") != null";
2218        else
2219            return super.testIfPropertySet(prop);
2220    }
2221
2222    protected String JavaDoc testIfPropertyNotSet(Property prop) {
2223        if (!prop.isAttribute() && prop.isScalar() &&
2224            !Common.isBoolean(prop.type))
2225            return "getValue("+prop.constName+") == null";
2226        else
2227            return super.testIfPropertyNotSet(prop);
2228    }
2229}
2230
2231//******************************************************************************
2232
// END_NOI18N
2233
// This class does not (and will not) cantain strings that need to be localized.
2234
//******************************************************************************
2235
Popular Tags