From e94bb5ffe81469e0acd660c8e8a1905af674a4f2 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sun, 18 Nov 2012 03:40:26 +0100 Subject: [PATCH] Moved the global configurator so seperate interface so xsd binds are correct. --- todo.txt | 1 - .../java/org/x4o/xml/core/X4ODebugWriter.java | 13 ++- .../x4o/xml/core/X4OPhaseHandlerFactory.java | 33 +++++--- .../org/x4o/xml/eld/EldModuleLoaderCore.java | 18 ++++- .../eld/lang/ElementModuleBindingHandler.java | 10 +-- .../AbstractElementLanguageModule.java | 16 ++-- .../x4o/xml/element/ElementConfigurator.java | 2 +- .../element/ElementConfiguratorGlobal.java | 35 ++++++++ .../xml/element/ElementLanguageModule.java | 8 +- .../resources/META-INF/cel/cel-core-1.0.xsd | 52 +++++------- .../resources/META-INF/cel/cel-root-1.0.xsd | 34 ++------ .../resources/META-INF/eld/eld-conv-1.0.xsd | 28 +------ .../resources/META-INF/eld/eld-lang-1.0.xsd | 79 ++++++++++--------- .../main/resources/META-INF/eld/eld-lang.eld | 11 ++- .../resources/META-INF/eld/eld-root-1.0.xsd | 31 +------- .../org/x4o/xml/eld/doc/EldDocGenerator.java | 2 +- .../org/x4o/xml/eld/doc/EldDocHtmlWriter.java | 13 ++- 17 files changed, 195 insertions(+), 191 deletions(-) create mode 100644 x4o-core/src/main/java/org/x4o/xml/element/ElementConfiguratorGlobal.java diff --git a/todo.txt b/todo.txt index e63cb73..faa4dc1 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,6 @@ -- x4o TODO list -- -- fix bind of attributeFromBody on module ! - static field constant converter - full Xinclude test - compleet eld doc html/css. diff --git a/x4o-core/src/main/java/org/x4o/xml/core/X4ODebugWriter.java b/x4o-core/src/main/java/org/x4o/xml/core/X4ODebugWriter.java index 5fe339d..7ce0819 100644 --- a/x4o-core/src/main/java/org/x4o/xml/core/X4ODebugWriter.java +++ b/x4o-core/src/main/java/org/x4o/xml/core/X4ODebugWriter.java @@ -38,6 +38,7 @@ import org.x4o.xml.element.ElementClass; import org.x4o.xml.element.ElementClassAttribute; import org.x4o.xml.element.ElementClassBase; import org.x4o.xml.element.ElementConfigurator; +import org.x4o.xml.element.ElementConfiguratorGlobal; import org.x4o.xml.element.ElementLanguage; import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementInterface; @@ -231,7 +232,7 @@ public class X4ODebugWriter { //module.getElementInterfaces(); //module.getElementNamespaceContexts(); - debugElementConfigurator(module.getGlobalElementConfigurators()); + debugElementConfiguratorGlobal(module.getElementConfiguratorGlobals()); debugElementBindingHandler(module.getElementBindingHandlers()); for (ElementAttributeHandler p:module.getElementAttributeHandlers()) { @@ -467,6 +468,16 @@ public class X4ODebugWriter { } } + private void debugElementConfiguratorGlobal(List elementConfigurators) throws SAXException { + for (ElementConfiguratorGlobal elementConfigurator:elementConfigurators) { + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription()); + atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName()); + debugWriter.startElement (DEBUG_URI, "elementConfiguratorGlobal", "", atts); + debugWriter.endElement(DEBUG_URI, "elementConfiguratorGlobal", ""); + } + } + private void debugElementClassAttributes(Collection elementClassAttributes) throws SAXException { for (ElementClassAttribute elementClassAttribute:elementClassAttributes) { AttributesImpl atts = new AttributesImpl(); 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 576cc2a..1092f8f 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 @@ -45,6 +45,7 @@ import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementClass; import org.x4o.xml.element.ElementClassAttribute; import org.x4o.xml.element.ElementConfigurator; +import org.x4o.xml.element.ElementConfiguratorGlobal; import org.x4o.xml.element.ElementLanguage; import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementInterface; @@ -89,17 +90,17 @@ public class X4OPhaseHandlerFactory { } } - private void runElementConfigurators(List ecs,Element e,X4OPhaseHandler phase) throws X4OPhaseException { - int size = ecs.size(); - for (int i=0;i handlers2 = new ArrayList(handlers.size()); handlers2.addAll(handlers); - runElementConfigurators(handlers2,element,this); + for (ElementConfigurator ec:handlers) { + runElementConfigurator(ec,element,this); + } } }; X4OPhaseHandler result = new ConfigGlobalAttributePhase(); 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 4bd145e..c12f709 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 @@ -244,7 +244,7 @@ public class EldModuleLoaderCore implements ElementLanguageModuleLoader { elementClassList.add(ec); ec = new DefaultElementClass("configurator",null,BeanElement.class); - ec.addElementParent(CEL_ROOT_URI, "module"); + //ec.addElementParent(CEL_ROOT_URI, "module"); ec.addElementParent("", "elementInterface"); ec.addElementParent("", "element"); try { @@ -261,6 +261,22 @@ public class EldModuleLoaderCore implements ElementLanguageModuleLoader { } elementClassList.add(ec); + ec = new DefaultElementClass("configuratorGlobal",null,BeanElement.class); + ec.addElementParent(CEL_ROOT_URI, "module"); + try { + attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute()); + attr.setName("bean.class"); + attr.setRequired(true); + ec.addElementClassAttribute(attr); + + attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute()); + attr.setName("configAction"); + ec.addElementClassAttribute(attr); + } catch (Exception e) { + throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e); + } + elementClassList.add(ec); + ec = new DefaultElementClass("description",null,DescriptionElement.class); ec.setSchemaContentBase("string"); ec.addElementParent(CEL_ROOT_URI, "module"); diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementModuleBindingHandler.java b/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementModuleBindingHandler.java index 76648fe..9058e6e 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementModuleBindingHandler.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementModuleBindingHandler.java @@ -33,7 +33,7 @@ import org.x4o.xml.element.Element; import org.x4o.xml.element.ElementAttributeHandler; import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementBindingHandlerException; -import org.x4o.xml.element.ElementConfigurator; +import org.x4o.xml.element.ElementConfiguratorGlobal; import org.x4o.xml.element.ElementLanguage; import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementLanguageModule; @@ -56,7 +56,7 @@ public class ElementModuleBindingHandler extends AbstractElementBindingHandler ElementNamespaceContext.class, ElementBindingHandler.class, ElementAttributeHandler.class, - ElementConfigurator.class, + ElementConfiguratorGlobal.class, }; @@ -125,9 +125,9 @@ public class ElementModuleBindingHandler extends AbstractElementBindingHandler elementLanguageModule.addElementAttributeHandler(elementAttributeHandler); return; } - if (childObject instanceof ElementConfigurator) { - ElementConfigurator elementConfigurator = (ElementConfigurator)childObject; - elementLanguageModule.addGlobalElementConfigurator(elementConfigurator); + if (childObject instanceof ElementConfiguratorGlobal) { + ElementConfiguratorGlobal elementConfigurator = (ElementConfiguratorGlobal)childObject; + elementLanguageModule.addElementConfiguratorGlobal(elementConfigurator); return; } } 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 5aa229f..20f79a7 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 @@ -49,7 +49,7 @@ public abstract class AbstractElementLanguageModule extends AbstractElementMetaB /** The binding rules */ private List elementBindingHandlers = null; - private List globalElementConfigurators = null; + private List elementConfiguratorGlobals = null; private List elementInterfaces = null; @@ -65,7 +65,7 @@ public abstract class AbstractElementLanguageModule extends AbstractElementMetaB logger.finest("Creating new ParsingContext"); elementAttributeHandlers = new ArrayList(4); elementBindingHandlers = new ArrayList(4); - globalElementConfigurators = new ArrayList(4); + elementConfiguratorGlobals = new ArrayList(4); elementInterfaces = new ArrayList(20); elementNamespaceContexts = new HashMap(10); } @@ -140,22 +140,22 @@ public abstract class AbstractElementLanguageModule extends AbstractElementMetaB /** * @see org.x4o.xml.element.ElementLanguageModule#addGlobalElementConfigurator(ElementConfigurator) */ - public void addGlobalElementConfigurator(ElementConfigurator elementConfigurator) { + public void addElementConfiguratorGlobal(ElementConfiguratorGlobal elementConfigurator) { if (elementConfigurator==null) { throw new NullPointerException("Can't add null"); } if (elementConfigurator.getId()==null) { throw new NullPointerException("Can't add with null id property."); } - logger.finer("Adding GlobalElementConfigurator: "+elementConfigurator); - globalElementConfigurators.add(elementConfigurator); + logger.finer("Adding ElementConfiguratorGlobal: "+elementConfigurator); + elementConfiguratorGlobals.add(elementConfigurator); } /** - * @see org.x4o.xml.element.ElementLanguageModule#getGlobalElementConfigurators() + * @see org.x4o.xml.element.ElementLanguageModule#getElementConfiguratorGlobals() */ - public List getGlobalElementConfigurators() { - return globalElementConfigurators; + public List getElementConfiguratorGlobals() { + return elementConfiguratorGlobals; } /** diff --git a/x4o-core/src/main/java/org/x4o/xml/element/ElementConfigurator.java b/x4o-core/src/main/java/org/x4o/xml/element/ElementConfigurator.java index ae17146..78ba108 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/ElementConfigurator.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/ElementConfigurator.java @@ -25,7 +25,7 @@ package org.x4o.xml.element; /** - * Provides an Interface to configure Element(Object) more. + * Provides an Interface to configure Element(Object). * * * @author Willem Cazanders diff --git a/x4o-core/src/main/java/org/x4o/xml/element/ElementConfiguratorGlobal.java b/x4o-core/src/main/java/org/x4o/xml/element/ElementConfiguratorGlobal.java new file mode 100644 index 0000000..123257a --- /dev/null +++ b/x4o-core/src/main/java/org/x4o/xml/element/ElementConfiguratorGlobal.java @@ -0,0 +1,35 @@ +/* + * 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.element; + + +/** + * Provides an Interface to configure Element(Object) global. + * + * @author Willem Cazanders + * @version 1.0 Nov 18, 2012 + */ +public interface ElementConfiguratorGlobal extends ElementConfigurator { + +} diff --git a/x4o-core/src/main/java/org/x4o/xml/element/ElementLanguageModule.java b/x4o-core/src/main/java/org/x4o/xml/element/ElementLanguageModule.java index 11f71f4..1e4a9ee 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/ElementLanguageModule.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/ElementLanguageModule.java @@ -79,16 +79,16 @@ public interface ElementLanguageModule extends ElementMetaBase { List getElementBindingHandlers(); /** - * Adds an GlobalElementConfigurator. + * Adds an ElementConfiguratorGlobal. * @param elementConfigurator The ElementConfigurtor to add. */ - void addGlobalElementConfigurator(ElementConfigurator elementConfigurator); + void addElementConfiguratorGlobal(ElementConfiguratorGlobal elementConfigurator); /** - * Gets all global ElementConfigurators. + * Gets all ElementConfiguratorGlobals. * @return All gloval ElementConfigurators. */ - List getGlobalElementConfigurators(); + List getElementConfiguratorGlobals(); /** * Adds an ElementInterface. 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 a3cc496..62b7761 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 @@ -1,37 +1,13 @@ - - + @@ -72,8 +48,14 @@ - + + + + + + + @@ -95,13 +77,14 @@ + + + + - - - - + @@ -122,8 +105,8 @@ - + @@ -134,6 +117,7 @@ + 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 4b2d998..659b78b 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 @@ -1,37 +1,13 @@ - - + @@ -51,8 +27,8 @@ - + \ 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 1a46eee..a71162d 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 @@ -1,37 +1,13 @@ - - + - @@ -60,6 +36,11 @@ + + + + + @@ -68,14 +49,15 @@ + - - + + @@ -84,6 +66,13 @@ + + + + + + + @@ -94,9 +83,12 @@ - + + + - + + @@ -131,11 +123,12 @@ - + - - + + + @@ -155,11 +148,13 @@ - + + + - + @@ -188,6 +183,12 @@ + + + Adds an phase to skip to the parent element. + + + @@ -195,6 +196,12 @@ + + + Define an className in bean.class for an ElementConfiguratorGlobal. + + + Define an className in bean.class for an ElementConfigurator. 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 fe8249e..2071737 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 @@ -95,7 +95,7 @@ - + Define an className in bean.class for an ElementAttributeHandler. @@ -104,12 +104,19 @@ + + Define an className in bean.class for an ElementConfiguratorGlobal. + + + + + + Define an className in bean.class for an ElementConfigurator. - 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 f230b3f..c571920 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 @@ -1,37 +1,13 @@ - - - + 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 fb6ab20..a36242d 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 @@ -68,7 +68,7 @@ public class EldDocGenerator { for (ElementAttributeHandler attr:mod.getElementAttributeHandlers()) { writer.writeAttributeHandler(basePath,attr,mod); } - for (ElementConfigurator conf:mod.getGlobalElementConfigurators()) { + for (ElementConfigurator conf:mod.getElementConfiguratorGlobals()) { writer.writeElementConfigurator(basePath,conf,mod); } for (ElementInterface iface:mod.getElementInterfaces()) { 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 ab2e7a8..2ce70fc 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 @@ -37,6 +37,7 @@ import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementClass; import org.x4o.xml.element.ElementClassAttribute; import org.x4o.xml.element.ElementConfigurator; +import org.x4o.xml.element.ElementConfiguratorGlobal; import org.x4o.xml.element.ElementLanguage; import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementLanguageModule; @@ -148,7 +149,7 @@ public class EldDocHtmlWriter { attrHandlers =+ mod.getElementAttributeHandlers().size(); bindHandlers =+ mod.getElementBindingHandlers().size(); interFaces =+ mod.getElementInterfaces().size(); - eleConfigs =+ mod.getGlobalElementConfigurators().size(); + eleConfigs =+ mod.getElementConfiguratorGlobals().size(); for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) { namespaces++; elements =+ ns.getElementClasses().size(); @@ -225,7 +226,7 @@ public class EldDocHtmlWriter { printElementInterfaces(pw,mod.getElementInterfaces(),pathPrefixModule); printAttributeHandlers(pw,mod.getElementAttributeHandlers(),pathPrefixModule); printBindingHandlers(pw,mod.getElementBindingHandlers(),pathPrefixModule); - printConfigurators(pw, mod.getGlobalElementConfigurators(),pathPrefixModule); + printConfiguratorGlobals(pw, mod.getElementConfiguratorGlobals(),pathPrefixModule); printNamespaces(pw, mod.getElementNamespaceContexts(),pathPrefix,mod); printBottom(pw,pathPrefix); @@ -482,6 +483,14 @@ public class EldDocHtmlWriter { printTableEnd(pw); } + private void printConfiguratorGlobals(PrintWriter pw,List confs,String pathPrefix) { + printTableStart(pw,"Configurators"); + for (ElementConfigurator conf:confs) { + printTableRowOverview(pw,pathPrefix+"conf/"+toSafeUri(conf.getId())+".html",conf.getId(),conf.getDescription()); + } + printTableEnd(pw); + } + private void printBindingHandlers(PrintWriter pw,List binds,String pathPrefix) { printTableStart(pw,"Binding handlers"); for (ElementBindingHandler bind:binds) {