Package org.jbpm.wire.binding

Source Code of org.jbpm.wire.binding.ClassBinding

package org.jbpm.wire.binding;

import org.jbpm.wire.descriptor.ClassDescriptor;
import org.jbpm.wire.xml.WireParser;
import org.jbpm.xml.Binding;
import org.jbpm.xml.Parse;
import org.jbpm.xml.Parser;
import org.jbpm.xml.XmlUtil;
import org.w3c.dom.Element;

/**
* <p>this {@link Binding} specifies a {@link ClassDescriptor}.</p>
*
* <p>A Class descriptor is defined by a <b><code>{@literal <class>}</code></b> xml element.</p>
*
* <p>This element can have an attribute "name", which specifies the name of the created object in the WireContext.</p>
* <p>This element must have an attribute "classname", which specifies the name of the class to load as an object.</p>
*
* <h3>Example</h3>
*
* Consider the following class:
* <pre>public class Foo { ... }</pre>
*
* The following Xml declaration will load the class 'Foo' and store it under the name 'c' in the WireContext.
* <pre> &lt;objects&gt;
*   &lt;class name='c' classname='Foo' /&gt;
* &lt;/objects&gt;</pre>
*
* The object 'c' will be an instance of java.lang.Class&lt;Foo&gt;.
* The method <code>c.newInstance()</code> can for example be used to create a new instance of 'Foo'.
*
* @see WireParser
*
* @author Tom Baeyens
* @author Guillaume Porcher (documentation)
*/
public class ClassBinding implements Binding {

  public Object parse(Element element, Parse parse, Parser parser) {
    ClassDescriptor classDescriptor = null;
    String className = XmlUtil.attribute(element, "classname");
    if (className!=null) {
      classDescriptor = new ClassDescriptor();
      classDescriptor.setClassName(className);
    } else {
      parse.addProblem("class must have classname attribute: "+XmlUtil.toString(element));
    }
    return classDescriptor;
  }

}
TOP

Related Classes of org.jbpm.wire.binding.ClassBinding

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.