Made eld docs more compleet and updated xsd to add missing description

tag.
This commit is contained in:
Willem Cazander 2012-12-20 22:39:28 +01:00
parent 91064df3f3
commit aa9c9743d7
22 changed files with 609 additions and 124 deletions

View file

@ -53,7 +53,6 @@
##CODE
- Add (super) tag for extending tags of other namespace
- Add EldInfo element
- XMLOverrideEvent
- inboud sax parser !!
- input stream output converter :)
@ -71,5 +70,4 @@
- Xinclude option
- SAX events as input source
- (70%) XML debug output
- (20%) x4o comment element

View file

@ -217,7 +217,7 @@ public class EldModuleLoaderCore implements ElementLanguageModuleLoader {
ec = new DefaultElementClass("bindingHandler",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "elementInterface");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("id");
@ -247,8 +247,8 @@ public class EldModuleLoaderCore implements ElementLanguageModuleLoader {
ec = new DefaultElementClass("configurator",null,BeanElement.class);
//ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "elementInterface");
ec.addElementParent("", "element");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("bean.class");
@ -282,17 +282,18 @@ public class EldModuleLoaderCore implements ElementLanguageModuleLoader {
ec = new DefaultElementClass("description",null,DescriptionElement.class);
ec.setSchemaContentBase("string");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "attributeHandler");
ec.addElementParent("", "bindingHandler");
ec.addElementParent("", "configurator");
ec.addElementParent("", "configuratorGlobal");
ec.addElementParent("", "elementInterface");
ec.addElementParent("", "element");
ec.addElementParent("", "attribute");
ec.addElementParent(CEL_CORE_URI, "namespace");
ec.addElementParent(CEL_CORE_URI, "attributeHandler");
ec.addElementParent(CEL_CORE_URI, "bindingHandler");
ec.addElementParent(CEL_CORE_URI, "configurator");
ec.addElementParent(CEL_CORE_URI, "configuratorGlobal");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "attribute");
elementClassList.add(ec);
ec = new DefaultElementClass("elementParent",null,ElementClassAddParentElement.class);
ec.addElementParent("", "element");
ec.addElementParent(CEL_CORE_URI, "element");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("tag");

View file

@ -46,7 +46,7 @@ public class ElementClassAddParentElement extends AbstractElement {
}
String namespaceUri = getAttributes().get("uri");
if (namespaceUri==null) {
namespaceUri = ""; // current namespace ?
namespaceUri = getParent().getParent().getAttributes().get("uri"); // copy uri from namespace element.
}
if (getParent().getElementObject() instanceof ElementClass) {
((ElementClass)getParent().getElementObject()).addElementParent(namespaceUri,tag);

View file

@ -369,12 +369,6 @@ public class EldXsdXmlWriter {
if (parents!=null && parents.contains(ec.getTag())) {
refElements.add(checkClass.getTag());
}
if (nsWrite.getUri().equals(ns.getUri())) {
parents = checkClass.getElementParents("");
if (parents!=null && parents.contains(ec.getTag())) {
refElements.add(checkClass.getTag());
}
}
if (ec.getObjectClass()==null) {
continue;
}

View file

@ -111,6 +111,12 @@ public abstract class AbstractElementClass extends AbstractElementClassBase impl
* @see org.x4o.xml.element.ElementClass#addElementParent(java.lang.String,java.lang.String)
*/
public void addElementParent(String namespaceUri,String tag) {
if (namespaceUri==null) {
throw new NullPointerException("Can't add parent tag with null namespace uri.");
}
if (namespaceUri.isEmpty()) {
throw new IllegalArgumentException("Can't add parent tag with empty namespace uri.");
}
List<String> tags = elementParents.get(namespaceUri);
if (tags==null) {
tags = new ArrayList<String>(5);

View file

@ -123,9 +123,18 @@ public abstract class AbstractElementLanguageModule extends AbstractElementMetaB
* @see org.x4o.xml.element.ElementLanguageModule#addElementBindingHandler(ElementBindingHandler)
*/
public void addElementBindingHandler(ElementBindingHandler elementBindingHandler) {
if (elementBindingHandler==null) {
throw new NullPointerException("Can't add null binding handler.");
}
if (elementBindingHandler.getId()==null) {
throw new NullPointerException("Can't add with null id property.");
}
// Check so doc tree does not loop; see EldDocHtmlWriter.findChilderen()
for (Class<?> cl:elementBindingHandler.getBindChildClasses()) {
if (elementBindingHandler.getBindParentClass().equals(cl)) {
throw new IllegalStateException("Can't add binding handler: "+elementBindingHandler.getId()+" with same parent as child class.");
}
}
logger.finer("Adding ElementBindingHandler: "+elementBindingHandler);
elementBindingHandlers.add(elementBindingHandler);
}

View file

@ -7,25 +7,26 @@
ModuleName: Core Element Languag Module
Namespaces: 2
Namespace: http://cel.x4o.org/xml/ns/cel-core
Created on: Sun Nov 18 06:22:14 CET 2012
Created on: Thu Dec 20 22:30:55 CET 2012
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:this="http://cel.x4o.org/xml/ns/cel-core"
version="1.0" elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://cel.x4o.org/xml/ns/cel-core">
<complexType name="namespaceType">
<choice minOccurs="0" maxOccurs="unbounded">
<element name="description" type="this:descriptionType"/>
<element name="element" type="this:elementType"/>
</choice>
<attribute name="uri" type="string" use="required"/>
<attribute name="name" type="string"/>
<attribute name="prefixMapping" type="string"/>
<attribute name="elementNamespaceInstanceProvider" type="string"/>
<attribute name="schemaUri" type="string"/>
<attribute name="schemaResource" type="string"/>
<attribute name="schemaPrefix" type="string"/>
<attribute name="languageRoot" type="boolean"/>
<attribute name="elementNamespaceInstanceProvider" type="string"/>
<attribute name="schemaUri" type="string"/>
<attribute name="id" type="string"/>
<attribute name="prefixMapping" type="string"/>
<attribute name="description" type="string"/>
<attribute name="id" type="string"/>
</complexType>
<complexType name="descriptionType">
<simpleContent>
@ -44,12 +45,12 @@
<attribute name="objectClass" type="string"/>
<attribute name="elementClass" type="string"/>
<attribute name="tag" type="string"/>
<attribute name="schemaContentBase" type="string"/>
<attribute name="autoAttributes" type="boolean"/>
<attribute name="schemaContentComplex" type="boolean"/>
<attribute name="schemaContentMixed" type="boolean"/>
<attribute name="autoAttributes" type="boolean"/>
<attribute name="id" type="string"/>
<attribute name="schemaContentBase" type="string"/>
<attribute name="description" type="string"/>
<attribute name="id" type="string"/>
</complexType>
<complexType name="configuratorGlobalType">
<choice minOccurs="0" maxOccurs="unbounded">
@ -80,14 +81,14 @@
<element name="description" type="this:descriptionType"/>
</choice>
<attribute name="name" type="string"/>
<attribute name="defaultValue" type="string"/>
<attribute name="required" type="boolean"/>
<attribute name="runResolveEL" type="boolean"/>
<attribute name="runConverters" type="boolean"/>
<attribute name="runBeanFill" type="boolean"/>
<attribute name="defaultValue" type="string"/>
<attribute name="objectConverter" type="string"/>
<attribute name="required" type="boolean"/>
<attribute name="id" type="string"/>
<attribute name="runBeanFill" type="boolean"/>
<attribute name="description" type="string"/>
<attribute name="id" type="string"/>
</complexType>
<complexType name="classConverterType">
<choice minOccurs="0" maxOccurs="unbounded"/>
@ -108,8 +109,8 @@
<element name="description" type="this:descriptionType"/>
</choice>
<attribute name="interfaceClass" type="string"/>
<attribute name="id" type="string"/>
<attribute name="description" type="string"/>
<attribute name="id" type="string"/>
</complexType>
<complexType name="elementParentType">
<choice minOccurs="0" maxOccurs="unbounded"/>

View file

@ -7,7 +7,7 @@
ModuleName: Core Element Languag Module
Namespaces: 2
Namespace: http://cel.x4o.org/xml/ns/cel-root
Created on: Sun Nov 18 06:22:14 CET 2012
Created on: Thu Dec 20 22:30:55 CET 2012
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:cel-core="http://cel.x4o.org/xml/ns/cel-core"
@ -25,10 +25,10 @@
</choice>
<attribute name="name" type="string"/>
<attribute name="providerName" type="string"/>
<attribute name="sourceResource" type="string"/>
<attribute name="elementLanguageModuleLoader" type="string"/>
<attribute name="id" type="string"/>
<attribute name="sourceResource" type="string"/>
<attribute name="description" type="string"/>
<attribute name="id" type="string"/>
</complexType>
</element>
</schema>

View file

@ -7,7 +7,7 @@
ModuleName: Element Language Definition
Namespaces: 3
Namespace: http://eld.x4o.org/xml/ns/eld-conv
Created on: Sun Nov 18 06:22:58 CET 2012
Created on: Thu Dec 20 22:30:10 CET 2012
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:this="http://eld.x4o.org/xml/ns/eld-conv"

View file

@ -7,7 +7,7 @@
ModuleName: Element Language Definition
Namespaces: 3
Namespace: http://eld.x4o.org/xml/ns/eld-lang
Created on: Sun Nov 18 06:22:58 CET 2012
Created on: Thu Dec 20 22:30:10 CET 2012
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:conv="http://eld.x4o.org/xml/ns/eld-conv"
@ -16,16 +16,17 @@
<import namespace="http://eld.x4o.org/xml/ns/eld-conv" schemaLocation="eld-conv-1.0.xsd"/>
<complexType name="namespaceType">
<choice minOccurs="0" maxOccurs="unbounded">
<element name="description" type="this:descriptionType"/>
<element name="element" type="this:elementType"/>
</choice>
<attribute name="uri" type="string" use="required"/>
<attribute name="name" type="string"/>
<attribute name="elementNamespaceInstanceProvider" type="string"/>
<attribute name="schemaUri" type="string"/>
<attribute name="schemaResource" type="string"/>
<attribute name="schemaPrefix" type="string"/>
<attribute name="prefixMapping" type="string"/>
<attribute name="languageRoot" type="boolean"/>
<attribute name="elementNamespaceInstanceProvider" type="string"/>
<attribute name="prefixMapping" type="string"/>
<attribute name="id" type="string"/>
<attribute name="description" type="string"/>
</complexType>

View file

@ -32,6 +32,7 @@
providerName="eld.x4o.org"
id="eld-module"
>
<description>The full element language definition(eld) which is used to define xml languages.</description>
<bindingHandler id="ElementClassBindingHandler" bean.class="org.x4o.xml.eld.lang.ElementClassBindingHandler"/>
<bindingHandler id="ElementModuleBindingHandler" bean.class="org.x4o.xml.eld.lang.ElementModuleBindingHandler"/>
@ -50,7 +51,7 @@
languageRoot="true"
id="eld-root"
>
<!-- Root Element for nice namespace'ing -->
<description>Single root namespace so xsd schema generation works correct.</description>
<element tag="module" objectClass="${parentLanguageConfiguration.defaultElementLanguageModule}" elementClass="org.x4o.xml.eld.lang.ModuleElement">
<attribute name="id" required="true">
<description>The module id.</description>
@ -67,6 +68,7 @@
name="Element Language Definition"
id="eld-lang"
>
<description>Some basic language definitions and some helper tags.</description>
<!-- First copy some core elements over from parent config -->
<element tag="namespace" objectClass="${parentLanguageConfiguration.defaultElementNamespaceContext}">
@ -160,6 +162,7 @@
<element tag="description" elementClass="org.x4o.xml.eld.lang.DescriptionElement" schemaContentBase="string">
<description>An ELD elementDescription field which lets you type text like this one in xml characters instead of an attribute.</description>
<elementParent tag="module" uri="http://eld.x4o.org/xml/ns/eld-root"/>
<elementParent tag="namespace"/>
<elementParent tag="bindingHandler"/>
<elementParent tag="attributeHandler"/>
<elementParent tag="configurator"/>
@ -267,7 +270,8 @@
name="Element Attribute Converters"
id="eld-conv"
>
<!-- Config all converters, move ? -->
<description>Basic set of attribute value converters.</description>
<element tag="beanConverter" elementClass="org.x4o.xml.eld.lang.BeanElement">
<description>Define an loadable in bean.class for an ObjectConverter.</description>
<attribute name="bean.class">

View file

@ -7,7 +7,7 @@
ModuleName: Element Language Definition
Namespaces: 3
Namespace: http://eld.x4o.org/xml/ns/eld-root
Created on: Sun Nov 18 06:22:58 CET 2012
Created on: Thu Dec 20 22:30:10 CET 2012
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:conv="http://eld.x4o.org/xml/ns/eld-conv"
@ -29,9 +29,9 @@
</choice>
<attribute name="id" type="string" use="required"/>
<attribute name="name" type="string"/>
<attribute name="sourceResource" type="string"/>
<attribute name="elementLanguageModuleLoader" type="string"/>
<attribute name="providerName" type="string"/>
<attribute name="elementLanguageModuleLoader" type="string"/>
<attribute name="sourceResource" type="string"/>
<attribute name="description" type="string"/>
</complexType>
</element>

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.test.swixml.bind;
import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
*
*
* @author Willem Cazander
* @version 1.0 Aug 16, 2012
*/
public class JFrameBindingHandler extends AbstractElementBindingHandler {
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return JFrame.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return new Class[] {JMenuBar.class,JComponent.class};
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException {
JFrame frame = (JFrame)parentObject;
if (childObject instanceof JMenuBar) {
JMenuBar child = (JMenuBar)childObject;
frame.getRootPane().setJMenuBar(child);
} else if (childObject instanceof JComponent) {
JComponent child = (JComponent)childObject;
String c = childElement.getAttributes().get("constraints");
Object con = null;
if ("BorderLayout.CENTER".equals(c)) {
con = BorderLayout.CENTER;
} else if ("BorderLayout.NORTH".equals(c)) {
con = BorderLayout.NORTH;
} else if ("BorderLayout.CENTER".equals(c)) {
con = BorderLayout.CENTER;
} else if ("BorderLayout.SOUTH".equals(c)) {
con = BorderLayout.SOUTH;
}
if (con==null) {
frame.getContentPane().add(child);
} else {
frame.getContentPane().add(child,con);
}
}
}
}

View file

@ -25,13 +25,8 @@ package org.x4o.xml.test.swixml.bind;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
@ -43,14 +38,13 @@ import org.x4o.xml.element.ElementBindingHandlerException;
* @author Willem Cazander
* @version 1.0 Aug 16, 2012
*/
public class JComponentBindingHandler extends AbstractElementBindingHandler {
public class JInternalFrameBindingHandler extends AbstractElementBindingHandler {
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return JComponent.class;
//return new Class[] {JPanel.class,JScrollPane.class,JSplitPane.class,JFrame.class,JInternalFrame.class};
return JInternalFrame.class;
}
/**
@ -78,41 +72,11 @@ public class JComponentBindingHandler extends AbstractElementBindingHandler {
con = BorderLayout.SOUTH;
}
if (parentObject instanceof JSplitPane) {
JSplitPane pane = (JSplitPane)parentObject;
if (pane.getLeftComponent() instanceof JButton) { // strange swing constructor for splitpane
pane.setLeftComponent(child);
} else if (pane.getRightComponent() instanceof JButton) {
pane.setRightComponent(child);
} else {
throw new ElementBindingHandlerException("SplitPane is full.");
}
} else if (parentObject instanceof JScrollPane) {
JScrollPane pane = (JScrollPane)parentObject;
pane.setViewportView(child);
} else if (parentObject instanceof JFrame) {
JFrame frame = (JFrame)parentObject;
if (con==null) {
frame.getContentPane().add(child);
} else {
frame.getContentPane().add(child,con);
}
} else if (parentObject instanceof JInternalFrame) {
JInternalFrame frame = (JInternalFrame)parentObject;
if (con==null) {
frame.getContentPane().add(child);
} else {
frame.getContentPane().add(child,con);
}
} else if (parentObject instanceof JPanel) {
JPanel parent = (JPanel)parentObject;
if (con==null) {
parent.add(child);
} else {
parent.add(child,con);
}
} else {
// No bind but this destroys the xsd, change into multiple classes.
}
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.test.swixml.bind;
import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
*
*
* @author Willem Cazander
* @version 1.0 Aug 16, 2012
*/
public class JPanelBindingHandler extends AbstractElementBindingHandler {
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return JPanel.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return new Class[] {JComponent.class};
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException {
JComponent child = (JComponent)childObject;
String c = childElement.getAttributes().get("constraints");
Object con = null;
if ("BorderLayout.CENTER".equals(c)) {
con = BorderLayout.CENTER;
} else if ("BorderLayout.NORTH".equals(c)) {
con = BorderLayout.NORTH;
} else if ("BorderLayout.CENTER".equals(c)) {
con = BorderLayout.CENTER;
} else if ("BorderLayout.SOUTH".equals(c)) {
con = BorderLayout.SOUTH;
}
JPanel parent = (JPanel)parentObject;
if (con==null) {
parent.add(child);
} else {
parent.add(child,con);
}
}
}

View file

@ -23,41 +23,48 @@
package org.x4o.xml.test.swixml.bind;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JSplitPane;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
*
* JSplitPaneBindingHandler binds components to the JSplitPane
*
* @author Willem Cazander
* @version 1.0 Aug 16, 2012
*/
public class JMenuBarBindingHandler extends AbstractElementBindingHandler {
public class JSplitPaneBindingHandler extends AbstractElementBindingHandler {
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return JFrame.class;
return JSplitPane.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return new Class[] {JMenuBar.class};
return new Class[] {JComponent.class};
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException {
JMenuBar child = (JMenuBar)childObject;
JFrame frame = (JFrame)parentObject;
frame.getRootPane().setJMenuBar(child);
JComponent child = (JComponent)childObject;
JSplitPane pane = (JSplitPane)parentObject;
if (pane.getLeftComponent() instanceof JButton) { // strange swing constructor for splitpane
pane.setLeftComponent(child);
} else if (pane.getRightComponent() instanceof JButton) {
pane.setRightComponent(child);
} else {
throw new ElementBindingHandlerException("SplitPane is full.");
}
}
}

View file

@ -34,8 +34,11 @@
id="swixml2-module"
>
<bindingHandler id="JComponentBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JComponentBindingHandler"/>
<bindingHandler id="JMenuBarBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JMenuBarBindingHandler"/>
<bindingHandler id="JFrameBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JFrameBindingHandler"/>
<bindingHandler id="JInternalFrameBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JInternalFrameBindingHandler"/>
<bindingHandler id="JPanelBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JPanelBindingHandler"/>
<bindingHandler id="JSplitPaneBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JSplitPaneBindingHandler"/>
<classBindingHandler id="JScrollPane-JComponent" parentClass="javax.swing.JScrollPane" childClass="javax.swing.JComponent" method="setViewportView"/>
<classBindingHandler id="JDesktopPane-JInternalFrame" parentClass="javax.swing.JDesktopPane" childClass="javax.swing.JInternalFrame" method="add"/>
<classBindingHandler id="JFrame-JDesktopPane" parentClass="javax.swing.JFrame" childClass="javax.swing.JDesktopPane" method="setContentPane"/>
<classBindingHandler id="JMenuBar-JMenu" parentClass="javax.swing.JMenuBar" childClass="javax.swing.JMenu" method="add"/>
@ -87,9 +90,10 @@
uri="http://swixml.x4o.org/xml/ns/swixml-root"
schemaUri="http://swixml.x4o.org/xml/ns/swixml-root-2.0.xsd"
schemaResource="swixml-root-2.0.xsd"
schemaPrefix="root"
schemaPrefix="sx-root"
name="Root element"
languageRoot="true"
id="sx-root"
>
<!-- Single element in language root to create nice tree, for imports in xsd namespace aware generated files. -->
<element tag="frame" objectClass="javax.swing.JFrame"/>
@ -99,6 +103,7 @@
schemaUri="http://swixml.x4o.org/xml/ns/swixml-lang-2.0.xsd"
schemaResource="swixml-lang-2.0.xsd"
schemaPrefix="sx-lang"
id="sx-lang"
>
<!-- Note frame should not be here(it can but xsd needs root), but else classic xml does not parse without xmlns additions. -->
<element tag="frame" objectClass="javax.swing.JFrame"/>

View file

@ -34,8 +34,11 @@
id="swixml3-module"
>
<bindingHandler id="JComponentBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JComponentBindingHandler"/>
<bindingHandler id="JMenuBarBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JMenuBarBindingHandler"/>
<bindingHandler id="JFrameBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JFrameBindingHandler"/>
<bindingHandler id="JInternalFrameBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JInternalFrameBindingHandler"/>
<bindingHandler id="JPanelBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JPanelBindingHandler"/>
<bindingHandler id="JSplitPaneBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JSplitPaneBindingHandler"/>
<classBindingHandler id="JScrollPane-JComponent" parentClass="javax.swing.JScrollPane" childClass="javax.swing.JComponent" method="setViewportView"/>
<classBindingHandler id="JDesktopPane-JInternalFrame" parentClass="javax.swing.JDesktopPane" childClass="javax.swing.JInternalFrame" method="add"/>
<classBindingHandler id="JFrame-JDesktopPane" parentClass="javax.swing.JFrame" childClass="javax.swing.JDesktopPane" method="setContentPane"/>
<classBindingHandler id="JMenuBar-JMenu" parentClass="javax.swing.JMenuBar" childClass="javax.swing.JMenu" method="add"/>
@ -84,9 +87,10 @@
uri="http://swixml.x4o.org/xml/ns/swixml-root"
schemaUri="http://swixml.x4o.org/xml/ns/swixml-root-3.0.xsd"
schemaResource="swixml-root-3.0.xsd"
schemaPrefix="root"
schemaPrefix="sx-root"
name="Root element"
languageRoot="true"
id="sx-root"
>
<element tag="JFrame" objectClass="javax.swing.JFrame"/>
</namespace>
@ -95,6 +99,7 @@
schemaUri="http://swixml.x4o.org/xml/ns/swixml-lang-3.0.xsd"
schemaResource="swixml-lang-3.0.xsd"
schemaPrefix="sx-lang"
id="sx-lang"
>
<element tag="JMenubar" objectClass="javax.swing.JMenuBar"/>
<element tag="JMenu" objectClass="javax.swing.JMenu"/>

View file

@ -56,6 +56,7 @@ public class EldDocGenerator {
writer.writeStylesheet(basePath);
writer.writeOverviewModule(basePath, context);
writer.writeOverviewNamespace(basePath, context);
writer.writeOverviewTree(basePath, context);
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
@ -88,7 +89,7 @@ public class EldDocGenerator {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
writer.writeOverviewElement(basePath, ns,mod);
for (ElementClass ec:ns.getElementClasses()) {
writer.writeElement(basePath, ec, ns, mod);
writer.writeElement(basePath, ec, ns, mod,context);
for (ElementConfigurator conf:ec.getElementConfigurators()) {
writer.writeElementConfigurator(basePath,conf,mod,ns,ec);
}

View file

@ -29,6 +29,8 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@ -100,6 +102,9 @@ public class EldDocHtmlWriter {
buf.append(File.separatorChar);
buf.append(toSafeUri(argu[argu.length-1]));
File outputFile = new File(buf.toString());
if (outputFile.exists()) {
outputFile.delete();
}
//System.out.println("Creating file: "+outputFile);
PrintWriter pw = new PrintWriter(outputFile);
return pw;
@ -143,13 +148,13 @@ public class EldDocHtmlWriter {
int elements = 0;
int namespaces = 0;
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
attrHandlers =+ mod.getElementAttributeHandlers().size();
bindHandlers =+ mod.getElementBindingHandlers().size();
interFaces =+ mod.getElementInterfaces().size();
eleConfigs =+ mod.getElementConfiguratorGlobals().size();
attrHandlers += mod.getElementAttributeHandlers().size();
bindHandlers += mod.getElementBindingHandlers().size();
interFaces += mod.getElementInterfaces().size();
eleConfigs += mod.getElementConfiguratorGlobals().size();
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
namespaces++;
elements =+ ns.getElementClasses().size();
elements += ns.getElementClasses().size();
}
}
@ -178,7 +183,7 @@ public class EldDocHtmlWriter {
PrintWriter pw = createPrintWriter(basePath,"module-overview.html");
try {
String title = context.getLanguageConfiguration().getLanguage()+" "+context.getLanguageConfiguration().getLanguageVersion()+" ELD";
printHeader(pw,"Overview ("+title+")","");
printHeader(pw,"Overview Modules ("+title+")","");
printPageIndexTitle(pw,title,null,null);
printTableStart(pw,"Modules");
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
@ -198,7 +203,7 @@ public class EldDocHtmlWriter {
String pathPrefix = "";
try {
String title = context.getLanguageConfiguration().getLanguage()+" "+context.getLanguageConfiguration().getLanguageVersion()+" ELD";
printHeader(pw,"Overview ("+title+")",pathPrefix);
printHeader(pw,"Overview Namespace("+title+")",pathPrefix);
printPageIndexTitle(pw,title,null,null);
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
printNamespaces(pw,mod.getElementNamespaceContexts(),pathPrefix,mod);
@ -211,6 +216,179 @@ public class EldDocHtmlWriter {
}
}
public void writeOverviewTree(File basePath,ElementLanguage context) throws IOException {
PrintWriter pw = createPrintWriter(basePath,"tree-overview.html");
String pathPrefix = "";
try {
String title = context.getLanguageConfiguration().getLanguage()+" "+context.getLanguageConfiguration().getLanguageVersion()+" ELD";
printHeader(pw,"Overview Tree ("+title+")",pathPrefix);
printPageIndexTitle(pw,title,null,null);
List<TreeNode> rootNodes = new ArrayList<TreeNode>(3);
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
if (ns.getLanguageRoot()!=null && ns.getLanguageRoot()) {
// found language root elements.
for (ElementClass ec:ns.getElementClasses()) {
TreeNode node = new TreeNode();
node.context=context;
node.module=mod;
node.namespace=ns;
node.elementClass=ec;
rootNodes.add(node);
}
}
}
}
for (TreeNode rootNode:rootNodes) {
walkTree(rootNode,pw,pathPrefix);
}
printBottom(pw,pathPrefix);
} finally {
if (pw!=null) {
pw.close();
}
}
}
class TreeNode {
ElementLanguage context;
ElementLanguageModule module;
ElementNamespaceContext namespace;
ElementClass elementClass;
TreeNode parent;
int indent = 0;
}
private void walkTree(TreeNode node,PrintWriter pw,String pathPrefix) {
for (int i=0;i<node.indent;i++) {
pw.print(TAB);
}
pw.print("-&nbsp;<a href=\"");
pw.print(pathPrefix);
pw.print(toSafeUri(node.module.getId()));
pw.print("/");
pw.print(toSafeUri(node.namespace.getId()));
pw.print("/");
pw.print(toSafeUri(node.elementClass.getTag()));
pw.print("/index.html\">");
pw.print(node.namespace.getId());
pw.print(":");
pw.print(node.elementClass.getTag());
pw.print("</a><br/>\n");
List<TreeNode> childs = findChilderen(node);
for (TreeNode child:childs) {
walkTree(child,pw,pathPrefix);
}
}
private List<TreeNode> findChilderen(TreeNode node) {
List<TreeNode> result = new ArrayList<TreeNode>(10);
if (node.indent>20) {
return result; // hard fail limit
}
for (ElementLanguageModule mod:node.context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
for (ElementClass ec:ns.getElementClasses()) {
TreeNode n=null;
List<String> tags = ec.getElementParents(node.namespace.getUri());
if (tags!=null && tags.contains(node.elementClass.getTag())) {
n = new TreeNode();
n.context=node.context;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
} else {
if (node.elementClass.getObjectClass()==null | ec.getObjectClass()==null) {
continue;
}
List<ElementBindingHandler> binds = node.context.findElementBindingHandlers(node.elementClass.getObjectClass(), ec.getObjectClass());
if (binds.isEmpty()==false) {
n = new TreeNode();
n.context=node.context;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
}
}
if (n!=null && isInTree(node,n)==false) {
result.add(n);
}
}
}
}
return result;
}
private boolean isInTree(TreeNode node,TreeNode checkNode) {
if (node.namespace.getUri().equals(checkNode.namespace.getUri())) {
if (node.elementClass.getTag().equals(checkNode.elementClass.getTag())) {
return true;
}
}
if (node.parent!=null) {
return isInTree(node.parent,checkNode);
}
return false;
}
private List<TreeNode> findParents(TreeNode node) {
List<TreeNode> result = new ArrayList<TreeNode>(10);
TreeNode n=null;
for (ElementLanguageModule mod:node.context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
List<String> tags = node.elementClass.getElementParents(ns.getUri());
if (tags!=null) {
for (ElementClass ec:ns.getElementClasses()) {
if (tags.contains(ec.getTag())) {
n = new TreeNode();
n.context=node.context;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
result.add(n);
}
}
}
for (ElementClass ec:ns.getElementClasses()) {
if (node.elementClass.getObjectClass()==null | ec.getObjectClass()==null) {
continue;
}
List<ElementBindingHandler> binds = node.context.findElementBindingHandlers(ec.getObjectClass(),node.elementClass.getObjectClass());
if (binds.isEmpty()==false) {
n = new TreeNode();
n.context=node.context;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
if (isInTree(node,n)==false) {
result.add(n);
}
}
}
}
}
return result;
}
public void writeOverviewModule(File basePath,ElementLanguageModule mod) throws IOException {
PrintWriter pw = createPrintWriter(basePath,mod.getId(),"index.html");
String pathPrefix = "../";
@ -255,28 +433,98 @@ public class EldDocHtmlWriter {
}
}
public void writeElement(File basePath,ElementClass ec,ElementNamespaceContext ns,ElementLanguageModule mod) throws IOException {
private String printList(List<String> list) {
StringBuffer buf = new StringBuffer(40);
buf.append("[L: ");
if (list.isEmpty()) {
buf.append("Empty.");
}
for (String s:list) {
buf.append(s);
buf.append(' ');
}
buf.append("]");
return buf.toString();
}
public void writeElement(File basePath,ElementClass ec,ElementNamespaceContext ns,ElementLanguageModule mod,ElementLanguage context) throws IOException {
PrintWriter pw = createPrintWriter(basePath,mod.getId(),ns.getId(),ec.getTag(),"index.html");
String pathPrefix = "../../../";
try {
printHeader(pw,"Tag ("+ec.getTag()+")",pathPrefix);
printPageTitle(pw,"Tag",ec.getTag(),ec.getDescription());
TreeNode node = new TreeNode();
node.context=context;
node.module=mod;
node.namespace=ns;
node.elementClass=ec;
List<TreeNode> parents = findParents(node);
printTableStart(pw,"Element Parents");
pw.print("\t<tr class=\"TableRowColor\">\n");
pw.print("\t\t<td colspan=\"2\">");
if (parents.isEmpty()) {
pw.print("No parent.");
}
for (TreeNode n:parents) {
pw.print("\t\t\t&nbsp;<a href=\"");
pw.print(pathPrefix);
pw.print(toSafeUri(n.module.getId()));
pw.print("/");
pw.print(toSafeUri(n.namespace.getId()));
pw.print("/");
pw.print(toSafeUri(n.elementClass.getTag()));
pw.print("/index.html\">");
pw.print(n.namespace.getId());
pw.print(":");
pw.print(n.elementClass.getTag());
pw.print("</a>\n");
}
pw.print("</td>\n");
pw.print("\t</tr>\n");
printTableEnd(pw);
List<TreeNode> childs = findChilderen(node);
printTableStart(pw,"Element Childeren");
pw.print("\t<tr class=\"TableRowColor\">\n");
pw.print("\t\t<td colspan=\"2\">");
if (childs.isEmpty()) {
pw.print("No childeren.");
}
for (TreeNode n:childs) {
pw.print("\t\t\t&nbsp;<a href=\"");
pw.print(pathPrefix);
pw.print(toSafeUri(n.module.getId()));
pw.print("/");
pw.print(toSafeUri(n.namespace.getId()));
pw.print("/");
pw.print(toSafeUri(n.elementClass.getTag()));
pw.print("/index.html\">");
pw.print(n.namespace.getId());
pw.print(":");
pw.print(n.elementClass.getTag());
pw.print("</a>\n");
}
pw.print("</td>\n");
pw.print("\t</tr>\n");
printTableEnd(pw);
printTableStart(pw,"Element Properties");
printTableRowSummary(pw,"id",""+ec.getId());
printTableRowSummary(pw,"tag",""+ec.getTag());
printTableRowSummary(pw,"objectClass",""+ec.getObjectClass());
printTableRowSummary(pw,"elementClass",""+ec.getElementClass());
printTableRowSummary(pw,"autoAttributes",""+ec.getAutoAttributes());
printTableRowSummary(pw,"skipPhases",printList(ec.getSkipPhases()));
printTableRowSummary(pw,"schemaContentBase",""+ec.getSchemaContentBase());
printTableRowSummary(pw,"schemaContentComplex",""+ec.getSchemaContentComplex());
printTableRowSummary(pw,"schemaContentMixed",""+ec.getSchemaContentMixed());
//printTableRowSummary(pw,"description",""+ec.getDescription());
printTableEnd(pw);
printTableStart(pw,"Element Attributes");
for (ElementClassAttribute attr:ec.getElementClassAttributes()) {
printTableRowSummary(pw,attr.getName(),attr.getDescription());
}
printTableEnd(pw);
printElementAttributes(pw,ec.getElementClassAttributes());
if (ec.getObjectClass()!=null) {
printClassProperties(pw, ec.getObjectClass());
}
@ -300,7 +548,8 @@ public class EldDocHtmlWriter {
printConfigurators(pw,iface.getElementConfigurators(),pathLocal);
printBindingHandlers(pw,iface.getElementBindingHandlers(),pathLocal);
//iface.getElementClassAttributes()
printElementAttributes(pw,iface.getElementClassAttributes());
printBeanProperties(pw, iface);
printBottom(pw,pathPrefix);
@ -366,11 +615,13 @@ public class EldDocHtmlWriter {
printHeader(pw,"BindingHandler ("+bind.getId()+")",pathPrefix);
printPageTitle(pw,"BindingHandler",bind.getId(),bind.getDescription());
/*
printTableStart(pw,"Child Classes");
for (Class<?> clazz:bind.getBindChildClasses()) {
printTableRowSummary(pw,"class",""+clazz.getName());
}
printTableEnd(pw);
*/
printBeanProperties(pw, bind);
printBottom(pw,pathPrefix);
} finally {
@ -458,12 +709,62 @@ public class EldDocHtmlWriter {
e.printStackTrace();
}
printTableRowSummary(pw,n,""+value);
printTableRowSummary(pw,n,printValue(value));
}
}
printTableEnd(pw);
}
private String printValue(Object value) {
if (value==null) {
return "null";
}
if (value instanceof String) {
return (String)value;
}
if (value instanceof Class) {
return "class "+((Class<?>)value).getName();
}
if (value instanceof List) {
StringBuffer buf = new StringBuffer(100);
buf.append("[L: ");
List<?> l = (List<?>)value;
if (l.isEmpty()) {
buf.append("Empty");
}
for (Object o:l) {
buf.append(""+o);
buf.append(" ");
}
buf.append("]");
return buf.toString();
}
if (value instanceof Object[]) {
StringBuffer buf = new StringBuffer(100);
buf.append("[A: ");
Object[] l = (Object[])value;
if (l.length==0) {
buf.append("Empty");
}
for (Object o:l) {
buf.append(""+o);
buf.append(" ");
}
buf.append("]");
return buf.toString();
}
return value.toString();
}
private void printElementAttributes(PrintWriter pw,Collection<ElementClassAttribute> elementClassAttributes) {
printTableStart(pw,"Element Attributes");
for (ElementClassAttribute attr:elementClassAttributes) {
printTableRowSummary(pw,attr.getName(),attr.getDescription());
}
printTableEnd(pw);
}
private void printNamespaces(PrintWriter pw,List<ElementNamespaceContext> namespaces,String pathPrefix ,ElementLanguageModule mod) {
printTableStart(pw,"Namespaces");
for (ElementNamespaceContext ns:namespaces) {
@ -564,6 +865,7 @@ public class EldDocHtmlWriter {
if (description!=null) {
pw.print(description);
pw.print("<br/>\n");
pw.print("<br/>\n");
}
}
@ -676,5 +978,6 @@ public class EldDocHtmlWriter {
pw.print("\t\t<td class=\"NavBarCell1\"><a href=\""+pathPrefix+"index.html\">Index</a>&nbsp;</td>\n");
pw.print("\t\t<td class=\"NavBarCell1\"><a href=\""+pathPrefix+"module-overview.html\">Modules</a>&nbsp;</td>\n");
pw.print("\t\t<td class=\"NavBarCell1\"><a href=\""+pathPrefix+"namespace-overview.html\">Namespaces</a>&nbsp;</td>\n");
pw.print("\t\t<td class=\"NavBarCell1\"><a href=\""+pathPrefix+"tree-overview.html\">Tree</a>&nbsp;</td>\n");
}
}

View file

@ -26,7 +26,9 @@ package org.x4o.xml.eld.doc;
import java.io.File;
import org.x4o.xml.eld.EldParserSupport;
import org.x4o.xml.eld.EldParserSupportCore;
import org.x4o.xml.test.TestParserSupport;
import org.x4o.xml.test.swixml.SwiXmlParserSupport2;
import org.x4o.xml.test.swixml.SwiXmlParserSupport3;
import junit.framework.TestCase;
@ -51,6 +53,13 @@ public class EldDocTest extends TestCase {
return result;
}
public void testCelDoc() throws Exception {
X4OLanguageEldDocWriter writer = new X4OLanguageEldDocWriter();
writer.setBasePath(getTempPath("junit-cel"));
writer.setLanguageParserSupport(EldParserSupportCore.class);
writer.execute();
}
public void testEldDoc() throws Exception {
X4OLanguageEldDocWriter writer = new X4OLanguageEldDocWriter();
writer.setBasePath(getTempPath("junit-eld"));
@ -65,6 +74,13 @@ public class EldDocTest extends TestCase {
writer.execute();
}
public void testSwiXml2Doc() throws Exception {
X4OLanguageEldDocWriter writer = new X4OLanguageEldDocWriter();
writer.setBasePath(getTempPath("junit-swixml2"));
writer.setLanguageParserSupport(SwiXmlParserSupport2.class);
writer.execute();
}
public void testSwiXml3Doc() throws Exception {
X4OLanguageEldDocWriter writer = new X4OLanguageEldDocWriter();
writer.setBasePath(getTempPath("junit-swixml3"));