From aa9c9743d769950001bf75090a4cad163b4853dd Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Thu, 20 Dec 2012 22:39:28 +0100 Subject: [PATCH] Made eld docs more compleet and updated xsd to add missing description tag. --- todo.txt | 2 - .../x4o/xml/core/X4OPhaseHandlerFactory.java | 8 +- .../org/x4o/xml/eld/EldModuleLoaderCore.java | 23 +- .../lang/ElementClassAddParentElement.java | 2 +- .../org/x4o/xml/eld/xsd/EldXsdXmlWriter.java | 6 - .../x4o/xml/element/AbstractElementClass.java | 6 + .../AbstractElementLanguageModule.java | 9 + .../resources/META-INF/cel/cel-core-1.0.xsd | 27 +- .../resources/META-INF/cel/cel-root-1.0.xsd | 6 +- .../resources/META-INF/eld/eld-conv-1.0.xsd | 2 +- .../resources/META-INF/eld/eld-lang-1.0.xsd | 7 +- .../main/resources/META-INF/eld/eld-lang.eld | 8 +- .../resources/META-INF/eld/eld-root-1.0.xsd | 6 +- .../swixml/bind/JFrameBindingHandler.java | 88 +++++ ...java => JInternalFrameBindingHandler.java} | 48 +-- .../swixml/bind/JPanelBindingHandler.java | 82 +++++ ...ler.java => JSplitPaneBindingHandler.java} | 25 +- .../META-INF/swixml/swixml-lang-2.0.eld | 11 +- .../META-INF/swixml/swixml-lang-3.0.eld | 11 +- .../org/x4o/xml/eld/doc/EldDocGenerator.java | 3 +- .../org/x4o/xml/eld/doc/EldDocHtmlWriter.java | 337 +++++++++++++++++- .../java/org/x4o/xml/eld/doc/EldDocTest.java | 16 + 22 files changed, 609 insertions(+), 124 deletions(-) create mode 100644 x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JFrameBindingHandler.java rename x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/{JComponentBindingHandler.java => JInternalFrameBindingHandler.java} (63%) create mode 100644 x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JPanelBindingHandler.java rename x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/{JMenuBarBindingHandler.java => JSplitPaneBindingHandler.java} (75%) diff --git a/todo.txt b/todo.txt index faa4dc1..b81759e 100644 --- a/todo.txt +++ b/todo.txt @@ -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 diff --git a/x4o-core/src/main/java/org/x4o/xml/core/X4OPhaseHandlerFactory.java b/x4o-core/src/main/java/org/x4o/xml/core/X4OPhaseHandlerFactory.java index 1092f8f..62a8943 100644 --- a/x4o-core/src/main/java/org/x4o/xml/core/X4OPhaseHandlerFactory.java +++ b/x4o-core/src/main/java/org/x4o/xml/core/X4OPhaseHandlerFactory.java @@ -623,7 +623,7 @@ public class X4OPhaseHandlerFactory { protected void setX4OPhase() { phase = X4OPhase.fillTemplatingPhase; } - public void runElementPhase(Element element) throws X4OPhaseException { + public void runElementPhase(Element element) throws X4OPhaseException { } }; return result; @@ -638,13 +638,13 @@ public class X4OPhaseHandlerFactory { protected void setX4OPhase() { phase = X4OPhase.transformPhase; } - public void runElementPhase(Element element) throws X4OPhaseException { + public void runElementPhase(Element element) throws X4OPhaseException { if (element.isTransformingTree()==false) { return; } try { if (hasX4ODebugWriter()) { - getX4ODebugWriter().debugElement(element); + getX4ODebugWriter().debugElement(element); } element.doElementRun(); } catch (ElementException e) { @@ -665,7 +665,7 @@ public class X4OPhaseHandlerFactory { protected void setX4OPhase() { phase = X4OPhase.runDirtyElementPhase; } - public void runElementPhase(Element element) throws X4OPhaseException { + public void runElementPhase(Element element) throws X4OPhaseException { Map dirtyElements = element.getElementLanguage().getDirtyElements(); if (dirtyElements.isEmpty()) { return; diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java b/x4o-core/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java index 0a5c7eb..f46ea95 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java @@ -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"); diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementClassAddParentElement.java b/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementClassAddParentElement.java index 82c0005..0613c8d 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementClassAddParentElement.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementClassAddParentElement.java @@ -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); diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlWriter.java b/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlWriter.java index 95b6d8f..7c7af6e 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlWriter.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlWriter.java @@ -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; } diff --git a/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClass.java b/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClass.java index 3ae66a5..6c0f861 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClass.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClass.java @@ -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 tags = elementParents.get(namespaceUri); if (tags==null) { tags = new ArrayList(5); diff --git a/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementLanguageModule.java b/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementLanguageModule.java index bcffcc1..a82f3ef 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementLanguageModule.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementLanguageModule.java @@ -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); } diff --git a/x4o-core/src/main/resources/META-INF/cel/cel-core-1.0.xsd b/x4o-core/src/main/resources/META-INF/cel/cel-core-1.0.xsd index f0a6024..29087eb 100644 --- a/x4o-core/src/main/resources/META-INF/cel/cel-core-1.0.xsd +++ b/x4o-core/src/main/resources/META-INF/cel/cel-core-1.0.xsd @@ -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 --> + - + + - - - + + @@ -44,12 +45,12 @@ - + - - + + @@ -80,14 +81,14 @@ - + - + - - + + @@ -108,8 +109,8 @@ - + diff --git a/x4o-core/src/main/resources/META-INF/cel/cel-root-1.0.xsd b/x4o-core/src/main/resources/META-INF/cel/cel-root-1.0.xsd index b76a7e5..dfd34c6 100644 --- a/x4o-core/src/main/resources/META-INF/cel/cel-root-1.0.xsd +++ b/x4o-core/src/main/resources/META-INF/cel/cel-root-1.0.xsd @@ -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 --> - - + + \ No newline at end of file diff --git a/x4o-core/src/main/resources/META-INF/eld/eld-conv-1.0.xsd b/x4o-core/src/main/resources/META-INF/eld/eld-conv-1.0.xsd index ff0062b..380da65 100644 --- a/x4o-core/src/main/resources/META-INF/eld/eld-conv-1.0.xsd +++ b/x4o-core/src/main/resources/META-INF/eld/eld-conv-1.0.xsd @@ -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 --> + + - - + diff --git a/x4o-core/src/main/resources/META-INF/eld/eld-lang.eld b/x4o-core/src/main/resources/META-INF/eld/eld-lang.eld index 8f1fbb7..a116097 100644 --- a/x4o-core/src/main/resources/META-INF/eld/eld-lang.eld +++ b/x4o-core/src/main/resources/META-INF/eld/eld-lang.eld @@ -32,6 +32,7 @@ providerName="eld.x4o.org" id="eld-module" > + The full element language definition(eld) which is used to define xml languages. @@ -50,7 +51,7 @@ languageRoot="true" id="eld-root" > - + Single root namespace so xsd schema generation works correct. The module id. @@ -67,6 +68,7 @@ name="Element Language Definition" id="eld-lang" > + Some basic language definitions and some helper tags. @@ -160,6 +162,7 @@ An ELD elementDescription field which lets you type text like this one in xml characters instead of an attribute. + @@ -267,7 +270,8 @@ name="Element Attribute Converters" id="eld-conv" > - + Basic set of attribute value converters. + Define an loadable in bean.class for an ObjectConverter. diff --git a/x4o-core/src/main/resources/META-INF/eld/eld-root-1.0.xsd b/x4o-core/src/main/resources/META-INF/eld/eld-root-1.0.xsd index fe6cef6..05ccba1 100644 --- a/x4o-core/src/main/resources/META-INF/eld/eld-root-1.0.xsd +++ b/x4o-core/src/main/resources/META-INF/eld/eld-root-1.0.xsd @@ -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 --> - - + + diff --git a/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JFrameBindingHandler.java b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JFrameBindingHandler.java new file mode 100644 index 0000000..ecccfd0 --- /dev/null +++ b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JFrameBindingHandler.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JComponentBindingHandler.java b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java similarity index 63% rename from x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JComponentBindingHandler.java rename to x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java index a736109..6f3f982 100644 --- a/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JComponentBindingHandler.java +++ b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java @@ -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); - } + JInternalFrame frame = (JInternalFrame)parentObject; + if (con==null) { + frame.getContentPane().add(child); } else { - // No bind but this destroys the xsd, change into multiple classes. + frame.getContentPane().add(child,con); } } } \ No newline at end of file diff --git a/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JPanelBindingHandler.java b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JPanelBindingHandler.java new file mode 100644 index 0000000..414bbec --- /dev/null +++ b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JPanelBindingHandler.java @@ -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); + } + } +} diff --git a/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JMenuBarBindingHandler.java b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JSplitPaneBindingHandler.java similarity index 75% rename from x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JMenuBarBindingHandler.java rename to x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JSplitPaneBindingHandler.java index bbccae4..ec80790 100644 --- a/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JMenuBarBindingHandler.java +++ b/x4o-core/src/test/java/org/x4o/xml/test/swixml/bind/JSplitPaneBindingHandler.java @@ -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."); + } } } \ No newline at end of file diff --git a/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld b/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld index da2bc52..c7e8a5b 100644 --- a/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld +++ b/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld @@ -34,8 +34,11 @@ id="swixml2-module" > - - + + + + + @@ -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" > @@ -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" > diff --git a/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld b/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld index e16bc2e..a038c8d 100644 --- a/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld +++ b/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld @@ -34,8 +34,11 @@ id="swixml3-module" > - - + + + + + @@ -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" > @@ -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" > diff --git a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java index a36242d..997ed97 100644 --- a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java +++ b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java @@ -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); } diff --git a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocHtmlWriter.java b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocHtmlWriter.java index 0d8cd7c..d8df1e9 100644 --- a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocHtmlWriter.java +++ b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocHtmlWriter.java @@ -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 rootNodes = new ArrayList(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"); + pw.print(node.namespace.getId()); + pw.print(":"); + pw.print(node.elementClass.getTag()); + pw.print("
\n"); + + List childs = findChilderen(node); + for (TreeNode child:childs) { + walkTree(child,pw,pathPrefix); + } + } + + private List findChilderen(TreeNode node) { + List result = new ArrayList(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 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 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 findParents(TreeNode node) { + List result = new ArrayList(10); + TreeNode n=null; + for (ElementLanguageModule mod:node.context.getElementLanguageModules()) { + for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) { + + List 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 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 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 parents = findParents(node); + printTableStart(pw,"Element Parents"); + pw.print("\t\n"); + pw.print("\t\t"); + if (parents.isEmpty()) { + pw.print("No parent."); + } + for (TreeNode n:parents) { + pw.print("\t\t\t "); + pw.print(n.namespace.getId()); + pw.print(":"); + pw.print(n.elementClass.getTag()); + pw.print("\n"); + } + pw.print("\n"); + pw.print("\t\n"); + printTableEnd(pw); + + List childs = findChilderen(node); + printTableStart(pw,"Element Childeren"); + pw.print("\t\n"); + pw.print("\t\t"); + if (childs.isEmpty()) { + pw.print("No childeren."); + } + for (TreeNode n:childs) { + pw.print("\t\t\t "); + pw.print(n.namespace.getId()); + pw.print(":"); + pw.print(n.elementClass.getTag()); + pw.print("\n"); + } + pw.print("\n"); + pw.print("\t\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 elementClassAttributes) { + printTableStart(pw,"Element Attributes"); + for (ElementClassAttribute attr:elementClassAttributes) { + printTableRowSummary(pw,attr.getName(),attr.getDescription()); + } + printTableEnd(pw); + } + private void printNamespaces(PrintWriter pw,List 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("
\n"); + pw.print("
\n"); } } @@ -676,5 +978,6 @@ public class EldDocHtmlWriter { pw.print("\t\tIndex \n"); pw.print("\t\tModules \n"); pw.print("\t\tNamespaces \n"); + pw.print("\t\tTree \n"); } } diff --git a/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/EldDocTest.java b/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/EldDocTest.java index 343811e..7c9465e 100644 --- a/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/EldDocTest.java +++ b/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/EldDocTest.java @@ -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")); @@ -64,6 +73,13 @@ public class EldDocTest extends TestCase { writer.setLanguageParserSupport(TestParserSupport.class); 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();