use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class CollectionConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
// First we need to get ourselves the collection data
Iterator it;
if (data instanceof Collection) {
Collection col = (Collection) data;
it = col.iterator();
} else if (data instanceof Iterator) {
it = (Iterator) data;
} else {
throw new MarshallException(data.getClass());
}
// Stash this bit of data to cope with recursion
ArrayOutboundVariable ov = new ArrayOutboundVariable(outctx);
outctx.put(data, ov);
// Convert all the data members
List ovs = new ArrayList();
while (it.hasNext()) {
Object member = it.next();
OutboundVariable nested;
try {
nested = config.convertOutbound(member, outctx);
} catch (Exception ex) {
String errorMessage = "Conversion error for " + data.getClass().getName() + ".";
log.warn(errorMessage, ex);
nested = new ErrorOutboundVariable(outctx, errorMessage, true);
}
ovs.add(nested);
}
// Group the list of converted objects into this OutboundVariable
ov.init(ovs);
return ov;
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class CollectionConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
String value = iv.getValue();
// If the text is null then the whole bean is null
if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) {
return null;
}
if (!value.startsWith(ProtocolConstants.INBOUND_ARRAY_START)) {
throw new MarshallException(paramType, Messages.getString("CollectionConverter.FormatError", ProtocolConstants.INBOUND_ARRAY_START));
}
if (!value.endsWith(ProtocolConstants.INBOUND_ARRAY_END)) {
throw new MarshallException(paramType, Messages.getString("CollectionConverter.FormatError", ProtocolConstants.INBOUND_ARRAY_END));
}
value = value.substring(1, value.length() - 1);
try {
TypeHintContext icc = inctx.getCurrentTypeHintContext();
TypeHintContext subthc = icc.createChildContext(0);
Class subtype = subthc.getExtraTypeInfo();
// subtype.getMethod("h", null).getTypeParameters();
Collection col;
// at the end.
if (Iterator.class.isAssignableFrom(paramType)) {
col = new ArrayList();
} else // If paramType is concrete then just use whatever we've got.
if (!paramType.isInterface() && !Modifier.isAbstract(paramType.getModifiers())) {
// If there is a problem creating the type then we have no way
// of completing this - they asked for a specific type and we
// can't create that type. I don't know of a way of finding
// subclasses that might be instaniable so we accept failure.
col = (Collection) paramType.newInstance();
} else // If they want a SortedSet then use TreeSet
if (SortedSet.class.isAssignableFrom(paramType)) {
col = new TreeSet();
} else // If they want a Set then use HashSet
if (Set.class.isAssignableFrom(paramType)) {
col = new HashSet();
} else // If they want a List then use an ArrayList
if (List.class.isAssignableFrom(paramType)) {
col = new ArrayList();
} else // If they just want a Collection then just use an ArrayList
if (Collection.class.isAssignableFrom(paramType)) {
col = new ArrayList();
} else {
throw new MarshallException(paramType);
}
// We should put the new object into the working map in case it
// is referenced later nested down in the conversion process.
inctx.addConverted(iv, paramType, col);
StringTokenizer st = new StringTokenizer(value, ProtocolConstants.INBOUND_ARRAY_SEPARATOR);
int size = st.countTokens();
for (int i = 0; i < size; i++) {
String token = st.nextToken();
String[] split = ParseUtil.splitInbound(token);
String splitType = split[LocalUtil.INBOUND_INDEX_TYPE];
String splitValue = split[LocalUtil.INBOUND_INDEX_VALUE];
InboundVariable nested = new InboundVariable(iv.getLookup(), null, splitType, splitValue);
Object output = config.convertInbound(subtype, nested, inctx, subthc);
col.add(output);
}
// the type we created
if (Iterator.class.isAssignableFrom(paramType)) {
return col.iterator();
} else {
return col;
}
} catch (Exception ex) {
throw new MarshallException(paramType, ex);
}
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class DOM4JConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
String value = LocalUtil.decode(iv.getValue());
try {
SAXReader xmlReader = new SAXReader();
Document doc = xmlReader.read(new StringReader(value));
if (paramType == Document.class) {
return doc;
} else if (paramType == Element.class) {
return doc.getRootElement();
}
throw new MarshallException(paramType);
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(paramType, ex);
}
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class DateConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
String value = iv.getValue();
// If the text is null then the whole bean is null
if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) {
return null;
}
try {
long millis = 0;
if (value.length() > 0) {
millis = Long.parseLong(value);
}
Date date = new Date(millis);
if (paramType == Date.class) {
return date;
} else if (paramType == java.sql.Date.class) {
return new java.sql.Date(date.getTime());
} else if (paramType == Time.class) {
return new Time(date.getTime());
} else if (paramType == Timestamp.class) {
return new Timestamp(date.getTime());
} else if (paramType == Calendar.class) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
} else {
throw new MarshallException(paramType);
}
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(paramType, ex);
}
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class ExceptionConverter method getPropertyMapFromClass.
/* (non-Javadoc)
* @see org.directwebremoting.convert.BasicBeanConverter#getPropertyDescriptors(java.lang.Class, boolean, boolean)
*/
public Map getPropertyMapFromClass(Class type, boolean readRequired, boolean writeRequired) throws MarshallException {
Map descriptors = super.getPropertyMapFromClass(type, readRequired, writeRequired);
descriptors.put("javaClassName", new PlainProperty("javaClassName", type.getName()));
// (fix for Bean Introspector peculiarities)
try {
fixMissingThrowableProperty(descriptors, "message", "getMessage");
fixMissingThrowableProperty(descriptors, "cause", "getCause");
} catch (IntrospectionException ex) {
throw new MarshallException(type, ex);
}
return descriptors;
}
Aggregations