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/26 20:14:31 UTC

[3/3] incubator-juneau git commit: Rename @Transform to @Pojo(transform=x)

Rename @Transform to @Pojo(transform=x)

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/7100939a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/7100939a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/7100939a

Branch: refs/heads/master
Commit: 7100939a47bb6df15fb7aebcbd5f53f0e18e3b5e
Parents: c039a53
Author: jamesbognar <ja...@gmail.com>
Authored: Fri Aug 26 16:14:21 2016 -0400
Committer: jamesbognar <ja...@gmail.com>
Committed: Fri Aug 26 16:14:21 2016 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/juneau/ClassMeta.java  |  6 +-
 .../java/org/apache/juneau/annotation/Pojo.java | 88 ++++++++++++++++++++
 .../org/apache/juneau/annotation/Transform.java | 86 -------------------
 juneau-core/src/main/java/overview.html         |  3 +-
 .../a/rttests/RoundTripTransformBeansTest.java  |  4 +-
 .../java/org/apache/juneau/html/HtmlTest.java   |  6 +-
 6 files changed, 98 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7100939a/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java b/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java
index ae2bce5..f49b7ad 100644
--- a/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/src/main/java/org/apache/juneau/ClassMeta.java
@@ -26,7 +26,7 @@ import org.apache.juneau.annotation.*;
 import org.apache.juneau.internal.*;
 import org.apache.juneau.transform.*;
 import org.apache.juneau.transform.Transform;
-import org.apache.juneau.utils.*; 
+import org.apache.juneau.utils.*;
 
 /**
  * A wrapper class around the {@link Class} object that provides cached information
@@ -431,9 +431,9 @@ public final class ClassMeta<T> implements Type {
 
 	private Transform findTransform(BeanContext context) {
 		try {
-			org.apache.juneau.annotation.Transform b = innerClass.getAnnotation(org.apache.juneau.annotation.Transform.class);
+			org.apache.juneau.annotation.Pojo b = innerClass.getAnnotation(org.apache.juneau.annotation.Pojo.class);
 			if (b != null) {
-				Class<? extends Transform> c = b.value();
+				Class<? extends Transform> c = b.transform();
 				if (c != Transform.NULL.class) {
 					Transform f = c.newInstance();
 					f.setBeanContext(context);

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7100939a/juneau-core/src/main/java/org/apache/juneau/annotation/Pojo.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/annotation/Pojo.java b/juneau-core/src/main/java/org/apache/juneau/annotation/Pojo.java
new file mode 100644
index 0000000..d4919ee
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/annotation/Pojo.java
@@ -0,0 +1,88 @@
+/***************************************************************************************************************************
+ * 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.annotation;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.*;
+
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.transform.*;
+
+/**
+ * Used to tailor how POJOs get interpreted by the framework.
+ * <p>
+ * 	Annotation that can be applied to POJOs to associate transforms with them.
+ * <p>
+ * 	Typically used to associate {@link PojoTransform PojoTransforms} with classes using annotations
+ * 		instead of programatically through a method such as {@link Serializer#addTransforms(Class...)}.
+ *
+ * <h6 class='topic'>Example</h6>
+ * <p>
+ * 	In this case, a transform is being applied to a bean that will force it to be serialized as a <code>String</code>
+ * <p class='bcode'>
+ * 	<jc>// Our bean class</jc>
+ * 	<ja>@Pojo</ja>(transform=BTransform.<jk>class</jk>)
+ * 	<jk>public class</jk> B {
+ * 		<jk>public</jk> String <jf>f1</jf>;
+ * 	}
+ *
+ * 	<jc>// Our transform to force the bean to be serialized as a String</jc>
+ * 	<jk>public class</jk> BTransform <jk>extends</jk> PojoTransform&lt;B,String&gt; {
+ * 		<jk>public</jk> String transform(B o) <jk>throws</jk> SerializeException {
+ * 			<jk>return</jk> o.f1;
+ * 		}
+ * 		<jk>public</jk> B normalize(String f, ClassMeta&lt;?&gt; hint) <jk>throws</jk> ParseException {
+ * 			B b1 = <jk>new</jk> B();
+ * 			b1.<jf>f1</jf> = f;
+ * 			<jk>return</jk> b1;
+ * 		}
+ * 	}
+ *
+ * 	<jk>public void</jk> testTransform() <jk>throws</jk> Exception {
+ * 		WriterSerializer s = JsonSerializer.<jsf>DEFAULT</jsf>;
+ * 		B b = <jk>new</jk> B();
+ * 		b.<jf>f1</jf> = <js>"bar"</js>;
+ * 		String json = s.serialize(b);
+ * 		<jsm>assertEquals</jsm>(<js>"'bar'"</js>, json);
+ *
+ * 		ReaderParser p = JsonParser.<jsf>DEFAULT</jsf>;
+ * 		b = p.parse(json, B.<jk>class</jk>);
+ * 		<jsm>assertEquals</jsm>(<js>"bar"</js>, t.<jf>f1</jf>);
+ * 	}
+ * </p>
+ * <p>
+ * 	Note that using this annotation is functionally equivalent to adding transforms to the serializers and parsers:
+ * <p class='bcode'>
+ * 	WriterSerializer s = <jk>new</jk> JsonSerializer.addTransforms(BTransform.<jk>class</jk>);
+ * 	ReaderParser p = <jk>new</jk> JsonParser.addTransforms(BTransform.<jk>class</jk>);
+ * </p>
+ * <p>
+ * 	It is technically possible to associate a {@link BeanTransform} with a bean class using this annotation.
+ * 	However in practice, it's almost always less code to simply use the {@link Bean @Bean} annotation.
+ * </p>
+ *
+ * @author James Bognar (james.bognar@salesforce.com)
+ */
+@Documented
+@Target(TYPE)
+@Retention(RUNTIME)
+@Inherited
+public @interface Pojo {
+
+	/**
+	 * The transform class.
+	 */
+	Class<? extends Transform> transform() default Transform.NULL.class;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7100939a/juneau-core/src/main/java/org/apache/juneau/annotation/Transform.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/annotation/Transform.java b/juneau-core/src/main/java/org/apache/juneau/annotation/Transform.java
deleted file mode 100644
index f0029a6..0000000
--- a/juneau-core/src/main/java/org/apache/juneau/annotation/Transform.java
+++ /dev/null
@@ -1,86 +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.annotation;
-
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.*;
-
-import java.lang.annotation.*;
-
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.transform.*;
-
-/**
- * Annotation that can be applied to a class to associate a transform with it.
- * <p>
- * 	Typically used to associate {@link PojoTransform PojoTransforms} with classes using annotations
- * 		instead of programatically through a method such as {@link Serializer#addTransforms(Class...)}.
- *
- * <h6 class='topic'>Example</h6>
- * <p>
- * 	In this case, a transform is being applied to a bean that will force it to be serialized as a <code>String</code>
- * <p class='bcode'>
- * 	<jc>// Our bean class</jc>
- * 	<ja>@Transform</ja>(BTransform.<jk>class</jk>)
- * 	<jk>public class</jk> B {
- * 		<jk>public</jk> String <jf>f1</jf>;
- * 	}
- *
- * 	<jc>// Our transform to force the bean to be serialized as a String</jc>
- * 	<jk>public class</jk> BTransform <jk>extends</jk> PojoTransform&lt;B,String&gt; {
- * 		<jk>public</jk> String transform(B o) <jk>throws</jk> SerializeException {
- * 			<jk>return</jk> o.f1;
- * 		}
- * 		<jk>public</jk> B normalize(String f, ClassMeta&lt;?&gt; hint) <jk>throws</jk> ParseException {
- * 			B b1 = <jk>new</jk> B();
- * 			b1.<jf>f1</jf> = f;
- * 			<jk>return</jk> b1;
- * 		}
- * 	}
- *
- * 	<jk>public void</jk> testTransform() <jk>throws</jk> Exception {
- * 		WriterSerializer s = JsonSerializer.<jsf>DEFAULT</jsf>;
- * 		B b = <jk>new</jk> B();
- * 		b.<jf>f1</jf> = <js>"bar"</js>;
- * 		String json = s.serialize(b);
- * 		<jsm>assertEquals</jsm>(<js>"'bar'"</js>, json);
- *
- * 		ReaderParser p = JsonParser.<jsf>DEFAULT</jsf>;
- * 		b = p.parse(json, B.<jk>class</jk>);
- * 		<jsm>assertEquals</jsm>(<js>"bar"</js>, t.<jf>f1</jf>);
- * 	}
- * </p>
- * <p>
- * 	Note that using this annotation is functionally equivalent to adding transforms to the serializers and parsers:
- * <p class='bcode'>
- * 	WriterSerializer s = <jk>new</jk> JsonSerializer.addTransforms(BTransform.<jk>class</jk>);
- * 	ReaderParser p = <jk>new</jk> JsonParser.addTransforms(BTransform.<jk>class</jk>);
- * </p>
- * <p>
- * 	It is technically possible to associate a {@link BeanTransform} with a bean class using this annotation.
- * 	However in practice, it's almost always less code to simply use the {@link Bean @Bean} annotation.
- * </p>
- *
- * @author James Bognar (james.bognar@salesforce.com)
- */
-@Documented
-@Target(TYPE)
-@Retention(RUNTIME)
-@Inherited
-public @interface Transform {
-
-	/**
-	 * The transform class.
-	 */
-	Class<? extends org.apache.juneau.transform.Transform> value() default org.apache.juneau.transform.Transform.NULL.class;
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7100939a/juneau-core/src/main/java/overview.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/overview.html b/juneau-core/src/main/java/overview.html
index 4acf5c5..8d0c17f 100644
--- a/juneau-core/src/main/java/overview.html
+++ b/juneau-core/src/main/java/overview.html
@@ -4704,7 +4704,7 @@
 		<p>
 			The major change is rebranding from "Juno" to "Juneau" in preparation for donation to the Apache Foundation.
 		</p>
-		
+
 		<h6 class='topic'>org.apache.juneau</h6>
 		<ul class='spaced-list'>
 			<li>Major changes around how serializer and parser class properties are defined to improve performance
@@ -4778,6 +4778,7 @@
 					<li>{@link org.apache.juneau.BeanPropertyMetaExtended} / {@link org.apache.juneau.BeanPropertyMetaMeta#getExtendedMeta(Class)} 
 				</ul>
 			</li>
+			<li>Renamed <code>@Transform</code> annotation to {@link Pojo @Pojo} so that it can be used for various POJO-related behavior, not just associating transforms.  
 		</ul>		
 
 		<h6 class='topic'>org.apache.juneau.server</h6>

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7100939a/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java b/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
index 7f9d1c9..8433862 100755
--- a/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
+++ b/juneau-core/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
@@ -21,7 +21,7 @@ import javax.xml.datatype.*;
 
 import org.apache.juneau.*;
 import org.apache.juneau.annotation.*;
-import org.apache.juneau.annotation.Transform;
+import org.apache.juneau.annotation.Pojo;
 import org.apache.juneau.json.*;
 import org.apache.juneau.parser.*;
 import org.apache.juneau.serializer.*;
@@ -228,7 +228,7 @@ public class RoundTripTransformBeansTest extends RoundTripTest {
 		assertEquals("bar", t.f1);
 	}
 
-	@Transform(BTransform.class)
+	@Pojo(transform=BTransform.class)
 	public static class B {
 		public String f1;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7100939a/juneau-core/src/test/java/org/apache/juneau/html/HtmlTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/test/java/org/apache/juneau/html/HtmlTest.java b/juneau-core/src/test/java/org/apache/juneau/html/HtmlTest.java
index 17e3b4b..79c8748 100755
--- a/juneau-core/src/test/java/org/apache/juneau/html/HtmlTest.java
+++ b/juneau-core/src/test/java/org/apache/juneau/html/HtmlTest.java
@@ -19,7 +19,7 @@ import java.util.*;
 
 import org.apache.juneau.*;
 import org.apache.juneau.annotation.*;
-import org.apache.juneau.annotation.Transform;
+import org.apache.juneau.annotation.Pojo;
 import org.apache.juneau.html.annotation.*;
 import org.apache.juneau.serializer.*;
 import org.apache.juneau.testbeans.*;
@@ -100,7 +100,7 @@ public class HtmlTest {
 		public String f2 = "f2";
 	}
 
-	@Transform(A4Transform.class)
+	@Pojo(transform=A4Transform.class)
 	public static class A4 {
 		public String f2 = "f2";
 	}
@@ -112,7 +112,7 @@ public class HtmlTest {
 		}
 	}
 
-	@Transform(A5Transform.class)
+	@Pojo(transform=A5Transform.class)
 	public static class A5 {
 		public String f2 = "f2";
 	}