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.Set ; 25 import org.netbeans.modules.xml.schema.model.Annotation; 26 import org.netbeans.modules.xml.schema.model.Element; 27 import org.netbeans.modules.xml.schema.model.Element.Block; 28 import org.netbeans.modules.xml.schema.model.Constraint; 29 import org.netbeans.modules.xml.schema.model.GlobalType; 30 import org.netbeans.modules.xml.schema.model.LocalElement; 31 import org.netbeans.modules.xml.schema.model.LocalType; 32 import org.netbeans.modules.xml.schema.model.Schema; 33 import org.netbeans.modules.xml.schema.model.SchemaComponent; 34 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 35 39 public abstract class ElementImpl extends NamedImpl implements Element { 40 41 44 public ElementImpl(SchemaModelImpl model, org.w3c.dom.Element el) { 45 super(model, el); 46 } 47 48 protected Class getAttributeMemberType(SchemaAttributes attr) { 49 switch(attr) { 50 case BLOCK: 51 return Block.class; 52 default: 53 return super.getAttributeMemberType(attr); 54 } 55 } 56 57 public void setDefault(String defaultValue) { 58 setAttribute(DEFAULT_PROPERTY ,SchemaAttributes.DEFAULT, defaultValue); 59 } 60 61 public void setFixed(String fixed) { 62 setAttribute(FIXED_PROPERTY ,SchemaAttributes.FIXED, fixed); 63 } 64 65 public void setType(NamedComponentReference<? extends GlobalType> t) { 66 setAttribute(LocalElement.TYPE_PROPERTY, SchemaAttributes.TYPE, t); 67 } 68 69 public void setNillable(Boolean nillable) { 70 setAttribute(NILLABLE_PROPERTY, SchemaAttributes.NILLABLE, nillable); 71 } 72 73 76 public void addConstraint(Constraint c) { 77 Collection <java.lang.Class <? extends SchemaComponent>> list = new ArrayList <java.lang.Class <? extends SchemaComponent>>(); 78 list.add(Annotation.class); 79 list.add(LocalType.class); 80 addAfter(CONSTRAINT_PROPERTY, (SchemaComponent) c, list); 81 } 82 83 86 public void removeConstraint(Constraint c) { 87 removeChild(CONSTRAINT_PROPERTY , (SchemaComponent) c); 88 } 89 90 93 public void setInlineType(LocalType t) { 94 Collection <Class <? extends SchemaComponent>> list = new ArrayList <Class <? extends SchemaComponent>>(); 95 list.add(Annotation.class); 96 setChild(LocalType.class, LocalElement.INLINE_TYPE_PROPERTY, t, list); 97 } 98 99 100 public void setBlock(Set <Block> block) { 101 setAttribute(BLOCK_PROPERTY, SchemaAttributes.BLOCK, 102 block == null ? null : 103 Util.convertEnumSet(Block.class, block)); 104 } 105 106 public Set <Block> getBlock() { 107 String s = getAttribute(SchemaAttributes.BLOCK); 108 return s == null ? null : Util.valuesOf(Block.class, s); 109 } 110 111 public Set <Block> getBlockEffective() { 112 Set <Block> v = getBlock(); 113 return v == null ? getBlockDefault() : v; 114 } 115 116 public Set <Block> getBlockDefault() { 117 Set <Schema.Block> v = getModel().getSchema().getBlockDefaultEffective(); 118 return Util.convertEnumSet(Block.class, v); 119 } 120 121 124 public Collection <Constraint> getConstraints() { 125 return getChildren(Constraint.class); 126 } 127 128 131 public String getDefault() { 132 return getAttribute(SchemaAttributes.DEFAULT); 133 } 134 135 138 public String getFixed() { 139 return getAttribute(SchemaAttributes.FIXED); 140 } 141 142 145 public LocalType getInlineType() { 146 Collection <LocalType> elements = getChildren(LocalType.class); 147 if(!elements.isEmpty()){ 148 return elements.iterator().next(); 149 } 150 return null; 151 } 152 153 156 public NamedComponentReference<? extends GlobalType> getType() { 157 return resolveGlobalReference(GlobalType.class, SchemaAttributes.TYPE); 158 } 159 160 163 public Boolean isNillable() { 164 String s = getAttribute(SchemaAttributes.NILLABLE); 165 return s == null ? null : Boolean.parseBoolean(s); 166 } 167 168 public boolean getNillableDefault() { 169 return false; 170 } 171 172 public boolean getNillableEffective() { 173 Boolean v = isNillable(); 174 return v == null ? getNillableDefault() : v; 175 } 176 177 } 178 | Popular Tags |