KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.schema2beansdev;
21
22 import java.util.*;
23 import java.io.*;
24
25 import org.w3c.dom.*;
26 import org.xml.sax.*;
27 import javax.xml.parsers.*;
28
29 import org.netbeans.modules.schema2beans.*;
30 import org.netbeans.modules.schema2beansdev.gen.XMLWriter;
31 import org.netbeans.modules.schema2beansdev.metadd.*;
32
33 public class XMLSchemaParser extends GeneralParser implements SchemaParser {
34     public final static String JavaDoc JAVA_TYPE_NS = "http://schema2beans.netbeans.org/javaTypes";
35
36     // Handler to callback with the tokens found in the Schema.
37
private DocDefHandler handler;
38
39     private boolean debug;
40     private GenBeans.Config config = null;
41     private Stack parentTypes = new Stack();
42     private Stack parentUniqueNames = new Stack();
43     private String JavaDoc lastDefinedType = null;
44     private boolean lastDefinedExternalType = true;
45     private List perAttributeExtraData = new LinkedList();
46     private String JavaDoc targetNamespace;
47     private Map elementsAlreadyDefined = new IdentityHashMap();
48
49     SchemaRep schema;
50
51     public XMLSchemaParser(GenBeans.Config config, DocDefHandler handler) {
52         this.config = config;
53         this.filename = config.getFilename();
54         this.schemaIn = config.getFileIn();
55         this.handler = handler;
56         this.debug = config.isTraceParse();
57
58         schema = new SchemaRep();
59         schema.debug = debug;
60         handler.setPrefixGuesser(schema);
61     }
62
63     public void process() throws java.io.IOException JavaDoc, Schema2BeansException {
64         startupReader();
65         try {
66             MetaDD mdd = config.getMetaDD();
67             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
68             dbf.setNamespaceAware(true);
69             dbf.setIgnoringComments(true);
70             dbf.setIgnoringElementContentWhitespace(true);
71             DocumentBuilder db = dbf.newDocumentBuilder();
72             Document xmlSchema = db.parse(new InputSource(reader));
73             schema.setCurrentParsedURI(getReaderURI());
74             if (config.isForME())
75                 schema.setSchemaTypesForME(true);
76             overrideSchemaTypes();
77             schema.readDocument(xmlSchema);
78         } catch (javax.xml.parsers.ParserConfigurationException JavaDoc e) {
79             throw new Schema2BeansNestedException(Common.getMessage("MSG_FailedToParse", filename), e);
80         } catch (org.xml.sax.SAXException JavaDoc e) {
81             throw new Schema2BeansNestedException(Common.getMessage("MSG_FailedToParse", filename), e);
82         } finally {
83             shutdownReader();
84         }
85         if (debug) {
86             PrintWriter pw = new PrintWriter(config.messageOut);
87             schema.writeXMLSchemaStandalone(pw);
88             pw.flush();
89         }
90         schema.optimize();
91         handler.startDocument(config.getDocRoot());
92         process(schema.getRootElement());
93         handler.endDocument();
94     }
95
96     /**
97      * Search thru the input beangraphs for anything that might affect
98      * the definition of types from xsd: or xml:
99      */

100     protected void overrideSchemaTypes() {
101         String JavaDoc xsdNS = schema.getNamespaceURI("xsd");
102         String JavaDoc xmlNS = schema.getNamespaceURI("xml");
103         for (Iterator it = config.readBeanGraphs(); it.hasNext(); ) {
104             org.netbeans.modules.schema2beansdev.beangraph.BeanGraph bg = (org.netbeans.modules.schema2beansdev.beangraph.BeanGraph) it.next();
105             for (int i = 0; i < bg.sizeSchemaTypeMapping(); ++i) {
106                 org.netbeans.modules.schema2beansdev.beangraph.SchemaTypeMappingType stm = bg.getSchemaTypeMapping(i);
107                 if (xsdNS.equals(stm.getSchemaTypeNamespace()) ||
108                     xmlNS.equals(stm.getSchemaTypeNamespace())) {
109                     setSchemaType(stm);
110                 }
111             }
112         }
113     }
114
115     public void setSchemaType(org.netbeans.modules.schema2beansdev.beangraph.BeanGraph bg) {
116         for (int i = 0; i < bg.sizeSchemaTypeMapping(); ++i) {
117             setSchemaType(bg.getSchemaTypeMapping(i));
118         }
119     }
120
121     public void setSchemaType(org.netbeans.modules.schema2beansdev.beangraph.SchemaTypeMappingType stm) {
122         schema.setSchemaTypeMapping(stm.getSchemaTypeNamespace(),
123                                     stm.getSchemaTypeName(),
124                                     stm.getJavaType());
125     }
126
127     protected void process(SchemaRep.ElementExpr ee) throws Schema2BeansException {
128         if (ee instanceof SchemaRep.Element) {
129             processElement((SchemaRep.Element) ee);
130         } else if (ee instanceof SchemaRep.ComplexType) {
131             // named ComplexType
132
processComplexType((SchemaRep.ComplexType) ee);
133         } else if (ee instanceof SchemaRep.UnionType) {
134             // named SimpleType
135
processUnionType((SchemaRep.UnionType) ee);
136         } else if (ee instanceof SchemaRep.SimpleType) {
137             // named SimpleType
138
processSimpleType((SchemaRep.SimpleType) ee);
139         } else if (ee instanceof SchemaRep.Restriction) {
140             processRestriction((SchemaRep.Restriction) ee);
141         } else if (ee instanceof SchemaRep.SchemaNode) {
142             processSchemaNode((SchemaRep.SchemaNode) ee);
143         } else if (ee instanceof SchemaRep.ElementInformationItem) {
144             if (parentTypes.empty()) {
145                 //config.messageOut.println("parentTypes1 is empty! ee="+ee);
146
} else {
147                 handler.addExtraDataNode((String JavaDoc) parentUniqueNames.peek(),
148                         (String JavaDoc) parentTypes.peek(), ee);
149             }
150         } else if (ee instanceof SchemaRep.RestrictionType) {
151             // Do nothing here as RestrictionType's are handled elsewhere.
152
} else if (ee instanceof SchemaRep.ModelGroup) {
153             processModelGroup((SchemaRep.ModelGroup) ee);
154         } else if (ee instanceof SchemaRep.Annotation) {
155             processAnnotation((SchemaRep.Annotation) ee);
156         } else if (ee instanceof SchemaRep.Extension) {
157             processExtension((SchemaRep.Extension) ee);
158         } else if (ee instanceof SchemaRep.ContainsSubElements) {
159             processContainsSubElements((SchemaRep.ContainsSubElements) ee);
160         } else {
161             config.messageOut.println("XMLSchemaPraser.process: Hit unknown ElementExpr: "+ee);
162         }
163
164     }
165
166     protected void processContainsSubElements(SchemaRep.ContainsSubElements cse) throws Schema2BeansException {
167         Iterator it = cse.subElementsIterator();
168         while (it.hasNext()) {
169             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
170             process(childee);
171         }
172     }
173
174     protected void processContainsSubElementsAndAttributes(SchemaRep.ContainsSubElements cse, String JavaDoc elementName) throws Schema2BeansException {
175         Iterator it = cse.subElementsIterator();
176         while (it.hasNext()) {
177             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
178             if (childee instanceof SchemaRep.Attribute) {
179                 processAttribute(elementName, (SchemaRep.Attribute)childee);
180             } else {
181                 process(childee);
182             }
183         }
184     }
185
186     protected void processElement(SchemaRep.Element el) throws Schema2BeansException {
187         boolean alreadyDefined = false;
188         if (elementsAlreadyDefined.containsKey(el))
189             alreadyDefined = true;
190         else
191             elementsAlreadyDefined.put(el, el);
192         setLastDefined(config.getDefaultElementType(), true);
193         perAttributeExtraData.clear();
194
195         String JavaDoc name = el.getElementName();
196         SchemaRep.Restriction[] restrict = null;
197         boolean externalType = false;
198         String JavaDoc schemaType;
199         String JavaDoc namespace = targetNamespace;
200         if (el.getRef() == null) {
201             schemaType = el.getXMLSchemaType();
202             namespace = el.getElementNamespace();
203         } else {
204             SchemaRep.Element referredElement = el.getRefElement();
205             if (referredElement == null) {
206                 config.messageOut.println("referredElement is null for "+el);
207                 throw new IllegalStateException JavaDoc("referredElement is null for "+el);
208             }
209             if (elementsAlreadyDefined.containsKey(referredElement))
210                 alreadyDefined = true;
211             else
212                 elementsAlreadyDefined.put(referredElement, el);
213             name = referredElement.getElementName();
214             schemaType = referredElement.getXMLSchemaType();
215             if (schemaType == null) {
216                 // The referred to element either does not have a type
217
// associated with it, or it's type is defined in it's
218
// subelements.
219
schemaType = name;
220             }
221             String JavaDoc ns = schema.prefixOf(name);
222             if (ns != null) {
223                 name = schema.removePrefix(name);
224                 //namespace = schema.getNamespaceURI(ns);
225
}
226             namespace = referredElement.getElementNamespace();
227         }
228         if (debug)
229             config.messageOut.println("processElement (start: elementName="+name+" namespace="+namespace);
230         if (name == null) {
231             config.messageOut.println("WARNING: elementName is null.");
232         }
233         boolean definedInSubElements;
234         if (schemaType == null) {
235             definedInSubElements = true;
236             schemaType = name;
237         } else {
238             definedInSubElements = false;
239         }
240         String JavaDoc fullSchemaType = schema.resolveNamespaceDefault(schemaType, namespace);
241         /*
242         if (schemaType.equals(fullSchemaType) && namespace != null) {
243             // No namespace prefix, so add the one we're defined with.
244             fullSchemaType = schema.canonicalQName(namespace, schemaType);
245             System.out.println("HAD to add namespace to fullSchemaType: "+fullSchemaType);
246             }*/

247         String JavaDoc defaultValue = el.getDefault();
248         if (debug)
249             config.messageOut.println("processElement: name="+name+" schemaType="+schemaType+" fullSchemaType="+fullSchemaType+" definedInSubElements="+definedInSubElements);
250         if (!definedInSubElements) {
251             SchemaRep.ElementExpr schemaTypeDef = schema.getSchemaTypeDef(schemaType);
252             if (schemaTypeDef instanceof SchemaRep.ContainsSubElements)
253                 if (hasUnionType((SchemaRep.ContainsSubElements)schemaTypeDef))
254                     handler.setUnion(el.getFullContentName(), fullSchemaType, true);
255             //config.messageOut.println("schemaType="+schemaType+" schemaTypeDef="+schemaTypeDef);
256
// Look for restriction
257
if (schemaTypeDef instanceof SchemaRep.ContainsSubElements) {
258                 SchemaRep.ContainsSubElements cse = (SchemaRep.ContainsSubElements) schemaTypeDef;
259                 restrict = lookForRestriction(cse);
260                 String JavaDoc foundDefault = lookForDefault(restrict);
261                 if (foundDefault != null)
262                     defaultValue = foundDefault;
263             }
264             String JavaDoc javaType = null;
265             if (schemaTypeDef instanceof SchemaRep.HasJavaTypeName) {
266                 javaType = ((SchemaRep.HasJavaTypeName)schemaTypeDef).getJavaTypeName();
267             } else {
268                 String JavaDoc ns = schema.prefixOf(schemaType);
269                 String JavaDoc nsURI = schema.getNamespaceURI(ns);
270                 if (JAVA_TYPE_NS.equals(nsURI)) {
271                     javaType = schema.removePrefix(schemaType);
272                 }
273             }
274             handler.element(el.getFullContentName(), fullSchemaType,
275                             name, namespace,
276                             getInstanceValue(el.getMinOccurs(),
277                                              el.getMaxOccurs()),
278                             externalType, defaultValue);
279             addExtraDataForType(el.getFullContentName(), fullSchemaType, schemaTypeDef);
280             if (javaType != null) {
281                 //config.messageOut.println("It has a java type: "+javaType);
282
handler.javaType(el.getFullContentName(), fullSchemaType, javaType);
283                 if (parentTypes.isEmpty()) {
284                     // Top level element def
285
String JavaDoc mySchemaType = schema.resolveNamespaceDefault(name, namespace);
286                     //config.messageOut.println("mySchemaType="+mySchemaType);
287
handler.javaType(el.getFullContentName(), mySchemaType, javaType);
288                 }
289             }
290             handler.nillable(el.isNillable());
291         } else {
292             restrict = lookForRestriction(el);
293             boolean existsAlready;
294             while (!alreadyDefined) {
295                 existsAlready = handler.doesElementExist(fullSchemaType);
296                 if (!existsAlready)
297                     break;
298                 if (debug)
299                     config.messageOut.println("existsAlready: "+existsAlready+", "+el);
300                 String JavaDoc contextName = null;
301                 if (!parentTypes.isEmpty()) {
302                     contextName = (String JavaDoc) parentTypes.peek();
303                     int curlyBracePos = contextName.lastIndexOf('}');
304                     if (curlyBracePos >= 0)
305                         contextName = contextName.substring(curlyBracePos+1);
306                 }
307                 if (contextName == null)
308                     contextName = "other";
309                 fullSchemaType += '-' + contextName;
310                 if (debug)
311                     config.messageOut.println("New name: "+fullSchemaType);
312             }
313         }
314         parentTypes.push(fullSchemaType);
315         parentUniqueNames.push(el.getFullContentName());
316         processContainsSubElements(el);
317
318         parentUniqueNames.pop();
319         parentTypes.pop();
320
321         if (definedInSubElements) {
322             //config.messageOut.println("lastDefinedType="+lastDefinedType+" name="+name);
323
// If we're a top level element and they hadn't defined the type,
324
// then the sub elements defined it for us. If they hadn't
325
// defined a type, and we're not a top level element, then we now
326
// know what type we are (in lastDefinedType), and we should
327
// add ourselves to our enclosing element.
328
if (!parentTypes.isEmpty()) {
329                 if (restrict != null) {
330                     String JavaDoc foundDefault = lookForDefault(restrict);
331                     if (foundDefault != null)
332                         defaultValue = foundDefault;
333                 }
334                 handler.element(el.getFullContentName(), lastDefinedType,
335                                 name, namespace,
336                                 getInstanceValue(el.getMinOccurs(),
337                                                  el.getMaxOccurs()),
338                                 lastDefinedExternalType, defaultValue);
339                 handler.nillable(el.isNillable());
340             }
341             SchemaRep.ElementExpr schemaTypeDef = schema.getSchemaTypeDefResolvedNamespace(lastDefinedType);
342             if (schemaTypeDef instanceof SchemaRep.HasJavaTypeName) {
343                 String JavaDoc javaType = ((SchemaRep.HasJavaTypeName)schemaTypeDef).getJavaTypeName();
344                 //config.messageOut.println("javaType="+javaType);
345
if (javaType != null) {
346                     handler.javaType(el.getFullContentName(),
347                                      lastDefinedType, javaType);
348                 }
349             }
350         }
351
352         // Load in all of the restrictions into this element
353
if (restrict != null) {
354             addExtraDataCurLink(restrict);
355         }
356         if (!("1".equals(el.getMaxOccurs()) || "unbounded".equals(el.getMaxOccurs()))) {
357             // Unusual maxOccurs amount, add a restriction
358
handler.addExtraDataCurLink(new MaxOccursRestriction(el.getMaxOccurs()));
359         }
360         if (!("1".equals(el.getMinOccurs()) || "0".equals(el.getMinOccurs()))) {
361             // Unusual minOccurs amount, add a restriction
362
handler.addExtraDataCurLink(new MinOccursRestriction(el.getMinOccurs()));
363         }
364         if (perAttributeExtraData.size() > 0) {
365             for (Iterator it = perAttributeExtraData.iterator(); it.hasNext(); ) {
366                 handler.addExtraDataCurLink(it.next());
367             }
368         }
369
370         if (debug)
371             config.messageOut.println("processElement finish): elementName="+name);
372     }
373
374     protected boolean hasUnionType(SchemaRep.ContainsSubElements schemaTypeDef) {
375         if (schemaTypeDef instanceof SchemaRep.UnionType)
376             return true;
377         Iterator itr = schemaTypeDef.subElementsIterator();
378         while (itr.hasNext()) {
379             SchemaRep.ElementExpr ee = (SchemaRep.ElementExpr) itr.next();
380             if (ee instanceof SchemaRep.ContainsSubElements) {
381                 if (hasUnionType((SchemaRep.ContainsSubElements)ee))
382                     return true;
383             }
384         }
385         return false;
386     }
387
388     protected SchemaRep.Restriction[] lookForRestriction(SchemaRep.ContainsSubElements schemaTypeDef) {
389         if (schemaTypeDef instanceof SchemaRep.UnionType) {
390             ArrayList restrictions = new ArrayList();
391             SchemaRep.Restriction restricts[] = null;
392 /*
393             String memberTypes = ((SchemaRep.UnionType)schemaTypeDef).getMemberTypes();
394             if (memberTypes != null && memberTypes.trim().length() > 0) {
395                 String[] members = memberTypes.trim().split(" ");
396                 for (int i=0; i < members.length; i++) {
397                     restricts = null;
398                     if (members[i].length() == 0)
399                         continue;
400                     SchemaRep.ElementExpr ee = schema.getSchemaTypeDef(members[i]);
401                     if (ee instanceof SchemaRep.ContainsSubElements)
402                         restricts = lookForRestriction((SchemaRep.ContainsSubElements)ee);
403                     if (restricts != null) {
404                         for (int j=0; j < restricts.length; j++)
405                             restrictions.add(restricts[j]);
406                     }
407                 }
408             }
409 */

410             SchemaRep.ElementExpr[] eeList =
411                     ((SchemaRep.UnionType)schemaTypeDef).getMemberTypeElements();
412             if (eeList != null) {
413                 for (int i=0; i < eeList.length; i++) {
414                     restricts = null;
415                     if (eeList[i] instanceof SchemaRep.ContainsSubElements)
416                         restricts = lookForRestriction((SchemaRep.ContainsSubElements)eeList[i]);
417                     if (restricts != null) {
418                         for (int j=0; j < restricts.length; j++)
419                             restrictions.add(restricts[j]);
420                     }
421                 }
422             }
423             Iterator itr = schemaTypeDef.subElementsIterator();
424             while (itr.hasNext()) {
425                 restricts = null;
426                 SchemaRep.ElementExpr ee = (SchemaRep.ElementExpr) itr.next();
427                 if (ee instanceof SchemaRep.ContainsSubElements)
428                     restricts = lookForRestriction((SchemaRep.ContainsSubElements)ee);
429                 else {
430                     continue;
431                 }
432                 if (restricts != null) {
433                     for (int i=0; i < restricts.length; i++)
434                         restrictions.add(restricts[i]);
435                 }
436             }
437             if (restrictions.size() == 0)
438                 return null;
439             restricts = new SchemaRep.Restriction[restrictions.size()];
440             return (SchemaRep.Restriction[])restrictions.toArray(restricts);
441         } else if (schemaTypeDef instanceof SchemaRep.SimpleType) {
442             SchemaRep.ContainsSubElements sube =
443                 (SchemaRep.ContainsSubElements)
444                         schemaTypeDef.findSubElement(SchemaRep.UnionType.class);
445             if (sube != null)
446                 return lookForRestriction(sube);
447             else {
448                 SchemaRep.Restriction restrict =
449                                 (SchemaRep.Restriction)
450                                     schemaTypeDef.findSubElement(
451                                         SchemaRep.Restriction.class);
452                 if (restrict == null)
453                     return null;
454                 return (new SchemaRep.Restriction[] { restrict });
455             }
456         } else if (schemaTypeDef instanceof SchemaRep.SimpleContent) {
457             SchemaRep.Restriction restrict =
458                             (SchemaRep.Restriction)
459                                 schemaTypeDef.findSubElement(
460                                     SchemaRep.Restriction.class);
461             if (restrict == null)
462                 return null;
463             return (new SchemaRep.Restriction[] { restrict });
464         } else if (schemaTypeDef instanceof SchemaRep.Element) {
465             return lookForRestriction((SchemaRep.ContainsSubElements)schemaTypeDef.findSubElement(SchemaRep.SimpleType.class));
466         } else if (schemaTypeDef instanceof SchemaRep.ComplexType) {
467             return lookForRestriction((SchemaRep.ContainsSubElements)schemaTypeDef.findSubElement(SchemaRep.SimpleContent.class));
468         }
469         return null;
470     }
471
472     protected void processComplexType(SchemaRep.ComplexType el) throws Schema2BeansException {
473         setLastDefined(null, true);
474         String JavaDoc name = el.getTypeName();
475         if (debug)
476             config.messageOut.println("processComplexType: el="+el);
477         if (name == null) {
478             if (debug)
479                 config.messageOut.println("Found unnamed complexType.");
480             if (!parentTypes.isEmpty())
481                 name = (String JavaDoc) parentTypes.peek();
482             if (name == null)
483                 name = el.getFullContentName();
484         } else {
485             name = schema.resolveNamespace(name);
486         }
487         parentTypes.push(name);
488         parentUniqueNames.push(el.getFullContentName());
489         handler.startElement(el.getFullContentName(), name, Common.ELEMENT);
490         handler.setAbstract(el.getFullContentName(), name, el.isAbstract());
491         for (Iterator it = el.subElementsIterator(); it.hasNext(); ) {
492             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
493             if (childee instanceof SchemaRep.ModelGroup) {
494                 processModelGroup((SchemaRep.ModelGroup) childee);
495             } else if (childee instanceof SchemaRep.Attribute) {
496                 processAttribute(name, (SchemaRep.Attribute)childee);
497             } else if (childee instanceof SchemaRep.AttributeGroup) {
498                 processAttributeGroup(name, (SchemaRep.AttributeGroup)childee);
499             } else if (childee instanceof SchemaRep.SimpleContent) {
500                 processSimpleContent((SchemaRep.SimpleContent) childee);
501             } else if (childee instanceof SchemaRep.Annotation) {
502                 processAnnotation((SchemaRep.Annotation) childee);
503             } else if (childee instanceof SchemaRep.ComplexContent) {
504                 processComplexContent((SchemaRep.ComplexContent) childee);
505             } else {
506                 config.messageOut.println("processComplexType: Unfamiliar subelement: "+childee);
507             }
508         }
509         handler.endElement();
510         parentUniqueNames.pop();
511         parentTypes.pop();
512         setLastDefined(name, false);
513     }
514
515     protected void processComplexContent(SchemaRep.ComplexContent el) throws Schema2BeansException {
516         //config.messageOut.println("el="+el);
517
for (Iterator it = el.subElementsIterator(); it.hasNext(); ) {
518             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
519             if (childee instanceof SchemaRep.Extension) {
520                 processExtension((SchemaRep.Extension) childee);
521             } else if (childee instanceof SchemaRep.Restriction) {
522                 processRestriction((SchemaRep.Restriction) childee);
523             } else if (childee instanceof SchemaRep.Annotation) {
524                 processAnnotation((SchemaRep.Annotation) childee);
525             } else {
526                 config.messageOut.println("processComplexContent: Unfamiliar subelement: "+childee);
527             }
528         }
529     }
530
531     protected void processSimpleContent(SchemaRep.SimpleContent el) throws Schema2BeansException {
532         processContainsSubElements(el);
533         //System.out.println("lastDefinedType="+lastDefinedType);
534
if (lastDefinedType == null)
535             return;
536         SchemaRep.ElementExpr schemaTypeDef = schema.getSchemaTypeDefResolvedNamespace(lastDefinedType);
537         if (schemaTypeDef == null)
538             return;
539         //System.out.println("processSimpleContent: schemaTypeDef="+schemaTypeDef);
540
String JavaDoc javaType = null;
541         if (schemaTypeDef instanceof SchemaRep.HasJavaTypeName) {
542             javaType = ((SchemaRep.HasJavaTypeName)schemaTypeDef).getJavaTypeName();
543         }
544         addExtraDataForType((String JavaDoc) parentUniqueNames.peek(),
545                 (String JavaDoc) parentTypes.peek(), schemaTypeDef);
546         if (javaType != null) {
547             handler.javaType((String JavaDoc) parentUniqueNames.peek(),
548                     (String JavaDoc) parentTypes.peek(), javaType);
549         }
550     }
551
552     protected void processExtension(SchemaRep.Extension el) throws Schema2BeansException {
553         if (debug)
554             config.messageOut.println("extension el="+el);
555         String JavaDoc uniqueName = (String JavaDoc) parentUniqueNames.peek();
556         String JavaDoc name = (String JavaDoc) parentTypes.peek();
557         String JavaDoc base = el.getBase();
558         SchemaRep.ElementExpr baseDef = schema.getSchemaTypeDef(base);
559         //config.messageOut.println("baseDef="+baseDef);
560
SchemaRep.Restriction[] restrict = null;
561         if (baseDef instanceof SchemaRep.ContainsSubElements) {
562             restrict = lookForRestriction((SchemaRep.ContainsSubElements)baseDef);
563             // We're extending something defined internally.
564
if (!config.isRespectExtension())
565                 processContainsSubElementsAndAttributes((SchemaRep.ContainsSubElements)baseDef, name);
566         }
567         addExtraDataForType(uniqueName, name, baseDef);
568         if (baseDef instanceof SchemaRep.ComplexType) {
569             SchemaRep.ComplexType complexType = (SchemaRep.ComplexType) baseDef;
570             String JavaDoc resolvedExtendsName = schema.resolveNamespace(complexType.getTypeName());
571             //config.messageOut.println("resolvedExtendsName="+resolvedExtendsName);
572
handler.setExtension(uniqueName, name, resolvedExtendsName);
573         }
574         String JavaDoc javaType = el.getJavaTypeName();
575         if (javaType != null) {
576             if (debug)
577                 config.messageOut.println("Setting javatype of "+name+" to "+javaType);
578             handler.javaType(uniqueName, name, javaType);
579             if (restrict != null) {
580                 addExtraDataNode(uniqueName, name, restrict);
581             }
582         }
583         processContainsSubElementsAndAttributes(el, name);
584     }
585
586     protected void addExtraDataForType(String JavaDoc uniqueName, String JavaDoc name,
587                                        SchemaRep.ElementExpr schemaTypeDef) throws Schema2BeansException {
588         if (schemaTypeDef instanceof SchemaRep.Base64Binary ||
589             schemaTypeDef instanceof SchemaRep.HexBinary) {
590             handler.addExtraDataNode(uniqueName, name, schemaTypeDef);
591             //System.out.println("Adding extradata to "+name+" of "+schemaTypeDef);
592
} else if (schemaTypeDef instanceof SchemaRep.ContainsSubElements) {
593             SchemaRep.Restriction[] restrict =
594                 lookForRestriction((SchemaRep.ContainsSubElements) schemaTypeDef);
595             //System.out.println("restrict="+restrict);
596
if (restrict != null)
597                 for (int i=0; i < restrict.length; i++)
598                     addExtraDataForType(uniqueName, name,
599                                     schema.getSchemaTypeDef(restrict[i].getBase()));
600         } else {
601             //System.out.println("name="+name+" schemaTypeDef="+schemaTypeDef);
602
}
603     }
604
605     protected void processModelGroup(SchemaRep.ModelGroup group) throws Schema2BeansException {
606         if (debug)
607             config.messageOut.println("processModelGroup: group="+group);
608         if (group instanceof SchemaRep.Group) {
609             SchemaRep.Group grp = (SchemaRep.Group) group;
610             if (grp.getRef() == null) {
611                 // This is a group definition which only used thru
612
// a reference.
613
return;
614             } else {
615                 SchemaRep.Group referredGroup = grp.getRefGroup();
616                 if (referredGroup == null) {
617                     config.messageOut.println(Common.getMessage("MSG_UnableToFind", "group", grp.getRef()));
618                 } else {
619                     processContainsSubElements(referredGroup);
620                 }
621                 return;
622             }
623         }
624         char separator = ' ';
625         if (group instanceof SchemaRep.Sequence)
626             separator = ',';
627         else if (group instanceof SchemaRep.Choice)
628             separator = '|';
629         int groupInstance = getInstanceValue(group.getMinOccurs(),
630                                              group.getMaxOccurs());
631         handler.startGroupElements();
632
633         boolean first = true;
634         Iterator it = group.subElementsIterator();
635         while (it.hasNext()) {
636             if (first)
637                 first = false;
638             else
639                 handler.character(separator);
640
641             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
642             if (childee instanceof SchemaRep.Element) {
643                 processElement((SchemaRep.Element) childee);
644             } else if (childee instanceof SchemaRep.ModelGroup) {
645                 processModelGroup((SchemaRep.ModelGroup) childee);
646             } else if (childee instanceof SchemaRep.Annotation) {
647             } else if (childee instanceof SchemaRep.Any) {
648                 processAny((SchemaRep.Any) childee);
649             } else {
650                 config.messageOut.println("processModelGroup: Unfamiliar subelement: "+childee);
651             }
652         }
653
654         handler.endGroupElements(groupInstance);
655     }
656
657     protected void processSimpleType(SchemaRep.SimpleType el) throws Schema2BeansException {
658         if (debug)
659             config.messageOut.println("processSimpleType: el="+el);
660         /*
661         String name = el.getTypeName();
662         if (name != null) {
663             parentTypes.push(name);
664             handler.startElement(el.getFullContentName(), name, Common.ELEMENT);
665         }
666         */

667         processContainsSubElements(el);
668         //addExtraDataForType(schema.resolveNamespace(el.getTypeName()), el);
669
/*
670         if (name != null) {
671             handler.endElement();
672             parentTypes.pop();
673             setLastDefined(name, true);
674         }
675         */

676     }
677
678     protected void processUnionType(SchemaRep.UnionType el) throws Schema2BeansException {
679         if (debug)
680             config.messageOut.println("processUnionType: el="+el);
681         /*
682         String name = el.getTypeName();
683         if (name != null) {
684             parentTypes.push(name);
685             handler.startElement(el.getFullContentName(), name, Common.ELEMENT);
686         }
687         */

688 /*
689         String memberTypes = el.getMemberTypes();
690         if (memberTypes != null && memberTypes.trim().length() > 0) {
691             String[] members = memberTypes.trim().split(" ");
692             for (int i=0; i < members.length; i++) {
693                 if (members[i].length() == 0)
694                     continue;
695                 SchemaRep.ElementExpr schemaTypeDef = schema.getSchemaTypeDef(members[i]);
696                 process(schemaTypeDef);
697             }
698         }
699 */

700         processContainsSubElements(el);
701         //addExtraDataForType(schema.resolveNamespace(el.getTypeName()), el);
702
/*
703         if (name != null) {
704             handler.endElement();
705             parentTypes.pop();
706             setLastDefined(name, true);
707         }
708         */

709     }
710
711     protected void processRestriction(SchemaRep.Restriction el) throws Schema2BeansException {
712         /*
713         boolean externalType = true;
714         String typeName = el.getJavaTypeName();
715         if (typeName == null) {
716             externalType = false;
717             typeName = el.getBase();
718         } else {
719             setLastDefined(typeName, externalType);
720         }
721         */

722         //System.out.println("processRestriction: el.base="+el.getBase()+" el.javaType="+el.getJavaTypeName());
723
setLastDefined(schema.resolveNamespace(el.getBase()), false);
724         //setLastDefined(el.getBase(), false);
725
//handler.element(el.getFullContentName(), typeName, typeName, Common.TYPE_1, externalType);
726
processContainsSubElements(el);
727     }
728
729     protected void processAny(SchemaRep.Any el) throws Schema2BeansException {
730         if (debug)
731             config.messageOut.println("Found "+el);
732         String JavaDoc namespace = el.getNamespace();
733         if (namespace != null && namespace.startsWith("##"))
734             namespace = null;
735         handler.element(el.getFullContentName(), "any",
736                         "any", namespace,
737                         getInstanceValue(el.getMinOccurs(),
738                                          el.getMaxOccurs()),
739                         true, null);
740         handler.javaType("any", "any", "org.w3c.dom.Element");
741         handler.addExtraDataCurLink(el);
742     }
743
744     protected void processSchemaNode(SchemaRep.SchemaNode sn) throws Schema2BeansException {
745         targetNamespace = sn.getTargetNamespace();
746         if (targetNamespace != null && !"".equals(targetNamespace))
747             handler.setDefaultNamespace(targetNamespace);
748         processContainsSubElements(sn);
749     }
750
751     protected void setLastDefined(String JavaDoc typeName) {
752         //config.messageOut.println("setLastDefined: typeName="+typeName);
753
this.lastDefinedType = typeName;
754         this.lastDefinedExternalType = false;
755     }
756
757     protected void setLastDefined(String JavaDoc typeName, boolean externalType) {
758         //config.messageOut.println("setLastDefined: typeName="+typeName);
759
this.lastDefinedType = typeName;
760         this.lastDefinedExternalType = externalType;
761     }
762
763     protected void addTopAttributes(SchemaRep.Element parentElement,
764                                     SchemaRep.Element el) {
765         //config.messageOut.println("fullContentName="+el.getFullContentName());
766
Iterator it = el.subElementsIterator();
767         while (it.hasNext()) {
768             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
769             if (childee instanceof SchemaRep.Attribute) {
770                 //addTopAttributes(parentElement, (SchemaRep.Attribute) childee);
771
} else if (childee instanceof SchemaRep.AttributeGroup) {
772                 //addTopAttributes(parentElement, (SchemaRep.AttributeGroup) childee);
773
} else if (childee instanceof SchemaRep.ComplexType) {
774                 addTopAttributes(parentElement, (SchemaRep.ComplexType) childee);
775             }
776         }
777     }
778
779     protected void addTopAttributes(SchemaRep.Element parentElement,
780                                     SchemaRep.ComplexType el) {
781         Iterator it = el.subElementsIterator();
782         while (it.hasNext()) {
783             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
784             if (childee instanceof SchemaRep.Attribute) {
785                 //addTopAttributes(parentElement, (SchemaRep.Attribute) childee);
786
} else if (childee instanceof SchemaRep.AttributeGroup) {
787                 //addTopAttributes(parentElement, (SchemaRep.AttributeGroup) childee);
788
}
789         }
790     }
791
792     protected void processAttribute(String JavaDoc parentElement,
793                                     SchemaRep.Attribute attr) throws Schema2BeansException {
794         if (debug)
795             config.messageOut.println("processAttribute to "+parentElement+" attr="+attr);
796         if (attr.getRef() != null) {
797             SchemaRep.Attribute referredAttr = attr.getRefAttribute();
798             if (referredAttr == null) {
799                 config.messageOut.println(Common.getMessage("MSG_UnableToFind", "attribute", attr.getRef()));
800             } else {
801                 processAttribute(parentElement, referredAttr);
802             }
803             return;
804         }
805
806         //config.messageOut.println("fullContentName="+attr.getFullContentName());
807
String JavaDoc attributeName = attr.getAttributeName();
808         boolean externalType = true;
809         String JavaDoc attrType = attr.getJavaType();
810         String JavaDoc schemaType = attr.getType();
811         String JavaDoc defaultValue = attr.getDefaultValue();
812         SchemaRep.Restriction[] restrict = null;
813         SchemaRep.ElementExpr ee = null;
814         if (schemaType != null && defaultValue == null) {
815             ee = schema.getSchemaTypeDef(schemaType);
816             if (ee instanceof SchemaRep.SimpleType) {
817                 SchemaRep.SimpleType st = (SchemaRep.SimpleType) ee;
818                 SchemaRep.Restriction r =
819                         (SchemaRep.Restriction) st.findSubElement("restriction");
820                 if (r != null)
821                     restrict = new SchemaRep.Restriction[] { r };
822                 //config.messageOut.println("restrict="+restrict);
823
String JavaDoc foundDefault = lookForDefault(restrict);
824                 if (foundDefault != null)
825                     defaultValue = foundDefault;
826             } else {
827                 config.messageOut.println("Type for attribute "+attributeName+" is not simple enough: "+ee);
828             }
829             //config.messageOut.println("defaultValue="+defaultValue);
830
}
831         int instance;
832         if (defaultValue != null || attr.getFixed() != null || attr.isRequired())
833             instance = Common.TYPE_1;
834         else {
835             instance = Common.TYPE_0_1;
836         }
837         handler.startElement(attr.getFullContentName(),
838                              parentElement,
839                              Common.ATTLIST);
840         handler.element(attr.getFullContentName(), attrType,
841                         attributeName, attr.getAttributeNamespace(),
842                         instance, externalType, defaultValue);
843         handler.element("CDATA", "CDATA", instance);
844         if (attr.getFixed() != null) {
845             handler.element("#FIXED", "#FIXED", instance); // NOI18N
846
handler.element(attr.getFullContentName(), attrType,
847                             attr.getFixed(), null, instance, externalType,
848                             defaultValue);
849         } else if (attr.isRequired()) {
850             handler.element("#REQUIRED", "#REQUIRED", instance); // NOI18N
851
} else {
852             handler.element("#IMPLIED", "#IMPLIED", instance); // NOI18N
853
}
854         handler.javaType(attr.getFullContentName(), attr.getAttributeName(),
855                          attrType);
856         if (ee != null) {
857             addExtraDataForType(attr.getFullContentName(), attr.getAttributeName(), ee);
858         }
859         if (restrict != null) {
860             addExtraDataCurLink(restrict);
861         }
862         handler.endElement();
863     }
864
865     protected void addExtraDataCurLink(SchemaRep.Restriction[] restrict) {
866         //config.messageOut.println("restrict="+restrict);
867
for (int i=0; i < restrict.length; i++)
868             if (restrict[i].subElementsIterator().hasNext())
869                 handler.addExtraDataCurLink(restrict[i]);
870 /*
871             for (Iterator it = restrict[i].subElementsIterator(); it.hasNext(); ) {
872                 Object o = it.next();
873                 if (o instanceof SchemaRep.RestrictionType) {
874                     //config.messageOut.println("Adding RestrictionType: "+o);
875                     handler.addExtraDataCurLink(o);
876                 }
877             }
878 */

879     }
880
881     protected void addExtraDataNode(String JavaDoc uniqueName, String JavaDoc name,
882                                     SchemaRep.Restriction[] restrict) throws org.netbeans.modules.schema2beans.Schema2BeansException {
883         for (int i=0; i < restrict.length; i++)
884             if (restrict[i].subElementsIterator().hasNext())
885                 handler.addExtraDataNode(uniqueName, name, restrict[i]);
886 /*
887             for (Iterator it = restrict[i].subElementsIterator(); it.hasNext(); ) {
888                 Object o = it.next();
889                 if (o instanceof SchemaRep.RestrictionType) {
890                     handler.addExtraDataNode(name, o);
891                 }
892             }
893 */

894     }
895
896     /**
897      * Given the restrictions, can we pick a decent default.
898      */

899     protected String JavaDoc lookForDefault(SchemaRep.Restriction[] restrict) {
900         if (config.isMakeDefaults() && restrict != null) {
901             for (int i=0; i < restrict.length; i++)
902                 for (Iterator subelements = restrict[i].subElementsIterator();
903                      subelements.hasNext(); ) {
904                     Object JavaDoc rt = subelements.next();
905                     //config.messageOut.println("rt="+rt);
906
// If we find an Enumeration, then let's pick the
907
// first value as the default, since it's gotta be
908
// one of the values.
909
if (rt instanceof SchemaRep.Enumeration) {
910                         String JavaDoc defaultValue = ((SchemaRep.Enumeration)rt).getValue();
911                         //config.messageOut.println("Found defaultValue="+defaultValue);
912
return defaultValue;
913                     }
914                 }
915         }
916         return null;
917     }
918
919     protected void processAttributeGroup(String JavaDoc parentElement,
920                                          SchemaRep.AttributeGroup attrGroup) throws Schema2BeansException {
921         SchemaRep.AttributeGroup schemaTypeDef = (SchemaRep.AttributeGroup) schema.getSchemaTypeDef(attrGroup.getRef());
922         if (debug)
923             config.messageOut.println("processAttributeGroup schemaTypeDef="+schemaTypeDef);
924         if (schemaTypeDef == null)
925             throw new IllegalStateException JavaDoc("attributeGroup ref has reference to unknown name: "+attrGroup.getRef());
926
927         Iterator it = schemaTypeDef.subElementsIterator();
928         while (it.hasNext()) {
929             SchemaRep.ElementExpr childee = (SchemaRep.ElementExpr) it.next();
930             if (childee instanceof SchemaRep.Attribute) {
931                 processAttribute(parentElement, (SchemaRep.Attribute) childee);
932             } else if (childee instanceof SchemaRep.AttributeGroup) {
933                 processAttributeGroup(parentElement, (SchemaRep.AttributeGroup) childee);
934             }
935         }
936     }
937
938     protected void processAnnotation(SchemaRep.Annotation ann) throws Schema2BeansException {
939         SchemaRep.Documentation doc = (SchemaRep.Documentation) ann.findSubElement(SchemaRep.Documentation.class);
940         String JavaDoc name = null;
941         if (!parentTypes.isEmpty())
942             name = (String JavaDoc) parentTypes.peek();
943         if (name == null)
944             return;
945         String JavaDoc uniqueName = (String JavaDoc) parentUniqueNames.peek();
946         if (doc != null) {
947             StringBuffer JavaDoc comment = new StringBuffer JavaDoc();
948             for (Iterator subelements = doc.subElementsIterator();
949                  subelements.hasNext(); ) {
950                 SchemaRep.ElementExpr el = (SchemaRep.ElementExpr) subelements.next();
951                 if (el instanceof SchemaRep.TextNode) {
952                     comment.append(((SchemaRep.TextNode)el).getText());
953                 } else if (el instanceof SchemaRep.AnyNode) {
954                     try {
955                         XMLWriter xw = new XMLWriter(false);
956                         ((SchemaRep.AnyNode)el).writeXMLSchema(xw);
957                         xw.writeTo(comment);
958                     } catch (IOException e) {
959                         // Should not occur
960
throw new RuntimeException JavaDoc(e);
961                     }
962                 }
963             }
964             handler.setExtendedProperty(uniqueName, name, "comment", comment.toString());
965         }
966         SchemaRep.AppInfo appInfo = (SchemaRep.AppInfo) ann.findSubElement(SchemaRep.AppInfo.class);
967         if (appInfo != null) {
968             String JavaDoc switchName = null;
969             String JavaDoc switchHelp = null;
970             boolean switchMandatory = false;
971             for (Iterator subelements = appInfo.subElementsIterator();
972                  subelements.hasNext(); ) {
973                 SchemaRep.ElementExpr el = (SchemaRep.ElementExpr) subelements.next();
974                 if (el instanceof SchemaRep.AnyNode) {
975                     SchemaRep.AnyNode anyNode = (SchemaRep.AnyNode) el;
976                     String JavaDoc anyNodeName = anyNode.getContentName();
977                     if (anyNodeName == null)
978                         continue;
979                     anyNodeName = anyNodeName.intern();
980                     if ("extends" == anyNodeName) {
981                         SchemaRep.TextNode value = (SchemaRep.TextNode) anyNode.findSubElement(SchemaRep.TextNode.class);
982                         if (value != null) {
983                             handler.setExtendedProperty(uniqueName, name, "extends", value.getText());
984                         }
985                     } else if ("implements" == anyNodeName) {
986                         SchemaRep.TextNode value = (SchemaRep.TextNode) anyNode.findSubElement(SchemaRep.TextNode.class);
987                         if (value != null) {
988                             handler.setExtendedProperty(uniqueName, name, "implements", value.getText());
989                         }
990                     } else if ("switch" == anyNodeName) {
991                         SchemaRep.TextNode value = (SchemaRep.TextNode) anyNode.findSubElement(SchemaRep.TextNode.class);
992                         if (value != null)
993                             switchName = value.getText();
994                     } else if ("switchHelp" == anyNodeName) {
995                         SchemaRep.TextNode value = (SchemaRep.TextNode) anyNode.findSubElement(SchemaRep.TextNode.class);
996                         if (value != null)
997                             switchHelp = value.getText();
998                     } else if ("switchMandatory" == anyNodeName) {
999                         SchemaRep.TextNode value = (SchemaRep.TextNode) anyNode.findSubElement(SchemaRep.TextNode.class);
1000                        if (value != null) {
1001                            switchMandatory = "true".equalsIgnoreCase(value.getText());
1002                        }
1003                    }
1004                }
1005            }
1006            if (switchName != null) {
1007                perAttributeExtraData.add(new SwitchData(switchName,
1008                                                         switchHelp,
1009                                                         switchMandatory));
1010            }
1011        }
1012    }
1013
1014    static protected int getInstanceValue(String JavaDoc minOccurs, String JavaDoc maxOccurs) {
1015        if (minOccurs == null)
1016            minOccurs = "1";
1017        if (maxOccurs == null)
1018            maxOccurs = "1";
1019
1020        if (minOccurs.equals("0")) {
1021            if (maxOccurs.equals("1"))
1022                return Common.TYPE_0_1;
1023            //if (maxOccurs.equals("unbounded"))
1024
return Common.TYPE_0_N;
1025        }
1026        if (maxOccurs.equals("1"))
1027            return Common.TYPE_1;
1028        return Common.TYPE_1_N;
1029    }
1030
1031    public static class MaxOccursRestriction implements DataListRestriction/*, HasAnnotation*/ {
1032        private String JavaDoc maxOccurs;
1033
1034        public MaxOccursRestriction(String JavaDoc maxOccurs) {
1035            //assert "unbounded".equalsIgnoreCase(maxOccurs) || Integer.parseInt(maxOccurs) >= 0;
1036
this.maxOccurs = maxOccurs;
1037        }
1038
1039        public void genRestriction(Writer out, String JavaDoc sizeExpr,
1040                                   String JavaDoc readMethod, String JavaDoc type,
1041                                   String JavaDoc failVar, boolean passCheck)
1042                throws IOException {
1043            if (!passCheck) {
1044                out.write("if ("+sizeExpr+" > "+maxOccurs+") {\n");
1045                out.write(failVar+" = true;\n");
1046                out.write("}\n");
1047            } else {
1048                out.write("if ("+sizeExpr+" <= "+maxOccurs+") {\n");
1049                out.write(failVar+" = true;\n");
1050                out.write("}\n");
1051            }
1052        }
1053        
1054        public int getMaxOccurs() {
1055            if ("unbounded".equalsIgnoreCase(maxOccurs))
1056                return Integer.MAX_VALUE;
1057            return Integer.parseInt(maxOccurs);
1058        }
1059
1060        public String JavaDoc toString() {
1061            return "maxOccurs ("+maxOccurs+")";
1062        }
1063
1064        public String JavaDoc genAnnotation() {
1065            return "MaxOccurs("+maxOccurs+")";
1066        }
1067
1068    }
1069
1070    public static class MinOccursRestriction implements DataListRestriction/*, HasAnnotation*/ {
1071        private String JavaDoc minOccurs;
1072
1073        public MinOccursRestriction(String JavaDoc minOccurs) {
1074            //assert Integer.parseInt(minOccurs) >= 0;
1075
this.minOccurs = minOccurs;
1076        }
1077
1078        public void genRestriction(Writer out, String JavaDoc sizeExpr,
1079                                   String JavaDoc readMethod, String JavaDoc type,
1080                                   String JavaDoc failVar, boolean passCheck)
1081                throws IOException {
1082            if (!passCheck) {
1083                out.write("if ("+sizeExpr+" < "+minOccurs+") {\n");
1084                out.write(failVar+" = true;\n");
1085                out.write("}\n");
1086            } else {
1087                out.write("if ("+sizeExpr+" >= "+minOccurs+") {\n");
1088                out.write(failVar+" = true;\n");
1089                out.write("}\n");
1090            }
1091        }
1092        
1093        public int getMinOccurs() {
1094            return Integer.parseInt(minOccurs);
1095        }
1096
1097        public String JavaDoc toString() {
1098            return "minOccurs ("+minOccurs+")";
1099        }
1100        
1101        public String JavaDoc genAnnotation() {
1102            return "MinOccurs("+minOccurs+")";
1103        }
1104
1105    }
1106    
1107    public static class GeneralAnnotation implements HasAnnotation {
1108        private String JavaDoc annotation;
1109        
1110        public GeneralAnnotation(String JavaDoc annotation) {
1111            this.annotation = annotation;
1112        }
1113        
1114        public String JavaDoc genAnnotation() {
1115            return annotation;
1116        }
1117    }
1118
1119    public static class SwitchData {
1120        private String JavaDoc switchName;
1121        private String JavaDoc switchHelp;
1122        private boolean mandatory;
1123
1124        public SwitchData(String JavaDoc switchName) {
1125            this.switchName = switchName;
1126        }
1127
1128        public SwitchData(String JavaDoc switchName, String JavaDoc switchHelp) {
1129            this.switchName = switchName;
1130            this.switchHelp = switchHelp;
1131        }
1132
1133        public SwitchData(String JavaDoc switchName, String JavaDoc switchHelp, boolean mandatory) {
1134            this.switchName = switchName;
1135            this.switchHelp = switchHelp;
1136            this.mandatory = mandatory;
1137        }
1138
1139        public String JavaDoc getName() {
1140            return switchName;
1141        }
1142
1143        public String JavaDoc getHelp() {
1144            return switchHelp;
1145        }
1146
1147        public boolean isMandatory() {
1148            return mandatory;
1149        }
1150
1151        public String JavaDoc toString() {
1152            return "Switch";
1153        }
1154    }
1155}
1156
Popular Tags