Java Code Examples for javax.xml.datatype.DatatypeConfigurationException#printStackTrace()

The following examples show how to use javax.xml.datatype.DatatypeConfigurationException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiteralsTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectXMLGregorianCalendar() throws Exception {

	GregorianCalendar c = new GregorianCalendar();
	c.setTime(new Date());
	try {
		Object obj = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
		Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
		assertNotNull(l);
		assertEquals(l.getDatatype(), XMLSchema.DATETIME);
		// TODO check lexical value?
	} catch (DatatypeConfigurationException e) {
		e.printStackTrace();
		fail("Could not instantiate javax.xml.datatype.DatatypeFactory");
	}

}
 
Example 2
Source File: Client.java    From cxf with Apache License 2.0 6 votes vote down vote up
private NestedComplexType createComplexType() {
    NestedComplexType complexType = new NestedComplexType();
    complexType.setVarString("#12345ABc");
    complexType.setVarUByte((short)255);
    complexType.setVarUnsignedLong(new BigInteger("13691056728"));
    complexType.setVarFloat(Float.MAX_VALUE);
    complexType.setVarQName(new QName("http://cxf.apache.org", "return"));
    try {
        complexType.setVarStruct(getSimpleStruct());
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    complexType.setVarEnum(ColourEnum.RED);
    byte[] binary = new byte[256];
    for (int jdx = 0; jdx < 256; jdx++) {
        binary[jdx] = (byte)(jdx - 128);
    }
    complexType.setVarHexBinary(binary);
    complexType.setVarBase64Binary(binary);
    return complexType;
}
 
Example 3
Source File: DEXService.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
private XMLGregorianCalendar toXMLCal(Calendar cal) {
	if (cal == null) {
		return null;
	}

	DatatypeFactory dtf = null;
	try {
		dtf = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		e.printStackTrace();
		return null;
	}

	GregorianCalendar gc = new GregorianCalendar();
	gc.setTimeInMillis(cal.getTimeInMillis());
	return dtf.newXMLGregorianCalendar(gc);
}
 
Example 4
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDurationMultiply() {
    int num = 5000; // millisends. 5 seconds
    int factor = 2;
    try {
        Duration dur = DatatypeFactory.newInstance().newDuration(num);
        if (dur.multiply(factor).getSeconds() != 10) {
            Assert.fail("duration.multiply() return wrong value");
        }
        // factor is 2*10^(-1)
        if (dur.multiply(new BigDecimal(new BigInteger("2"), 1)).getSeconds() != 1) {
            Assert.fail("duration.multiply() return wrong value");
        }
        if (dur.subtract(DatatypeFactory.newInstance().newDuration(1000)).multiply(new BigDecimal(new BigInteger("2"), 1)).getSeconds() != 0) {
            Assert.fail("duration.multiply() return wrong value");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDurationSubtract() {
    try {
        Duration bigDur = DatatypeFactory.newInstance().newDuration(20000);
        Duration smallDur = DatatypeFactory.newInstance().newDuration(10000);
        if (smallDur.subtract(bigDur).getSign() != -1) {
            Assert.fail("smallDur.subtract(bigDur).getSign() is not -1");
        }
        if (bigDur.subtract(smallDur).getSign() != 1) {
            Assert.fail("bigDur.subtract(smallDur).getSign() is not 1");
        }
        if (smallDur.subtract(smallDur).getSign() != 0) {
            Assert.fail("smallDur.subtract(smallDur).getSign() is not 0");
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: Client.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void initTestData() {
    NestedComplexType complexType = new NestedComplexType();
    complexType.setVarString("#12345ABc");
    complexType.setVarUByte(Short.MAX_VALUE);
    complexType.setVarUnsignedLong(new BigInteger("13691056728"));
    complexType.setVarFloat(Float.MAX_VALUE);
    complexType.setVarQName(new QName("return", "return"));
    try {
        complexType.setVarStruct(getSimpleStruct());
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    complexType.setVarEnum(ColourEnum.RED);
    byte[] binary = new byte[1024];
    for (int idx = 0; idx < 4; idx++) {
        for (int jdx = 0; jdx < 256; jdx++) {
            binary[idx * 256 + jdx] = (byte)(jdx - 128);
        }
    }
    complexType.setVarBase64Binary(binary);
    complexType.setVarHexBinary(binary);

    for (int i = 0; i < packetSize; i++) {
        complexTypeSeq.getItem().add(complexType);
    }
}
 
Example 7
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void newDurationDayTimeTester(boolean isPositive, boolean normalizedIsPositive, BigInteger years, BigInteger normalizedYears, BigInteger months,
        BigInteger normalizedMonths, BigInteger days, BigInteger normalizedDays, BigInteger hours, BigInteger normalizedHours, BigInteger minutes,
        BigInteger normalizedMinutes, BigDecimal seconds, BigDecimal normalizedSeconds, long durationInMilliSeconds, long normalizedDurationInMilliSeconds,
        String lexicalRepresentation, String normalizedLexicalRepresentation) {

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    // create 4 dayTime Durations using the 4 different constructors

    Duration durationDayTimeBigInteger = datatypeFactory.newDurationDayTime(isPositive, days, hours, minutes, seconds.toBigInteger());
    durationAssertEquals(durationDayTimeBigInteger, DatatypeConstants.DURATION_DAYTIME, normalizedIsPositive, normalizedYears.intValue(),
            normalizedMonths.intValue(), normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    /*
     * Duration durationDayTimeInt = datatypeFactory.newDurationDayTime(
     * isPositive, days.intValue(), hours.intValue(), minutes.intValue(),
     * seconds.intValue()); Duration durationDayTimeMilliseconds =
     * datatypeFactory.newDurationDayTime( durationInMilliSeconds); Duration
     * durationDayTimeLexical = datatypeFactory.newDurationDayTime(
     * lexicalRepresentation);
     * Duration durationYearMonthBigInteger =
     * datatypeFactory.newDurationYearMonth( isPositive, years, months);
     * Duration durationYearMonthInt = datatypeFactory.newDurationYearMonth(
     * isPositive, years.intValue(), months.intValue()); Duration
     * durationYearMonthMilliseconds = datatypeFactory.newDurationYearMonth(
     * durationInMilliSeconds); Duration durationYearMonthLexical =
     * datatypeFactory.newDurationYearMonth( lexicalRepresentation) ;
     */

}
 
Example 8
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void newDurationTester(boolean isPositive, boolean normalizedIsPositive, BigInteger years, BigInteger normalizedYears, BigInteger months,
        BigInteger normalizedMonths, BigInteger days, BigInteger normalizedDays, BigInteger hours, BigInteger normalizedHours, BigInteger minutes,
        BigInteger normalizedMinutes, BigDecimal seconds, BigDecimal normalizedSeconds, long durationInMilliSeconds, long normalizedDurationInMilliSeconds,
        String lexicalRepresentation, String normalizedLexicalRepresentation) {

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    // create 4 Durations using the 4 different constructors

    Duration durationBigInteger = datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
    durationAssertEquals(durationBigInteger, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    Duration durationInt = datatypeFactory.newDuration(isPositive, years.intValue(), months.intValue(), days.intValue(), hours.intValue(),
            minutes.intValue(), seconds.intValue());
    durationAssertEquals(durationInt, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    Duration durationMilliseconds = datatypeFactory.newDuration(durationInMilliSeconds);
    durationAssertEquals(durationMilliseconds, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    Duration durationLexical = datatypeFactory.newDuration(lexicalRepresentation);
    durationAssertEquals(durationLexical, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);
}
 
Example 9
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEqualsWithEqualObjectParam() {
    try {
        AssertJUnit.assertTrue("equals method is expected to return true", duration.equals(DatatypeFactory.newInstance().newDuration(100)));
    } catch (DatatypeConfigurationException dce) {
        dce.printStackTrace();
        Assert.fail("Failed to create instance of DatatypeFactory " + dce.getMessage());
    }
}
 
Example 10
Source File: XmlCalendar2Date.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Date toDate(String str){

		try {
			return toDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(str));
		} catch (DatatypeConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
 
Example 11
Source File: XmlCalendar2Date.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static XMLGregorianCalendar toXmlGregorianCalendar(String str){

		try {
			return DatatypeFactory.newInstance().newXMLGregorianCalendar(str);
		} catch (DatatypeConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
 
Example 12
Source File: XmlCalendar2Date.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Date toDate(String str){

		try {
			return toDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(str));
		} catch (DatatypeConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
 
Example 13
Source File: XmlCalendar2Date.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static XMLGregorianCalendar toXmlGregorianCalendar(String str){

		try {
			return DatatypeFactory.newInstance().newXMLGregorianCalendar(str);
		} catch (DatatypeConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
 
Example 14
Source File: DtoFactoryAbstract.java    From estatio with Apache License 2.0 5 votes vote down vote up
/**
 * For convenience of subclasses.
 */
protected static XMLGregorianCalendar asXMLGregorianCalendar(final LocalDate date) {
    if (date == null) {
        return null;
    }
    try {
        return DatatypeFactory
                .newInstance().newXMLGregorianCalendar(date.getYear(),date.getMonthOfYear(), date.getDayOfMonth(), 0,0,0,0,0);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();

    }
    return null;
    //return JodaLocalDateXMLGregorianCalendarAdapter.print(date);
}
 
Example 15
Source File: ConfigUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar getDefaultVersion() {

        Calendar cal = Calendar.getInstance();
        cal.set(1980, 1, 1, 0, 0, 0);
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(cal.getTime());
        try {
            XMLGregorianCalendar gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
            return gc;
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
            return null;
        }
    }
 
Example 16
Source File: ConfigUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar getDefaultVersion() {

        Calendar cal = Calendar.getInstance();
        cal.set(1980, 1, 1, 0, 0, 0);
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(cal.getTime());
        try {
            XMLGregorianCalendar gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
            return gc;
        } catch (DatatypeConfigurationException e) {
            e.printStackTrace();
            return null;
        }
    }
 
Example 17
Source File: ConfigUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static XMLGregorianCalendar getDefaultVersion() {
   Calendar cal = Calendar.getInstance();
   cal.set(1980, 1, 1, 0, 0, 0);
   GregorianCalendar c = new GregorianCalendar();
   c.setTime(cal.getTime());

   try {
      XMLGregorianCalendar gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
      return gc;
   } catch (DatatypeConfigurationException var3) {
      var3.printStackTrace();
      return null;
   }
}
 
Example 18
Source File: DurationComparison.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Verify cases around the INDETERMINATE relations
 */
public void testVerifyOtherRelations() {

    final String [][] partialOrder = { // partialOrder
       {"P1Y", ">", "P364D"},
       {"P1Y", "<", "P367D"},
       {"P1Y2D", ">", "P366D"},
       {"P1M", ">", "P27D"},
       {"P1M", "<", "P32D"},
       {"P1M", "<", "P31DT1H"},
       {"P5M", ">", "P149D"},
       {"P5M", "<", "P154D"},
       {"P5M", "<", "P153DT1H"},
       {"PT2419199S", "<", "P1M"},  //PT2419200S -> P28D
       {"PT2678401S", ">", "P1M"},  //PT2678400S -> P31D
       {"PT31535999S", "<", "P1Y"}, //PT31536000S -> P365D
       {"PT31622401S", ">", "P1Y"}, //PT31622400S -> P366D
       {"PT525599M59S", "<", "P1Y"},  //PT525600M -> P365D
       {"PT527040M1S", ">", "P1Y"},  //PT527040M -> P366D
       {"PT8759H59M59S", "<", "P1Y"},    //PT8760H -> P365D
       {"PT8784H1S", ">", "P1Y"},    //PT8784H -> P366D
    };

    DatatypeFactory df = null;
    try {
        df = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        fail(ex.toString());
    }

    for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
        Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
        Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
        int cmp = duration1.compare(duration2);
        int expected = ">".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.GREATER
                 : "<".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.LESSER
                 : "==".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.EQUAL
                 : DatatypeConstants.INDETERMINATE;

        if (expected != cmp) {
            fail("returned " + cmp2str(cmp)
                + " for durations \'" + duration1 + "\' and "
                + duration2 + "\', but expected " + cmp2str(expected));
        } else {
            success("Comparing " + duration1 + " and " + duration2 +
                    ": expected: " + cmp2str(expected) +
                    " actual: " + cmp2str(cmp));
        }
    }
}
 
Example 19
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Inspired by CR 5077522 Duration.compare makes mistakes for some values.
 */
@Test
public void testCompareWithInderterminateRelation() {

    final String[][] partialOrder = { // partialOrder
    { "P1Y", "<>", "P365D" }, { "P1Y", "<>", "P366D" }, { "P1M", "<>", "P28D" }, { "P1M", "<>", "P29D" }, { "P1M", "<>", "P30D" }, { "P1M", "<>", "P31D" },
            { "P5M", "<>", "P150D" }, { "P5M", "<>", "P151D" }, { "P5M", "<>", "P152D" }, { "P5M", "<>", "P153D" }, { "PT2419200S", "<>", "P1M" },
            { "PT2678400S", "<>", "P1M" }, { "PT31536000S", "<>", "P1Y" }, { "PT31622400S", "<>", "P1Y" }, { "PT525600M", "<>", "P1Y" },
            { "PT527040M", "<>", "P1Y" }, { "PT8760H", "<>", "P1Y" }, { "PT8784H", "<>", "P1Y" }, { "P365D", "<>", "P1Y" }, };

    DatatypeFactory df = null;
    try {
        df = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    boolean compareErrors = false;

    for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
        Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
        Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
        int cmp = duration1.compare(duration2);
        int expected = ">".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.GREATER
                : "<".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.LESSER : "==".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.EQUAL
                        : DatatypeConstants.INDETERMINATE;

        // just note any errors, do not fail until all cases have been
        // tested
        if (expected != cmp) {
            compareErrors = true;
            System.err.println("returned " + cmp2str(cmp) + " for durations \'" + duration1 + "\' and " + duration2 + "\', but expected "
                    + cmp2str(expected));
        }
    }

    if (compareErrors) {
        // TODO; fix bug, these tests should pass
        if (false) {
            Assert.fail("Errors in comparing indeterminate relations, see Stderr");
        } else {
            System.err.println("Please fix this bug: " + "Errors in comparing indeterminate relations, see Stderr");
        }
    }
}
 
Example 20
Source File: IfcXmlDeserializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void parseHeader(XMLStreamReader reader) throws XMLStreamException {
	/*
	 * 
	 * <name>Lise-Meitner-Str.1, 10589 Berlin</name>
   <time_stamp>2015-10-05T10:20:47.3587387+02:00</time_stamp>
   <author>Lellonek</author>
   <organization>eTASK Service-Management GmbH</organization>
   <preprocessor_version>.NET API etask.ifc</preprocessor_version>
   <originating_system>.NET API etask.ifc</originating_system>
   <authorization>file created with .NET API etask.ifc</authorization>
   <documentation>ViewDefinition [notYetAssigned]</documentation>
	 */
	
	IfcHeader ifcHeader = model.getModelMetaData().getIfcHeader();
	if (ifcHeader == null) {
		ifcHeader = StoreFactory.eINSTANCE.createIfcHeader();
		model.getModelMetaData().setIfcHeader(ifcHeader);
	}

	while (reader.hasNext()) {
		reader.next();
		if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
			String localname = reader.getLocalName();
			if (localname.equalsIgnoreCase("name")) {
				reader.next();
				ifcHeader.setFilename(reader.getText());
			} else if (localname.equals("time_stamp")) {
				reader.next();
				try {
					ifcHeader.setTimeStamp(DatatypeFactory
					  .newInstance()
					  .newXMLGregorianCalendar(reader.getText()).toGregorianCalendar().getTime());
				} catch (DatatypeConfigurationException e1) {
					e1.printStackTrace();
				}
			} else if (localname.equals("author")) {
				reader.next();
				ifcHeader.getAuthor().add(reader.getText());
			} else if (localname.equals("organization")) {
				reader.next();
				ifcHeader.getOrganization().add(reader.getText());
			} else if (localname.equals("preprocessor_version")) {
				reader.next();
				ifcHeader.setPreProcessorVersion(reader.getText());
			} else if (localname.equals("originating_system")) {
				reader.next();
				ifcHeader.setOriginatingSystem(reader.getText());
			} else if (localname.equals("authorization")) {
				reader.next();
				ifcHeader.setAuthorization(reader.getText());
			} else if (localname.equals("documentation")) {
			}
		} else if (reader.getEventType() == XMLStreamReader.END_ELEMENT) {
			if (reader.getLocalName().equals("header")) {
				return;
			}
		}
	}
}