001: /*
002: * Element.java
003: *
004: * Created on October 9, 2006, 5:08 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package org.netbeans.modules.e2e.api.schema;
011:
012: import java.util.ArrayList;
013: import java.util.Collections;
014: import java.util.List;
015: import javax.xml.namespace.QName;
016:
017: /**
018: *
019: * @author Michal Skvor
020: */
021: public class Element extends RepeatableSchemaConstruct {
022:
023: private boolean nillable;
024: private Type elementType;
025:
026: public Element() {
027: super (SchemaConstruct.ConstructType.ELEMENT);
028:
029: setMinOccurs(1);
030: setMaxOccurs(1);
031: nillable = false;
032: }
033:
034: public Element(QName name) {
035: super (SchemaConstruct.ConstructType.ELEMENT, name);
036: setMinOccurs(1);
037: setMaxOccurs(1);
038: nillable = false;
039:
040: setName(name);
041: }
042:
043: public Element(QName name, Type elementType) {
044: this (name);
045: this .elementType = elementType;
046: }
047:
048: public Element(QName name, Type elementType, int minOccurs,
049: int maxOccurs) {
050: this (name, elementType);
051: nillable = false;
052:
053: setMinOccurs(minOccurs);
054: setMaxOccurs(maxOccurs);
055: }
056:
057: public void setNillable(boolean nillable) {
058: this .nillable = nillable;
059: }
060:
061: public boolean isNillable() {
062: return nillable;
063: }
064:
065: public void setType(Type elementType) {
066: this .elementType = elementType;
067: }
068:
069: public Type getType() {
070: return elementType;
071: }
072:
073: public String getJavaName() {
074: String javaName = getJavaName();
075: if (javaName != null)
076: return javaName;
077: return getName().getLocalPart()
078: + (getMaxOccurs() > 1 ? "[]" : "");
079: }
080:
081: public String toString() {
082: StringBuffer sb = new StringBuffer();
083: sb.append("element");
084: if (getName() != null)
085: sb.append(" name='" + getName() + "'");
086: sb.append(" minOccurs='" + getMinOccurs() + "'");
087: if (getMaxOccurs() == RepeatableSchemaConstruct.UNBOUNDED) {
088: sb.append(" maxOccurs='unbounded'");
089: } else {
090: sb.append(" maxOccurs='" + getMaxOccurs() + "'");
091: }
092: sb.append(" nillable='" + nillable + "'");
093: // if( type != null ) sb.append( " type='" + type.getPrefix() + ":" + type.getLocalPart() + "'");
094: sb.append('\n');
095: // for( ComplexType ct : complexTypes ) {
096: // sb.append( '\t' + ct.toString());
097: // }
098:
099: return sb.toString();
100: }
101: }
|