/** * 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(); }
public static Object xmlDecode (final org.jdom.Element elt) throws BeanCoderException { final XmlBeanCoder coder = new XmlBeanCoder(elt); return coder.decode(); }
protected void encodeField (final String fieldName, final Object value) throws BeanCoderException { final org.jdom.Element elt = new org.jdom.Element(E_FIELD); elt.setAttribute(A_NAME, fieldName); beginElement(elt); encode(value); endElement(); }
/** * 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)); }
/** * Encoding a bean to an XML string. * If 'null' is given as encoding, the default encoding will be used. */ public static String encodeToString (final Object bean, final String encoding) throws BeanCoderException { final org.jdom.Document doc = xmlEncode(bean); return XmlUtils.toString(doc, encoding); }
private void loadState () { final java.io.File f = new java.io.File(this.cacheFileName); if ( ! f.exists()) { log.debug ("loadState() nothing to load, no file at "+this.cacheFileName); this.masters = new java.util.HashMap(); this.slaves = new java.util.HashMap(); return; } try { final java.util.Map state = (java.util.Map)XmlBeanCoder.load(this.cacheFileName); this.masters = (java.util.Map)state.get("masters"); this.slaves = (java.util.Map)state.get("slaves"); log.debug("loadState() done."); } catch (final Exception e) { log.warn("loadState() failure with file "+this.cacheFileName, e); } }
protected void encodeNull () throws BeanCoderException { addContent(new org.jdom.Element(E_NULL)); }
protected void beginMapEntry () throws BeanCoderException { final org.jdom.Element elt = new org.jdom.Element(E_ENTRY); beginElement(elt); }
protected void beginCollection (final java.util.Collection col) throws BeanCoderException { beginWithClass(E_COLLECTION, col); }
private FlowExpression deserializeExpressionAsXml(final Node c) throws Exception { if (!c.hasProperty(WorkflowConstants.NODEDATA_VALUE)) { return null; } final InputStream is = c.getProperty(WorkflowConstants.NODEDATA_VALUE).getStream(); final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(is); return (FlowExpression) XmlBeanCoder.xmlDecode(doc); }
private void serializeExpressionAsXml(final Node c, FlowExpression fe) throws Exception { final org.jdom.Document doc = XmlBeanCoder.xmlEncode(fe); final String s = XmlUtils.toString(doc, null); MgnlContext.doInSystemContext(new Op<Void, RepositoryException>() { @Override public Void exec() throws RepositoryException { c.setProperty(WorkflowConstants.NODEDATA_VALUE, s); return null; } }, true); }
(ParticipantExpression)XmlBeanCoder.load(fileName);
public static Object xmlDecode (final org.jdom.Document doc) throws BeanCoderException { final XmlBeanCoder coder = new XmlBeanCoder(doc); return coder.decode(); }
protected void encodeXmlContent (final Object xml) { org.jdom.Content con = null; if (xml instanceof org.jdom.Content) con = (org.jdom.Content)xml; else con = ((org.jdom.Document)xml).getRootElement(); final org.jdom.Element e = new org.jdom.Element(E_RAW_XML); con = (org.jdom.Content)con.clone(); con.detach(); e.addContent(con); addContent(e); }
/** * classy, isn't it ? */ protected void beginWithClass (final String eltName, final Object bean) { final org.jdom.Element elt = new org.jdom.Element(eltName); elt.setAttribute(A_CLASS, bean.getClass().getName()); beginElement(elt); }
protected void beginBean (final Object bean) throws BeanCoderException { //beginWithClass(E_INSTANCE, bean); beginWithClass(E_BEAN, bean); }
/** * Saving a bean / instance to a file */ public static void save (final String fileName, final Object bean) { java.io.FileOutputStream fos = null; try { fos = new java.io.FileOutputStream(fileName); save(fos, bean); } catch (final Throwable t) { log.error ("save() failed to open outputstream to file "+fileName, t); } }
/** * 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+"<"; } }