You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2005/09/06 22:26:25 UTC
svn commit: r279090 - in /webservices/jaxme/branches/b0_5:
src/jaxme/org/apache/ws/jaxme/generator/types/DateTimeSG.java
src/jaxme/org/apache/ws/jaxme/impl/JMControllerImpl.java
src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java status.xml
Author: jochen
Date: Tue Sep 6 13:26:11 2005
New Revision: 279090
URL: http://svn.apache.org/viewcvs?rev=279090&view=rev
Log:
Fixed use of the JAXME_FORMAT_* attributes.
Submitted by: David Gilliland, dgilliland62 at users.sourceforge.net
Modified:
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/types/DateTimeSG.java
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/impl/JMControllerImpl.java
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java
webservices/jaxme/branches/b0_5/status.xml
Modified: webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/types/DateTimeSG.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/types/DateTimeSG.java?rev=279090&r1=279089&r2=279090&view=diff
==============================================================================
--- webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/types/DateTimeSG.java (original)
+++ webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/types/DateTimeSG.java Tue Sep 6 13:26:11 2005
@@ -118,15 +118,21 @@
}
}
- public void forAllNonNullValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException {
- LocalJavaField f = pMethod.newJavaField(CALENDAR_TYPE);
- f.addLine(pValue);
- pMethod.addIf(f, " != null");
- pSGlet.generate(pMethod, pValue);
- pMethod.addEndIf();
- }
+ public TypedValue getCastToString(SimpleTypeSG pController, Object pValue, DirectAccessible pData) {
+ Object v = new Object[]{pData, ".getJMMarshaller().get" + getDatatypeName()
+ + "Format().format(", pValue, ")"};
+ return new TypedValueImpl(v, StringSG.STRING_TYPE);
+ }
- public void forAllValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException {
- pSGlet.generate(pMethod, pValue);
- }
+ public void forAllNonNullValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException {
+ LocalJavaField f = pMethod.newJavaField(CALENDAR_TYPE);
+ f.addLine(pValue);
+ pMethod.addIf(f, " != null");
+ pSGlet.generate(pMethod, pValue);
+ pMethod.addEndIf();
+ }
+
+ public void forAllValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException {
+ pSGlet.generate(pMethod, pValue);
+ }
}
Modified: webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/impl/JMControllerImpl.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/impl/JMControllerImpl.java?rev=279090&r1=279089&r2=279090&view=diff
==============================================================================
--- webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/impl/JMControllerImpl.java (original)
+++ webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/impl/JMControllerImpl.java Tue Sep 6 13:26:11 2005
@@ -91,10 +91,13 @@
return;
} else if (JAXME_FORMAT_DATETIME.equals(pProperty)) {
setDateTimeFormat((Format) pValue);
+ return;
} else if (JAXME_FORMAT_DATE.equals(pProperty)) {
setDateFormat((Format) pValue);
+ return;
} else if (JAXME_FORMAT_TIME.equals(pProperty)) {
setTimeFormat((Format) pValue);
+ return;
}
throw new PropertyException("Unknown property: " + pProperty);
Modified: webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java?rev=279090&r1=279089&r2=279090&view=diff
==============================================================================
--- webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java (original)
+++ webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/MarshallerTest.java Tue Sep 6 13:26:11 2005
@@ -22,15 +22,21 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DateFormat;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
@@ -43,6 +49,7 @@
import org.apache.ws.jaxme.XMLWriter;
import org.apache.ws.jaxme.impl.DatatypeConverterImpl;
import org.apache.ws.jaxme.impl.JAXBContextImpl;
+import org.apache.ws.jaxme.impl.JMControllerImpl;
import org.apache.ws.jaxme.impl.JMMarshallerImpl;
import org.apache.ws.jaxme.test.misc.address.Address;
import org.apache.ws.jaxme.test.misc.address.AddressType;
@@ -56,6 +63,9 @@
import org.apache.ws.jaxme.test.misc.types.impl.AllSimpleTypesImpl;
import org.apache.ws.jaxme.test.misc.types.impl.AllTypesElementImpl;
import org.apache.ws.jaxme.util.Duration;
+import org.apache.ws.jaxme.xs.util.XsDateFormat;
+import org.apache.ws.jaxme.xs.util.XsDateTimeFormat;
+import org.apache.ws.jaxme.xs.util.XsTimeFormat;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -434,7 +444,7 @@
assertEquals(60, duration2.getSeconds());
}
- protected String getAllElementString(boolean pRandom) {
+ protected String getAllElementString(boolean pRandom, Format pDateTimeFormat, Format pDateFormat, Format pTimeFormat) {
AllElementImpl elem = new AllElementImpl();
String uri = elem.getQName().getNamespaceURI();
String[] elements = new String[]{
@@ -444,9 +454,9 @@
"<ex:ShortElem>23878</ex:ShortElem>",
"<ex:DoubleElem>2.397978293792324E13</ex:DoubleElem>",
"<ex:FloatElem>-34768.348</ex:FloatElem>",
- "<ex:DateTimeElem>2002-11-22T16:43:37Z</ex:DateTimeElem>",
- "<ex:DateElem>2002-11-22Z</ex:DateElem>",
- "<ex:TimeElem>16:43:37Z</ex:TimeElem>",
+ "<ex:DateTimeElem>" + pDateTimeFormat.format(getDateTime()) + "</ex:DateTimeElem>",
+ "<ex:DateElem>" + pDateFormat.format(getDate()) + "</ex:DateElem>",
+ "<ex:TimeElem>" + pTimeFormat.format(getTime()) + "</ex:TimeElem>",
"<ex:DurationElem>P1Y2M3DT4H5M6.7S</ex:DurationElem>",
"<ex:HexBinaryElem>0111234E739DBBFF</ex:HexBinaryElem>",
"<ex:Base64BinaryElem>AREjTnOdu/8=</ex:Base64BinaryElem>",
@@ -484,19 +494,70 @@
* contents.</p>
*/
public void testAllElement() throws Exception {
- String s = getAllElementString(true);
- JAXBContext context = getFactory();
- AllElement e = (AllElement) context.createUnmarshaller().unmarshal(new InputSource(new StringReader(s)));
- StringWriter sw = new StringWriter();
- Marshaller marshaller = context.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "ASCII");
- marshaller.setProperty(JMMarshallerImpl.JAXME_XML_DECLARATION, Boolean.FALSE);
- marshaller.marshal(e, sw);
- String got = sw.toString();
- String expect = getAllElementString(false);
- assertEquals(expect, got);
- }
+ final Format defaultDateTimeFormat = new XsDateTimeFormat();
+ final Format defaultDateFormat = new XsDateFormat();
+ final Format defaultTimeFormat = new XsTimeFormat();
+ testAllElement(defaultDateTimeFormat, defaultDateFormat, defaultTimeFormat);
+
+ final Format otherDateTimeFormat = new Format(){
+ private static final long serialVersionUID = -6173879133371739286L;
+ private final DateFormat df = new SimpleDateFormat("yyyy.MMM.dd 'at' HH:mm:ss.SSS z");
+ public StringBuffer format(Object pObj, StringBuffer pAppendTo, FieldPosition pPos) {
+ return df.format(((Calendar) pObj).getTime(), pAppendTo, pPos);
+ }
+ public Object parseObject(String pSource, ParsePosition pPos) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) df.parseObject(pSource, pPos));
+ return cal;
+ }
+ };
+ final Format otherDateFormat = new Format(){
+ private final DateFormat df = new SimpleDateFormat("yyyy.MMM.dd z");
+ public StringBuffer format(Object pObj, StringBuffer pAppendTo, FieldPosition pPos) {
+ return df.format(((Calendar) pObj).getTime(), pAppendTo, pPos);
+ }
+ public Object parseObject(String pSource, ParsePosition pPos) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) df.parseObject(pSource, pPos));
+ return cal;
+ }
+ };
+ final Format otherTimeFormat = new Format(){
+ private static final long serialVersionUID = -6173879133371739286L;
+ private final DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS z");
+ public StringBuffer format(Object pObj, StringBuffer pAppendTo, FieldPosition pPos) {
+ return df.format(((Calendar) pObj).getTime(), pAppendTo, pPos);
+ }
+ public Object parseObject(String pSource, ParsePosition pPos) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) df.parseObject(pSource, pPos));
+ return cal;
+ }
+ };
+ testAllElement(otherDateTimeFormat, otherDateFormat, otherTimeFormat);
+ }
+
+ private void testAllElement(final Format pDateTimeFormat, final Format pDateFormat, final Format pTimeFormat) throws JAXBException, PropertyException {
+ String s = getAllElementString(true, pDateTimeFormat, pDateFormat, pTimeFormat);
+ JAXBContext context = getFactory();
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ unmarshaller.setProperty(JMControllerImpl.JAXME_FORMAT_DATETIME, pDateTimeFormat);
+ unmarshaller.setProperty(JMControllerImpl.JAXME_FORMAT_DATE, pDateFormat);
+ unmarshaller.setProperty(JMControllerImpl.JAXME_FORMAT_TIME, pTimeFormat);
+ AllElement e = (AllElement) unmarshaller.unmarshal(new InputSource(new StringReader(s)));
+ StringWriter sw = new StringWriter();
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "ASCII");
+ marshaller.setProperty(JMMarshallerImpl.JAXME_XML_DECLARATION, Boolean.FALSE);
+ marshaller.setProperty(JMControllerImpl.JAXME_FORMAT_DATETIME, pDateTimeFormat);
+ marshaller.setProperty(JMControllerImpl.JAXME_FORMAT_DATE, pDateFormat);
+ marshaller.setProperty(JMControllerImpl.JAXME_FORMAT_TIME, pTimeFormat);
+ marshaller.marshal(e, sw);
+ String got = sw.toString();
+ String expect = getAllElementString(false, pDateTimeFormat, pDateFormat, pTimeFormat);
+ assertEquals(expect, got);
+}
private RootElementHandler getRootElementInfo(String pElement) throws ParserConfigurationException, IOException, SAXException {
RootElementHandler reh = new RootElementHandler();
Modified: webservices/jaxme/branches/b0_5/status.xml
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/status.xml?rev=279090&r1=279089&r2=279090&view=diff
==============================================================================
--- webservices/jaxme/branches/b0_5/status.xml (original)
+++ webservices/jaxme/branches/b0_5/status.xml Tue Sep 6 13:26:11 2005
@@ -45,6 +45,14 @@
build scripts. (JAXME-67, Boris Gruschke,
<boris at gruschke.de>)
</action>
+ <action dev="JW" type="fix" context="runtime">
+ It wasn't possible to set the properties JAXME_FORMAT_*.
+ David Gilliland <dgilliland62 at users.sourceforge.net>
+ </action>
+ <action dev="JW" type="fix" context="generator">
+ The generated marshallers didn't honor the JAXME_FORMAT_*.
+ properties.
+ </action>
</release>
<release version="0.5" date="2005-Aug-08">
<action dev="JW" type="enhancement" context="js">
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org