To integrate x4o as parser for your language there needs to be a few minimal steps be te taken, to have a working language.
public class FooBarParser extends X4OParser { static public String FOOBAR_LANGUAGE = "foobar"; public FooBarParser() throws Exception { super(FOOBAR_LANGUAGE); } }
public class FooBarParserSupport implements X4OParserSupport { public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException { FooBarParser parser = new FooBarParser(); return parser.loadElementLanguageSupport(); } public TestBeanRoot getRoot() { // Simple way to return single root object. // note; element tree is cleared after parsing only root element is there. return (TestBeanRoot)getDriver().getElementLanguage().getRootElement().getElementObject(); } }
Create the file "META-INF/foobar/foobar-modules.xml" with:
<?xml version="1.0" encoding="UTF-8"?> <modules version="1.0" xmlns="http://language.x4o.org/xml/ns/modules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd" > <language version="1.0"> <eld-resource>foobar-lang.eld</eld-resource> </language> </modules>
Create the file "META-INF/foobar/foobar-lang.eld" with:
<?xml version="1.0" encoding="UTF-8"?> <root:module xmlns:root="http://eld.x4o.org/xml/ns/eld-root" xmlns:eld="http://eld.x4o.org/xml/ns/eld-lang" xmlns:conv="http://eld.x4o.org/xml/ns/eld-conv" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd" providerName="foobar.test.x4o.org" name="FooBar Language" id="foobar" > <eld:classBindingHandler id="test1" bean.class="org.foo.bar.x4o.MyFooBarBindingHandler"/> <eld:classBindingHandler id="test2" parentClass="org.foo.bar.TestObjectParent" childClass="org.foo.bar.TestObjectChild" method="addTestObjectChild"/> <eld:elementInterface id="JComponent" interfaceClass="javax.swing.JComponent"> <eld:classBindingHandler id="JComponent-JComponent" parentClass="javax.swing.JComponent" childClass="javax.swing.JComponent" method="add"/> </eld:elementInterface> <eld:namespace uri="http://foobar.test.x4o.org/xml/ns/foobar-root" schemaUri="http://test.x4o.org/xml/ns/foobar-root-1.0.xsd" schemaResource="foobar-root-1.0.xsd" schemaPrefix="root" name="FooBar Root Namespace" languageRoot="true" > <eld:element tag="root" objectClass="org.foo.bar.TestBeanRoot"> <eld:description>The root element.</eld:description> </eld:element> </eld:namespace> <eld:namespace uri="http://foobar.test.x4o.org/xml/ns/foobar-lang" schemaUri="http://foobar.test.x4o.org/xml/ns/foobar-lang-1.0.xsd" schemaResource="foobar-lang-1.0.xsd" schemaPrefix="lang" name="FooBar Language Namespace" > <eld:element tag="testBean" objectClass="org.foo.bar.TestBean"/> <!-- etc --> </eld:namespace> </root:module>
Now you can startup the parser to see it work.