1 22 23 package org.xquark.schema; 24 25 import org.xquark.schema.validation.ValidationContextProvider; 26 import org.xquark.schema.validation.ValidationInfo; 27 28 46 public abstract class Declaration extends SchemaComponent 47 implements Cloneable 48 { 49 private static final String RCSRevision = "$Revision: 1.1 $"; 50 private static final String RCSName = "$Name: $"; 51 protected SchemaScope scope; 52 private Type type = null; 53 protected String defaultValue = null; 54 protected String fixedValue = null; 55 private boolean qualified = false; 56 57 65 protected Declaration(Schema schema, String name, SchemaScope scope) { 66 super(schema, name); 67 this.scope = scope; 68 } 69 70 public Object clone() throws CloneNotSupportedException { 71 Object result = null; 72 result = super.clone(); 73 return result; 74 } 75 76 public void accept(SchemaVisitor visitor) throws SchemaException { 77 visitor.visit(this); 78 } 79 80 86 public String getNamespace() { 87 if (qualified) return super.getNamespace(); 88 else return null; 89 } 90 91 97 public Type getType() { 98 return type; 99 } 100 101 107 public SchemaScope getScope() { 108 return scope; 109 } 110 111 public String getValueConstraint() { 112 if (defaultValue != null) return defaultValue; 113 else if (fixedValue != null) return fixedValue; 114 else return null; 115 } 116 117 public void setValueConstraint(String value) { 118 if (defaultValue != null) defaultValue = value; 119 else if (fixedValue != null) fixedValue = value; 120 } 121 122 127 public String getDefaultValue() { 128 return defaultValue; 129 } 130 131 public void setDefaultValue(String defaultValue) { 132 this.defaultValue = defaultValue; 133 } 134 135 140 public String getFixedValue() { 141 return fixedValue; 142 } 143 144 public void setFixedValue(String fixedValue) { 145 this.fixedValue = fixedValue; 146 } 147 148 public void setType(Type type) { 149 this.type = type; 150 } 151 152 public void setScope(SchemaScope scope) { 153 this.scope = scope; 154 } 155 156 public void setQualified(boolean qualified) { 157 this.qualified = qualified; 158 } 159 160 178 public int validate(String value, ValidationContextProvider context) throws SchemaException { 179 if ( type == null ) return -1; 180 SimpleType valueType = type.getValueType(); 181 if (valueType == null ) return -1; 182 ValidationInfo info = valueType.validate(value, true, context); 183 SimpleType realType = info.getValidationType(); 184 Object actualValue = info.getActualValue(); 185 if ( getFixedValue() != null) { 186 if (!getFixedValue().equals(realType.toXMLString(actualValue))) { 187 if ( this instanceof AttributeDeclaration ) 188 throw new SchemaException("cvc-attribute.4", this); 189 else 190 throw new SchemaException("cvc-elt.5.2.2.2.2", this); 191 } 192 } 193 194 return 0; 195 } 196 197 } 198 | Popular Tags |