KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
25 import org.netbeans.modules.xml.schema.model.AnyAttribute;
26 import org.netbeans.modules.xml.schema.model.AttributeGroupReference;
27 import org.netbeans.modules.xml.schema.model.AttributeReference;
28 import org.netbeans.modules.xml.schema.model.Extension;
29 import org.netbeans.modules.xml.schema.model.GlobalType;
30 import org.netbeans.modules.xml.schema.model.LocalAttribute;
31 import org.netbeans.modules.xml.schema.model.SchemaComponent;
32 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
33 import org.w3c.dom.Element JavaDoc;
34
35 /**
36  *
37  * @author rico
38  */

39 public abstract class CommonExtensionImpl extends SchemaComponentImpl implements Extension{
40     
41     /** Creates a new instance of CommonExtensionImpl */
42     public CommonExtensionImpl(SchemaModelImpl model, Element JavaDoc el) {
43         super(model, el);
44     }
45     
46     public void removeLocalAttribute(LocalAttribute attr) {
47         removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
48     }
49     
50     public void addLocalAttribute(LocalAttribute attr) {
51         List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
52         list.add(AnyAttribute.class);
53         addBefore(LOCAL_ATTRIBUTE_PROPERTY, attr, list);
54     }
55     
56     public Collection JavaDoc<LocalAttribute> getLocalAttributes() {
57         return getChildren(LocalAttribute.class);
58     }
59     
60     public void removeAttributeReference(AttributeReference attr) {
61         removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
62     }
63     
64     public void addAttributeReference(AttributeReference attr) {
65         List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
66         list.add(AnyAttribute.class);
67         addBefore(LOCAL_ATTRIBUTE_PROPERTY, attr, list);
68     }
69     
70     public Collection JavaDoc<AttributeReference> getAttributeReferences() {
71         return getChildren(AttributeReference.class);
72     }
73     
74     public void setBase(NamedComponentReference<GlobalType> type) {
75         setAttribute(BASE_PROPERTY, SchemaAttributes.BASE, type);
76         //setAttribute(SchemaAttributes.BASE, type.getRawURI());
77
}
78     
79     public NamedComponentReference<GlobalType> getBase() {
80         return resolveGlobalReference(GlobalType.class, SchemaAttributes.BASE);
81     }
82     
83     public void setAnyAttribute(AnyAttribute attr) {
84         appendChild(ANY_ATTRIBUTE_PROPERTY, attr);
85     }
86     
87     public AnyAttribute getAnyAttribute() {
88         Collection JavaDoc<AnyAttribute> elements = getChildren(AnyAttribute.class);
89         if(!elements.isEmpty()){
90             return elements.iterator().next();
91         }
92         //TODO should we throw exception if there is no definition?
93
return null;
94     }
95     
96     public void removeAttributeGroupReference(AttributeGroupReference ref) {
97         removeChild(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref);
98     }
99     
100     public void addAttributeGroupReference(AttributeGroupReference ref) {
101         List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
102         list.add(AnyAttribute.class);
103         addBefore(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref, list);
104     }
105     
106     public Collection JavaDoc<AttributeGroupReference> getAttributeGroupReferences() {
107         return getChildren(AttributeGroupReference.class);
108     }
109 }
110
Popular Tags