| 1 |
package com.thaiopensource.relaxng.util; |
| 2 |
|
| 3 |
import com.thaiopensource.util.PropertyMap; |
| 4 |
import com.thaiopensource.util.PropertyMapBuilder; |
| 5 |
import com.thaiopensource.validate.ValidateProperty; |
| 6 |
import com.thaiopensource.validate.ValidationDriver; |
| 7 |
import com.thaiopensource.validate.prop.rng.RngProperty; |
| 8 |
import com.thaiopensource.validate.rng.CompactSchemaReader; |
| 9 |
import com.thaiopensource.xml.sax.XMLReaderCreator; |
| 10 |
import com.thaiopensource.xml.sax.Sax2XMLReaderCreator; |
| 11 |
import org.xml.sax.ErrorHandler; |
| 12 |
|
| 13 |
/** |
| 14 |
* Provides a compatibility wrapper around ValidationDriver. New applications |
| 15 |
* should use ValidationDriver directly. |
| 16 |
* |
| 17 |
* @author <a href="mailto:[email protected]">James Clark</a> |
| 18 |
* @see ValidationDriver |
| 19 |
* @deprecated |
| 20 |
*/ |
| 21 |
public class ValidationEngine extends ValidationDriver { |
| 22 |
|
| 23 |
/** |
| 24 |
* Flag indicating that ID/IDREF/IDREFS should be checked. |
| 25 |
* @see RngProperty#CHECK_ID_IDREF |
| 26 |
*/ |
| 27 |
public static final int CHECK_ID_IDREF = 01; |
| 28 |
/** |
| 29 |
* Flag indicating that the schema is in the RELAX NG compact syntax rather than the XML syntax. |
| 30 |
* @see CompactSchemaReader |
| 31 |
*/ |
| 32 |
public static final int COMPACT_SYNTAX = 02; |
| 33 |
/** |
| 34 |
* @see RngProperty#FEASIBLE |
| 35 |
*/ |
| 36 |
public static final int FEASIBLE = 04; |
| 37 |
|
| 38 |
/** |
| 39 |
* Default constructor. Equivalent to <code>ValidationEngine(null, null, CHECK_ID_IDREF)</code>. |
| 40 |
*/ |
| 41 |
public ValidationEngine() { |
| 42 |
this(null, null, CHECK_ID_IDREF); |
| 43 |
} |
| 44 |
/** |
| 45 |
* Constructs a <code>ValidationEngine</code>. |
| 46 |
* |
| 47 |
* @param xrc the <code>XMLReaderCreator</code> to be used for constructing <code>XMLReader</code>s; |
| 48 |
* if <code>null</code> uses <code>Sax2XMLReaderCreator</code> |
| 49 |
* @param eh the <code>ErrorHandler</code> to be used for reporting errors; if <code>null</code> |
| 50 |
* uses <code>DraconianErrorHandler</code> |
| 51 |
* @param flags bitwise OR of flags selected from <code>CHECK_ID_IDREF</code>, <code>COMPACT_SYNTAX</code>, |
| 52 |
* <code>FEASIBLE</code>, <code>MNS</code> |
| 53 |
* @see com.thaiopensource.xml.sax.DraconianErrorHandler |
| 54 |
* @see com.thaiopensource.xml.sax.Sax2XMLReaderCreator |
| 55 |
* @see #CHECK_ID_IDREF |
| 56 |
* @see #COMPACT_SYNTAX |
| 57 |
* @see #FEASIBLE |
| 58 |
*/ |
| 59 |
public ValidationEngine(XMLReaderCreator xrc, |
| 60 |
ErrorHandler eh, |
| 61 |
int flags) { |
| 62 |
super(makePropertyMap(xrc, eh, flags), |
| 63 |
(flags & COMPACT_SYNTAX) == 0 ? null : CompactSchemaReader.getInstance()); |
| 64 |
} |
| 65 |
|
| 66 |
private static PropertyMap makePropertyMap(XMLReaderCreator xrc, ErrorHandler eh, int flags) { |
| 67 |
PropertyMapBuilder builder = new PropertyMapBuilder(); |
| 68 |
if (xrc == null) |
| 69 |
xrc = new Sax2XMLReaderCreator(); |
| 70 |
builder.put(ValidateProperty.XML_READER_CREATOR, xrc); |
| 71 |
if (eh != null) |
| 72 |
builder.put(ValidateProperty.ERROR_HANDLER, eh); |
| 73 |
if ((flags & CHECK_ID_IDREF) != 0) |
| 74 |
RngProperty.CHECK_ID_IDREF.add(builder); |
| 75 |
if ((flags & FEASIBLE) != 0) |
| 76 |
RngProperty.FEASIBLE.add(builder); |
| 77 |
return builder.toPropertyMap(); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Constructs a <code>ValidationEngine</code>. |
| 82 |
* |
| 83 |
* @param xrc the <code>XMLReaderCreator</code> to be used for constructing <code>XMLReader</code>s; |
| 84 |
* if <code>null</code> uses <code>Sax2XMLReaderCreator</code> |
| 85 |
* @param eh the <code>ErrorHandler</code> to be used for reporting errors; if <code>null</code> |
| 86 |
* uses <code>DraconianErrorHandler</code> |
| 87 |
* @param checkIdIdref <code>true</code> if ID/IDREF/IDREFS should be checked; <code>false</code> otherwise |
| 88 |
* @see com.thaiopensource.xml.sax.DraconianErrorHandler |
| 89 |
* @see com.thaiopensource.xml.sax.Sax2XMLReaderCreator |
| 90 |
*/ |
| 91 |
public ValidationEngine(XMLReaderCreator xrc, |
| 92 |
ErrorHandler eh, |
| 93 |
boolean checkIdIdref) { |
| 94 |
this(xrc, eh, checkIdIdref ? CHECK_ID_IDREF : 0); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Constructs a <code>ValidationEngine</code>. |
| 99 |
* |
| 100 |
* @param xrc the <code>XMLReaderCreator</code> to be used for constructing <code>XMLReader</code>s; |
| 101 |
* if <code>null</code> uses <code>Sax2XMLReaderCreator</code> |
| 102 |
* @param eh the <code>ErrorHandler</code> to be used for reporting errors; if <code>null</code> |
| 103 |
* uses <code>DraconianErrorHandler</code> |
| 104 |
* @param checkIdIdref <code>true</code> if ID/IDREF/IDREFS should be checked; <code>false</code> otherwise |
| 105 |
* @param compactSyntax <code>true</code> if the RELAX NG compact syntax should be used to parse the schema; |
| 106 |
* <code>false</code> if the XML syntax should be used |
| 107 |
* @see com.thaiopensource.xml.sax.DraconianErrorHandler |
| 108 |
* @see com.thaiopensource.xml.sax.Sax2XMLReaderCreator |
| 109 |
*/ |
| 110 |
public ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref, boolean compactSyntax) { |
| 111 |
this(xrc, |
| 112 |
eh, |
| 113 |
(checkIdIdref ? CHECK_ID_IDREF : 0) |
| 114 |
| (compactSyntax ? COMPACT_SYNTAX : 0)); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
public ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref, boolean compactSyntax, |
| 119 |
boolean feasible) { |
| 120 |
this(xrc, |
| 121 |
eh, |
| 122 |
(checkIdIdref ? CHECK_ID_IDREF : 0) |
| 123 |
| (compactSyntax ? COMPACT_SYNTAX : 0) |
| 124 |
| (feasible ? FEASIBLE : 0)); |
| 125 |
} |
| 126 |
|
| 127 |
} |