Skip to content

Commit

Permalink
GH-2828: Remove validation for XML-only datatypes
Browse files Browse the repository at this point in the history
Issue: #2828

Remove the code for validating datatypes that according to the RDF 1.1 spec SHOULD NOT be used: QName, ENTITY, ID, IDREF, NOTATION, ENTITIES, NMTOKENS, IDREFS. Also remove code for validating XSD lists and unions.
  • Loading branch information
Ostrzyciel authored and afs committed Nov 20, 2024
1 parent 1c44de8 commit dc89c67
Showing 15 changed files with 120 additions and 1,500 deletions.
137 changes: 28 additions & 109 deletions jena-core/src/main/java/org/apache/jena/datatypes/xsd/XSDDatatype.java
Original file line number Diff line number Diff line change
@@ -112,9 +112,6 @@ public class XSDDatatype extends BaseDatatype {
public static final XSDDatatype XSDnormalizedString = new XSDBaseStringType("normalizedString", String.class);

/** Datatype representing xsd:anyURI */
// If you see this, remove commented lines.
// Merely temporary during switch over and testing.
//public static final XSDDatatype XSDanyURI = new XSDDatatype("anyURI", URI.class);
public static final XSDDatatype XSDanyURI = new XSDPlainType("anyURI", URI.class);

/** Datatype representing xsd:token */
@@ -123,10 +120,11 @@ public class XSDDatatype extends BaseDatatype {
/** Datatype representing xsd:Name */
public static final XSDDatatype XSDName = new XSDBaseStringType("Name");

/** Datatype representing xsd:QName */
// If you see this, remove commented lines.
// Merely temporary during switch over and testing.
// public static final XSDDatatype XSDQName = new XSDDatatype("QName");
/**
* Datatype representing xsd:QName
* @deprecated will be removed in Jena 6
*/
@Deprecated(forRemoval = true)
public static final XSDDatatype XSDQName = new XSDPlainType("QName");

/** Datatype representing xsd:language */
@@ -135,25 +133,35 @@ public class XSDDatatype extends BaseDatatype {
/** Datatype representing xsd:NMTOKEN */
public static final XSDDatatype XSDNMTOKEN = new XSDBaseStringType("NMTOKEN");

/** Datatype representing xsd:ENTITY */
/**
* Datatype representing xsd:ENTITY
* @deprecated will be removed in Jena 6
*/
@Deprecated(forRemoval = true)
public static final XSDDatatype XSDENTITY = new XSDBaseStringType("ENTITY");

/** Datatype representing xsd:ID */
/**
* Datatype representing xsd:ID
* @deprecated will be removed in Jena 6
*/
@Deprecated(forRemoval = true)
public static final XSDDatatype XSDID = new XSDBaseStringType("ID");

/** Datatype representing xsd:NCName */
public static final XSDDatatype XSDNCName = new XSDBaseStringType("NCName");

/** Datatype representing xsd:IDREF */
// If you see this, remove commented lines.
// Merely temporary during switch over and testing.
//public static final XSDDatatype XSDIDREF = new XSDDatatype("IDREF");
/**
* Datatype representing xsd:IDREF
* @deprecated will be removed in Jena 6
*/
@Deprecated(forRemoval = true)
public static final XSDDatatype XSDIDREF = new XSDPlainType("IDREF");

/** Datatype representing xsd:NOTATION */
// If you see this, remove commented lines.
// Merely temporary during switch over and testing.
//public static final XSDDatatype XSDNOTATION = new XSDDatatype("NOTATION");
/**
* Datatype representing xsd:NOTATION
* @deprecated will be removed in Jena 6
*/
@Deprecated(forRemoval = true)
public static final XSDDatatype XSDNOTATION = new XSDPlainType("NOTATION");

/** Datatype representing xsd:hexBinary */
@@ -198,17 +206,6 @@ public class XSDDatatype extends BaseDatatype {
/** Datatype representing xsd:gMonthDay */
public static final XSDDatatype XSDgMonthDay = new XSDMonthDayType("gMonthDay");

// The following are list rather than simple types and are omitted for now

// /** Datatype representing xsd:ENTITIES */
// public static final XSDDatatype XSDENTITIES = new XSDBaseStringType("ENTITIES");
//
// /** Datatype representing xsd:NMTOKENS */
// public static final XSDDatatype XSDNMTOKENS = new XSDBaseStringType("NMTOKENS");
//
// /** Datatype representing xsd:IDREFS */
// public static final XSDDatatype XSDIDREFS = new XSDBaseStringType("IDREFS");

//=======================================================================
// local variables

@@ -311,83 +308,6 @@ public Object extendedTypeDefinition() {
return typeDeclaration;
}

// The following code parses an external XSD file for XSD datatype definitions.
// See an example "testing/xsd/daml+oil-ex-dt.xsd" and TestTypeLiterals.testUserDefined.
// It calls into Xerces internal XM parsing, which is problematic if switching to the
// JDK built-in XML parser in Java9 and later.

// /**
// * Create and register a set of types specified in a user schema file.
// * We use the (illegal) DAML+OIL approach that the uriref of the type
// * is the url of the schema file with fragment ID corresponding the
// * the name of the type.
// *
// * @param uri the absolute uri of the schema file to be loaded
// * @param reader the Reader stream onto the file (useful if you wish to load a cached copy of the schema file)
// * @param encoding the encoding of the source file (can be null)
// * @param tm the type mapper into which to load the definitions
// * @return a List of strings giving the uri's of the newly defined datatypes
// * @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
// * in default mode for load which may provide diagnostic output direct to stderr)
// */
// public static List<String> loadUserDefined(String uri, Reader reader, String encoding, TypeMapper tm) throws DatatypeFormatException {
// return loadUserDefined(new XMLInputSource(null, uri, uri, reader, encoding), tm);
// }
//
// /**
// * Create and register a set of types specified in a user schema file.
// * We use the (illegal) DAML+OIL approach that the uriref of the type
// * is the url of the schema file with fragment ID corresponding the
// * the name of the type.
// *
// * @param uri the absolute uri of the schema file to be loaded, this should be a resolvable URL
// * @param encoding the encoding of the source file (can be null)
// * @param tm the type mapper into which to load the definitions
// * @return a List of strings giving the uri's of the newly defined datatypes
// * @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
// * in default mode for load which may provide diagnostic output direct to stderr)
// */
// public static List<String> loadUserDefined(String uri, String encoding, TypeMapper tm) throws DatatypeFormatException {
// return loadUserDefined(new XMLInputSource(null, uri, uri), tm);
// }
//
// /**
// * Internal implementation of loadUserDefined
// *
// * @param uri the absolute uri of the schema file to be loaded
// * @param reader the Reader stream onto the file (useful if you wish to load a cached copy of the schema file)
// * @param encoding the encoding of the source file (can be null)
// * @param tm the type mapper into which to load the definitions
// * @return a List of strings giving the uri's of the newly defined datatypes
// * @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
// * in default mode for load which may provide diagnostic output direct to stderr)
// */
// private static List<String> loadUserDefined(XMLInputSource source, TypeMapper tm) throws DatatypeFormatException {
// XMLGrammarPreparser parser = new XMLGrammarPreparser();
// parser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
// try {
// XSGrammar xsg = (XSGrammar) parser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, source);
// org.apache.xerces.xs.XSModel xsm = xsg.toXSModel();
// XSNamedMap map = xsm.getComponents(XSTypeDefinition.SIMPLE_TYPE);
// int numDefs = map.getLength();
// ArrayList<String> names = new ArrayList<>(numDefs);
// for (int i = 0; i < numDefs; i++) {
// XSSimpleType xstype = (XSSimpleType) map.item(i);
// // Filter built in types - only needed for 2.6.0
// if ( ! XSD.equals(xstype.getNamespace()) ) {
// //xstype.derivedFrom()
// XSDDatatype definedType = new XSDGenericType(xstype, source.getSystemId());
// tm.registerDatatype(definedType);
// names.add(definedType.getURI());
// }
// }
// return names;
// } catch (Exception e) {
// e.printStackTrace(); // Temp
// throw new DatatypeFormatException(e.toString());
// }
// }

/**
* Convert a validated xerces data value into the corresponding java data value.
* This function is currently the most blatently xerces-version dependent part
@@ -596,17 +516,16 @@ public static void loadXSDSimpleTypes(TypeMapper tm) {
tm.registerDatatype(XSDtoken);
tm.registerDatatype(XSDName);
tm.registerDatatype(XSDlanguage);

// According to the RDF 1.1 spec, these datatypes SHOULD NOT be used in RDF.
// Jena will not do any special handling or validation of these datatypes.
tm.registerDatatype(XSDQName);
tm.registerDatatype(XSDNMTOKEN);
tm.registerDatatype(XSDID);
tm.registerDatatype(XSDENTITY);
tm.registerDatatype(XSDNCName);
tm.registerDatatype(XSDNOTATION);
tm.registerDatatype(XSDIDREF);

// tm.registerDatatype(XSDIDREFS);
// tm.registerDatatype(XSDENTITIES);
// tm.registerDatatype(XSDNMTOKENS);
}

/**
Original file line number Diff line number Diff line change
@@ -91,35 +91,4 @@ protected SchemaDVFactory() {}
public abstract XSSimpleType createTypeRestriction(String name, String targetNamespace,
short finalSet, XSSimpleType base,
XSObjectList annotations);

/**
* Create a new simple type which is derived by list from another simple
* type.
*
* @param name name of the new type, could be null
* @param targetNamespace target namespace of the new type, could be null
* @param finalSet value of "final"
* @param itemType item type of the list type
* @param annotations set of annotations
* @return the newly created simple type
*/
public abstract XSSimpleType createTypeList(String name, String targetNamespace,
short finalSet, XSSimpleType itemType,
XSObjectList annotations);

/**
* Create a new simple type which is derived by union from a list of other
* simple types.
*
* @param name name of the new type, could be null
* @param targetNamespace target namespace of the new type, could be null
* @param finalSet value of "final"
* @param memberTypes member types of the union type
* @param annotations set of annotations
* @return the newly created simple type
*/
public abstract XSSimpleType createTypeUnion(String name, String targetNamespace,
short finalSet, XSSimpleType[] memberTypes,
XSObjectList annotations);

}
Original file line number Diff line number Diff line change
@@ -51,6 +51,8 @@ public interface XSSimpleType extends XSSimpleTypeDefinition {
* see <a href='http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes'>
* XML Schema Part 2: Datatypes </a>
*/
/** "anySimpleType" type */
public static final short PRIMITIVE_ANYSIMPLETYPE = 0;
/** "string" type */
public static final short PRIMITIVE_STRING = 1;
/** "boolean" type */
@@ -85,22 +87,10 @@ public interface XSSimpleType extends XSSimpleTypeDefinition {
public static final short PRIMITIVE_BASE64BINARY = 16;
/** "anyURI" type */
public static final short PRIMITIVE_ANYURI = 17;
/** "QName" type */
public static final short PRIMITIVE_QNAME = 18;
/** "precisionDecimal" type */
public static final short PRIMITIVE_PRECISIONDECIMAL = 19;
public static final short PRIMITIVE_PRECISIONDECIMAL = 18;
/** "NOTATION" type */
public static final short PRIMITIVE_NOTATION = 20;

/**
* return an ID representing the built-in primitive base type.
* REVISIT: This method is (currently) for internal use only.
* the constants returned from this method are not finalized yet.
* the names and values might change in the further.
*
* @return an ID representing the built-in primitive base type
*/
public short getPrimitiveKind();
public static final short PRIMITIVE_NOTATION = 19;

/**
* validate a given string against this simple type.
@@ -180,16 +170,6 @@ public void applyFacets(XSFacets facets, short presentFacet, short fixedFacet, V
*/
//public short compare(Object value1, Object value2);

/**
* Check whether this type is or is derived from ID.
* REVISIT: this method makes ID special, which is not a good design.
* but since ID is not a primitive, there doesn't seem to be a
* clean way of doing it except to define special method like this.
*
* @return whether this simple type is or is derived from ID.
*/
public boolean isIDType();

/**
* Return the whitespace corresponding to this datatype.
*
Original file line number Diff line number Diff line change
@@ -86,44 +86,6 @@ public XSSimpleType createTypeRestriction(String name, String targetNamespace,
return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations);
}

/**
* Create a new simple type which is derived by list from another simple
* type.
*
* @param name name of the new type, could be null
* @param targetNamespace target namespace of the new type, could be null
* @param finalSet value of "final"
* @param itemType item type of the list type
* @param annotations set of annotations
* @return the newly created simple type
*/
public XSSimpleType createTypeList(String name, String targetNamespace,
short finalSet, XSSimpleType itemType,
XSObjectList annotations) {
return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations);
}

/**
* Create a new simple type which is derived by union from a list of other
* simple types.
*
* @param name name of the new type, could be null
* @param targetNamespace target namespace of the new type, could be null
* @param finalSet value of "final"
* @param memberTypes member types of the union type
* @param annotations set of annotations
* @return the newly created simple type
*/
public XSSimpleType createTypeUnion(String name, String targetNamespace,
short finalSet, XSSimpleType[] memberTypes,
XSObjectList annotations) {
int typeNum = memberTypes.length;
XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);

return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations);
}

// create all built-in types
static void createBuiltInTypes(SymbolHash types) {
// base schema simple type names
Loading

0 comments on commit dc89c67

Please sign in to comment.