You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2011/05/15 16:34:06 UTC
svn commit: r1103397 - in /labs/magma/trunk/foundation-beans/src:
main/java/org/apache/magma/beans/ main/java/org/apache/magma/conversion/
test/java/org/apache/magma/beans/
Author: simoneg
Date: Sun May 15 14:34:05 2011
New Revision: 1103397
URL: http://svn.apache.org/viewvc?rev=1103397&view=rev
Log:
Added Map support, fixed string values refresh bug
Added:
labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/DummyBean.java
- copied, changed from r812575, labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/TestBean.java
Removed:
labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/TestBean.java
Modified:
labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeansHandlerAspect.aj
labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java
labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj
labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanDataTest.java
labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanHandlerTest.java
Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeansHandlerAspect.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeansHandlerAspect.aj?rev=1103397&r1=1103396&r2=1103397&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeansHandlerAspect.aj (original)
+++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/BeansHandlerAspect.aj Sun May 15 14:34:05 2011
@@ -65,13 +65,16 @@ public aspect BeansHandlerAspect perthis
* Intercepts calls to a setter on a managed bean, to notify handlers.
* @param bean
*/
- pointcut calledSetter(MagmaBeanSupport bean) : execution(public void MagmaBeanSupport+.set*(..)) && !cflow(execution(* BeanHandler+.*(..))) && this(bean);
+ pointcut calledSetter(MagmaBeanSupport bean) :
+ execution(public void MagmaBeanSupport+.set*(..))
+ && !cflow(execution(* BeanHandler+.*(..)))
+ && this(bean);
/**
* Notifies handlers that a property on the bean has changed.
* @param bean the bean that has been changed
*/
- after(MagmaBeanSupport bean) returning : calledSetter(bean) {
+ after(MagmaBeanSupport bean) : calledSetter(bean) {
if (((MethodSignature)thisJoinPointStaticPart.getSignature()).getMethod().isSynthetic()) return;
Method method = ((MethodSignature)thisJoinPointStaticPart.getSignature()).getMethod();
BeanData data = bean.beanData();
Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java?rev=1103397&r1=1103396&r2=1103397&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java (original)
+++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/beans/PropertyInfo.java Sun May 15 14:34:05 2011
@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.magma.basics.MagmaException;
@@ -85,12 +86,28 @@ public class PropertyInfo implements Clo
* Whether the property represents a collection (this includes {@link List}, {@link Set} and arrays, but not maps or tables).
*/
private boolean isCollection;
-
+
/**
* The type of elements contained in the collection (could be Object if it's not possible to deduce it)
*/
@SuppressWarnings("unchecked")
private Class collectionClass;
+
+
+ /**
+ * Whether the property represents a map (this includes {@link Map} and tables).
+ */
+ private boolean isMap;
+
+
+ /**
+ * The type of keys in the map (could be Object if it's not possible to deduce it)
+ */
+ private Class mapKeyClass;
+ /**
+ * The type of values in the map (could be Object if it's not possible to deduce it)
+ */
+ private Class mapValueClass;
/**
* If content of this property is rendered as a string, the maximum size of this string.
@@ -144,7 +161,7 @@ public class PropertyInfo implements Clo
}
/**
- * @return true if the type is a basic type, that is a primitive type, a wrapper, one of java.math numbers, or Date.
+ * @return true if the type is a basic type, that is a primitive type, a wrapper, one of java.math numbers or Date.
*/
public boolean isBasicType() {
return this.isBasicType;
@@ -209,20 +226,37 @@ public class PropertyInfo implements Clo
this.writeable = writeMethod != null;
if (this.type != null) {
this.isCollection = Collection.class.isAssignableFrom(this.type);
- if (!this.isCollection) {
+ this.isMap = Map.class.isAssignableFrom(this.type);
+ if (this.isCollection) {
+ if (readable) {
+ GenericClass returnType = GenericClass.forReturnType(readMethod);
+ if (!returnType.getBaseClass().equals(this.type))
+ returnType = GenericClass.forClass(this.type);
+ // It must have an add method
+ List<MethodDef> methods = returnType.findMethods("add", new Class<?>[] {null});
+ // It must have a single parameter of the type of the collection
+ this.collectionClass = methods.get(0).getParameterTypes()[0].getBaseClass();
+ }
+ } else if (this.isMap) {
+ if (readable) {
+ GenericClass returnType = GenericClass.forReturnType(readMethod);
+ if (!returnType.getBaseClass().equals(this.type))
+ returnType = GenericClass.forClass(this.type);
+ // It must have a put method
+ List<MethodDef> methods = returnType.findMethods("put", new Class<?>[] {null, null});
+ // It must have a single parameter of the type of the collection
+ MethodDef putmethod = methods.get(0);
+ GenericClass[] parameterTypes = putmethod.getParameterTypes();
+ this.mapKeyClass = parameterTypes[0].getBaseClass();
+ this.mapValueClass = parameterTypes[1].getBaseClass();
+ }
+ } else {
this.isBasicType =
this.type.isPrimitive() ||
this.type.getName().startsWith("java.lang") ||
this.type.getName().startsWith("java.math") ||
Date.class.isAssignableFrom(this.type);
-
- } else if (readable) {
- GenericClass returnType = GenericClass.forReturnType(readMethod);
- // It must have an add method
- List<MethodDef> methods = returnType.findMethods("add", new Class<?>[] {null});
- // It must have a single parameter of the type of the collection
- this.collectionClass = methods.get(0).getParameterTypes()[0].getBaseClass();
- }
+ }
}
}
@@ -362,4 +396,26 @@ public class PropertyInfo implements Clo
if (underlyingType == null) return value;
return underlyingConverter.from(value);
}
+
+ /**
+ * @return Whether the property represents a map (this includes {@link Map} and tables).
+ */
+ public boolean isMap() {
+ return isMap;
+ }
+
+ /**
+ * @return the Class of the keys in the map if this property {@link #isMap} and if it's possible to determine its generics.
+ */
+ public Class getMapKeyClass() {
+ return mapKeyClass;
+ }
+
+ /**
+ * @return the Class of the values in the map if this property {@link #isMap} and if it's possible to determine its generics.
+ */
+ public Class getMapValueClass() {
+ return mapValueClass;
+ }
+
}
Modified: labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj?rev=1103397&r1=1103396&r2=1103397&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj (original)
+++ labs/magma/trunk/foundation-beans/src/main/java/org/apache/magma/conversion/AddConversionInHandler.aj Sun May 15 14:34:05 2011
@@ -204,14 +204,14 @@ public privileged aspect AddConversionIn
* @param handler the handler
* @param propname the property being changed
*/
- pointcut calledUpdated(BeanHandler handler, String propname) :
- execution(public void BeanHandler.updated(String)) && args(propname) && this(handler);
+ pointcut calledUpdated(BeanHandler handler, PropertyInfo pi) :
+ execution(public void BeanHandler.updated(..)) && args(pi) && this(handler);
/**
* Hooks to the handler updated event, to update also the temporary string values.
*/
- after(BeanHandler handler, String name) : calledUpdated(handler, name) {
- handler.updatedStringValue(name);
+ after(BeanHandler handler, PropertyInfo pi) : calledUpdated(handler, pi) {
+ handler.updatedStringValue(pi.getName());
}
/**
Modified: labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanDataTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanDataTest.java?rev=1103397&r1=1103396&r2=1103397&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanDataTest.java (original)
+++ labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanDataTest.java Sun May 15 14:34:05 2011
@@ -30,13 +30,13 @@ public class BeanDataTest {
@Before
public void setUp() throws Exception {
- TestBean tb = new TestBean();
+ DummyBean tb = new DummyBean();
bd = tb.beanData();
}
@Test
public void testBeanData() {
- BeanData data = BeanData.getFor(TestBean.class);
+ BeanData data = BeanData.getFor(DummyBean.class);
assertEquals(data.getPropertyNames(), bd.getPropertyNames());
}
@@ -46,7 +46,7 @@ public class BeanDataTest {
assertTrue(propertyNames.contains("privString"));
assertTrue(propertyNames.contains("class"));
- assertEquals(7, propertyNames.size());
+ assertEquals(9, propertyNames.size());
}
@Test
@@ -60,7 +60,7 @@ public class BeanDataTest {
@Test
public void testGetBeanClass() {
- assertEquals(TestBean.class, bd.getBeanClass());
+ assertEquals(DummyBean.class, bd.getBeanClass());
}
@Test
@@ -72,6 +72,17 @@ public class BeanDataTest {
}
@Test
+ public void maps() throws Exception {
+ PropertyInfo property = bd.getProperty("AMap");
+ assertTrue(property.isMap());
+ assertNotNull(property.getMapKeyClass());
+ assertNotNull(property.getMapValueClass());
+ assertEquals(String.class, property.getMapKeyClass());
+ assertEquals(Integer.class, property.getMapValueClass());
+ }
+
+
+ @Test
public void consider() throws Exception {
PropertyInfo property = bd.getProperty("maskedDate");
assertEquals(Date.class, property.getType());
Modified: labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanHandlerTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanHandlerTest.java?rev=1103397&r1=1103396&r2=1103397&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanHandlerTest.java (original)
+++ labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/BeanHandlerTest.java Sun May 15 14:34:05 2011
@@ -30,7 +30,7 @@ public class BeanHandlerTest {
@Test
public void testRetrieve() throws Exception {
- final TestBean b = new TestBean();
+ final DummyBean b = new DummyBean();
BeanHandler h = b.handler();
assertNotNull(h);
BeanHandler h2 = b.handler();
@@ -79,7 +79,7 @@ public class BeanHandlerTest {
@Test
public void testGetters() throws Exception {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
b.setPrivString("test");
BeanHandler h = b.handler();
Object val = h.getValue("privString");
@@ -95,7 +95,7 @@ public class BeanHandlerTest {
@Test
public void testSetters() throws Exception {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
BeanHandler h = b.handler();
h.setValue("privString", "test");
Object val = h.getValue("privString");
@@ -112,7 +112,7 @@ public class BeanHandlerTest {
@Test
public void rollback() throws Exception {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
b.setPrivString("test");
BeanHandler h = b.handler();
h.setValue("privString", "wrong");
@@ -132,21 +132,21 @@ public class BeanHandlerTest {
@Test(expected=MagmaException.class)
public void unexistentGet() {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
BeanHandler h = b.handler();
h.getValue("doesnotexist");
}
@Test(expected=MagmaException.class)
public void unexistentSet() {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
BeanHandler h = b.handler();
h.setValue("doesnotexist", "test");
}
@Test(expected=MagmaException.class)
public void nonReadableGet() {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
BeanHandler h = b.handler();
h.getValue("writeOnly");
h.setValue("doesnotexist", "test");
@@ -154,33 +154,50 @@ public class BeanHandlerTest {
@Test(expected=MagmaException.class)
public void nonWriteableSet() {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
BeanHandler h = b.handler();
h.setValue("readOnly", "test");
}
@Test(expected=MagmaException.class)
public void wrongTypeSet() {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
BeanHandler h = b.handler();
h.setValue("privString", 2);
}
@Test
public void selfUpdate() throws Exception {
- TestBean b = new TestBean();
+ DummyBean b = new DummyBean();
b.setPrivString("test");
+ b.setItdString("itd");
+
BeanHandler h = b.handler();
+
Object val = h.getValue("privString");
assertNotNull(val);
assertTrue(val instanceof String);
assertEquals((String)val, "test");
+
+ val = h.getValue("itdString");
+ assertNotNull(val);
+ assertTrue(val instanceof String);
+ assertEquals((String)val, "itd");
+
b.setPrivString("other");
+ b.setItdString("otheritd");
+
val = h.getValue("privString");
assertNotNull(val);
assertTrue(val instanceof String);
- assertEquals((String)val, "other");
+ assertEquals((String)val, "other");
+
+ val = h.getValue("itdString");
+ assertNotNull(val);
+ assertTrue(val instanceof String);
+ assertEquals((String)val, "otheritd");
+
}
}
Copied: labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/DummyBean.java (from r812575, labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/TestBean.java)
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/DummyBean.java?p2=labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/DummyBean.java&p1=labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/TestBean.java&r1=812575&r2=1103397&rev=1103397&view=diff
==============================================================================
--- labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/TestBean.java (original)
+++ labs/magma/trunk/foundation-beans/src/test/java/org/apache/magma/beans/DummyBean.java Sun May 15 14:34:05 2011
@@ -18,15 +18,17 @@ package org.apache.magma.beans;
import java.util.Date;
import java.util.List;
+import java.util.Map;
import org.junit.Ignore;
@Ignore("This is not a test")
@MagmaBean
-public class TestBean {
+public class DummyBean {
private String privString;
private List<String> aList;
+ private Map<String,Integer> aMap;
private String maskedDate;
private String roProp;
@@ -66,4 +68,11 @@ public class TestBean {
this.maskedDate = maskedDate;
}
+ public Map<String, Integer> getAMap() {
+ return aMap;
+ }
+ public void setAMap(Map<String, Integer> aMap) {
+ this.aMap = aMap;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org