1 19 20 21 package org.netbeans.modules.xml.schema.model.impl; 22 23 import org.netbeans.modules.xml.schema.model.LengthFacet; 24 import org.w3c.dom.Element ; 25 26 31 32 public abstract class CommonLength extends SchemaComponentImpl implements LengthFacet { 33 34 35 public CommonLength(SchemaModelImpl model, Element e) { 36 super(model, e); 37 } 38 39 public abstract String getComponentName(); 40 41 public void setValue(int v) { 42 if (v < 0) { 43 throw new IllegalArgumentException ("Element '" + getComponentName() + "' can only have positive integer value."); 44 } 45 setAttribute(VALUE_PROPERTY, SchemaAttributes.VALUE, String.valueOf(v)); 46 } 47 48 public int getValue() { 49 String v = super.getAttribute(SchemaAttributes.VALUE); 50 if (v == null) { 51 return 1; 52 } 53 int i = Integer.valueOf(v); 54 if (i < 0) { 55 throw new IllegalArgumentException ("Element '" + getComponentName() + "' can only has positive integer value."); 56 } 57 return i; 58 } 59 60 public Boolean isFixed() { 61 String v = super.getAttribute(SchemaAttributes.FIXED); 62 return v == null ? null : Boolean.valueOf(v); 63 } 64 65 public void setFixed(Boolean isFixed) { 66 setAttribute(FIXED_PROPERTY, SchemaAttributes.FIXED, isFixed); 67 } 68 69 protected Class getAttributeType(SchemaAttributes attr) { 70 switch(attr) { 71 case FIXED: 72 return String .class; 73 default: 74 return super.getAttributeType(attr); 75 } 76 } 77 78 public boolean getFixedEffective() { 79 Boolean v = isFixed(); 80 return v == null ? getFixedDefault() : v; 81 } 82 83 public boolean getFixedDefault() { 84 return false; 85 } 86 } 87 | Popular Tags |