/** Returns the built in type this type is derived from. */ public SimpleType getBuiltInBaseType() { SimpleType base = this; while ((base != null) && (!SimpleTypesFactory.isBuiltInType(base.getTypeCode()))) { base = (SimpleType) base.getBaseType(); } return base; }
/** * Returns an Enumeration of all the Facets (including inherited) facets for this type. * * @return an Enumeration of all the Facets for this type */ public Enumeration getFacets() { FacetListEnumerator fle = null; SimpleType datatype = (SimpleType) getBaseType(); if (datatype != null) { fle = (FacetListEnumerator) datatype.getFacets(); } fle = new FacetListEnumerator(facets, fle); return fle; } // -- getFacets
/** * Returns the SimpleType associated with the given name, or null if no such SimpleType exists. * * @return the SimpleType associated with the given name, or null if no such SimpleType exists. */ public SimpleType getSimpleType(String name) { // -- Null? if (name == null) { String err = NULL_ARGUMENT + "getSimpleType: "; err += "'name' cannot be null."; throw new IllegalArgumentException(err); } // -- Namespace prefix? String canonicalName = name; String nsPrefix = ""; String ns = null; int colon = name.indexOf(':'); if (colon >= 0) { canonicalName = name.substring(colon + 1); nsPrefix = name.substring(0, colon); ns = (String) namespaces.get(nsPrefix); if (ns == null) { String err = "getSimpleType: "; err += "Namespace prefix not recognised '" + name + "'"; throw new IllegalArgumentException(err); } } // -- Get SimpleType object SimpleType result = null; if (ns == null) { // -- first try built-in types result = simpleTypesFactory.getBuiltInType(name); // if we have a built-in type not declared in the good namespace -> Exception if ((result != null) && (namespaces.containsValue(DEFAULT_SCHEMA_NS))) { String err = "getSimpleType: the simple type '" + name + "' has not been declared in XML Schema namespace."; throw new IllegalArgumentException(err); } // -- otherwise check user-defined types if (result == null) result = (SimpleType) simpleTypes.get(name); } else if (ns.equals(schemaNS)) result = simpleTypesFactory.getBuiltInType(canonicalName); else if (ns.equals(targetNS)) result = (SimpleType) simpleTypes.get(canonicalName); else { Schema schema = getImportedSchema(ns); if (schema != null) result = schema.getSimpleType(canonicalName); } // -- Result could be a deferredSimpleType => getType will resolve it if (result != null) result = (SimpleType) result.getType(); return result; } // -- getSimpleType
/** * Removes the given top level SimpleType from this Schema * * @param SimpleType the SimpleType to remove * @return true if the SimpleType has been removed, or false if the SimpleType wasn't top level or * didn't exist in this Schema */ public boolean removeSimpleType(SimpleType simpleType) { if (simpleTypes.contains(simpleType)) { simpleTypes.remove(simpleType.getName()); return true; } return false; } // -- removeSimpleType
/** * Adds the given SimpletType definition to this Schema defintion * * @param simpletype the SimpleType to add to this Schema * @exception SchemaException if the SimpleType does not have a name or if another SimpleType * already exists with the same name */ public synchronized void addSimpleType(SimpleType simpleType) throws SchemaException { String name = simpleType.getName(); if ((name == null) || (name.length() == 0)) { String err = "No name found for top-level SimpleType. " + " A top-level SimpleType must have a name."; throw new SchemaException(err); } if (simpleType.getSchema() != this) { String err = "invalid attempt to add a SimpleType which "; err += "belongs to a different Schema; type name: " + name; throw new SchemaException(err); } if (simpleTypes.get(name) != null) { String err = "a SimpleType already exists with the given name: "; throw new SchemaException(err + name); } simpleType.setParent(this); simpleTypes.put(name, simpleType); } // -- addSimpleType
/** Copy this type's facet in the other type (other.facets= facets; ) */ protected void copyFacets(SimpleType other) { other.facets = facets; }