Author: shane.bryzak(a)jboss.com
Date: 2009-12-31 23:42:31 -0500 (Thu, 31 Dec 2009)
New Revision: 11896
Removed:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ChangeSet.java
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BeanWrapper.java
Log:
cleanup, removed unnecessary ChangeSet class
Deleted:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ChangeSet.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ChangeSet.java 2009-12-30
23:38:56 UTC (rev 11895)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ChangeSet.java 2010-01-01
04:42:31 UTC (rev 11896)
@@ -1,6 +0,0 @@
-package org.jboss.seam.remoting.model;
-
-public class ChangeSet
-{
-
-}
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2009-12-30
23:38:56 UTC (rev 11895)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/Model.java 2010-01-01
04:42:31 UTC (rev 11896)
@@ -17,6 +17,7 @@
import org.jboss.seam.remoting.AnnotationsParser;
import org.jboss.seam.remoting.Call;
import org.jboss.seam.remoting.CallContext;
+import org.jboss.seam.remoting.wrapper.BeanWrapper;
import org.jboss.seam.remoting.wrapper.ConversionException;
import org.jboss.seam.remoting.wrapper.Wrapper;
@@ -182,63 +183,6 @@
beanProperties.put(alias, new BeanProperty(bean, propertyName));
}
- public void setModelProperty(int refId, String name, Wrapper wrapper)
- {
- Wrapper outRef = callContext.getOutRefs().get(refId);
-
- try
- {
- Field f = outRef.getValue().getClass().getField(name);
- if (wrapper.conversionScore(f.getType()).getScore() > 0)
- {
- // found a match
- boolean accessible = f.isAccessible();
- try
- {
- if (!f.isAccessible()) f.setAccessible(true);
- f.set(outRef.getValue(), wrapper.convert(f.getType()));
- }
- catch (ConversionException ex)
- {
- throw new RuntimeException("Exception converting model property
value", ex);
- }
- catch (IllegalAccessException ex)
- {
- throw new RuntimeException("Exception setting model property",
ex);
- }
- finally
- {
- f.setAccessible(accessible);
- }
- }
- }
- catch (NoSuchFieldException ex)
- {
- String methodName = "set" + name.substring(0, 1).toUpperCase() +
name.substring(1);
- for (Method m : outRef.getValue().getClass().getMethods())
- {
- if (m.getName().equals(methodName) && m.getParameterTypes().length ==
1 &&
- wrapper.conversionScore(m.getParameterTypes()[0]).getScore() > 0)
- {
- try
- {
- m.invoke(outRef.getValue(),
wrapper.convert(m.getParameterTypes()[0]));
- break;
- }
- catch (Exception ex2)
- {
- throw new RuntimeException("Exception converting model property
value", ex2);
- }
- }
- }
- }
- }
-
- public void applyChanges(Set<ChangeSet> delta)
- {
-
- }
-
public void setAction(Call action)
{
this.action = action;
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2009-12-30
23:38:56 UTC (rev 11895)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-01
04:42:31 UTC (rev 11896)
@@ -4,9 +4,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import javax.enterprise.context.Conversation;
import javax.enterprise.inject.spi.BeanManager;
@@ -22,6 +20,8 @@
import org.jboss.seam.remoting.MarshalUtils;
import org.jboss.seam.remoting.RequestContext;
import org.jboss.seam.remoting.RequestHandler;
+import org.jboss.seam.remoting.wrapper.BagWrapper;
+import org.jboss.seam.remoting.wrapper.BeanWrapper;
import org.jboss.seam.remoting.wrapper.Wrapper;
import org.jboss.weld.Container;
import org.jboss.weld.context.ContextLifecycle;
@@ -231,12 +231,35 @@
for (Element member : (List<Element>)
changeset.elements("member"))
{
String name = member.attributeValue("name");
+
Wrapper w = model.getCallContext().createWrapperFromElement(
(Element) member.elementIterator().next());
- model.setModelProperty(refId, name, w);
+
+ if (w instanceof BagWrapper)
+ {
+ // TODO process collection updates
+ }
+ else
+ {
+ Wrapper ref = model.getCallContext().getOutRefs().get(refId);
+ if (ref instanceof BeanWrapper)
+ {
+ ((BeanWrapper) ref).setBeanProperty(name, w);
+ }
+ else
+ {
+ throw new IllegalStateException("Changeset for refId ["
+
+ refId + "] does not reference a valid bean
object");
+ }
+ }
+
}
}
+ if (changeset.elements("bag").size() > 0)
+ {
+ // TODO process root node collection updates
+ }
}
}
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BeanWrapper.java
===================================================================
---
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BeanWrapper.java 2009-12-30
23:38:56 UTC (rev 11895)
+++
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/wrapper/BeanWrapper.java 2010-01-01
04:42:31 UTC (rev 11896)
@@ -79,120 +79,123 @@
}
}
}
-
- @SuppressWarnings("unchecked")
- @Override
- public void unmarshal()
+
+ public void setBeanProperty(String propertyName, Wrapper valueWrapper)
{
- List<Element> members = element.elements("member");
+ Class<?> cls = value.getClass();
- for (Element member : members)
- {
- String name = member.attributeValue("name");
+ // We're going to try a combination of ways to set the property value
+ // here
+ Method method = null;
+ Field field = null;
- Wrapper w = context.createWrapperFromElement((Element) member
- .elementIterator().next());
+ // First try to find the best matching method
+ String setter = "set" + Character.toUpperCase(propertyName.charAt(0))
+ + propertyName.substring(1);
- Class cls = value.getClass();
-
- // We're going to try a combination of ways to set the property value
- // here
- Method method = null;
- Field field = null;
-
- // First try to find the best matching method
- String setter = "set" + Character.toUpperCase(name.charAt(0))
- + name.substring(1);
-
- ConversionScore score = ConversionScore.nomatch;
- for (Method m : cls.getMethods())
+ ConversionScore score = ConversionScore.nomatch;
+ for (Method m : cls.getMethods())
+ {
+ if (setter.equals(m.getName()) && m.getParameterTypes().length == 1)
{
- if (setter.equals(m.getName()) && m.getParameterTypes().length == 1)
+ ConversionScore s = valueWrapper.conversionScore(m.getParameterTypes()[0]);
+ if (s.getScore() > score.getScore())
{
- ConversionScore s = w.conversionScore(m.getParameterTypes()[0]);
- if (s.getScore() > score.getScore())
- {
- method = m;
- score = s;
- }
+ method = m;
+ score = s;
}
}
+ }
- // If we can't find a method, look for a matching field name
- if (method == null)
+ // If we can't find a method, look for a matching field name
+ if (method == null)
+ {
+ while (field == null && !cls.equals(Object.class))
{
- while (field == null && !cls.equals(Object.class))
+ try
{
- try
- {
- // First check the declared fields
- field = cls.getDeclaredField(name);
- }
- catch (NoSuchFieldException ex)
- {
- // Couldn't find the field.. try the superclass
- cls = cls.getSuperclass();
- }
+ // First check the declared fields
+ field = cls.getDeclaredField(propertyName);
}
-
- if (field == null)
+ catch (NoSuchFieldException ex)
{
- throw new RuntimeException(
- String
- .format(
- "Error while unmarshalling - property [%s] not
found in class [%s]",
- name, value.getClass().getName()));
+ // Couldn't find the field.. try the superclass
+ cls = cls.getSuperclass();
}
}
- // Now convert the field value to the correct target type
- Object fieldValue = null;
+ if (field == null)
+ {
+ throw new RuntimeException(String.format(
+ "Error while unmarshalling - property [%s] not found in class
[%s]",
+ propertyName, value.getClass().getName()));
+ }
+ }
+
+ // Now convert the field value to the correct target type
+ Object fieldValue = null;
+ try
+ {
+ fieldValue = valueWrapper.convert(method != null ? method
+ .getGenericParameterTypes()[0] : field.getGenericType());
+ }
+ catch (ConversionException ex)
+ {
+ throw new RuntimeException(
+ "Could not convert value while unmarshaling", ex);
+ }
+
+ // If we have a setter method, invoke it
+ if (method != null)
+ {
try
{
- fieldValue = w.convert(method != null ? method
- .getGenericParameterTypes()[0] : field.getGenericType());
+ method.invoke(value, fieldValue);
}
- catch (ConversionException ex)
+ catch (Exception e)
{
- throw new RuntimeException(
- "Could not convert value while unmarshaling", ex);
+ throw new RuntimeException(String.format(
+ "Could not invoke setter method [%s]", method.getName()));
}
-
- // If we have a setter method, invoke it
- if (method != null)
+ }
+ else
+ {
+ // Otherwise try to set the field value directly
+ boolean accessible = field.isAccessible();
+ try
{
- try
- {
- method.invoke(value, fieldValue);
- }
- catch (Exception e)
- {
- throw new RuntimeException(String.format(
- "Could not invoke setter method [%s]",
method.getName()));
- }
+ if (!accessible)
+ field.setAccessible(true);
+ field.set(value, fieldValue);
}
- else
+ catch (Exception ex)
{
- // Otherwise try to set the field value directly
- boolean accessible = field.isAccessible();
- try
- {
- if (!accessible)
- field.setAccessible(true);
- field.set(value, fieldValue);
- }
- catch (Exception ex)
- {
- throw new RuntimeException("Could not set field value.", ex);
- }
- finally
- {
- field.setAccessible(accessible);
- }
+ throw new RuntimeException("Could not set field value.", ex);
}
+ finally
+ {
+ field.setAccessible(accessible);
+ }
}
+
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public void unmarshal()
+ {
+ List<Element> members = element.elements("member");
+
+ for (Element member : members)
+ {
+ String name = member.attributeValue("name");
+
+ Wrapper w = context.createWrapperFromElement((Element) member
+ .elementIterator().next());
+ setBeanProperty(name, w);
+ }
+ }
+
public Object convert(Type type) throws ConversionException
{
if (type instanceof Class<?>