KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > impl > ElementRef


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 /*
22  * ElementRef.java
23  *
24  * Created on May 5, 2006, 11:15 AM
25  *
26  * To change this template, choose Tools | Template Manager
27  * and open the template in the editor.
28  */

29
30 package org.netbeans.modules.xml.axi.impl;
31
32 import java.util.List JavaDoc;
33 import org.netbeans.modules.xml.axi.AXIComponent;
34 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType;
35 import org.netbeans.modules.xml.axi.AXIModel;
36 import org.netbeans.modules.xml.axi.AXIType;
37 import org.netbeans.modules.xml.axi.AbstractAttribute;
38 import org.netbeans.modules.xml.axi.AbstractElement;
39 import org.netbeans.modules.xml.axi.Compositor;
40 import org.netbeans.modules.xml.axi.ContentModel;
41 import org.netbeans.modules.xml.axi.Element;
42 import org.netbeans.modules.xml.axi.datatype.Datatype;
43 import org.netbeans.modules.xml.schema.model.Form;
44 import org.netbeans.modules.xml.schema.model.SchemaComponent;
45
46 /**
47  * Represents an Element reference. For an Element reference
48  * most of the calls are delegated to the original Element,
49  * except for calls related to min and max occurs.
50  *
51  * See http://www.w3.org/TR/xmlschema-1/#d0e4233.
52  * @author Samaresh (Samaresh.Panda@Sun.Com)
53 */

54 public class ElementRef extends Element {
55                 
56     /**
57      * Creates a new instance of ElementRef
58      */

59     public ElementRef(AXIModel model, Element referent) {
60         super(model, referent);
61     }
62     
63     /**
64      * Creates a new instance of ElementRef
65      */

66     public ElementRef(AXIModel model, SchemaComponent component, Element referent) {
67         super(model, component);
68         super.setSharedComponent(referent);
69     }
70     
71     /**
72      * Returns the type of this component,
73      * may be local, shared, proxy or reference.
74      * @see ComponentType.
75      */

76     public ComponentType getComponentType() {
77         return ComponentType.REFERENCE;
78     }
79     
80     /**
81      * Returns the referent if isReference() is true.
82      */

83     public Element getReferent() {
84         return (Element)getSharedComponent();
85     }
86         
87     /**
88      * Sets the new referent.
89      */

90     public void setRef(Element referent) {
91         ElementImpl oldRef = (ElementImpl) getReferent();
92         if(oldRef == referent)
93             return;
94         oldRef.removeListener(this);
95         setSharedComponent(referent);
96         firePropertyChangeEvent(PROP_ELEMENT_REF, oldRef, referent);
97         forceFireEvent();
98         if(canVisitChildren()) {
99             removeAllChildren();
100             Util.addProxyChildren(this, referent, null);
101         }
102     }
103     
104     /**
105      * Returns true if it is a reference, false otherwise.
106      */

107     public boolean isReference() {
108         return true;
109     }
110     
111     /**
112      * Returns the name.
113      */

114     public String JavaDoc getName() {
115         return getReferent().getName();
116     }
117     
118     /**
119      * Sets the name.
120      */

121     public void setName(String JavaDoc name) {
122         getReferent().setName(name);
123     }
124     
125     /**
126      * Returns abstract property.
127      */

128     public boolean getAbstract() {
129         return getReferent().getAbstract();
130     }
131     
132     /**
133      * Sets the abstract property.
134      */

135     public void setAbstract(boolean value) {
136         getReferent().setAbstract(value);
137     }
138     
139     /**
140      * Returns the block.
141      */

142     public String JavaDoc getBlock() {
143         return getReferent().getBlock();
144     }
145         
146     /**
147      * Sets the block property.
148      */

149     public void setBlock(String JavaDoc value) {
150         getReferent().setBlock(value);
151     }
152     
153     /**
154      * Returns the final property.
155      */

156     public String JavaDoc getFinal() {
157         return getReferent().getFinal();
158     }
159     
160     /**
161      * Sets the final property.
162      */

163     public void setFinal(String JavaDoc value) {
164         getReferent().setFinal(value);
165     }
166     
167     /**
168      * Returns the fixed value.
169      */

170     public String JavaDoc getFixed() {
171         return getReferent().getFixed();
172     }
173     
174     /**
175      * Sets the fixed value.
176      */

177     public void setFixed(String JavaDoc value) {
178         getReferent().setFixed(value);
179     }
180     
181     /**
182      * Returns the default value.
183      */

184     public String JavaDoc getDefault() {
185         return getReferent().getDefault();
186     }
187     
188     /**
189      * Sets the default value.
190      */

191     public void setDefault(String JavaDoc value) {
192         getReferent().setDefault(value);
193     }
194     
195     /**
196      * Returns the form.
197      */

198     public Form getForm() {
199         return getReferent().getForm();
200     }
201     
202     /**
203      * Sets the form.
204      */

205     public void setForm(Form value) {
206         getReferent().setForm(value);
207     }
208         
209     /**
210      * Returns the nillable.
211      */

212     public boolean getNillable() {
213         return getReferent().getNillable();
214     }
215     
216     /**
217      * Sets the nillable property.
218      */

219     public void setNillable(boolean value) {
220         getReferent().setNillable(value);
221     }
222     
223     /**
224      * Adds a Compositor as its child.
225      * Compositor must always be at the 0th index.
226      */

227     public void addCompositor(Compositor compositor) {
228         getReferent().addCompositor(compositor);
229     }
230     
231     /**
232      * Removes a Compositor.
233      */

234     public void removeCompositor(Compositor compositor) {
235         getReferent().removeCompositor(compositor);
236     }
237     
238     /**
239      * Adds an Element as its child.
240      * If attributes exist, add the new child before all attributes.
241      * Attributes must always be added at the end of the list.
242      */

243     public void addElement(AbstractElement child) {
244         getReferent().addElement(child);
245     }
246     
247     /**
248      * Removes an Element.
249      */

250     public void removeElement(AbstractElement element) {
251         getReferent().removeElement(element);
252     }
253     
254     /**
255      * Adds an attribute.
256      */

257     public void addAttribute(AbstractAttribute attribute) {
258         getReferent().addAttribute(attribute);
259     }
260     
261     /**
262      * Removes an attribute.
263      */

264     public void removeAttribute(AbstractAttribute attribute) {
265         getReferent().removeAttribute(attribute);
266     }
267     
268     public AXIType getType() {
269         return getReferent().getType();
270     }
271     
272     /**
273      * sets the type of this element.
274      */

275     public void setType(AXIType type) {
276         if(type instanceof Element) {
277             setRef((Element)type);
278             return;
279         }
280         
281         int index = this.getIndex();
282         AXIComponent parent = getParent();
283         Element e = getModel().getComponentFactory().createElement();
284         e.setName(getReferent().getName());
285         parent.removeChild(this);
286         parent.insertAtIndex(Element.PROP_ELEMENT, e, index);
287         e.setType(type);
288     }
289     
290     /**
291      * Returns the compositor.
292      */

293     public Compositor getCompositor() {
294         return getReferent().getCompositor();
295     }
296     
297     /**
298      * For an element-ref or attribute-ref, most of the properties come from the actual
299      * element or attribute. So when something changes in the ref, we must forcibly fire
300      * an event so that the UI updates itself.
301      */

302     void forceFireEvent() {
303         firePropertyChangeEvent(Element.PROP_NAME, null, getReferent().getName());
304     }
305 }
306
Popular Tags