From bcce73b2ad7b177c8b1bd90033853444a57e3d42 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Tue, 8 Jan 2013 15:16:57 +0100 Subject: [PATCH] Added elementParent tag also to elementInterface and fixed eld elementParent namespace uri bug and updated elddoc and xsd for extra search. --- .../org/x4o/xml/eld/EldModuleLoaderCore.java | 1 + .../lang/ElementClassAddParentElement.java | 8 ++-- .../org/x4o/xml/eld/xsd/EldXsdXmlWriter.java | 29 ++++++++++--- .../x4o/xml/element/AbstractElementClass.java | 38 ----------------- .../xml/element/AbstractElementClassBase.java | 39 +++++++++++++++++- .../AbstractElementLanguageModule.java | 3 +- .../org/x4o/xml/element/ElementClass.java | 23 ----------- .../org/x4o/xml/element/ElementClassBase.java | 24 +++++++++++ .../resources/META-INF/cel/cel-core-1.0.xsd | 13 +++--- .../resources/META-INF/cel/cel-root-1.0.xsd | 4 +- .../resources/META-INF/eld/eld-conv-1.0.xsd | 2 +- .../resources/META-INF/eld/eld-lang-1.0.xsd | 9 ++-- .../main/resources/META-INF/eld/eld-lang.eld | 5 ++- .../resources/META-INF/eld/eld-root-1.0.xsd | 4 +- .../resources/META-INF/test/test-lang.eld | 10 ++++- .../org/x4o/xml/eld/doc/EldDocHtmlWriter.java | 41 +++++++++++++++++-- 16 files changed, 159 insertions(+), 94 deletions(-) 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 f46ea95..4e92190 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 @@ -294,6 +294,7 @@ public class EldModuleLoaderCore implements ElementLanguageModuleLoader { ec = new DefaultElementClass("elementParent",null,ElementClassAddParentElement.class); ec.addElementParent(CEL_CORE_URI, "element"); + ec.addElementParent(CEL_CORE_URI, "elementInterface"); 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 0613c8d..7612b11 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 @@ -24,7 +24,7 @@ package org.x4o.xml.eld.lang; import org.x4o.xml.element.AbstractElement; -import org.x4o.xml.element.ElementClass; +import org.x4o.xml.element.ElementClassBase; import org.x4o.xml.element.ElementException; /** @@ -48,10 +48,10 @@ public class ElementClassAddParentElement extends AbstractElement { if (namespaceUri==null) { namespaceUri = getParent().getParent().getAttributes().get("uri"); // copy uri from namespace element. } - if (getParent().getElementObject() instanceof ElementClass) { - ((ElementClass)getParent().getElementObject()).addElementParent(namespaceUri,tag); + if (getParent().getElementObject() instanceof ElementClassBase) { + ((ElementClassBase)getParent().getElementObject()).addElementParent(namespaceUri,tag); } else { - throw new ElementException("Wrong parent class is not ElementClass but: "+getParent().getElementObject()); + throw new ElementException("Wrong parent class is not ElementClassBase but: "+getParent().getElementObject()); } } } 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 7c7af6e..b997996 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 @@ -37,6 +37,7 @@ import org.x4o.xml.element.ElementAttributeHandler; import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementClass; import org.x4o.xml.element.ElementClassAttribute; +import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementLanguage; import org.x4o.xml.element.ElementLanguageModule; import org.x4o.xml.element.ElementNamespaceContext; @@ -129,6 +130,12 @@ public class EldXsdXmlWriter { } } } + for (ElementInterface ei:context.findElementInterfaces(objectClass)) { + List eiTags = ei.getElementParents(namespaceUri); + if (eiTags!=null) { + startNamespace(nsContext.getUri(),nsContext.getSchemaPrefix()); + } + } } } } @@ -261,9 +268,10 @@ public class EldXsdXmlWriter { if (ec.getSchemaContentBase()==null) { atts = new AttributesImpl(); - atts.addAttribute ("", "minOccurs", "", "", "0"); // make unordered elements + atts.addAttribute ("", "minOccurs", "", "", "0"); // TODO: make unordered elements atts.addAttribute ("", "maxOccurs", "", "", "unbounded"); xmlWriter.startElement (SCHEMA_URI, "choice", "", atts); + for (ElementLanguageModule mod:context.getElementLanguageModules()) { for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) { writeElementClassNamespaces(ec,nsWrite,ns); @@ -361,27 +369,36 @@ public class EldXsdXmlWriter { } } - private void writeElementClassNamespaces(ElementClass ec,ElementNamespaceContext nsWrite,ElementNamespaceContext ns) throws SAXException { + private void writeElementClassNamespaces(ElementClass ecWrite,ElementNamespaceContext nsWrite,ElementNamespaceContext ns) throws SAXException { AttributesImpl atts = new AttributesImpl(); List refElements = new ArrayList(20); for (ElementClass checkClass:ns.getElementClasses()) { List parents = checkClass.getElementParents(nsWrite.getUri()); - if (parents!=null && parents.contains(ec.getTag())) { + if (parents!=null && parents.contains(ecWrite.getTag())) { refElements.add(checkClass.getTag()); - } - if (ec.getObjectClass()==null) { continue; } if (checkClass.getObjectClass()==null) { continue; } - Class objectClass = ec.getObjectClass(); + for (ElementInterface ei:context.findElementInterfaces(checkClass.getObjectClass())) { + parents = ei.getElementParents(nsWrite.getUri()); + if (parents!=null && parents.contains(ecWrite.getTag())) { + refElements.add(checkClass.getTag()); + break; + } + } + if (ecWrite.getObjectClass()==null) { + continue; + } + Class objectClass = ecWrite.getObjectClass(); Class checkObjectClass = checkClass.getObjectClass(); List b = context.findElementBindingHandlers(objectClass,checkObjectClass); if (b.isEmpty()==false) { refElements.add(checkClass.getTag()); } } + if (refElements.isEmpty()==false) { Set s = new HashSet(refElements.size()); s.addAll(refElements); 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 6c0f861..00fb897 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 @@ -40,14 +40,12 @@ public abstract class AbstractElementClass extends AbstractElementClassBase impl private Class objectClass = null; private Class elementClass = null; private Boolean autoAttributes = true; - private Map> elementParents = null; private String schemaContentBase = null; private Boolean schemaContentComplex = null; private Boolean schemaContentMixed = null; private List skipPhases = null; public AbstractElementClass() { - elementParents = new HashMap>(5); skipPhases = new ArrayList(3); } @@ -107,42 +105,6 @@ public abstract class AbstractElementClass extends AbstractElementClassBase impl this.autoAttributes = autoAttributes; } - /** - * @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); - elementParents.put(namespaceUri, tags); - } - tags.add(tag); - } - - /** - * @see org.x4o.xml.element.ElementClass#removeElementParent(java.lang.String,java.lang.String) - */ - public void removeElementParent(String namespaceUri,String tag) { - List tags = elementParents.get(namespaceUri); - if (tags==null) { - return; - } - tags.remove(tag); - } - - /** - * @see org.x4o.xml.element.ElementClass#getElementParents(java.lang.String) - */ - public List getElementParents(String namespaceUri) { - return elementParents.get(namespaceUri); - } - /** * @return the schemaContentBase */ diff --git a/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java b/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java index dc72fed..4f59632 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java @@ -39,13 +39,14 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i private Map elementClassAttributes = null; private List elementConfigurators = null; + private Map> elementParents = null; public AbstractElementClassBase() { elementConfigurators = new ArrayList(5); elementClassAttributes = new HashMap(15); + elementParents = new HashMap>(5); } - /** * @see ElementClass#getElementConfigurators() */ @@ -77,4 +78,40 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i public ElementClassAttribute getElementClassAttributeByName(String attributeName) { return elementClassAttributes.get(attributeName); } + + /** + * @see org.x4o.xml.element.ElementClassBase#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); + elementParents.put(namespaceUri, tags); + } + tags.add(tag); + } + + /** + * @see org.x4o.xml.element.ElementClassBase#removeElementParent(java.lang.String,java.lang.String) + */ + public void removeElementParent(String namespaceUri,String tag) { + List tags = elementParents.get(namespaceUri); + if (tags==null) { + return; + } + tags.remove(tag); + } + + /** + * @see org.x4o.xml.element.ElementClassBase#getElementParents(java.lang.String) + */ + public List getElementParents(String namespaceUri) { + return elementParents.get(namespaceUri); + } } 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 a82f3ef..fb6653c 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 @@ -130,11 +130,12 @@ public abstract class AbstractElementLanguageModule extends AbstractElementMetaB 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/java/org/x4o/xml/element/ElementClass.java b/x4o-core/src/main/java/org/x4o/xml/element/ElementClass.java index 0a5da85..d3f4194 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/ElementClass.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/ElementClass.java @@ -78,29 +78,6 @@ public interface ElementClass extends ElementClassBase { */ void setAutoAttributes(Boolean autoAttributes); - /** - * Add an parent element tag. - * Used: for xsd only. - * @param namespaceUri The namespace uri of this tag relation. - * @param tag The parent element tag. - */ - void addElementParent(String namespaceUri,String tag); - - /** - * Remove and parent element - * Used: for xsd only. - * @param namespaceUri The namespace uri of this tag relation. - * @param tag The parent element tag. - */ - void removeElementParent(String namespaceUri,String tag); - - /** - * Returns list of parent element tags. - * @param namespaceUri The namespace uri of this tag relation. - * @return The list of tags. - */ - List getElementParents(String namespaceUri); - /** * @return the schemaContentBase */ diff --git a/x4o-core/src/main/java/org/x4o/xml/element/ElementClassBase.java b/x4o-core/src/main/java/org/x4o/xml/element/ElementClassBase.java index 612e869..294fc88 100644 --- a/x4o-core/src/main/java/org/x4o/xml/element/ElementClassBase.java +++ b/x4o-core/src/main/java/org/x4o/xml/element/ElementClassBase.java @@ -41,4 +41,28 @@ public interface ElementClassBase extends ElementMetaBase { Collection getElementClassAttributes(); ElementClassAttribute getElementClassAttributeByName(String attributeName); void addElementClassAttribute(ElementClassAttribute elementClassAttribute); + + /** + * Add an parent element tag. + * Used: for xsd/doc only. + * @param namespaceUri The namespace uri of this tag relation. + * @param tag The parent element tag. + */ + void addElementParent(String namespaceUri,String tag); + + /** + * Remove and parent element + * Used: for xsd/doc only. + * @param namespaceUri The namespace uri of this tag relation. + * @param tag The parent element tag. + */ + void removeElementParent(String namespaceUri,String tag); + + /** + * Returns list of parent element tags. + * Used: for xsd/doc only. + * @param namespaceUri The namespace uri of this tag relation. + * @return The list of tags. + */ + List getElementParents(String namespaceUri); } 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 29087eb..033c97e 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,7 +7,7 @@ ModuleName: Core Element Languag Module Namespaces: 2 Namespace: http://cel.x4o.org/xml/ns/cel-core - Created on: Thu Dec 20 22:30:55 CET 2012 + Created on: Tue Jan 08 06:02:28 CET 2013 --> - + - + @@ -81,12 +81,12 @@ - + - - + + @@ -107,6 +107,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 dfd34c6..3d08e60 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: Thu Dec 20 22:30:55 CET 2012 + Created on: Tue Jan 08 06:02:28 CET 2013 --> - + 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 380da65..ba7f45f 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: Thu Dec 20 22:30:10 CET 2012 + Created on: Tue Jan 08 06:03:20 CET 2013 --> - + @@ -128,11 +128,11 @@ + - @@ -169,6 +169,7 @@ + @@ -177,7 +178,7 @@ - + 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 a116097..72d6227 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 @@ -180,11 +180,12 @@ Adds an parent element tag for xsd + The parent tag to have object for. - - The element namespace uri if non local. + + The element namespace uri if non local parent. 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 05ccba1..b08851f 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: Thu Dec 20 22:30:10 CET 2012 + Created on: Tue Jan 08 06:03:20 CET 2013 --> - + diff --git a/x4o-core/src/test/resources/META-INF/test/test-lang.eld b/x4o-core/src/test/resources/META-INF/test/test-lang.eld index f1b6756..cc08648 100644 --- a/x4o-core/src/test/resources/META-INF/test/test-lang.eld +++ b/x4o-core/src/test/resources/META-INF/test/test-lang.eld @@ -46,6 +46,12 @@ Binds the TestBean to the TestObjectRoot + + Binds j components. + + + Binds panel to frame components as unit check. + Configs the Component based objects. @@ -132,7 +138,9 @@ --> - + + + 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 381c843..9111347 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 @@ -298,7 +298,6 @@ public class EldDocHtmlWriter { 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()) { @@ -313,7 +312,25 @@ public class EldDocHtmlWriter { n.indent=node.indent+1; n.parent=node; } else { - if (node.elementClass.getObjectClass()==null | ec.getObjectClass()==null) { + if (ec.getObjectClass()==null) { + continue; + } + // Check interfaces of child , and see if parent tag is there. + for (ElementInterface ei:node.context.findElementInterfaces(ec.getObjectClass())) { + List eiTags = ei.getElementParents(node.namespace.getUri()); + if (eiTags!=null && eiTags.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; + break; + } + } + + if (node.elementClass.getObjectClass()==null) { continue; } List binds = node.context.findElementBindingHandlers(node.elementClass.getObjectClass(), ec.getObjectClass()); @@ -372,7 +389,25 @@ public class EldDocHtmlWriter { } } for (ElementClass ec:ns.getElementClasses()) { - if (node.elementClass.getObjectClass()==null | ec.getObjectClass()==null) { + if (ec.getObjectClass()==null) { + continue; + } + // Check interfaces of child , and see if parent tag is there. + for (ElementInterface ei:node.context.findElementInterfaces(ec.getObjectClass())) { + List eiTags = ei.getElementParents(node.namespace.getUri()); + if (eiTags!=null && eiTags.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; + result.add(n); + break; + } + } + if (node.elementClass.getObjectClass()==null) { continue; } List binds = node.context.findElementBindingHandlers(ec.getObjectClass(),node.elementClass.getObjectClass());