001: /*
002: *
003: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025:
026: package javax.microedition.xml.rpc;
027:
028: import javax.xml.namespace.QName;
029: import javax.xml.rpc.JAXRPCException;
030:
031: /**
032: * The class <code>Element</code> is a special Object
033: * used to represent an xsd:element defined in a Web Service's
034: * WSDL definition. An element can have the additional properties
035: * of being an array, being nillable, and has minOccurs and
036: * maxOccurs values.
037: *
038: * @version 0.1
039: * @see javax.xml.rpc.Stub
040: * @see javax.microedition.xml.rpc.Operation
041: */
042: public class Element extends Type {
043:
044: /**
045: * The QName of this element
046: */
047: public final QName name;
048:
049: /**
050: * The Type of this Element's content.
051: */
052: public final Type contentType;
053:
054: /**
055: * True if this element is nillable
056: */
057: public final boolean isNillable;
058:
059: /**
060: * True if this element is an array
061: */
062: public final boolean isArray;
063:
064: /**
065: * True if this element is optional, that is, its minOccurs
066: * is defined as being 0.
067: */
068: public final boolean isOptional;
069:
070: /**
071: * The 'minOccurs' attribute of this element. -1 if this
072: * element has no 'minOccurs' attribute.
073: */
074: public final int minOccurs;
075:
076: /**
077: * The 'maxOccurs' attribute of this element. -1 if this
078: * element has no 'maxOccurs' attribute.
079: */
080: public final int maxOccurs;
081:
082: /**
083: * Constant use to indicate that <code>maxOccurrs</code>
084: * is unbounded.
085: */
086: public final static int UNBOUNDED = -1;
087:
088: /**
089: * Construct an Element with the given properties.
090: * This Type subclass will have an <code>intValue()</code> of 9.
091: *
092: * @param name the QName of this element
093: * @param type the Type of this element's content
094: * @param minOccurs indicates the minimum number of times this
095: * element can occur. A value of '0' indicates
096: * this element is optional.
097: * @param maxOccurs indicates the maximum number of times this
098: * element can occur. A value > 1, in addition
099: * to <code>isArray</code> being true, indicates
100: * this element is an array.
101: * @throws IllegalArgumentException
102: * <UL>
103: * <LI>if <code>minOccurs < 0</code>, or
104: * <LI>if <code>name</code> or <code>type</code> are <code>null</code>
105: * <LI>if <code>type</code> is an instance of <code>Element</code>
106: * </UL>
107: */
108: public Element(QName name, Type type, int minOccurs, int maxOccurs,
109: boolean nillable) throws IllegalArgumentException {
110: super (9);
111:
112: if (name == null || type == null || type instanceof Element) {
113: throw new IllegalArgumentException();
114: }
115:
116: this .name = name;
117: this .contentType = type;
118:
119: if (minOccurs < 0 || (maxOccurs <= 0 && maxOccurs != UNBOUNDED)) {
120: throw new IllegalArgumentException(
121: "[min|max]Occurs must >= 0");
122: } else if (maxOccurs < minOccurs && maxOccurs != UNBOUNDED) {
123: throw new IllegalArgumentException(
124: "maxOccurs must > minOccurs");
125: }
126: this .minOccurs = minOccurs;
127: this .isOptional = (minOccurs == 0);
128: this .maxOccurs = maxOccurs;
129: this .isArray = (maxOccurs > 1 || maxOccurs == UNBOUNDED);
130: this .isNillable = nillable;
131: }
132:
133: /**
134: * Construct an Element with the given properties. The defaults for
135: * the unspecified properties are:
136: * <UL>
137: * <LI>minOccurs = 1
138: * <LI>maxOccurs = 1
139: * <LI>isOptional = false
140: * <LI>isArray = false
141: * <LI>nillable = false
142: * </UL>
143: *
144: * This Type subclass will have an <code>intValue()</code> of 9.
145: *
146: * @param name the QName of this element
147: * @param type the Type of this element's content
148: *
149: * @throws IllegalArgumentException
150: * <UL>
151: * <LI>if <code>name</code> or <code>type</code> are <code>null</code>
152: * <LI>if <code>type</code> is an instance of <code>Element</code>
153: * </UL>
154: */
155: public Element(QName name, Type type)
156: throws IllegalArgumentException
157:
158: {
159: super (9);
160:
161: if (name == null || type == null || type instanceof Element) {
162: throw new IllegalArgumentException();
163: }
164:
165: this .name = name;
166: this .contentType = type;
167: this .minOccurs = 1;
168: this .maxOccurs = 1;
169: this .isArray = false;
170: this .isOptional = false;
171: this .isNillable = false;
172: }
173: }
|