1 22 23 package org.xquark.schema.datatypes; 24 25 import java.net.URL ; 26 27 import org.xquark.schema.SchemaException; 28 import org.xquark.schema.datatypes.URI.MalformedURIException; 29 import org.xquark.schema.validation.ValidationContextProvider; 30 31 32 class AnyURIType extends MesureableType { 33 private static final String RCSRevision = "$Revision: 1.3 $"; 34 private static final String RCSName = "$Name: $"; 35 36 AnyURIType() { 37 super("anyURI", PrimitiveType.ANY_URI); 38 } 39 40 protected Object toValidType(Object data) { 41 if (data instanceof URL ) { 42 try { 43 return toURI(data.toString()); 44 } catch (SchemaException e) { 45 return (URI) data; 47 } 48 } else { 49 return (URI) data; 50 } 51 } 52 53 protected URI toURI(String value) throws SchemaException { 54 try { 55 return new URI(value); 56 } catch (MalformedURIException e) { 57 super.invalidValue(value); 58 return null; 59 } 60 } 61 62 public void checkFacets(Object valueSpace) throws SchemaException { 63 super.checkFacets(valueSpace); 64 super.checkLength(((URI) valueSpace).getLength(), valueSpace); 65 } 66 67 protected Object toValueSpace(String value, ValidationContextProvider context) throws SchemaException { 68 return toURI(value); 69 } 70 } 71 | Popular Tags |