This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes XSD TYPE dateTime - returns XMLGregorian calendar- how to convert into java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "XSD TYPE dateTime - returns XMLGregorian calendar- how to convert into java.util.Date" Watch "XSD TYPE dateTime - returns XMLGregorian calendar- how to convert into java.util.Date" New topic
Author

XSD TYPE dateTime - returns XMLGregorian calendar- how to convert into java.util.Date

prince davies
Ranch Hand

Joined: May 08, 2009
Posts: 74

XSD GENERATED METHOD RETURNS XMLGREGORIAN CALENDAR,I want to convert that into java.util.Date?

How do I do that?

Thanks,
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Do you want to retrieve an instance of Date from an instance of XMLGregorianCalendar?
If so, then this may help you:

Best wishes!
Pradeepta Bhattacharya
Greenhorn

Joined: Mar 02, 2007
Posts: 4
Please use bindings to convert your datatype at the time of code generation. You can pass the binding file as a binding parameter during code generation time. A Sample file is pasted below for your reference.

<?xml version="1.0" encoding="UTF-8" ?>
<jaxb:bindings
version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:time"
parseMethod="javax.xml.bind.DatatypeConverter.parseTime"
printMethod="javax.xml.bind.DatatypeConverter.printTime"/>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:date"
parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate"/>
<jaxb:serializable uid="1"/>
</jaxb:globalBindings>
</jaxb:bindings>

Pradeepta Bhattacharya,
thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
I am getting runtime error

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl

I am planning to insert date into database.I use XSD to get parameters from FRONT END UI to my webservice method.
I set all parameters using XSD.

In my XSD,I have the following code
<xs:element name="creationDate" type="xs:dateTime" minOccurs="0"/>

And in my DAO,I have the following code to insert into database.

Date carDate = new java.util.Date();
if(creditAssessmentRequest.getCreationDate()!=null) {
carDate = creditAssessmentRequest.getCreationDate().toGregorianCalendar().getTime();
}
When I unzip my war,I could find xercesImpl-2.7.1.jar.When I search for XMLGregorianCalendarImpl.This class is in xercesImpl-2.7.1.jar.It has exactly same package as it is in the error like org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl.Why it is not finding it in Runtime?
but I have the following error ,When insert data into database.
####<21-Mar-2010 10:56:03 o'clock PM PDT> <Error> <HTTP> <D008678> <AdminServer> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1269237363273> <BEA-101017> <[ServletContext@13951824[app:telus-crd-assessment-webservices-9 module:telus-crd-assessment-webservices-9.1.war path:/telus-crd-assessment-webservices-9.1 spec-version:2.5], request: weblogic.servlet.internal.ServletRequestImpl@108da58[
POST /telus-crd-assessment-webservices-9.1/CreditAssessmentService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "createCreditAssessmentRequest"
User-Agent: Jakarta Commons-HttpClient/3.1
Content-Length: 2423

]] Root cause of ServletException.
java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl
at org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.parse(RuntimeBuiltinLeafInfoImpl.java:546)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.parse(RuntimeBuiltinLeafInfoImpl.java:520)
at com.sun.xml.bind.v2.runtime.FilterTransducer.parse(FilterTransducer.java:80)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:241)
at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:61)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:468)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.processText(StAXStreamConnector.java:367)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleEndElement(StAXStreamConnector.java:245)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:214)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:358)
at com.sun.xml.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:120)
at com.sun.xml.bind.api.Bridge.unmarshal(Bridge.java:233)
at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(EndpointArgumentsBuilder.java:517)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:250)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:604)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:563)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:548)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:445)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:275)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:250)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:140)
at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:319)
at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:232)
at weblogic.wsee.jaxws.JAXWSServlet.doPost(JAXWSServlet.java:310)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at weblogic.wsee.jaxws.JAXWSServlet.service(JAXWSServlet.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3594)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

] Root cause of ServletException.
java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl
at org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.parse(RuntimeBuiltinLeafInfoImpl.java:546)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.parse(RuntimeBuiltinLeafInfoImpl.java:520)
at com.sun.xml.bind.v2.runtime.FilterTransducer.parse(FilterTransducer.java:80)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:241)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:296)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:269)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
Truncated. see log file for complete stacktrace

If I want to insert system timestamp,how do I do that?
If I want to insert just Date,how do I do that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSD TYPE dateTime - returns XMLGregorian calendar- how to convert into java.util.Date
 
Similar Threads
GregorianCalendar to string and back to Date
xsd datetime format
add 10 days to currentDate in java.util.Date or cast to Calendar?
Date to Calendar object
java.util.Date to java.sql.Date