1 19 20 package org.netbeans.modules.xml.schema.model.impl; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 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 ; 32 33 34 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 el){ 45 super(model, el); 46 } 47 48 52 public Class <? extends SchemaComponent> getComponentType() { 53 return Union.class; 54 } 55 56 public java.util.List <NamedComponentReference<GlobalSimpleType>> getMemberTypes() { 57 58 String val = getAttribute(SchemaAttributes.MEMBER_TYPES); 59 if (val == null) { 60 return null; 61 } 62 List <NamedComponentReference<GlobalSimpleType>> gsts = new ArrayList <NamedComponentReference<GlobalSimpleType>>(); 63 if (val.trim().length()==0) return gsts; 64 String [] 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 refVal = getPrefixedName(gst.getEffectiveNamespace(), 76 gst.get().getName()); 77 String val = getAttribute(SchemaAttributes.MEMBER_TYPES); 78 StringBuffer sb = new StringBuffer (); 79 if (val != null) { 80 String [] ss = val.split("( |\t|\n|\r|\f)+"); 81 boolean first = true; 82 for (String 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 val = getAttribute(SchemaAttributes.MEMBER_TYPES); 97 String 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 <NamedComponentReference<GlobalSimpleType>> types) { 107 String val = types == null ? null : getRefsString(types); 108 setAttribute(MEMBER_TYPES_PROPERTY, SchemaAttributes.MEMBER_TYPES, val); 109 } 110 111 private String getRefsString(java.util.List <NamedComponentReference<GlobalSimpleType>> types) { 112 StringBuilder refVal = new StringBuilder (); 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 <LocalSimpleType> getInlineTypes() { 133 return getChildren(LocalSimpleType.class); 134 } 135 } 136 | Popular Tags |