1 19 20 package org.netbeans.modules.xml.axi.impl; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import org.netbeans.modules.xml.axi.AXIComponent; 25 import org.netbeans.modules.xml.axi.AXIModel; 26 import org.netbeans.modules.xml.axi.AXIType; 27 import org.netbeans.modules.xml.axi.AbstractAttribute; 28 import org.netbeans.modules.xml.axi.Compositor; 29 import org.netbeans.modules.xml.axi.ContentModel; 30 import org.netbeans.modules.xml.axi.Element; 31 import org.netbeans.modules.xml.axi.datatype.Datatype; 32 import org.netbeans.modules.xml.axi.visitor.AXIVisitor; 33 import org.netbeans.modules.xml.schema.model.Form; 34 import org.netbeans.modules.xml.schema.model.SchemaComponent; 35 import org.netbeans.modules.xml.schema.model.SimpleType; 36 37 41 public final class ElementImpl extends Element { 42 43 46 public ElementImpl(AXIModel model) { 47 super(model); 48 } 49 50 53 public ElementImpl(AXIModel model, SchemaComponent schemaComponent) { 54 super(model, schemaComponent); 55 } 56 57 60 public boolean isReference() { 61 return false; 62 } 63 64 67 public Element getReferent() { 68 return null; 69 } 70 71 74 public boolean getAbstract() { 75 return isAbstract; 76 } 77 78 81 public void setAbstract(boolean value) { 82 boolean oldValue = getAbstract(); 83 if(oldValue != value) { 84 this.isAbstract = value; 85 firePropertyChangeEvent(PROP_ABSTRACT, oldValue, value); 86 } 87 } 88 89 92 public String getBlock() { 93 return block; 94 } 95 96 99 public void setBlock(String value) { 100 String oldValue = getBlock(); 101 if( (oldValue == null && value == null) || 102 (oldValue != null && oldValue.equals(value)) ) { 103 return; 104 } 105 this.block = value; 106 firePropertyChangeEvent(PROP_BLOCK, oldValue, value); 107 } 108 109 112 public String getFinal() { 113 return finalValue; 114 } 115 116 119 public void setFinal(String value) { 120 String oldValue = getFinal(); 121 if( (oldValue == null && value == null) || 122 (oldValue != null && oldValue.equals(value)) ) { 123 return; 124 } 125 this.finalValue = value; 126 firePropertyChangeEvent(PROP_FINAL, oldValue, value); 127 } 128 129 132 public String getFixed() { 133 return fixedValue; 134 } 135 136 139 public void setFixed(String value) { 140 String oldValue = getFixed(); 141 if( (oldValue == null && value == null) || 142 (oldValue != null && oldValue.equals(value)) ) { 143 return; 144 } 145 this.fixedValue = value; 146 firePropertyChangeEvent(PROP_FIXED, oldValue, value); 147 } 148 149 152 public String getDefault() { 153 return defaultValue; 154 } 155 156 159 public void setDefault(String value) { 160 String oldValue = getDefault(); 161 if( (oldValue == null && value == null) || 162 (oldValue != null && oldValue.equals(value)) ) { 163 return; 164 } 165 this.defaultValue = value; 166 firePropertyChangeEvent(PROP_DEFAULT, oldValue, value); 167 } 168 169 172 public Form getForm() { 173 return form; 174 } 175 176 179 public void setForm(Form value) { 180 Form oldValue = getForm(); 181 if(oldValue != value) { 182 this.form = value; 183 firePropertyChangeEvent(PROP_FORM, oldValue, value); 184 } 185 } 186 187 190 public boolean getNillable() { 191 return isNillable; 192 } 193 194 197 public void setNillable(boolean value) { 198 boolean oldValue = getNillable(); 199 if(oldValue != value) { 200 this.isNillable = value; 201 firePropertyChangeEvent(PROP_NILLABLE, oldValue, value); 202 } 203 } 204 205 208 public AXIType getType() { 209 if(axiType != null) 210 return axiType; 211 212 this.axiType = Util.getAXIType(this, typeSchemaComponent); 213 return axiType; 214 } 215 216 219 public void setType(AXIType newValue) { 220 if( (this == newValue) || 221 (this.isGlobal() && (newValue instanceof Element)) ) 222 return; 223 224 if(newValue instanceof Element) { 225 setElementAsType(newValue); 226 return; 227 } 228 229 AXIType oldValue = getType(); 230 if(!Util.canSetType(oldValue, newValue)) 231 return; 232 233 updateChildren(oldValue, newValue); 234 this.axiType = newValue; 235 firePropertyChangeEvent(PROP_TYPE, oldValue, newValue); 236 setTypeSchemaComponent(getSchemaType(newValue)); 237 if(newValue instanceof ContentModel) { 238 ((ContentModel)newValue).addListener(this); 239 } 240 } 241 242 private void setElementAsType(final AXIType newValue) { 243 if(newValue == this) 244 return; 245 int index = this.getIndex(); 246 AXIComponent parent = getParent(); 247 Element ref = getModel().getComponentFactory().createElementReference((Element)newValue); 248 parent.removeChild(this); 249 parent.insertAtIndex(Element.PROP_ELEMENT_REF, ref, index); 250 } 251 252 261 public void populateChildren(List <AXIComponent> children) { 262 if(getPeer() == null) { 263 return; 264 } 265 266 SchemaComponent type = Util.getSchemaType((AXIModelImpl)getModel(), getPeer()); 268 setTypeSchemaComponent(type); 269 270 if(type == null || type instanceof SimpleType) 271 return; 272 273 AXIModelBuilder builder = new AXIModelBuilder(this); 274 builder.populateChildren(type, false, children); 275 } 276 277 280 SchemaComponent getTypeSchemaComponent() { 281 return typeSchemaComponent; 282 } 283 284 287 void setTypeSchemaComponent(SchemaComponent type) { 288 this.typeSchemaComponent = type; 289 } 290 291 private SchemaComponent getSchemaType(AXIType axiType) { 292 if(axiType instanceof Datatype) 293 return null; 294 if(axiType instanceof ContentModel) 295 return ((ContentModel)axiType).getPeer(); 296 if(axiType instanceof AnonymousType) 297 return ((AnonymousType)axiType).getPeer(); 298 299 return null; 300 } 301 302 311 private void updateChildren(AXIType oldValue, AXIType newValue) { 312 if(oldValue instanceof Datatype && newValue instanceof AnonymousType) { 315 return; 316 } 317 318 removeAllChildren(); 320 if( (newValue == null) || (newValue instanceof Datatype) ) { 321 return; 322 } 323 324 if(oldValue != null && oldValue instanceof ContentModel) { 326 ContentModel cm = (ContentModel)oldValue; 327 cm.removeListener(this); 328 } 329 330 if(newValue instanceof ContentModel) 332 Util.addProxyChildren(this, (ContentModel)newValue, null); 333 334 if(newValue instanceof AnonymousType) { 335 List <AXIComponent> children = new ArrayList <AXIComponent>(); 336 AXIModelBuilder builder = new AXIModelBuilder(this); 337 builder.populateChildren( ((AnonymousType)newValue).getPeer(), false, children); 338 for(AXIComponent child : children) { 339 this.appendChild(child); 340 } 341 } 342 } 343 344 347 public static class AnonymousType implements AXIType { 348 private SchemaComponent schemaComponent; 349 public AnonymousType(SchemaComponent schemaComponent) { 350 this.schemaComponent = schemaComponent; 351 } 352 public String getName() { 353 return null; 354 } 355 public void accept(AXIVisitor visitor) { 356 } 357 public SchemaComponent getPeer() { 358 return schemaComponent; 359 } 360 } 361 362 365 public void addCompositor(Compositor compositor) { 366 if( getType() != null && getType() instanceof ContentModel && 367 getModel() != ((ContentModel)getType()).getModel() ) { 368 return; 371 } 372 373 if(getType() instanceof Datatype) { 374 setType(new AnonymousType(null)); 375 } 376 super.addCompositor(compositor); 377 } 378 379 382 public void addAttribute(AbstractAttribute attribute) { 383 AXIType type = getType(); 384 if(type != null && type instanceof ContentModel) { 385 ((ContentModel)type).addAttribute(attribute); 386 return; 387 } 388 389 if(type instanceof Datatype) { 390 setType(new AnonymousType(null)); 391 } 392 393 super.addAttribute(attribute); 394 } 395 396 397 private AXIType axiType; 398 private SchemaComponent typeSchemaComponent; 399 } 400 | Popular Tags |