Author: alessio.soldano(a)jboss.com
Date: 2013-01-29 02:52:36 -0500 (Tue, 29 Jan 2013)
New Revision: 472
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/ClientConversationBean.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/DurationWiseTreeElement.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/EnumerationWiseTreeElement.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/QNameWiseTreeElement.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElement.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElementFactory.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/WiseTreeElementBuilder.java
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/XMLGregorianWiseTreeElement.java
Log:
More on nill / notNillable + make sure RPC/Lit main parameters are not nillable
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/ClientConversationBean.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/ClientConversationBean.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/ClientConversationBean.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -33,6 +33,7 @@
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.jws.soap.SOAPBinding;
import org.jboss.wise.core.client.InvocationResult;
import org.jboss.wise.core.client.WSDynamicClient;
@@ -148,8 +149,14 @@
WiseTreeElementBuilder builder = new WiseTreeElementBuilder(client);
TreeNodeImpl rootElement = new TreeNodeImpl();
Collection<? extends WebParameter> parameters = wsMethod.getWebParams().values();
+ SOAPBinding soapBindingAnn =
wsMethod.getEndpoint().getUnderlyingObjectClass().getAnnotation(SOAPBinding.class);
+ boolean rpcLit = false;
+ if (soapBindingAnn != null) {
+ SOAPBinding.Style style = soapBindingAnn.style();
+ rpcLit = style != null && SOAPBinding.Style.RPC.equals(style);
+ }
for (WebParameter parameter : parameters) {
- WiseTreeElement wte = builder.buildTreeFromType(parameter.getType(),
parameter.getName());
+ WiseTreeElement wte = builder.buildTreeFromType(parameter.getType(),
parameter.getName(), !rpcLit);
rootElement.addChild(wte.getId(), wte);
}
return rootElement;
@@ -160,7 +167,7 @@
TreeNodeImpl rootElement = new TreeNodeImpl();
for (Entry<String, Object> res : result.getResult().entrySet()) {
Object resObj = res.getValue();
- WiseTreeElement wte = builder.buildTreeFromType(resObj.getClass(), res.getKey(),
resObj);
+ WiseTreeElement wte = builder.buildTreeFromType(resObj.getClass(), res.getKey(),
resObj, true);
rootElement.addChild(wte.getId(), wte);
}
return rootElement;
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/DurationWiseTreeElement.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/DurationWiseTreeElement.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/DurationWiseTreeElement.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -64,6 +64,13 @@
this.setValue(null);
}
}
+
+ @Override
+ public void enforceNotNillable() {
+ this.nillable = false;
+ this.nil = false;
+ this.value = "0";
+ }
@Override
public Object toObject() {
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/EnumerationWiseTreeElement.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/EnumerationWiseTreeElement.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/EnumerationWiseTreeElement.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -54,6 +54,13 @@
element.setNillable(this.isNillable());
return element;
}
+
+ @Override
+ public void enforceNotNillable() {
+ this.nillable = false;
+ this.nil = false;
+ this.value = getValidValue().keySet().iterator().next();
+ }
@Override
public void parseObject(Object obj) {
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/QNameWiseTreeElement.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/QNameWiseTreeElement.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/QNameWiseTreeElement.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -76,6 +76,13 @@
public void setLocalPart(String localPart) {
this.localPart = localPart;
}
+
+ @Override
+ public void enforceNotNillable() {
+ this.nillable = false;
+ this.nil = false;
+ this.value = "";
+ }
@Override
public void parseObject(Object obj) {
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElement.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElement.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElement.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -53,9 +53,7 @@
this.id = IDGenerator.nextVal();
this.classType = classType;
this.name = name;
- this.value = value;
- this.nillable = !classType.isPrimitive(); // primitive are not nillable
- this.nil = (value == null && nillable); // thus they can't be nil
+ init(classType, value);
}
/**
@@ -112,6 +110,7 @@
element.setClassType(this.classType);
element.setRemovable(this.isRemovable());
element.setNillable(this.isNillable());
+ element.init((Class<?>)this.classType, null);
return element;
}
@@ -125,6 +124,56 @@
this.setValue(obj == null ? null : obj.toString());
this.nil = (obj == null && nillable);
}
+
+ /**
+ * Make sure this element can't be nill and set the default value
+ * (this is to be used e.g. for main RPC/Lit parameters)
+ */
+ public void enforceNotNillable() {
+ this.nillable = false;
+ this.nil = false;
+ this.value = getDefaultValue((Class<?>) classType);
+ }
+
+ private void init(Class<?> classType, String value) {
+ // primitive are not nillable, thus they can't be nil or have a null value
+ this.value = (value == null && classType.isPrimitive()) ?
getDefaultValue(classType) : value;
+ this.nillable = !classType.isPrimitive();
+ this.nil = (value == null && nillable);
+ }
+
+ private static String getDefaultValue(Class<?> cl) {
+ if (cl.isPrimitive()) {
+ cl = JavaUtils.getWrapperType(cl);
+ }
+ if ("java.lang.String".equalsIgnoreCase(cl.getName())) {
+ return "";
+ } else if ("java.lang.Boolean".equalsIgnoreCase(cl.getName())) {
+ return "false";
+ } else if ("java.lang.Byte".equalsIgnoreCase(cl.getName())) {
+ return "0";
+ } else if ("java.lang.Character".equalsIgnoreCase(cl.getName())) {
+ return "";
+ } else if ("java.lang.Double".equalsIgnoreCase(cl.getName())) {
+ return "0.0";
+ } else if ("java.lang.Float".equalsIgnoreCase(cl.getName())) {
+ return "0.0";
+ } else if ("java.lang.Integer".equalsIgnoreCase(cl.getName())) {
+ return "0";
+ } else if ("java.lang.Long".equalsIgnoreCase(cl.getName())) {
+ return "0";
+ } else if ("java.lang.Short".equalsIgnoreCase(cl.getName())) {
+ return "0";
+ } else if ("java.math.BigDecimal".equalsIgnoreCase(cl.getName())) {
+ return "0.0";
+ } else if ("java.math.BigInteger".equalsIgnoreCase(cl.getName())) {
+ return "0";
+ } else if ("java.lang.Object".equalsIgnoreCase(cl.getName())) {
+ return "";
+ } else {
+ throw new WiseRuntimeException("Class type not supported: " + cl);
+ }
+ }
public Object toObject() {
if (value == null) {
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElementFactory.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElementFactory.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/SimpleWiseTreeElementFactory.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -25,19 +25,22 @@
*/
public class SimpleWiseTreeElementFactory {
- public static SimpleWiseTreeElement create(Class<?> classType, String name) {
+ public static SimpleWiseTreeElement create(Class<?> classType, String name,
Object obj) {
+ SimpleWiseTreeElement element;
if (classType.isEnum()) {
- return new EnumerationWiseTreeElement(classType, name, null);
+ element = new EnumerationWiseTreeElement(classType, name, null);
} else if (QName.class.isAssignableFrom(classType)) {
- return new QNameWiseTreeElement(classType, name, null, null);
+ element = new QNameWiseTreeElement(classType, name, null, null);
} else if (XMLGregorianCalendar.class.isAssignableFrom(classType)) {
- return new XMLGregorianWiseTreeElement(classType, name, null);
+ element = new XMLGregorianWiseTreeElement(classType, name, null);
} else if (Duration.class.isAssignableFrom(classType)) {
- return new DurationWiseTreeElement(classType, name, null);
+ element = new DurationWiseTreeElement(classType, name, null);
} else {
- return new SimpleWiseTreeElement(classType, name, null);
+ element = new SimpleWiseTreeElement(classType, name, null);
}
-
+ if (obj != null) {
+ element.parseObject(obj);
+ }
+ return element;
}
-
}
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/WiseTreeElementBuilder.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/WiseTreeElementBuilder.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/WiseTreeElementBuilder.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -51,17 +51,18 @@
this.client = client;
}
- public WiseTreeElement buildTreeFromType(Type type, String name) {
- return buildTreeFromType(type, name, null, null, null, new HashMap<Type,
WiseTreeElement>(), new HashSet<Type>());
+ public WiseTreeElement buildTreeFromType(Type type, String name, boolean nillable) {
+ return buildTreeFromType(type, name, null, nillable, null, null, new HashMap<Type,
WiseTreeElement>(), new HashSet<Type>());
}
- public WiseTreeElement buildTreeFromType(Type type, String name, Object obj) {
- return buildTreeFromType(type, name, obj, null, null, new HashMap<Type,
WiseTreeElement>(), new HashSet<Type>());
+ public WiseTreeElement buildTreeFromType(Type type, String name, Object obj, boolean
nillable) {
+ return buildTreeFromType(type, name, obj, nillable, null, null, new HashMap<Type,
WiseTreeElement>(), new HashSet<Type>());
}
private WiseTreeElement buildTreeFromType(Type type,
String name,
Object obj,
+ boolean nillable,
Class<?> scope,
String namespace,
Map<Type, WiseTreeElement> typeMap,
@@ -74,7 +75,7 @@
} else {
Logger.getLogger(this.getClass()).debug("Not a parameterized type... casting to
Class");
- return this.buildFromClass((Class<?>) type, name, obj, typeMap, stack);
+ return this.buildFromClass((Class<?>) type, name, obj, nillable, typeMap,
stack);
}
}
@@ -89,11 +90,11 @@
Set<Type> stack) {
Type firstTypeArg = pt.getActualTypeArguments()[0];
if (Collection.class.isAssignableFrom((Class<?>) pt.getRawType())) {
- WiseTreeElement prototype = this.buildTreeFromType(firstTypeArg, name, null, null,
null, typeMap, stack);
+ WiseTreeElement prototype = this.buildTreeFromType(firstTypeArg, name, null, true,
null, null, typeMap, stack);
GroupWiseTreeElement group = new GroupWiseTreeElement(pt, name, prototype);
if (obj != null) {
for (Object o : (Collection) obj) {
- group.addChild(IDGenerator.nextVal(), this.buildTreeFromType(firstTypeArg, name, o,
null, null, typeMap, stack));
+ group.addChild(IDGenerator.nextVal(), this.buildTreeFromType(firstTypeArg, name, o,
true, null, null, typeMap, stack));
}
}
return group;
@@ -102,7 +103,7 @@
if (obj != null && obj instanceof JAXBElement) {
obj = ((JAXBElement)obj).getValue();
}
- WiseTreeElement element = this.buildTreeFromType(firstTypeArg, name, obj, null,
null, typeMap, stack);
+ WiseTreeElement element = this.buildTreeFromType(firstTypeArg, name, obj, true,
null, null, typeMap, stack);
parameterized.addChild(element.getId(), element);
return parameterized;
}
@@ -111,6 +112,7 @@
private WiseTreeElement buildFromClass(Class<?> cl,
String name,
Object obj,
+ boolean nillable,
Map<Type, WiseTreeElement> typeMap,
Set<Type> stack) {
@@ -122,8 +124,10 @@
if (isSimpleType(cl, client)) {
Logger.getLogger(this.getClass()).debug("* simple");
- SimpleWiseTreeElement element = SimpleWiseTreeElementFactory.create(cl, name);
- element.parseObject(obj);
+ SimpleWiseTreeElement element = SimpleWiseTreeElementFactory.create(cl, name, obj);
+ if (!nillable) {
+ element.enforceNotNillable();
+ }
return element;
} else { // complex
if (stack.contains(cl)) {
@@ -160,11 +164,14 @@
throw new WiseRuntimeException("Error calling getter method for field " +
field, e);
}
}
- WiseTreeElement element = this.buildTreeFromType(field.getGenericType(), fieldName,
fieldValue, cl, namespace, typeMap, stack);
+ WiseTreeElement element = this.buildTreeFromType(field.getGenericType(), fieldName,
fieldValue, true, cl, namespace, typeMap, stack);
complex.addChild(element.getId(), element);
}
stack.remove(cl);
typeMap.put(cl, complex.clone());
+ if (!nillable) {
+ complex.setNillable(false);
+ }
return complex;
}
}
Modified:
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/XMLGregorianWiseTreeElement.java
===================================================================
---
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/XMLGregorianWiseTreeElement.java 2013-01-29
06:15:22 UTC (rev 471)
+++
webgui/branches/cdi-jsf/src/main/java/org/jboss/wise/gui/treeElement/XMLGregorianWiseTreeElement.java 2013-01-29
07:52:36 UTC (rev 472)
@@ -72,6 +72,13 @@
}
this.nil = obj == null;
}
+
+ @Override
+ public void enforceNotNillable() {
+ this.nillable = false;
+ this.nil = false;
+ this.value = new Date().toString();
+ }
@Override
public Object toObject() {