KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > impl > AllImpl


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.xml.schema.model.impl;
21
22 import java.util.Collection JavaDoc;
23 import org.netbeans.modules.xml.schema.model.All;
24 import org.netbeans.modules.xml.schema.model.ElementReference;
25 import org.netbeans.modules.xml.schema.model.GlobalGroup;
26 import org.netbeans.modules.xml.schema.model.LocalElement;
27 import org.netbeans.modules.xml.schema.model.SchemaComponent;
28 import org.netbeans.modules.xml.schema.model.Occur;
29 import org.netbeans.modules.xml.schema.model.visitor.SchemaVisitor;
30 import org.w3c.dom.Element JavaDoc;
31
32 /**
33  * This class implements the xml schema all type. The all
34  * type describes an unordered group of elements.
35  *
36  * @author nn136682
37  */

38 public class AllImpl extends SchemaComponentImpl implements All {
39     
40     public AllImpl(SchemaModelImpl model) {
41     this(model,createNewComponent(SchemaElements.ALL, model));
42     }
43     
44     /** Creates a new instance of AllImpl */
45     public AllImpl(SchemaModelImpl model, Element e) {
46     super(model, e);
47     }
48     
49     public Class JavaDoc<? extends SchemaComponent> getComponentType() {
50     return All.class;
51     }
52     
53     public void accept(SchemaVisitor visitor) {
54     visitor.visit(this);
55     }
56     
57     protected Class JavaDoc getAttributeType(SchemaAttributes attr) {
58     switch(attr) {
59         case MIN_OCCURS:
60         return Occur.ZeroOne.class;
61         default:
62         return super.getAttributeType(attr);
63     }
64     }
65     
66     
67     /**
68      * @return minimum occurrences, must be 0 <= x <= 1
69      */

70     public Occur.ZeroOne getMinOccurs() {
71     String JavaDoc s = super.getAttribute(SchemaAttributes.MIN_OCCURS);
72     return s == null ? null : Util.parse(Occur.ZeroOne.class, s);
73     }
74     
75     /**
76      * set the minimum number of occurs.
77      * @param occurs must satisfy 0 <= occurs <= 1
78      */

79     public void setMinOccurs(Occur.ZeroOne occurs) {
80     setAttribute(MIN_OCCURS_PROPERTY, SchemaAttributes.MIN_OCCURS, occurs);
81     }
82     
83     public Occur.ZeroOne getMinOccursDefault() {
84     return Occur.ZeroOne.ONE;
85     }
86     
87     public Occur.ZeroOne getMinOccursEffective() {
88     Occur.ZeroOne v = getMinOccurs();
89     return v == null ? getMinOccursDefault() : v;
90     }
91     
92     public Collection JavaDoc<LocalElement> getElements() {
93     return super.getChildren(LocalElement.class);
94     }
95     
96     public void addElement(LocalElement e) {
97     appendChild(ELEMENT_PROPERTY, e);
98     }
99     
100     public void removeElement(LocalElement e) {
101     removeChild(ELEMENT_PROPERTY, e);
102     }
103     
104     public Collection JavaDoc<ElementReference> getElementReferences() {
105     return super.getChildren(ElementReference.class);
106     }
107     
108     public void addElementReference(ElementReference e) {
109     appendChild(ELEMENT_REFERENCE_PROPERTY, e);
110     }
111     
112     public void removeElementReference(ElementReference e) {
113     removeChild(ELEMENT_REFERENCE_PROPERTY, e);
114     }
115     
116     public boolean allowsFullMultiplicity() {
117     return !(getParent() instanceof GlobalGroup);
118     }
119 }
120
Popular Tags