KickJava   Java API By Example, From Geeks To Geeks.

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


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.GlobalType;
29 import org.netbeans.modules.xml.schema.model.SchemaComponent;
30 import org.netbeans.modules.xml.schema.model.LocalAttribute;
31 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
32 import org.netbeans.modules.xml.schema.model.visitor.SchemaVisitor;
33 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
34 import org.w3c.dom.Element JavaDoc;
35
36 /**
37  *
38  * @author rico
39  */

40 public class SimpleContentRestrictionImpl extends CommonSimpleRestrictionImpl implements SimpleContentRestriction{
41     
42     /** Creates a new instance of SimpleContentRestrictionImpl */
43     protected SimpleContentRestrictionImpl(SchemaModelImpl model) {
44         this(model, createNewComponent(SchemaElements.RESTRICTION, model));
45     }
46     
47     public SimpleContentRestrictionImpl(SchemaModelImpl model, Element JavaDoc el){
48         super(model,el);
49     }
50
51     /**
52      *
53      *
54      */

55     public Class JavaDoc<? extends SchemaComponent> getComponentType() {
56         return SimpleContentRestriction.class;
57     }
58     
59      public void setBase(NamedComponentReference<GlobalType> type) {
60         setAttribute(BASE_PROPERTY, SchemaAttributes.BASE, type);
61     }
62     
63     public NamedComponentReference<GlobalType> getBase() {
64         return resolveGlobalReference(GlobalType.class, SchemaAttributes.BASE);
65     }
66     
67    public void removeLocalAttribute(LocalAttribute attr) {
68         removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
69     }
70     
71     public void addLocalAttribute(LocalAttribute attr) {
72         List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
73         list.add(AnyAttribute.class);
74         addBefore(LOCAL_ATTRIBUTE_PROPERTY, (SchemaComponentImpl)attr, list);
75     }
76     
77     public Collection JavaDoc<LocalAttribute> getLocalAttributes() {
78         return getChildren(LocalAttribute.class);
79     }
80     
81     public void removeAttributeReference(AttributeReference attr) {
82         removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
83     }
84     
85     public void addAttributeReference(AttributeReference attr) {
86         List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
87         list.add(AnyAttribute.class);
88         addBefore(LOCAL_ATTRIBUTE_PROPERTY, (SchemaComponentImpl)attr, list);
89     }
90     
91     public Collection JavaDoc<AttributeReference> getAttributeReferences() {
92         return getChildren(AttributeReference.class);
93     }
94     
95     public void removeAttributeGroupReference(AttributeGroupReference ref) {
96         removeChild(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref);
97     }
98     
99     public void addAttributeGroupReference(AttributeGroupReference ref) {
100         List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
101         list.add(AnyAttribute.class);
102         addBefore(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref, list);
103     }
104     
105     public Collection JavaDoc<AttributeGroupReference> getAttributeGroupReferences() {
106         return getChildren(AttributeGroupReference.class);
107     }
108     
109     public void setAnyAttribute(AnyAttribute attr) {
110         //anyAttribute should always be last
111
appendChild(ANY_ATTRIBUTE_PROPERTY, attr);
112     }
113     
114     public AnyAttribute getAnyAttribute() {
115         Collection JavaDoc<AnyAttribute> elements = getChildren(AnyAttribute.class);
116         if(!elements.isEmpty()){
117             return elements.iterator().next();
118         }
119         return null;
120     }
121     
122     public void accept(SchemaVisitor visitor) {
123         visitor.visit(this);
124     }
125     
126 }
127
Popular Tags