use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class BasicObjectConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
// Where we collect out converted children
Map ovs = new TreeMap();
// We need to do this before collecing the children to save recurrsion
ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
outctx.put(data, ov);
try {
Map properties = getPropertyMapFromObject(data, true, false);
for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
Property property = (Property) entry.getValue();
Object value = property.getValue(data);
OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
ovs.put(name, nested);
}
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(data.getClass(), ex);
}
ov.init(ovs, getJavascript());
return ov;
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class XOMConverter 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 {
Builder builder = new Builder();
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 H3BeanConverter method getPropertyMapFromObject.
/*
* (non-Javadoc)
*
* @see
* org.directwebremoting.convert.BeanConverter#getPropertyMapFromObject(
* java.lang.Object, boolean, boolean)
*/
public Map getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws MarshallException {
Class clazz = getClass(example);
try {
BeanInfo info = Introspector.getBeanInfo(clazz);
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;
}
// And this is something added by hibernate
if (name.equals("hibernateLazyInitializer")) {
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;
}
if (!assumeSession) {
// We don't marshall un-initialized properties for
// Hibernate3
String propertyName = descriptor.getName();
Method method = findGetter(example, propertyName);
if (method == null) {
log.warn("Failed to find property: " + propertyName);
properties.put(name, new PlainProperty(propertyName, null));
continue;
}
if (!Hibernate.isPropertyInitialized(example, propertyName)) {
properties.put(name, new PlainProperty(propertyName, null));
continue;
}
// This might be a lazy-collection so we need to double
// check
Object retval = method.invoke(example, new Object[] {});
if (!Hibernate.isInitialized(retval)) {
properties.put(name, new PlainProperty(propertyName, null));
continue;
}
}
properties.put(name, new H3PropertyDescriptorProperty(descriptor));
}
return properties;
} catch (Exception ex) {
throw new MarshallException(clazz, ex);
}
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class BlabberConverterManager method convertInbound.
/*
* (non-Javadoc)
*
* @see org.directwebremoting.ConverterManager#convertInbound(java.lang.Class,
* org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext,
* org.directwebremoting.TypeHintContext)
*/
public Object convertInbound(@SuppressWarnings("rawtypes") Class paramType, InboundVariable iv, InboundContext inctx, TypeHintContext incc) throws MarshallException {
Object converted = inctx.getConverted(iv, paramType);
if (converted == null) {
// Was the inbound variable marshalled as an Object in the client
// (could mean that this is an instance of one of our generated
// JavaScript classes)
Converter converter = getNamedConverter(paramType, iv.getType());
// didn't find anything above
if (converter == null) {
converter = getConverter(paramType);
}
if (converter == null) {
throw new MarshallException(paramType, Messages.getString("DefaultConverterManager.MissingConverter", paramType));
}
// from passing null to things they are not allowed to convert
if (iv.isNull()) {
return null;
}
inctx.pushContext(incc);
converted = converter.convertInbound(paramType, iv, inctx);
inctx.popContext();
}
return converted;
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class DOM4JConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
try {
// Using XSLT to convert to a stream. Setup the source
if (!(data instanceof Node)) {
throw new MarshallException(data.getClass());
}
Node node = (Node) data;
OutputFormat outformat = OutputFormat.createCompactFormat();
outformat.setEncoding("UTF-8");
// Setup the destination
StringWriter xml = new StringWriter();
XMLWriter writer = new XMLWriter(xml, outformat);
writer.write(node);
writer.flush();
xml.flush();
String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
outctx.put(data, ov);
return ov;
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(data.getClass(), ex);
}
}
Aggregations