1 22 23 package org.xquark.schema.datatypes; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.schema.SchemaException; 28 import org.xquark.schema.validation.ValidationContextProvider; 29 30 31 class PrimitiveUnionType extends EnumerableType { 32 private static final String RCSRevision = "$Revision: 1.2 $"; 33 private static final String RCSName = "$Name: $"; 34 35 ArrayList primitives = new ArrayList (); 36 37 PrimitiveUnionType(ArrayList primitives, String unionName) { 38 super(unionName, PrimitiveType.UNION); 39 nWhiteSpace = PrimitiveType.PRESERVE; 41 this.primitives = primitives; 42 } 43 44 protected Object toValidType(Object data) { 45 return data; 47 } 48 49 protected void setWhiteSpace(String value) throws SchemaException { 50 throw new SchemaException("cos-applicable-facets"); 52 } 53 54 protected void invalidValue(String value, SchemaException se) throws SchemaException { 55 throw new SchemaException("cvc-datatype-valid.1.2.3", this, se); 56 } 57 58 protected Object toValueSpace(String value, ValidationContextProvider context) throws SchemaException { 59 return checkUnion(value, context); 60 } 61 62 protected Object checkUnion(String value, ValidationContextProvider context) throws SchemaException { 63 Object result = null; 64 ArrayList exceptions = null; 65 for (int i = 0; i < primitives.size(); i++) { 66 try { 67 PrimitiveType pType = (PrimitiveType) primitives.get(i); 68 result = pType.convert(value, true, context); 69 break; 70 } catch (SchemaException ex) { 71 if (exceptions == null) 72 exceptions = new ArrayList (); 73 exceptions.add(ex); 74 } 75 } 76 if (result != null) { 77 return result; 78 } else { 79 throw new SchemaException("cvc-datatype-valid.1.2.3", this, exceptions); 80 } 81 } 82 } 83 | Popular Tags |