001 package com.thaiopensource.validate;
002
003 import com.thaiopensource.util.PropertyId;
004 import com.thaiopensource.util.PropertyMap;
005 import com.thaiopensource.util.PropertyMapBuilder;
006 import com.thaiopensource.xml.sax.XMLReaderCreator;
007 import org.xml.sax.ErrorHandler;
008 import org.xml.sax.EntityResolver;
009
010 /**
011 * Provides common properties to control reading schemas and validation.
012 *
013 * @see Schema#createValidator
014 * @see SchemaReader#createSchema
015 * @see PropertyMap
016 * @see PropertyId
017 * @see com.thaiopensource.validate.rng.RngProperty
018 * @see com.thaiopensource.validate.schematron.SchematronProperty
019 */
020 public class ValidateProperty {
021 /**
022 * Property specifying ErrorHandler to be used for reporting errors. The value
023 * to which this PropertyId maps must be an instance of ErrorHandler.
024 *
025 * @see ErrorHandler
026 */
027 public static final ErrorHandlerPropertyId ERROR_HANDLER = new ErrorHandlerPropertyId("ERROR_HANDLER");
028
029 /**
030 * Property specifying EntityResolver to be used for resolving entities. The value
031 * to which this PropertyId maps must be an instance of EntityResolver.
032 *
033 * @see EntityResolver
034 */
035 public static final EntityResolverPropertyId ENTITY_RESOLVER = new EntityResolverPropertyId("ENTITY_RESOLVER");
036
037 /**
038 * Property specifying XMLReaderCreator used to create XMLReader objects needed for
039 * parsing XML documents. The value to which this PropertyId maps must be an
040 * instance of XMLReaderCreator.
041 */
042 public static final XMLReaderCreatorPropertyId XML_READER_CREATOR
043 = new XMLReaderCreatorPropertyId("XML_READER_CREATOR");
044
045 private ValidateProperty() { }
046
047 /**
048 * A PropertyId whose value is constrained to be an instance of
049 * ErrorHandler.
050 *
051 * @see ErrorHandler
052 */
053 public static class ErrorHandlerPropertyId extends PropertyId {
054 public ErrorHandlerPropertyId(String name) {
055 super(name, ErrorHandler.class);
056 }
057
058 /**
059 * Returns the value of the property. This is a typesafe
060 * version of <code>PropertyMap.get</code>.
061 *
062 * @param properties the PropertyMap to be used
063 * @return the ErrorHandler to which the PropertyMap maps this PropertyId,
064 * or <code>null</code> if this PropertyId is not in the PropertyMap
065 * @see PropertyMap#get
066 */
067 public ErrorHandler get(PropertyMap properties) {
068 return (ErrorHandler)properties.get(this);
069 }
070
071 /**
072 * Sets the value of the property. Modifies the PropertyMapBuilder
073 * so that this PropertyId is mapped to the specified value. This
074 * is a typesafe version of PropertyMapBuilder.put.
075 *
076 * @param builder the PropertyMapBuilder to be modified
077 * @param value the ErrorHandler to which this PropertyId is to be mapped
078 * @return the ErrorHandler to which this PropertyId was mapped before,
079 * or <code>null</code> if it was not mapped
080 *
081 * @see PropertyMapBuilder#put
082 */
083 public ErrorHandler put(PropertyMapBuilder builder, ErrorHandler value) {
084 return (ErrorHandler)builder.put(this, value);
085 }
086 }
087
088 /**
089 * A PropertyId whose value is constrained to be an instance of
090 * EntityResolver.
091 *
092 * @see EntityResolver
093 */
094 public static class EntityResolverPropertyId extends PropertyId {
095 public EntityResolverPropertyId(String name) {
096 super(name, EntityResolver.class);
097 }
098
099 /**
100 * Returns the value of the property. This is a typesafe
101 * version of <code>PropertyMap.get</code>.
102 *
103 * @param properties the PropertyMap to be used
104 * @return the EntityResolver to which the PropertyMap maps this PropertyId,
105 * or <code>null</code> if this PropertyId is not in the PropertyMap
106 * @see PropertyMap#get
107 */
108 public EntityResolver get(PropertyMap properties) {
109 return (EntityResolver)properties.get(this);
110 }
111
112 /**
113 * Sets the value of the property. Modifies the PropertyMapBuilder
114 * so that this PropertyId is mapped to the specified value. This
115 * is a typesafe version of PropertyMapBuilder.put.
116 *
117 * @param builder the PropertyMapBuilder to be modified
118 * @param value the EntityResolver to which this PropertyId is to be mapped
119 * @return the EntityResolver to which this PropertyId was mapped before,
120 * or <code>null</code> if it was not mapped
121 *
122 * @see PropertyMapBuilder#put
123 */
124 public EntityResolver put(PropertyMapBuilder builder, EntityResolver value) {
125 return (EntityResolver)builder.put(this, value);
126 }
127 }
128
129 /**
130 * A PropertyId whose value is constrained to be an instance of
131 * XMLReaderCreator.
132 *
133 * @see XMLReaderCreator
134 */
135 public static class XMLReaderCreatorPropertyId extends PropertyId {
136 public XMLReaderCreatorPropertyId(String name) {
137 super(name, XMLReaderCreator.class);
138 }
139
140 /**
141 * Returns the value of the property. This is a typesafe
142 * version of <code>PropertyMap.get</code>.
143 *
144 * @param properties the PropertyMap to be used
145 * @return the XMLReaderCreator to which the PropertyMap maps this PropertyId,
146 * or <code>null</code> if this PropertyId is not in the PropertyMap
147 * @see PropertyMap#get
148 */
149 public XMLReaderCreator get(PropertyMap properties) {
150 return (XMLReaderCreator)properties.get(this);
151 }
152
153 /**
154 * Sets the value of the property. Modifies the PropertyMapBuilder
155 * so that this PropertyId is mapped to the specified value. This
156 * is a typesafe version of PropertyMapBuilder.put.
157 *
158 * @param builder the PropertyMapBuilder to be modified
159 * @param value the XMLReaderCreator to which this PropertyId is to be mapped
160 * @return the XMLReaderCreator to which this PropertyId was mapped before,
161 * or <code>null</code> if it was not mapped
162 *
163 * @see PropertyMapBuilder#put
164 */
165 public XMLReaderCreator put(PropertyMapBuilder builder, XMLReaderCreator value) {
166 return (XMLReaderCreator)builder.put(this, value);
167 }
168 }
169 }