KickJava   Java API By Example, From Geeks To Geeks.

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


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.GlobalSimpleType;
26 import org.netbeans.modules.xml.schema.model.LocalSimpleType;
27 import org.netbeans.modules.xml.schema.model.SchemaComponent;
28 import org.netbeans.modules.xml.schema.model.Union;
29 import org.netbeans.modules.xml.schema.model.visitor.SchemaVisitor;
30 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
31 import org.w3c.dom.Element JavaDoc;
32
33
34 /**
35  * DOM based implementation
36  * @author Chris Webster
37  * @author Vidhya Narayanan
38  */

39 public class UnionImpl extends SchemaComponentImpl implements Union {
40     protected UnionImpl(SchemaModelImpl model){
41         this(model, createNewComponent(SchemaElements.UNION, model));
42     }
43     
44     public UnionImpl(SchemaModelImpl model,Element JavaDoc el){
45         super(model, el);
46     }
47
48     /**
49      *
50      *
51      */

52     public Class JavaDoc<? extends SchemaComponent> getComponentType() {
53         return Union.class;
54     }
55     
56     public java.util.List JavaDoc<NamedComponentReference<GlobalSimpleType>> getMemberTypes() {
57         
58         String JavaDoc val = getAttribute(SchemaAttributes.MEMBER_TYPES);
59     if (val == null) {
60         return null;
61     }
62         List JavaDoc<NamedComponentReference<GlobalSimpleType>> gsts = new ArrayList JavaDoc<NamedComponentReference<GlobalSimpleType>>();
63         if (val.trim().length()==0) return gsts;
64         String JavaDoc[] ss = val.split("( |\t|\n|\r|\f)+");
65         for(int i = 0; i < ss.length; i++){
66             NamedComponentReference<GlobalSimpleType> ref =
67                     new GlobalReferenceImpl(GlobalSimpleType.class, this, ss[i]);
68             gsts.add(ref);
69         }
70         return gsts;
71         
72     }
73     
74     public void removeMemberType(NamedComponentReference<GlobalSimpleType> gst) {
75         String JavaDoc refVal = getPrefixedName(gst.getEffectiveNamespace(),
76                 gst.get().getName());
77         String JavaDoc val = getAttribute(SchemaAttributes.MEMBER_TYPES);
78         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
79         if (val != null) {
80             String JavaDoc[] ss = val.split("( |\t|\n|\r|\f)+");
81             boolean first = true;
82             for (String JavaDoc s : ss) {
83                 if (!s.equals(refVal)) {
84                     if (!first)
85                         sb.append(" ");
86                     else
87                         first = false;
88                     sb.append(s);
89                 }
90             }
91         }
92         setAttribute(MEMBER_TYPES_PROPERTY, SchemaAttributes.MEMBER_TYPES, sb.length()==0?null:sb.toString());
93     }
94     
95     public void addMemberType(NamedComponentReference<GlobalSimpleType> gst) {
96         String JavaDoc val = getAttribute(SchemaAttributes.MEMBER_TYPES);
97         String JavaDoc refVal = getPrefixedName(gst.getEffectiveNamespace(),
98                 gst.get().getName());
99         if (val == null)
100             val = refVal;
101         else
102             val = val.concat(" ").concat(refVal);
103         setAttribute(MEMBER_TYPES_PROPERTY, SchemaAttributes.MEMBER_TYPES, val);
104     }
105
106     public void setMemberTypes(java.util.List JavaDoc<NamedComponentReference<GlobalSimpleType>> types) {
107         String JavaDoc val = types == null ? null : getRefsString(types);
108         setAttribute(MEMBER_TYPES_PROPERTY, SchemaAttributes.MEMBER_TYPES, val);
109     }
110
111     private String JavaDoc getRefsString(java.util.List JavaDoc<NamedComponentReference<GlobalSimpleType>> types) {
112         StringBuilder JavaDoc refVal = new StringBuilder JavaDoc();
113         for (NamedComponentReference<GlobalSimpleType> ref : types) {
114             refVal.append(ref.getRefString());
115             refVal.append(" ");
116         }
117         return refVal.toString().trim();
118     }
119     
120      public void accept(SchemaVisitor visitor) {
121         visitor.visit(this);
122     }
123     
124     public void removeInlineType(LocalSimpleType type) {
125         removeChild(INLINE_TYPE_PROPERTY, type);
126     }
127     
128     public void addInlineType(LocalSimpleType type) {
129         appendChild(INLINE_TYPE_PROPERTY, type);
130     }
131       
132     public java.util.Collection JavaDoc<LocalSimpleType> getInlineTypes() {
133         return getChildren(LocalSimpleType.class);
134     }
135 }
136
Popular Tags