KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.netbeans.modules.xml.schema.model.Annotation;
26 import org.netbeans.modules.xml.schema.model.Element;
27 import org.netbeans.modules.xml.schema.model.Element.Block;
28 import org.netbeans.modules.xml.schema.model.Constraint;
29 import org.netbeans.modules.xml.schema.model.GlobalType;
30 import org.netbeans.modules.xml.schema.model.LocalElement;
31 import org.netbeans.modules.xml.schema.model.LocalType;
32 import org.netbeans.modules.xml.schema.model.Schema;
33 import org.netbeans.modules.xml.schema.model.SchemaComponent;
34 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
35 /**
36  *
37  * @author Vidhya Narayanan
38  */

39 public abstract class ElementImpl extends NamedImpl implements Element {
40     
41     /**
42      * Creates a new instance of CommonElementImpl
43      */

44     public ElementImpl(SchemaModelImpl model, org.w3c.dom.Element JavaDoc el) {
45         super(model, el);
46     }
47     
48     protected Class JavaDoc getAttributeMemberType(SchemaAttributes attr) {
49         switch(attr) {
50             case BLOCK:
51                 return Block.class;
52             default:
53                 return super.getAttributeMemberType(attr);
54         }
55     }
56     
57     public void setDefault(String JavaDoc defaultValue) {
58         setAttribute(DEFAULT_PROPERTY ,SchemaAttributes.DEFAULT, defaultValue);
59     }
60     
61     public void setFixed(String JavaDoc fixed) {
62         setAttribute(FIXED_PROPERTY ,SchemaAttributes.FIXED, fixed);
63     }
64     
65     public void setType(NamedComponentReference<? extends GlobalType> t) {
66         setAttribute(LocalElement.TYPE_PROPERTY, SchemaAttributes.TYPE, t);
67     }
68     
69     public void setNillable(Boolean JavaDoc nillable) {
70         setAttribute(NILLABLE_PROPERTY, SchemaAttributes.NILLABLE, nillable);
71     }
72     
73     /**
74      *
75      */

76     public void addConstraint(Constraint c) {
77         Collection JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
78     list.add(Annotation.class);
79     list.add(LocalType.class);
80         addAfter(CONSTRAINT_PROPERTY, (SchemaComponent) c, list);
81     }
82     
83     /**
84      *
85      */

86     public void removeConstraint(Constraint c) {
87         removeChild(CONSTRAINT_PROPERTY , (SchemaComponent) c);
88     }
89     
90     /**
91      *
92      */

93     public void setInlineType(LocalType t) {
94         Collection JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
95         list.add(Annotation.class);
96         setChild(LocalType.class, LocalElement.INLINE_TYPE_PROPERTY, t, list);
97     }
98     
99     
100     public void setBlock(Set JavaDoc<Block> block) {
101         setAttribute(BLOCK_PROPERTY, SchemaAttributes.BLOCK,
102                 block == null ? null :
103                     Util.convertEnumSet(Block.class, block));
104     }
105     
106     public Set JavaDoc<Block> getBlock() {
107         String JavaDoc s = getAttribute(SchemaAttributes.BLOCK);
108         return s == null ? null : Util.valuesOf(Block.class, s);
109     }
110
111     public Set JavaDoc<Block> getBlockEffective() {
112         Set JavaDoc<Block> v = getBlock();
113         return v == null ? getBlockDefault() : v;
114     }
115
116     public Set JavaDoc<Block> getBlockDefault() {
117         Set JavaDoc<Schema.Block> v = getModel().getSchema().getBlockDefaultEffective();
118         return Util.convertEnumSet(Block.class, v);
119     }
120
121     /**
122      *
123      */

124     public Collection JavaDoc<Constraint> getConstraints() {
125         return getChildren(Constraint.class);
126     }
127     
128     /**
129      *
130      */

131     public String JavaDoc getDefault() {
132         return getAttribute(SchemaAttributes.DEFAULT);
133     }
134     
135     /**
136      *
137      */

138     public String JavaDoc getFixed() {
139         return getAttribute(SchemaAttributes.FIXED);
140     }
141     
142     /**
143      *
144      */

145     public LocalType getInlineType() {
146         Collection JavaDoc<LocalType> elements = getChildren(LocalType.class);
147         if(!elements.isEmpty()){
148             return elements.iterator().next();
149         }
150         return null;
151     }
152     
153     /**
154      *
155      */

156     public NamedComponentReference<? extends GlobalType> getType() {
157        return resolveGlobalReference(GlobalType.class, SchemaAttributes.TYPE);
158     }
159     
160     /**
161      *
162      */

163     public Boolean JavaDoc isNillable() {
164         String JavaDoc s = getAttribute(SchemaAttributes.NILLABLE);
165         return s == null ? null : Boolean.parseBoolean(s);
166     }
167
168     public boolean getNillableDefault() {
169         return false;
170     }
171
172     public boolean getNillableEffective() {
173         Boolean JavaDoc v = isNillable();
174         return v == null ? getNillableDefault() : v;
175     }
176     
177 }
178
Popular Tags