use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class JDOMConverter 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 {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(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 ArrayConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
if (!data.getClass().isArray()) {
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
int size = Array.getLength(data);
List ovs = new ArrayList();
for (int i = 0; i < size; i++) {
OutboundVariable nested;
try {
nested = converterManager.convertOutbound(Array.get(data, i), 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 BasicObjectConverter method extractInboundTokens.
/**
* Loop over all the inputs and extract a Map of key:value pairs
* @param paramType The type we are converting to
* @param value The input string
* @return A Map of the tokens in the string
* @throws MarshallException If the marshalling fails
*/
protected Map extractInboundTokens(Class paramType, String value) throws MarshallException {
Map tokens = new HashMap();
StringTokenizer st = new StringTokenizer(value, ProtocolConstants.INBOUND_MAP_SEPARATOR);
int size = st.countTokens();
for (int i = 0; i < size; i++) {
String token = st.nextToken();
if (token.trim().length() == 0) {
continue;
}
int colonpos = token.indexOf(ProtocolConstants.INBOUND_MAP_ENTRY);
if (colonpos == -1) {
throw new MarshallException(paramType, Messages.getString("BeanConverter.MissingSeparator", ProtocolConstants.INBOUND_MAP_ENTRY, token));
}
String key = token.substring(0, colonpos).trim();
String val = token.substring(colonpos + 1).trim();
tokens.put(key, val);
}
return tokens;
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class BasicObjectConverter 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_MAP_START)) {
throw new MarshallException(paramType, Messages.getString("BeanConverter.FormatError", ProtocolConstants.INBOUND_MAP_START));
}
if (!value.endsWith(ProtocolConstants.INBOUND_MAP_END)) {
throw new MarshallException(paramType, Messages.getString("BeanConverter.FormatError", ProtocolConstants.INBOUND_MAP_START));
}
value = value.substring(1, value.length() - 1);
try {
Object bean;
if (instanceType != null) {
bean = instanceType.newInstance();
} else {
bean = paramType.newInstance();
}
// is referenced later nested down in the conversion process.
if (instanceType != null) {
inctx.addConverted(iv, instanceType, bean);
} else {
inctx.addConverted(iv, paramType, bean);
}
Map properties = getPropertyMapFromObject(bean, false, true);
// Loop through the properties passed in
Map tokens = extractInboundTokens(paramType, value);
for (Iterator it = tokens.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
String val = (String) entry.getValue();
Property property = (Property) properties.get(key);
if (property == null) {
log.warn("Missing java bean property to match javascript property: " + key + ". For causes see debug level logs:");
log.debug("- The javascript may be refer to a property that does not exist");
log.debug("- You may be missing the correct setter: set" + Character.toTitleCase(key.charAt(0)) + key.substring(1) + "()");
log.debug("- The property may be excluded using include or exclude rules.");
StringBuffer all = new StringBuffer();
for (Iterator pit = properties.keySet().iterator(); pit.hasNext(); ) {
all.append(pit.next());
if (pit.hasNext()) {
all.append(',');
}
}
log.debug("Fields exist for (" + all + ").");
continue;
}
Class propType = property.getPropertyType();
String[] split = ParseUtil.splitInbound(val);
String splitValue = split[LocalUtil.INBOUND_INDEX_VALUE];
String splitType = split[LocalUtil.INBOUND_INDEX_TYPE];
InboundVariable nested = new InboundVariable(iv.getLookup(), null, splitType, splitValue);
TypeHintContext incc = createTypeHintContext(inctx, property);
Object output = converterManager.convertInbound(propType, nested, inctx, incc);
property.setValue(bean, output);
}
return bean;
} 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 BeanConverter method getPropertyMapFromClass.
/* (non-Javadoc)
* @see org.directwebremoting.extend.NamedConverter#getPropertyMap(java.lang.Class, boolean, boolean)
*/
public Map getPropertyMapFromClass(Class type, boolean readRequired, boolean writeRequired) throws MarshallException {
try {
BeanInfo info = Introspector.getBeanInfo(type);
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
Map properties = new HashMap();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
String name = descriptor.getName();
// We don't marshall getClass()
if (name.equals("class")) {
continue;
}
// Access rules mean we might not want to do this one
if (!isAllowedByIncludeExcludeRules(name)) {
continue;
}
if (readRequired && descriptor.getReadMethod() == null) {
continue;
}
if (writeRequired && descriptor.getWriteMethod() == null) {
continue;
}
properties.put(name, new PropertyDescriptorProperty(descriptor));
}
return properties;
} catch (IntrospectionException ex) {
throw new MarshallException(type, ex);
}
}
Aggregations