/** * Get the name of this type as an EQName, that is, a string in the format Q{uri}local. * * @return an EQName identifying the type. */ public String getEQName() { return "Q{" + NamespaceConstant.SCHEMA + "}" + getName(); }
/** * Get the name of this type as an EQName, that is, a string in the format Q{uri}local. * * @return an EQName identifying the type. */ public String getEQName() { return "Q{" + NamespaceConstant.SCHEMA + "}" + getName(); }
/** * Generate Javascript code to convert a supplied Javascript value to this item type, * if conversion is possible, or throw an error otherwise. * * @param errorCode the error to be thrown if conversion is not possible * @param targetVersion 1 or 2 depending on the version of Saxon-JS we are targeting * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns the result of conversion to this type, or throws * an error if conversion is not possible. The variable "val" will hold the supplied Javascript * value. */ public String generateJavaScriptItemTypeAcceptor(String errorCode, int targetVersion) { if (targetVersion == 1) { return "return SaxonJS.U.Atomic." + getName() + ".cast(val);"; } else if (targetVersion == 2) { return "return SaxonJS.U.cast(val, '" + getName() + "');"; } else { throw new IllegalArgumentException(targetVersion+""); } }
/** * Generate Javascript code to test whether an item conforms to this item type * @param knownToBe a type that the item is known to conform to * @param targetVersion 1 or 2 depending on the version of Saxon-JS we are targeting * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns a boolean indication whether the value of the * variable "item" is an instance of this item type. * */ @Override public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) { if (this == NOTATION) { return "return false;"; } if (targetVersion == 1) { return "return SaxonJS.U.Atomic." + getName() + ".matches(item);"; } else if (targetVersion == 2) { return "return SaxonJS.U.hasAtomicType(item, '" + getName() + "');"; } else { throw new IllegalArgumentException(); } }
/** * Generate Javascript code to convert a supplied Javascript value to this item type, * if conversion is possible, or throw an error otherwise. * * @param errorCode the error to be thrown if conversion is not possible * @param targetVersion 1 or 2 depending on the version of Saxon-JS we are targeting * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns the result of conversion to this type, or throws * an error if conversion is not possible. The variable "val" will hold the supplied Javascript * value. */ public String generateJavaScriptItemTypeAcceptor(String errorCode, int targetVersion) { if (targetVersion == 1) { return "return SaxonJS.U.Atomic." + getName() + ".cast(val);"; } else if (targetVersion == 2) { return "return SaxonJS.U.cast(val, '" + getName() + "');"; } else { throw new IllegalArgumentException(targetVersion+""); } }
/** * Generate Javascript code to test whether an item conforms to this item type * @param knownToBe a type that the item is known to conform to * @param targetVersion 1 or 2 depending on the version of Saxon-JS we are targeting * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns a boolean indication whether the value of the * variable "item" is an instance of this item type. * */ @Override public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) { if (this == NOTATION) { return "return false;"; } if (targetVersion == 1) { return "return SaxonJS.U.Atomic." + getName() + ".matches(item);"; } else if (targetVersion == 2) { return "return SaxonJS.U.hasAtomicType(item, '" + getName() + "');"; } else { throw new IllegalArgumentException(); } }