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> <objects>
* <class name='c' classname='Foo' />
* </objects></pre>
*
* The object 'c' will be an instance of java.lang.Class<Foo>.
* 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;
}
}