DatatypeFactory { public Datatype getDatatype(QName qn) throws ValidationException { Datatype ret = constructed.get(qn); if(ret==null) { ret = constructDatatype(qn); constructed.put(qn, ret); } return ret; } @SuppressWarnings("OverridableMethodCallInConstructor") private  DatatypeFactory(ConversionRules conversionRules); Datatype getDatatype(QName qn); static DatatypeFactory getInstance(Configuration configuration); static final String NS_XSD; final Datatype XS_STRING; }
@Test public void getDatatypeXsInt() throws ValidationException { QName xsInt= new QName(DatatypeFactory.NS_XSD, "xs:int"); Datatype intDT = instance.getDatatype(xsInt); assertFalse("xs:int allows empty sequence", intDT.allowsEmpty()); assertFalse("xs:int allows multiple values", intDT.allowsMultiple()); XdmValue ret = intDT.convert("4", saxonConfiguration); assertTrue("value is not a XdmAtomicValue", ret instanceof XdmAtomicValue); XdmAtomicValue atomRet = (XdmAtomicValue)ret; Object javaValue = atomRet.getValue(); assertTrue("java value is not a BigInteger", javaValue instanceof BigInteger); }
@Test public void getDatatypeXsIntEmpty() throws ValidationException { QName xsInt= new QName(DatatypeFactory.NS_XSD, "xs:int?"); Datatype intDT = instance.getDatatype(xsInt); assertTrue("xs:int? does not allow empty sequence", intDT.allowsEmpty()); assertFalse("xs:int? allows multiple values", intDT.allowsMultiple()); XdmValue ret = intDT.convert("4", saxonConfiguration); assertTrue("value is not a XdmAtomicValue", ret instanceof XdmAtomicValue); ret = intDT.convert(null, saxonConfiguration); assertEquals("value is not an empty sequence", 0, ret.size()); }
@Test public void getDatatypeXsIntMultiple() throws ValidationException { QName xsInt= new QName(DatatypeFactory.NS_XSD, "xs:int+"); Datatype intDT = instance.getDatatype(xsInt); assertFalse("xs:int+ allows empty sequence", intDT.allowsEmpty()); assertTrue("xs:int+ doest not allow multiple values", intDT.allowsMultiple()); XdmValue ret = intDT.convert("4", saxonConfiguration); assertTrue("value is not a XdmAtomicValue", ret instanceof XdmAtomicValue); ret = intDT.convert("(4,5, 6 , 7 )", saxonConfiguration); assertEquals("value is not a sequence", 4, ret.size()); }
@Test(expected = ValidationException.class) public void getDatatypeDocumentMultiple() throws ValidationException { QName qn= new QName("document()*"); instance.getDatatype(qn); fail("document()* is not a valid datatype"); }
@Test public void getDatatypeDocumentEmpty() throws ValidationException { QName qn = new QName("document()?"); Datatype dt = instance.getDatatype(qn); assertTrue("Datatype for document()? does not allow empty", dt.allowsEmpty()); }
@Test public void getValueForSingleDatatypeWithMultipleValue() throws ValidationException { QName qn = new QName(DatatypeFactory.NS_XSD, "xs:string"); Datatype dt = instance.getDatatype(qn); assertFalse("xs:string allows multiple", dt.allowsMultiple()); String inputValue="1, 2, 3"; XdmValue value = dt.convert(inputValue, saxonConfiguration); assertEquals(inputValue+" do not produces a single value", 1, value.size()); assertEquals(inputValue, value.toString()); }