You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2016/08/27 15:38:23 UTC
[4/8] incubator-juneau git commit: Tweak new name 'Transform' into
'BeanFilter' and 'PojoSwap'
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongTransform.java
deleted file mode 100644
index aadc314..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/DateLongTransform.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.transform.*;
-
-/**
- * Transforms {@link Date Dates} to {@link Long Longs}.
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-public class DateLongTransform extends PojoTransform<Date,Long> {
-
- /**
- * Converts the specified {@link Date} to a {@link Long}.
- */
- @Override /* PojoTransform */
- public Long transform(Date o) {
- return o.getTime();
- }
-
- /**
- * Converts the specified {@link Long} to a {@link Date}.
- */
- @Override /* PojoTransform */
- public Date normalize(Long o, ClassMeta<?> hint) throws ParseException {
- Class<?> c = (hint == null ? java.util.Date.class : hint.getInnerClass());
- if (c == java.util.Date.class)
- return new java.util.Date(o);
- if (c == java.sql.Date.class)
- return new java.sql.Date(o);
- if (c == java.sql.Time.class)
- return new java.sql.Time(o);
- if (c == java.sql.Timestamp.class)
- return new java.sql.Timestamp(o);
- throw new ParseException("DateLongTransform is unable to narrow object of type ''{0}''", c);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
new file mode 100644
index 0000000..4120547
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapSwap.java
@@ -0,0 +1,56 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.transforms;
+
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.transform.*;
+
+/**
+ * Transforms {@link Date Dates} to {@link Map Maps} of the format <tt>{value:long}</tt>.
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+@SuppressWarnings("rawtypes")
+public class DateMapSwap extends PojoSwap<Date,Map> {
+
+ /**
+ * Converts the specified {@link Date} to a {@link Map}.
+ */
+ @Override /* PojoSwap */
+ public Map swap(Date o) {
+ ObjectMap m = new ObjectMap();
+ m.put("time", o.getTime());
+ return m;
+ }
+
+ /**
+ * Converts the specified {@link Map} to a {@link Date}.
+ */
+ @Override /* PojoSwap */
+ public Date unswap(Map o, ClassMeta<?> hint) throws ParseException {
+ Class<?> c = (hint == null ? java.util.Date.class : hint.getInnerClass());
+ long l = Long.parseLong(((Map<?,?>)o).get("time").toString());
+ if (c == java.util.Date.class)
+ return new java.util.Date(l);
+ if (c == java.sql.Date.class)
+ return new java.sql.Date(l);
+ if (c == java.sql.Time.class)
+ return new java.sql.Time(l);
+ if (c == java.sql.Timestamp.class)
+ return new java.sql.Timestamp(l);
+ throw new ParseException("DateMapSwap is unable to narrow object of type ''{0}''", c);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapTransform.java
deleted file mode 100644
index 3e34b5e..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/DateMapTransform.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.transform.*;
-
-/**
- * Transforms {@link Date Dates} to {@link Map Maps} of the format <tt>{value:long}</tt>.
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-@SuppressWarnings("rawtypes")
-public class DateMapTransform extends PojoTransform<Date,Map> {
-
- /**
- * Converts the specified {@link Date} to a {@link Map}.
- */
- @Override /* PojoTransform */
- public Map transform(Date o) {
- ObjectMap m = new ObjectMap();
- m.put("time", o.getTime());
- return m;
- }
-
- /**
- * Converts the specified {@link Map} to a {@link Date}.
- */
- @Override /* PojoTransform */
- public Date normalize(Map o, ClassMeta<?> hint) throws ParseException {
- Class<?> c = (hint == null ? java.util.Date.class : hint.getInnerClass());
- long l = Long.parseLong(((Map<?,?>)o).get("time").toString());
- if (c == java.util.Date.class)
- return new java.util.Date(l);
- if (c == java.sql.Date.class)
- return new java.sql.Date(l);
- if (c == java.sql.Time.class)
- return new java.sql.Time(l);
- if (c == java.sql.Timestamp.class)
- return new java.sql.Timestamp(l);
- throw new ParseException("DateMapTransform is unable to narrow object of type ''{0}''", c);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
new file mode 100644
index 0000000..dd66c13
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/DateSwap.java
@@ -0,0 +1,370 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.transforms;
+
+import java.text.*;
+import java.util.*;
+
+import javax.xml.bind.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.ParseException;
+import org.apache.juneau.transform.*;
+
+/**
+ * Transforms {@link Date Dates} to {@link String Strings}.
+ *
+ *
+ * <h6 class='topic'>Behavior-specific subclasses</h6>
+ * <p>
+ * The following direct subclasses are provided for convenience:
+ * <ul class='spaced-list'>
+ * <li>{@link ToString} - Transforms to {@link String Strings} using the {@code Date.toString()} method.
+ * <li>{@link ISO8601DT} - Transforms to ISO8601 date-time strings.
+ * <li>{@link ISO8601DTP} - Transforms to ISO8601 date-time strings with millisecond precision.
+ * <li>{@link ISO8601DTZ} - Same as {@link ISO8601DT}, except always serializes in GMT.
+ * <li>{@link ISO8601DTZP} - Same as {@link ISO8601DTZ}, except with millisecond precision.
+ * <li>{@link RFC2822DT} - Transforms to RFC2822 date-time strings.
+ * <li>{@link RFC2822DTZ} - Same as {@link RFC2822DT}, except always serializes in GMT.
+ * <li>{@link RFC2822D} - Transforms to RFC2822 date strings.
+ * <li>{@link SimpleDT} - Transforms to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings.
+ * <li>{@link SimpleT} - Transforms to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings.
+ * <li>{@link Medium} - Transforms to {@link DateFormat#MEDIUM} strings.
+ * </ul>
+ *
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+public class DateSwap extends PojoSwap<Date,String> {
+
+ /**
+ * Transforms {@link Date Dates} to {@link String Strings} using the {@code Date.toString()} method.
+ * <p>
+ * <dl>
+ * <dt>Example output:</dt>
+ * <dd>
+ * <ul>
+ * <li><js>"Wed Jul 04 15:30:45 EST 2001"</js>
+ * </ul>
+ * </dd>
+ * </dl>
+ */
+ public static class ToString extends DateSwap {
+ /** Constructor */
+ public ToString() {
+ super("EEE MMM dd HH:mm:ss zzz yyyy");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to ISO8601 date-time strings.
+ *
+ * <dl>
+ * <dt>Example output:</dt>
+ * <dd>
+ * <ul>
+ * <li><js>"2001-07-04T15:30:45-05:00"</js>
+ * <li><js>"2001-07-04T15:30:45Z"</js>
+ * </ul>
+ * </dd>
+ * <dt>Example input:</dt>
+ * <dd>
+ * <ul>
+ * <li><js>"2001-07-04T15:30:45-05:00"</js>
+ * <li><js>"2001-07-04T15:30:45Z"</js>
+ * <li><js>"2001-07-04T15:30:45.1Z"</js>
+ * <li><js>"2001-07-04T15:30Z"</js>
+ * <li><js>"2001-07-04"</js>
+ * <li><js>"2001-07"</js>
+ * <li><js>"2001"</js>
+ * </ul>
+ * </dd>
+ * </dl>
+ */
+ public static class ISO8601DT extends DateSwap {
+ private SimpleDateFormat tzFormat = new SimpleDateFormat("Z");
+
+ /** Constructor */
+ public ISO8601DT() {
+ this("yyyy-MM-dd'T'HH:mm:ss");
+ }
+
+ /**
+ * Constructor with specific pattern.
+ *
+ * @param pattern The {@link MessageFormat}-style format string.
+ */
+ protected ISO8601DT(String pattern) {
+ super(pattern);
+ }
+
+ @Override /* PojoSwap */
+ public Date unswap(String o, ClassMeta<?> hint) throws ParseException {
+ try {
+ if (StringUtils.isEmpty(o))
+ return null;
+ return convert(DatatypeConverter.parseDateTime(o).getTime(), hint);
+ } catch (ParseException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ParseException(e);
+ }
+ }
+
+ @Override /* PojoSwap */
+ public String swap(Date o) {
+ String s = super.swap(o);
+ String tz = tzFormat.format(o);
+ if (tz.equals("+0000"))
+ return s + "Z";
+ return s + tz.substring(0,3) + ':' + tz.substring(3);
+ }
+ }
+
+ /**
+ * Same as {@link ISO8601DT} except serializes to millisecond precision.
+ * <p>
+ * Example output: <js>"2001-07-04T15:30:45.123-05:00"</js>
+ */
+ public static class ISO8601DTP extends ISO8601DT {
+
+ /** Constructor */
+ public ISO8601DTP() {
+ super("yyyy-MM-dd'T'HH:mm:ss.SSS");
+ }
+ }
+
+ /**
+ * Same as {@link ISO8601DT} except serializes to millisecond precision and doesn't include timezone.
+ * <p>
+ * Example output: <js>"2001-07-04T15:30:45.123"</js>
+ */
+ public static class ISO8601DTPNZ extends DateSwap {
+
+ /** Constructor */
+ public ISO8601DTPNZ() {
+ super("yyyy-MM-dd'T'HH:mm:ss.SSS");
+ }
+ }
+
+ /**
+ * Same as {@link ISO8601DT}, except always serializes in GMT.
+ * <p>
+ * Example output: <js>"2001-07-04T15:30:45Z"</js>
+ */
+ public static class ISO8601DTZ extends DateSwap {
+
+ /** Constructor */
+ public ISO8601DTZ() {
+ this("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ }
+
+ /**
+ * Constructor with specific pattern.
+ *
+ * @param pattern The {@link MessageFormat}-style format string.
+ */
+ protected ISO8601DTZ(String pattern) {
+ super(pattern, "GMT");
+ }
+
+ @Override /* PojoSwap */
+ public Date unswap(String o, ClassMeta<?> hint) throws ParseException {
+ try {
+ if (StringUtils.isEmpty(o))
+ return null;
+ return convert(DatatypeConverter.parseDateTime(o).getTime(), hint);
+ } catch (ParseException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ParseException(e);
+ }
+ }
+ }
+
+ /**
+ * Same as {@link ISO8601DTZ} except serializes to millisecond precision.
+ * <p>
+ * Example output: <js>"2001-07-04T15:30:45.123Z"</js>
+ */
+ public static class ISO8601DTZP extends ISO8601DT {
+
+ /** Constructor */
+ public ISO8601DTZP() {
+ super("yyyy-MM-dd'T'HH:mm:ss.SSS");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to RFC2822 date-time strings.
+ */
+ public static class RFC2822DT extends DateSwap {
+ /** Constructor */
+ public RFC2822DT() {
+ super("EEE, dd MMM yyyy HH:mm:ss z");
+ }
+ }
+
+ /**
+ * Same as {@link RFC2822DT}, except always serializes in GMT.
+ * <p>
+ * Example output: <js>"2001-07-04T15:30:45Z"</js>
+ */
+ public static class RFC2822DTZ extends DateSwap {
+ /** Constructor */
+ public RFC2822DTZ() {
+ super("EEE, dd MMM yyyy HH:mm:ss z", "GMT");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to RFC2822 date strings.
+ */
+ public static class RFC2822D extends DateSwap {
+ /** Constructor */
+ public RFC2822D() {
+ super("dd MMM yyyy");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings.
+ */
+ public static class SimpleDT extends DateSwap {
+ /** Constructor */
+ public SimpleDT() {
+ super("yyyy/MM/dd HH:mm:ss");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to simple <js>"yyyy/MM/dd HH:mm:ss.SSS"</js> strings.
+ */
+ public static class SimpleDTP extends DateSwap {
+ /** Constructor */
+ public SimpleDTP() {
+ super("yyyy/MM/dd HH:mm:ss.SSS");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to simple <js>"HH:mm:ss"</js> strings.
+ */
+ public static class SimpleT extends DateSwap {
+ /** Constructor */
+ public SimpleT() {
+ super("HH:mm:ss");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to simple <js>"HH:mm:ss.SSS"</js> strings.
+ */
+ public static class SimpleTP extends DateSwap {
+ /** Constructor */
+ public SimpleTP() {
+ super("HH:mm:ss.SSS");
+ }
+ }
+
+ /**
+ * Transforms {@link Date Dates} to {@link DateFormat#MEDIUM} strings.
+ */
+ public static class Medium extends DateSwap {
+ /** Constructor */
+ public Medium() {
+ super(DateFormat.getDateInstance(DateFormat.MEDIUM));
+ }
+ }
+
+ /** The formatter to convert dates to Strings. */
+ private DateFormat format;
+
+ /**
+ * Construct a transform using the specified date format string that will be
+ * used to construct a {@link SimpleDateFormat} that will be used to convert
+ * dates to strings.
+ *
+ * @param simpleDateFormat The {@link SimpleDateFormat} pattern.
+ */
+ public DateSwap(String simpleDateFormat) {
+ this(new SimpleDateFormat(simpleDateFormat));
+ }
+
+ /**
+ * Construct a transform using the specified date format string that will be
+ * used to construct a {@link SimpleDateFormat} that will be used to convert
+ * dates to strings.
+ *
+ * @param simpleDateFormat The {@link SimpleDateFormat} pattern.
+ * @param timeZone The time zone to associate with the date pattern.
+ */
+ public DateSwap(String simpleDateFormat, String timeZone) {
+ this(new SimpleDateFormat(simpleDateFormat));
+ format.setTimeZone(TimeZone.getTimeZone(timeZone));
+ }
+
+ /**
+ * Construct a transform using the specified {@link DateFormat} that will be used to convert
+ * dates to strings.
+ *
+ * @param format The format to use to convert dates to strings.
+ */
+ public DateSwap(DateFormat format) {
+ super();
+ this.format = format;
+ }
+
+ /**
+ * Converts the specified {@link Date} to a {@link String}.
+ */
+ @Override /* PojoSwap */
+ public String swap(Date o) {
+ return format.format(o);
+ }
+
+ /**
+ * Converts the specified {@link String} to a {@link Date}.
+ */
+ @Override /* PojoSwap */
+ public Date unswap(String o, ClassMeta<?> hint) throws ParseException {
+ try {
+ if (StringUtils.isEmpty(o))
+ return null;
+ Date d = format.parse(o);
+ return convert(d, hint);
+ } catch (ParseException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ParseException(e);
+ }
+ }
+
+ private static Date convert(Date in, ClassMeta<?> hint) throws Exception {
+ if (in == null)
+ return null;
+ if (hint == null || hint.isInstance(in))
+ return in;
+ Class<?> c = hint.getInnerClass();
+ if (c == java.util.Date.class)
+ return in;
+ if (c == java.sql.Date.class)
+ return new java.sql.Date(in.getTime());
+ if (c == java.sql.Time.class)
+ return new java.sql.Time(in.getTime());
+ if (c == java.sql.Timestamp.class)
+ return new java.sql.Timestamp(in.getTime());
+ throw new ParseException("DateSwap is unable to narrow object of type ''{0}''", c);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/DateTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/DateTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/DateTransform.java
deleted file mode 100644
index f38a52b..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/DateTransform.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import java.text.*;
-import java.util.*;
-
-import javax.xml.bind.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.parser.ParseException;
-import org.apache.juneau.transform.*;
-
-/**
- * Transforms {@link Date Dates} to {@link String Strings}.
- *
- *
- * <h6 class='topic'>Behavior-specific subclasses</h6>
- * <p>
- * The following direct subclasses are provided for convenience:
- * <ul class='spaced-list'>
- * <li>{@link ToString} - Transforms to {@link String Strings} using the {@code Date.toString()} method.
- * <li>{@link ISO8601DT} - Transforms to ISO8601 date-time strings.
- * <li>{@link ISO8601DTP} - Transforms to ISO8601 date-time strings with millisecond precision.
- * <li>{@link ISO8601DTZ} - Same as {@link ISO8601DT}, except always serializes in GMT.
- * <li>{@link ISO8601DTZP} - Same as {@link ISO8601DTZ}, except with millisecond precision.
- * <li>{@link RFC2822DT} - Transforms to RFC2822 date-time strings.
- * <li>{@link RFC2822DTZ} - Same as {@link RFC2822DT}, except always serializes in GMT.
- * <li>{@link RFC2822D} - Transforms to RFC2822 date strings.
- * <li>{@link SimpleDT} - Transforms to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings.
- * <li>{@link SimpleT} - Transforms to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings.
- * <li>{@link Medium} - Transforms to {@link DateFormat#MEDIUM} strings.
- * </ul>
- *
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-public class DateTransform extends PojoTransform<Date,String> {
-
- /**
- * Transforms {@link Date Dates} to {@link String Strings} using the {@code Date.toString()} method.
- * <p>
- * <dl>
- * <dt>Example output:</dt>
- * <dd>
- * <ul>
- * <li><js>"Wed Jul 04 15:30:45 EST 2001"</js>
- * </ul>
- * </dd>
- * </dl>
- */
- public static class ToString extends DateTransform {
- /** Constructor */
- public ToString() {
- super("EEE MMM dd HH:mm:ss zzz yyyy");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to ISO8601 date-time strings.
- *
- * <dl>
- * <dt>Example output:</dt>
- * <dd>
- * <ul>
- * <li><js>"2001-07-04T15:30:45-05:00"</js>
- * <li><js>"2001-07-04T15:30:45Z"</js>
- * </ul>
- * </dd>
- * <dt>Example input:</dt>
- * <dd>
- * <ul>
- * <li><js>"2001-07-04T15:30:45-05:00"</js>
- * <li><js>"2001-07-04T15:30:45Z"</js>
- * <li><js>"2001-07-04T15:30:45.1Z"</js>
- * <li><js>"2001-07-04T15:30Z"</js>
- * <li><js>"2001-07-04"</js>
- * <li><js>"2001-07"</js>
- * <li><js>"2001"</js>
- * </ul>
- * </dd>
- * </dl>
- */
- public static class ISO8601DT extends DateTransform {
- private SimpleDateFormat tzFormat = new SimpleDateFormat("Z");
-
- /** Constructor */
- public ISO8601DT() {
- this("yyyy-MM-dd'T'HH:mm:ss");
- }
-
- /**
- * Constructor with specific pattern.
- *
- * @param pattern The {@link MessageFormat}-style format string.
- */
- protected ISO8601DT(String pattern) {
- super(pattern);
- }
-
- @Override /* PojoTransform */
- public Date normalize(String o, ClassMeta<?> hint) throws ParseException {
- try {
- if (StringUtils.isEmpty(o))
- return null;
- return convert(DatatypeConverter.parseDateTime(o).getTime(), hint);
- } catch (ParseException e) {
- throw e;
- } catch (Exception e) {
- throw new ParseException(e);
- }
- }
-
- @Override /* PojoTransform */
- public String transform(Date o) {
- String s = super.transform(o);
- String tz = tzFormat.format(o);
- if (tz.equals("+0000"))
- return s + "Z";
- return s + tz.substring(0,3) + ':' + tz.substring(3);
- }
- }
-
- /**
- * Same as {@link ISO8601DT} except serializes to millisecond precision.
- * <p>
- * Example output: <js>"2001-07-04T15:30:45.123-05:00"</js>
- */
- public static class ISO8601DTP extends ISO8601DT {
-
- /** Constructor */
- public ISO8601DTP() {
- super("yyyy-MM-dd'T'HH:mm:ss.SSS");
- }
- }
-
- /**
- * Same as {@link ISO8601DT} except serializes to millisecond precision and doesn't include timezone.
- * <p>
- * Example output: <js>"2001-07-04T15:30:45.123"</js>
- */
- public static class ISO8601DTPNZ extends DateTransform {
-
- /** Constructor */
- public ISO8601DTPNZ() {
- super("yyyy-MM-dd'T'HH:mm:ss.SSS");
- }
- }
-
- /**
- * Same as {@link ISO8601DT}, except always serializes in GMT.
- * <p>
- * Example output: <js>"2001-07-04T15:30:45Z"</js>
- */
- public static class ISO8601DTZ extends DateTransform {
-
- /** Constructor */
- public ISO8601DTZ() {
- this("yyyy-MM-dd'T'HH:mm:ss'Z'");
- }
-
- /**
- * Constructor with specific pattern.
- *
- * @param pattern The {@link MessageFormat}-style format string.
- */
- protected ISO8601DTZ(String pattern) {
- super(pattern, "GMT");
- }
-
- @Override /* PojoTransform */
- public Date normalize(String o, ClassMeta<?> hint) throws ParseException {
- try {
- if (StringUtils.isEmpty(o))
- return null;
- return convert(DatatypeConverter.parseDateTime(o).getTime(), hint);
- } catch (ParseException e) {
- throw e;
- } catch (Exception e) {
- throw new ParseException(e);
- }
- }
- }
-
- /**
- * Same as {@link ISO8601DTZ} except serializes to millisecond precision.
- * <p>
- * Example output: <js>"2001-07-04T15:30:45.123Z"</js>
- */
- public static class ISO8601DTZP extends ISO8601DT {
-
- /** Constructor */
- public ISO8601DTZP() {
- super("yyyy-MM-dd'T'HH:mm:ss.SSS");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to RFC2822 date-time strings.
- */
- public static class RFC2822DT extends DateTransform {
- /** Constructor */
- public RFC2822DT() {
- super("EEE, dd MMM yyyy HH:mm:ss z");
- }
- }
-
- /**
- * Same as {@link RFC2822DT}, except always serializes in GMT.
- * <p>
- * Example output: <js>"2001-07-04T15:30:45Z"</js>
- */
- public static class RFC2822DTZ extends DateTransform {
- /** Constructor */
- public RFC2822DTZ() {
- super("EEE, dd MMM yyyy HH:mm:ss z", "GMT");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to RFC2822 date strings.
- */
- public static class RFC2822D extends DateTransform {
- /** Constructor */
- public RFC2822D() {
- super("dd MMM yyyy");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings.
- */
- public static class SimpleDT extends DateTransform {
- /** Constructor */
- public SimpleDT() {
- super("yyyy/MM/dd HH:mm:ss");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to simple <js>"yyyy/MM/dd HH:mm:ss.SSS"</js> strings.
- */
- public static class SimpleDTP extends DateTransform {
- /** Constructor */
- public SimpleDTP() {
- super("yyyy/MM/dd HH:mm:ss.SSS");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to simple <js>"HH:mm:ss"</js> strings.
- */
- public static class SimpleT extends DateTransform {
- /** Constructor */
- public SimpleT() {
- super("HH:mm:ss");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to simple <js>"HH:mm:ss.SSS"</js> strings.
- */
- public static class SimpleTP extends DateTransform {
- /** Constructor */
- public SimpleTP() {
- super("HH:mm:ss.SSS");
- }
- }
-
- /**
- * Transforms {@link Date Dates} to {@link DateFormat#MEDIUM} strings.
- */
- public static class Medium extends DateTransform {
- /** Constructor */
- public Medium() {
- super(DateFormat.getDateInstance(DateFormat.MEDIUM));
- }
- }
-
- /** The formatter to convert dates to Strings. */
- private DateFormat format;
-
- /**
- * Construct a transform using the specified date format string that will be
- * used to construct a {@link SimpleDateFormat} that will be used to convert
- * dates to strings.
- *
- * @param simpleDateFormat The {@link SimpleDateFormat} pattern.
- */
- public DateTransform(String simpleDateFormat) {
- this(new SimpleDateFormat(simpleDateFormat));
- }
-
- /**
- * Construct a transform using the specified date format string that will be
- * used to construct a {@link SimpleDateFormat} that will be used to convert
- * dates to strings.
- *
- * @param simpleDateFormat The {@link SimpleDateFormat} pattern.
- * @param timeZone The time zone to associate with the date pattern.
- */
- public DateTransform(String simpleDateFormat, String timeZone) {
- this(new SimpleDateFormat(simpleDateFormat));
- format.setTimeZone(TimeZone.getTimeZone(timeZone));
- }
-
- /**
- * Construct a transform using the specified {@link DateFormat} that will be used to convert
- * dates to strings.
- *
- * @param format The format to use to convert dates to strings.
- */
- public DateTransform(DateFormat format) {
- super();
- this.format = format;
- }
-
- /**
- * Converts the specified {@link Date} to a {@link String}.
- */
- @Override /* PojoTransform */
- public String transform(Date o) {
- return format.format(o);
- }
-
- /**
- * Converts the specified {@link String} to a {@link Date}.
- */
- @Override /* PojoTransform */
- public Date normalize(String o, ClassMeta<?> hint) throws ParseException {
- try {
- if (StringUtils.isEmpty(o))
- return null;
- Date d = format.parse(o);
- return convert(d, hint);
- } catch (ParseException e) {
- throw e;
- } catch (Exception e) {
- throw new ParseException(e);
- }
- }
-
- private static Date convert(Date in, ClassMeta<?> hint) throws Exception {
- if (in == null)
- return null;
- if (hint == null || hint.isInstance(in))
- return in;
- Class<?> c = hint.getInnerClass();
- if (c == java.util.Date.class)
- return in;
- if (c == java.sql.Date.class)
- return new java.sql.Date(in.getTime());
- if (c == java.sql.Time.class)
- return new java.sql.Time(in.getTime());
- if (c == java.sql.Timestamp.class)
- return new java.sql.Timestamp(in.getTime());
- throw new ParseException("DateTransform is unable to narrow object of type ''{0}''", c);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationSwap.java
new file mode 100644
index 0000000..d20fbaa
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationSwap.java
@@ -0,0 +1,39 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.transforms;
+
+import java.util.*;
+
+import org.apache.juneau.transform.*;
+
+/**
+ * Transforms {@link Enumeration Enumerations} to {@code List<Object>} objects.
+ * <p>
+ * This is a one-way transform, since {@code Enumerations} cannot be reconstituted.
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+@SuppressWarnings({"unchecked","rawtypes"})
+public class EnumerationSwap extends PojoSwap<Enumeration,List> {
+
+ /**
+ * Converts the specified {@link Enumeration} to a {@link List}.
+ */
+ @Override /* PojoSwap */
+ public List swap(Enumeration o) {
+ List l = new LinkedList();
+ while (o.hasMoreElements())
+ l.add(o.nextElement());
+ return l;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationTransform.java
deleted file mode 100644
index 6c3b124..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/EnumerationTransform.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import java.util.*;
-
-import org.apache.juneau.transform.*;
-
-/**
- * Transforms {@link Enumeration Enumerations} to {@code List<Object>} objects.
- * <p>
- * This is a one-way transform, since {@code Enumerations} cannot be reconstituted.
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-@SuppressWarnings({"unchecked","rawtypes"})
-public class EnumerationTransform extends PojoTransform<Enumeration,List> {
-
- /**
- * Converts the specified {@link Enumeration} to a {@link List}.
- */
- @Override /* PojoTransform */
- public List transform(Enumeration o) {
- List l = new LinkedList();
- while (o.hasMoreElements())
- l.add(o.nextElement());
- return l;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorSwap.java
new file mode 100644
index 0000000..0980577
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorSwap.java
@@ -0,0 +1,39 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.transforms;
+
+import java.util.*;
+
+import org.apache.juneau.transform.*;
+
+/**
+ * Transforms {@link Iterator Iterators} to {@code List<Object>} objects.
+ * <p>
+ * This is a one-way transform, since {@code Iterators} cannot be reconstituted.
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+@SuppressWarnings({"unchecked","rawtypes"})
+public class IteratorSwap extends PojoSwap<Iterator,List> {
+
+ /**
+ * Converts the specified {@link Iterator} to a {@link List}.
+ */
+ @Override /* PojoSwap */
+ public List swap(Iterator o) {
+ List l = new LinkedList();
+ while (o.hasNext())
+ l.add(o.next());
+ return l;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorTransform.java
deleted file mode 100644
index d5bfa77..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/IteratorTransform.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import java.util.*;
-
-import org.apache.juneau.transform.*;
-
-/**
- * Transforms {@link Iterator Iterators} to {@code List<Object>} objects.
- * <p>
- * This is a one-way transform, since {@code Iterators} cannot be reconstituted.
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-@SuppressWarnings({"unchecked","rawtypes"})
-public class IteratorTransform extends PojoTransform<Iterator,List> {
-
- /**
- * Converts the specified {@link Iterator} to a {@link List}.
- */
- @Override /* PojoTransform */
- public List transform(Iterator o) {
- List l = new LinkedList();
- while (o.hasNext())
- l.add(o.next());
- return l;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderSwap.java
new file mode 100644
index 0000000..f291521
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderSwap.java
@@ -0,0 +1,112 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.transforms;
+
+import java.io.*;
+
+import org.apache.juneau.html.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.transform.*;
+import org.apache.juneau.xml.*;
+
+/**
+ * Transforms the contents of a {@link Reader} into an {@code Object}.
+ *
+ *
+ * <h6 class='topic'>Description</h6>
+ * <p>
+ * The {@code Reader} must contain JSON, Juneau-generated XML (output from {@link XmlSerializer}),
+ * or Juneau-generated HTML (output from {@link JsonSerializer}) in order to be parsed correctly.
+ * <p>
+ * Useful for serializing models that contain {@code Readers} created by {@code RestCall} instances.
+ * <p>
+ * This is a one-way transform, since {@code Readers} cannot be reconstituted.
+ *
+ *
+ * <h6 class='topic'>Behavior-specific subclasses</h6>
+ * <p>
+ * The following direct subclasses are provided for convenience:
+ * <ul class='spaced-list'>
+ * <li>{@link Json} - Parses JSON text.
+ * <li>{@link Xml} - Parses XML text.
+ * <li>{@link Html} - Parses HTML text.
+ * <li>{@link PlainText} - Parses plain text.
+ * </ul>
+ *
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+public class ReaderSwap extends PojoSwap<Reader,Object> {
+
+ /** Reader transform for reading JSON text. */
+ public static class Json extends ReaderSwap {
+ /** Constructor */
+ public Json() {
+ super(JsonParser.DEFAULT);
+ }
+ }
+
+ /** Reader transform for reading XML text. */
+ public static class Xml extends ReaderSwap {
+ /** Constructor */
+ public Xml() {
+ super(XmlParser.DEFAULT);
+ }
+ }
+
+ /** Reader transform for reading HTML text. */
+ public static class Html extends ReaderSwap {
+ /** Constructor */
+ public Html() {
+ super(HtmlParser.DEFAULT);
+ }
+ }
+
+ /** Reader transform for reading plain text. */
+ public static class PlainText extends ReaderSwap {
+ /** Constructor */
+ public PlainText() {
+ super(null);
+ }
+ }
+
+ /** The parser to use to parse the contents of the Reader. */
+ private ReaderParser parser;
+
+ /**
+ * @param parser The parser to use to convert the contents of the reader to Java objects.
+ */
+ public ReaderSwap(ReaderParser parser) {
+ this.parser = parser;
+ }
+
+ /**
+ * Converts the specified {@link Reader} to an {@link Object} whose type is determined
+ * by the contents of the reader.
+ */
+ @Override /* PojoSwap */
+ public Object swap(Reader o) throws SerializeException {
+ try {
+ if (parser == null)
+ return IOUtils.read(o);
+ return parser.parse(o, beanContext.object());
+ } catch (IOException e) {
+ return e.getLocalizedMessage();
+ } catch (Exception e) {
+ throw new SerializeException("ReaderSwap could not transform object of type ''{0}''", o == null ? null : o.getClass().getName()).initCause(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderTransform.java
deleted file mode 100644
index 77fb532..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/ReaderTransform.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import java.io.*;
-
-import org.apache.juneau.html.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.json.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.transform.*;
-import org.apache.juneau.xml.*;
-
-/**
- * Transforms the contents of a {@link Reader} into an {@code Object}.
- *
- *
- * <h6 class='topic'>Description</h6>
- * <p>
- * The {@code Reader} must contain JSON, Juneau-generated XML (output from {@link XmlSerializer}),
- * or Juneau-generated HTML (output from {@link JsonSerializer}) in order to be parsed correctly.
- * <p>
- * Useful for serializing models that contain {@code Readers} created by {@code RestCall} instances.
- * <p>
- * This is a one-way transform, since {@code Readers} cannot be reconstituted.
- *
- *
- * <h6 class='topic'>Behavior-specific subclasses</h6>
- * <p>
- * The following direct subclasses are provided for convenience:
- * <ul class='spaced-list'>
- * <li>{@link Json} - Parses JSON text.
- * <li>{@link Xml} - Parses XML text.
- * <li>{@link Html} - Parses HTML text.
- * <li>{@link PlainText} - Parses plain text.
- * </ul>
- *
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-public class ReaderTransform extends PojoTransform<Reader,Object> {
-
- /** Reader transform for reading JSON text. */
- public static class Json extends ReaderTransform {
- /** Constructor */
- public Json() {
- super(JsonParser.DEFAULT);
- }
- }
-
- /** Reader transform for reading XML text. */
- public static class Xml extends ReaderTransform {
- /** Constructor */
- public Xml() {
- super(XmlParser.DEFAULT);
- }
- }
-
- /** Reader transform for reading HTML text. */
- public static class Html extends ReaderTransform {
- /** Constructor */
- public Html() {
- super(HtmlParser.DEFAULT);
- }
- }
-
- /** Reader transform for reading plain text. */
- public static class PlainText extends ReaderTransform {
- /** Constructor */
- public PlainText() {
- super(null);
- }
- }
-
- /** The parser to use to parse the contents of the Reader. */
- private ReaderParser parser;
-
- /**
- * @param parser The parser to use to convert the contents of the reader to Java objects.
- */
- public ReaderTransform(ReaderParser parser) {
- this.parser = parser;
- }
-
- /**
- * Converts the specified {@link Reader} to an {@link Object} whose type is determined
- * by the contents of the reader.
- */
- @Override /* PojoTransform */
- public Object transform(Reader o) throws SerializeException {
- try {
- if (parser == null)
- return IOUtils.read(o);
- return parser.parse(o, beanContext.object());
- } catch (IOException e) {
- return e.getLocalizedMessage();
- } catch (Exception e) {
- throw new SerializeException("ReaderTransform could not transform object of type ''{0}''", o == null ? null : o.getClass().getName()).initCause(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarSwap.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarSwap.java b/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarSwap.java
new file mode 100644
index 0000000..c0d369c
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarSwap.java
@@ -0,0 +1,64 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.transforms;
+
+import javax.xml.datatype.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.transform.*;
+
+/**
+ * Transforms {@link XMLGregorianCalendar XMLGregorianCalendars} to ISO8601 date-time {@link String Strings}.
+ * <p>
+ * Objects are converted to strings using {@link XMLGregorianCalendar#toXMLFormat()}.
+ * <p>
+ * Strings are converted to objects using {@link DatatypeFactory#newXMLGregorianCalendar(String)}.
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+public class XMLGregorianCalendarSwap extends PojoSwap<XMLGregorianCalendar,String> {
+
+ private DatatypeFactory dtf;
+
+ /**
+ * Constructor.
+ */
+ public XMLGregorianCalendarSwap() {
+ try {
+ this.dtf = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Converts the specified <code>XMLGregorianCalendar</code> to a {@link String}.
+ */
+ @Override /* PojoSwap */
+ public String swap(XMLGregorianCalendar b) throws SerializeException {
+ return b.toXMLFormat();
+ }
+
+ /**
+ * Converts the specified {@link String} to an <code>XMLGregorianCalendar</code>.
+ */
+ @Override /* PojoSwap */
+ public XMLGregorianCalendar unswap(String s, ClassMeta<?> hint) throws ParseException {
+ if (StringUtils.isEmpty(s))
+ return null;
+ return dtf.newXMLGregorianCalendar(s);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarTransform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarTransform.java b/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarTransform.java
deleted file mode 100644
index ac56984..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/transforms/XMLGregorianCalendarTransform.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/***************************************************************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- ***************************************************************************************************************************/
-package org.apache.juneau.transforms;
-
-import javax.xml.datatype.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.transform.*;
-
-/**
- * Transforms {@link XMLGregorianCalendar XMLGregorianCalendars} to ISO8601 date-time {@link String Strings}.
- * <p>
- * Objects are converted to strings using {@link XMLGregorianCalendar#toXMLFormat()}.
- * <p>
- * Strings are converted to objects using {@link DatatypeFactory#newXMLGregorianCalendar(String)}.
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-public class XMLGregorianCalendarTransform extends PojoTransform<XMLGregorianCalendar,String> {
-
- private DatatypeFactory dtf;
-
- /**
- * Constructor.
- */
- public XMLGregorianCalendarTransform() {
- try {
- this.dtf = DatatypeFactory.newInstance();
- } catch (DatatypeConfigurationException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Converts the specified <code>XMLGregorianCalendar</code> to a {@link String}.
- */
- @Override /* PojoTransform */
- public String transform(XMLGregorianCalendar b) throws SerializeException {
- return b.toXMLFormat();
- }
-
- /**
- * Converts the specified {@link String} to an <code>XMLGregorianCalendar</code>.
- */
- @Override /* PojoTransform */
- public XMLGregorianCalendar normalize(String s, ClassMeta<?> hint) throws ParseException {
- if (StringUtils.isEmpty(s))
- return null;
- return dtf.newXMLGregorianCalendar(s);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java
index daeddf3..05a4311 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java
@@ -93,7 +93,7 @@ public class UonParser extends ReaderParser {
BeanContext bc = session.getBeanContext();
if (nt == null)
nt = (ClassMeta<T>)object();
- PojoTransform<T,Object> transform = (PojoTransform<T,Object>)nt.getPojoTransform();
+ PojoSwap<T,Object> transform = (PojoSwap<T,Object>)nt.getPojoSwap();
ClassMeta<?> ft = nt.getTransformedClassMeta();
Object o = null;
@@ -202,7 +202,7 @@ public class UonParser extends ReaderParser {
}
if (transform != null && o != null)
- o = transform.normalize(o, nt);
+ o = transform.unswap(o, nt);
if (outer != null)
setParent(nt, o, outer);
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java
index 4c11909..db3c13c 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java
@@ -274,9 +274,9 @@ public class UonSerializer extends WriterSerializer {
addClassAttr = (session.isAddClassAttrs() && ! eType.equals(aType));
// Transform if necessary
- PojoTransform transform = aType.getPojoTransform(); // The transform
+ PojoSwap transform = aType.getPojoSwap(); // The transform
if (transform != null) {
- o = transform.transform(o);
+ o = transform.swap(o);
// If the transform's getTransformedClass() method returns Object, we need to figure out
// the actual type now.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
index d759965..9e081c3 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
@@ -74,7 +74,7 @@ public class UrlEncodingParser extends UonParser {
BeanContext bc = session.getBeanContext();
if (nt == null)
nt = (ClassMeta<T>)object();
- PojoTransform<T,Object> transform = (PojoTransform<T,Object>)nt.getPojoTransform();
+ PojoSwap<T,Object> transform = (PojoSwap<T,Object>)nt.getPojoSwap();
ClassMeta<?> ft = nt.getTransformedClassMeta();
int c = r.peek();
@@ -126,7 +126,7 @@ public class UrlEncodingParser extends UonParser {
}
if (transform != null && o != null)
- o = transform.normalize(o, nt);
+ o = transform.unswap(o, nt);
if (outer != null)
setParent(nt, o, outer);
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java
index fd04afb..9b7541d 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializer.java
@@ -241,9 +241,9 @@ public class UrlEncodingSerializer extends UonSerializer {
addClassAttr = (session.isAddClassAttrs());
// Transform if necessary
- PojoTransform transform = aType.getPojoTransform(); // The transform
+ PojoSwap transform = aType.getPojoSwap(); // The transform
if (transform != null) {
- o = transform.transform(o);
+ o = transform.swap(o);
// If the transform's getTransformedClass() method returns Object, we need to figure out
// the actual type now.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html b/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html
index 932c418..f67d1ed 100644
--- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html
+++ b/juneau-core/src/main/java/org/apache/juneau/urlencoding/package.html
@@ -110,7 +110,7 @@
<li>Multi-dimensional arrays of any type on this list.
<li>Java Beans with properties of any type on this list.
<li>Classes with standard transformations to and from <code>Strings</code> (e.g. classes containing <code>toString()</code>, <code>fromString()</code>, <code>valueOf()</code>, <code>constructor(String)</code>).
- <li>Non-serializable classes and properties with associated <code>PojoTransforms</code> that convert them to serializable forms.
+ <li>Non-serializable classes and properties with associated <code>PojoSwaps</code> that convert them to serializable forms.
</ul>
<p>
Refer to <a href='../package-summary.html#PojoCategories' class='doclink'>POJO Categories</a> for a complete definition of supported POJOs.
@@ -215,7 +215,7 @@
<li>On classes through the <code><ja>@Bean</ja></code> annotation.
<li>On bean properties through the <code><ja>@BeanProperty</ja></code> annotations.
</ul>
- <h6 class='figure'>Example: A serialized Calendar object using <code>CalendarTransform.RFC2822DTZ</code> transform.</h6>
+ <h6 class='figure'>Example: A serialized Calendar object using <code>CalendarSwap.RFC2822DTZ</code> transform.</h6>
<p class='bcode'> http://localhost/sample?<xa>a1=<js>Sun~,+03+Mar+1901+09:05:06+GMT</js></p>
<p>
For more information about transforms, refer to {@link org.apache.juneau.transform}.
@@ -368,7 +368,7 @@
<jk>public</jk> URI <jf>uri</jf>;
<jk>public</jk> URI <jf>addressBookUri</jf>;
- <ja>@BeanProperty</ja>(transform=CalendarTransform.ISO8601DTZ.<jk>class</jk>) <jk>public</jk> Calendar <jf>birthDate</jf>;
+ <ja>@BeanProperty</ja>(transform=CalendarSwap.ISO8601DTZ.<jk>class</jk>) <jk>public</jk> Calendar <jf>birthDate</jf>;
<jc>// Bean constructor (needed by parser)</jc>
@@ -860,7 +860,7 @@
URI uri = m.get(URI.<jk>class</jk>, <js>"uri"</js>);
<jc>// Get a value using a transform.</jc>
- CalendarTransform transform = <jk>new</jk> CalendarTransform.ISO8601DTZ();
+ CalendarSwap transform = <jk>new</jk> CalendarSwap.ISO8601DTZ();
Calendar birthDate = m.get(transform, <js>"birthDate"</js>);
<jc>// Get the addresses.</jc>
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java
index cebfb1a..f4b27af 100644
--- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java
+++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlParser.java
@@ -67,7 +67,7 @@ public class XmlParser extends ReaderParser {
BeanContext bc = session.getBeanContext();
if (nt == null)
nt = (ClassMeta<T>)object();
- PojoTransform<T,Object> transform = (PojoTransform<T,Object>)nt.getPojoTransform();
+ PojoSwap<T,Object> transform = (PojoSwap<T,Object>)nt.getPojoSwap();
ClassMeta<?> ft = nt.getTransformedClassMeta();
session.setCurrentClass(ft);
@@ -171,7 +171,7 @@ public class XmlParser extends ReaderParser {
}
if (transform != null && o != null)
- o = transform.normalize(o, nt);
+ o = transform.unswap(o, nt);
if (outer != null)
setParent(nt, o, outer);
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java
index ee75f5a..2d9c285 100644
--- a/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java
+++ b/juneau-core/src/main/java/org/apache/juneau/xml/XmlSerializer.java
@@ -327,9 +327,9 @@ public class XmlSerializer extends WriterSerializer {
gType = aType.getTransformedClassMeta();
// Transform if necessary
- PojoTransform transform = aType.getPojoTransform();
+ PojoSwap transform = aType.getPojoSwap();
if (transform != null) {
- o = transform.transform(o);
+ o = transform.swap(o);
// If the transform's getTransformedClass() method returns Object, we need to figure out
// the actual type now.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0ce0e663/juneau-core/src/main/java/org/apache/juneau/xml/package.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/xml/package.html b/juneau-core/src/main/java/org/apache/juneau/xml/package.html
index bb0534f..9c7a2a3 100644
--- a/juneau-core/src/main/java/org/apache/juneau/xml/package.html
+++ b/juneau-core/src/main/java/org/apache/juneau/xml/package.html
@@ -852,7 +852,7 @@
<jk>public class</jk> Person {
<jc>// Bean properties</jc>
- <ja>@BeanProperty</ja>(transform=CalendarTransform.ISO8601DTZ.<jk>class</jk>) <jk>public</jk> Calendar birthDate;
+ <ja>@BeanProperty</ja>(transform=CalendarSwap.ISO8601DTZ.<jk>class</jk>) <jk>public</jk> Calendar birthDate;
...
<jc>// Normal constructor</jc>
@@ -1031,7 +1031,7 @@
<jk>public</jk> String <jf>name</jf>;
<ja>@BeanProperty</ja>(beanUri=<jk>true</jk>) <jk>public</jk> URI <jf>uri</jf>;
<jk>public</jk> URI <jf>addressBookUri</jf>;
- <ja>@BeanProperty</ja>(transform=CalendarTransform.ISO8601DTZ.<jk>class</jk>) <jk>public</jk> Calendar <jf>birthDate</jf>;
+ <ja>@BeanProperty</ja>(transform=CalendarSwap.ISO8601DTZ.<jk>class</jk>) <jk>public</jk> Calendar <jf>birthDate</jf>;
<jk>public</jk> LinkedList<Address> <jf>addresses</jf> = <jk>new</jk> LinkedList<Address>();
<jc>// Bean constructor (needed by parser)</jc>
@@ -1711,7 +1711,7 @@
URI uri = m.get(URI.<jk>class</jk>, <js>"uri"</js>);
<jc>// Get a value using a transform.</jc>
- CalendarTransform transform = <jk>new</jk> CalendarTransform.ISO8601DTZ();
+ CalendarSwap transform = <jk>new</jk> CalendarSwap.ISO8601DTZ();
Calendar birthDate = m.get(transform, <js>"birthDate"</js>);
<jc>// Get the addresses.</jc>