protected void convertFromJava(XMLOutputSerializer out, Object value) { this.out = out; ValueConverter.convertFromJava(value, this); this.out = null; }
protected void convertFromJava(XMLOutputSerializer out, Object value) { this.out = out; ValueConverter.convertFromJava(value, this); this.out = null; }
processor.process(null, null, null); else if (value instanceof BigDecimal) convertFromJava((BigDecimal) value, processor); else if (value instanceof BigInteger) convertFromJava((BigInteger) value, processor); else if (value instanceof Boolean) convertFromJava((Boolean) value, processor); else if (value instanceof Byte) convertFromJava((Byte) value, processor); else if (value instanceof byte[]) convertFromJava((byte[]) value, processor); else if (value instanceof Calendar) convertFromJava((Calendar) value, processor); else if (value instanceof Double) convertFromJava((Double) value, processor); else if (value instanceof Duration) convertFromJava((Duration) value, processor); else if (value instanceof Float) convertFromJava((Float) value, processor); else if (value instanceof Integer) convertFromJava((Integer) value, processor); else if (value instanceof Long) convertFromJava((Long) value, processor); else if (value instanceof Short) convertFromJava((Short) value, processor); else if (value instanceof String) convertFromJava((String) value, processor); else processor.process(
valueSerializer = new ValueSerializer(serializer); ValueConverter.convertFromJava(value, valueSerializer); } else { new DOMWriter(serializer).serializeNodeList((NodeList) value);
private void sendPropertiesImpl(final XMLStreamWriter serializer) throws XMLStreamException, TransformerFactoryConfigurationError, TransformerException { serializer.writeStartElement("prop", "properties", PROPERTY_API_NS); for (Map.Entry<QName, Object> property: getProperties().entrySet()) { QName propertyName = property.getKey(); Object value = property.getValue(); boolean hasNodeValue = value instanceof NodeList; String namespaceURI = propertyName.getNamespaceURI(); String prefix = null; String localPart = propertyName.getLocalPart(); if (namespaceURI != null && namespaceURI.length() > 0) { if (PROPERTY_API_NS.equals(namespaceURI)) continue; prefix = propertyName.getPrefix(); serializer.writeStartElement(prefix, localPart, namespaceURI); } else { serializer.writeStartElement(localPart); } if (!hasNodeValue) { if (valueSerializer == null) valueSerializer = new ValueSerializer(serializer); ValueConverter.convertFromJava(value, valueSerializer); } else { new DOMWriter(serializer).serializeNodeList((NodeList) value); } serializer.writeEndElement(); } serializer.writeEndElement(); } private void sendQualityImpl(XMLStreamWriter serializer) throws XMLStreamException {
valueSerializer = new ValueSerializer(serializer); ValueConverter.convertFromJava(value, valueSerializer); } else { new DOMWriter(serializer).serializeNodeList((NodeList) value);
private void sendPropertiesImpl(final XMLStreamWriter serializer) throws XMLStreamException, TransformerFactoryConfigurationError, TransformerException { if ( getProperties() == null || getProperties().size() == 0 ) return; serializer.writeStartElement("prop", "properties", PROPERTY_API_NS); for (Map.Entry<QName, Object> property: getProperties().entrySet()) { QName propertyName = property.getKey(); Object value = property.getValue(); boolean hasNodeValue = value instanceof NodeList; String namespaceURI = propertyName.getNamespaceURI(); String prefix = null; String localPart = propertyName.getLocalPart(); if (namespaceURI != null && namespaceURI.length() > 0) { if (PROPERTY_API_NS.equals(namespaceURI)) continue; prefix = propertyName.getPrefix(); serializer.writeStartElement(prefix, localPart, namespaceURI); } else { serializer.writeStartElement(localPart); } if (!hasNodeValue) { if (valueSerializer == null) valueSerializer = new ValueSerializer(serializer); ValueConverter.convertFromJava(value, valueSerializer); } else { new DOMWriter(serializer).serializeNodeList((NodeList) value); } serializer.writeEndElement(); } serializer.writeEndElement(); } private void sendQualityImpl(XMLStreamWriter serializer) throws XMLStreamException {
@Test public void testConvertFromJavaBigInteger() { BigInteger b = ValueConverter.MAX_UNSIGNED_LONG; ValueConverter.convertFromJava(b, processor); checkProcessor("unsigned long", "xs:unsignedLong", b); b = b.add(new BigInteger("1")); ValueConverter.convertFromJava(b, processor); checkProcessor("integer", "xs:integer", b); } @Test
@Test public void testConvertFromJavaLong() { long l = ValueConverter.MAX_UNSIGNED_INT; ValueConverter.convertFromJava(l, processor); checkProcessor("unsigned int", "xs:unsignedInt", l); l++; ValueConverter.convertFromJava(l, processor); checkProcessor("long", "xs:long", l); } @Test
@Test public void testConvertFromJavaObject() { Object o = new Object() { @Override public String toString() { return "object value"; } }; ValueConverter.convertFromJava(o, processor); checkProcessor("object", "xs:anySimpleType", o.toString()); } @Test
@Test public void testConvertFromJavaInteger() { int i = ValueConverter.MAX_UNSIGNED_SHORT; ValueConverter.convertFromJava(i, processor); checkProcessor("unsigned short", "xs:unsignedShort", i); i++; ValueConverter.convertFromJava(i, processor); checkProcessor("int", "xs:int", i); } @Test
@Test public void testConvertFromJavaBigDecimal() { BigDecimal b = new BigDecimal("10.02"); ValueConverter.convertFromJava(b, processor); checkProcessor("decimal", "xs:decimal", b); } @Test
@Test public void testConvertFromJavaBoolean() { boolean b = true; ValueConverter.convertFromJava(b, processor); checkProcessor("boolean", "xs:boolean", b); } @Test
@Test public void testConvertFromJavaString() { String s = "string value"; ValueConverter.convertFromJava(s, processor); checkProcessor("string", "xs:string", s); }
@Test public void testConvertFromJavaDuration() throws DatatypeConfigurationException { DatatypeFactory f = DatatypeFactory.newInstance(); Duration d = f.newDuration(true, 1, 2, 3, 4, 5, 6); ValueConverter.convertFromJava(d, processor); checkProcessor("duration", "xs:duration", d); d = f.newDurationYearMonth(true, 1, 2); ValueConverter.convertFromJava(d, processor); checkProcessor("year month duration", "xs:yearMonthDuration", d); d = f.newDurationDayTime(true, 3, 4, 5, 6); ValueConverter.convertFromJava(d, processor); checkProcessor("day time duration", "xs:dayTimeDuration", d); } @Test
@Test public void testConvertFromJavaByte() { byte b = 'a'; ValueConverter.convertFromJava(b, processor); checkProcessor("byte", "xs:byte", b); } @Test
@Test public void testConvertFromJavaDouble() { double d = 2.5d; ValueConverter.convertFromJava(d, processor); checkProcessor("double", "xs:double", d); } @Test
@Test public void testConvertFromJavaShort() { short s = 254; ValueConverter.convertFromJava(s, processor); checkProcessor("short", "xs:short", s); } @Test
@Test public void testConvertFromJavaFloat() { float f = 2.5f; ValueConverter.convertFromJava(f, processor); checkProcessor("float", "xs:float", f); } @Test
@Test public void testConvertFromJavaByteArray() { byte[] b = {'a', 'b', 'c'}; ValueConverter.convertFromJava(b, processor); assertEquals("byte array type", "xs:base64Binary", processor.type); byte[] c = (byte[]) ValueConverter.convertToJava( processor.type, processor.value ); boolean isSame = true; if (c == null || b.length != c.length) { isSame = false; } else { for (int i=0; i < c.length; i++) { if (b[i] != c[i]) isSame = false; } } assertTrue("byte array value", isSame); } @Test