/** * Overriding decodeBean() in the parent class to make sure that * embedded XML content doesn't get mistaken as a bean. */ protected Object decodeBean () throws BeanCoderException { if (currentType() == T_XML) return decodeXmlContent(); return super.decodeBean(); }
protected Object decodePrimitive () throws BeanCoderException { final Class primitiveClass = currentClass(); final String text = currentText(); return BeanCoderUtils.newPrimitive(primitiveClass, text); }
public static Object xmlDecode (final org.jdom.Element elt) throws BeanCoderException { final XmlBeanCoder coder = new XmlBeanCoder(elt); return coder.decode(); }
public Object decode () throws BeanCoderException { final int type = currentType(); //if (log.isDebugEnabled()) // log.debug("decode() type is "+type); if (type == T_NULL) return null; if (type == T_ARRAY) return decodeArray(); if (type == T_BYTE_ARRAY) return decodeByteArray(); if (type == T_MAP) return decodeMap(); if (type == T_COLLECTION) return decodeCollection(); if (type == T_PRIMITIVE) return decodePrimitive(); // else... return decodeBean(); }
protected void encodeMapEntry (final java.util.Map.Entry e) throws BeanCoderException { beginMapEntry(); encode(e.getKey()); encode(e.getValue()); endElement(); }
/** * Returns an XML string representation of this header. */ public String toString () { try { return openwfe.org.util.beancoder.XmlBeanCoder .encodeToString(this, null); // // setting the encoding to 'null' means : // use the default encoding (as set in the start scripts) } catch (final Exception e) { return "Failed to encode header because of "+e; } }
protected void saveExpression (final String fileName, final FlowExpression fe) throws Exception { XmlBeanCoder.save(fileName, fe); }
public static org.jdom.Document xmlEncode (final Object bean) throws BeanCoderException { final XmlBeanCoder coder = new XmlBeanCoder(); coder.encode(bean); return coder.getResult(); }
protected Class currentClass () throws BeanCoderException { final String className = currentClassName(); try { return Class.forName(className); } catch (final Throwable t) { throw new BeanCoderException ("failed to find class named '"+className+"'", t); } }
/** * Overriding encodeBean() to make sure that XML content is embedded * into the XML tree under construction. */ protected void encodeBean (final Object bean) throws BeanCoderException { if (bean instanceof org.jdom.Content || bean instanceof org.jdom.Document) { encodeXmlContent(bean); return; } super.encodeBean(bean); }
/** * Loading an object from a file */ public static Object load (final String fileName) throws java.io.IOException, org.jdom.JDOMException, BeanCoderException { return xmlDecode(XmlUtils.extractXml(fileName, false)); }
protected Object[] asPropertyMapEntry (final Object key, final Object val) { if (isSafeForAnItemName(key) && (val == null || BeanCoderUtils.isPrimitive(val))) { return new Object[] { key, val }; } return null; }
protected void beginCollection (final java.util.Collection col) throws BeanCoderException { beginWithClass(E_COLLECTION, col); }
protected java.util.Iterator subElementIterator () throws BeanCoderException { return new ElementIterator(this.currentElement); }
protected void encodeEntry (final int index, final Object entry) throws BeanCoderException { encode(entry); }
protected void beginMapEntry () throws BeanCoderException { final org.jdom.Element elt = new org.jdom.Element(E_ENTRY); beginElement(elt); }
/** * Dumps any bean into its XML string representation; will never * throw any error (will return the error message as a string instead). */ public static String dumpToString (final Object bean) { try { return encodeToString(bean, null); } catch (final Throwable t) { return ">failed to dumpToString : "+t+"<"; } }
public static Object xmlDecode (final org.jdom.Document doc) throws BeanCoderException { final XmlBeanCoder coder = new XmlBeanCoder(doc); return coder.decode(); }
protected void beginBean (final Object bean) throws BeanCoderException { //beginWithClass(E_INSTANCE, bean); beginWithClass(E_BEAN, bean); }
protected void beginMap (final java.util.Map map) throws BeanCoderException { beginWithClass(E_MAP, map); }