From 661ac8079e5077fba26a4a069d26a5e02e0410a1 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Tue, 9 Apr 2013 00:37:30 +0200 Subject: [PATCH] Added some javadoc and improved swixml unit test. --- .../java/org/x4o/xml/X4ODriverManager.java | 6 ++ .../lang/ElementRefectionBindingHandler.java | 82 +++++++++++++------ .../DefaultElementObjectPropertyValue.java | 10 ++- .../org/x4o/xml/io/AbstractX4OConnection.java | 6 ++ .../org/x4o/xml/io/AbstractX4OWriter.java | 6 ++ .../x4o/xml/io/AbstractX4OWriterContext.java | 6 ++ .../java/org/x4o/xml/io/DefaultX4ODriver.java | 6 ++ .../x4o/xml/io/DefaultX4OSchemaWriter.java | 6 ++ .../java/org/x4o/xml/io/DefaultX4OWriter.java | 10 ++- .../java/org/x4o/xml/io/X4OConnection.java | 6 ++ .../main/java/org/x4o/xml/io/X4OReader.java | 6 ++ .../java/org/x4o/xml/io/X4OReaderContext.java | 6 ++ .../java/org/x4o/xml/io/X4OSchemaWriter.java | 6 ++ .../main/java/org/x4o/xml/io/X4OWriter.java | 6 ++ .../java/org/x4o/xml/io/X4OWriterContext.java | 6 ++ .../java/org/x4o/xml/io/XMLConstants.java | 12 +++ .../java/org/x4o/xml/io/sax/XMLWriter.java | 3 + .../java/org/x4o/xml/io/X4OWriterTest.java | 27 +++++- .../org/x4o/xml/test/swixml/SwiXmlDriver.java | 4 - .../bind/JInternalFrameBindingHandler.java | 3 + .../META-INF/swixml/swixml-lang-2.0.eld | 3 + .../META-INF/swixml/swixml-lang-3.0.eld | 6 +- 22 files changed, 195 insertions(+), 37 deletions(-) diff --git a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java index 2f7bda0..3eb96cc 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java +++ b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java @@ -51,6 +51,12 @@ import org.xml.sax.XMLReader; import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.helpers.XMLReaderFactory; +/** + * X4ODriverManager controls all the x4o driver and languages loaded in the classpath. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public final class X4ODriverManager { public final static String X4O_DRIVERS_RESOURCE = "META-INF/x4o-drivers.xml"; diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java b/x4o-driver/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java index 9ae76bd..b8ed748 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java @@ -23,7 +23,6 @@ package org.x4o.xml.eld.lang; -import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Collection; import java.util.List; @@ -44,6 +43,7 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle private Class childClass = null; private String addMethod = null; private String getMethod = null; + private String skipChilderenClassRegex = null; /** * @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass() @@ -105,38 +105,54 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle if (getMethod.equalsIgnoreCase(m.getName())==false) { continue; } + Object result; try { - Object result = m.invoke(parentObject, new Object[]{}); - if (result==null) { - break; - } - if (result instanceof List) { - for (Object o:(List)result) { - createChild(parentElement, o); - } - return; - } else if (result instanceof Collection) { - for (Object o:(Collection)result) { - createChild(parentElement, o); - } - return; - } else if (result instanceof Array) { - for (Object o:(Object[])result) { - createChild(parentElement, o); - } - return; - } else { - throw new ElementBindingHandlerException("Unsuported return type: "+result.getClass()+" from: "+getMethod+" on: "+parentObject); - } + result = m.invoke(parentObject, new Object[]{}); } catch (Exception e) { - throw new ElementBindingHandlerException("Error invoke binding method of: "+getId()+" error: "+e.getMessage(),e); + throw new ElementBindingHandlerException("Invoke error: "+e.getMessage()+" from: "+getMethod+" on: "+parentObject+" id:"+getId(),e); + } + if (result==null) { + break; + } + if (result instanceof List) { + for (Object o:(List)result) { + createSafeChild(parentElement, o); + } + return; + } else if (result instanceof Collection) { + for (Object o:(Collection)result) { + createSafeChild(parentElement, o); + } + return; + } else if (result.getClass().isArray()) { + for (Object o:(Object[])result) { + createSafeChild(parentElement, o); + } + return; + } else if (childClass.isAssignableFrom(result.getClass())) { + createSafeChild(parentElement, result); + return; + } else { + throw new ElementBindingHandlerException("Unsuported return type: "+result.getClass()+" need: "+childClass+" from: "+getMethod+" on: "+parentObject+" id:"+getId()); } } throw new ElementBindingHandlerException("Could not find method: "+getMethod+" on: "+parentObject+" id:"+getId()); - - // } + + protected void createSafeChild(Element parentElement,Object childObject) { + if (childClass.isAssignableFrom(childObject.getClass())==false) { + return; + } + if (skipChilderenClassRegex!=null) { + if (childObject.getClass().getName().matches(skipChilderenClassRegex)) { + return; // skip + } + } + createChild(parentElement,childObject); + } + + /** * @return the parentClass */ @@ -192,4 +208,18 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle public void setGetMethod(String getMethod) { this.getMethod = getMethod; } + + /** + * @return the skipChilderenClassRegex + */ + public String getSkipChilderenClassRegex() { + return skipChilderenClassRegex; + } + + /** + * @param skipChilderenClassRegex the skipChilderenClassRegex to set + */ + public void setSkipChilderenClassRegex(String skipChilderenClassRegex) { + this.skipChilderenClassRegex = skipChilderenClassRegex; + } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementObjectPropertyValue.java b/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementObjectPropertyValue.java index c938d55..f48f22d 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementObjectPropertyValue.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementObjectPropertyValue.java @@ -272,7 +272,11 @@ public class DefaultElementObjectPropertyValue implements ElementObjectPropertyV // a bit hackie for(int i=0;i[] types = method.getParameterTypes(); + if (types.length != 0) { + continue; + } if(method.getName().equalsIgnoreCase(parameterNameSet)) { logger.finest("Found method: "+method.getName()); lastMethod = method; @@ -282,7 +286,7 @@ public class DefaultElementObjectPropertyValue implements ElementObjectPropertyV if (lastMethod==null) { for(int i=0;i extends AbstractX4OWriterContext implements X4OWriter { public AbstractX4OWriter(X4OLanguageContext elementLanguage) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java index 5a93f2e..16e8e94 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java @@ -34,6 +34,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.x4o.xml.lang.X4OLanguageContext; import org.xml.sax.SAXException; +/** + * AbstractX4OWriterContext. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public abstract class AbstractX4OWriterContext extends AbstractX4OConnection implements X4OWriterContext { public AbstractX4OWriterContext(X4OLanguageContext elementLanguage) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java index 07d7845..dd7581c 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java @@ -25,6 +25,12 @@ package org.x4o.xml.io; import org.x4o.xml.X4ODriver; +/** + * DefaultX4ODriver can be used to create language without code and type safty. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public class DefaultX4ODriver extends X4ODriver { private final String languageName; diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OSchemaWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OSchemaWriter.java index 493a212..c1777fa 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OSchemaWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OSchemaWriter.java @@ -30,6 +30,12 @@ import org.x4o.xml.element.ElementException; import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguagePropertyKeys; +/** + * DefaultX4OSchemaWriter can write the schema of a x4o language. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public class DefaultX4OSchemaWriter extends AbstractX4OConnection implements X4OSchemaWriter { public DefaultX4OSchemaWriter(X4OLanguageContext languageContext) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java index 8315595..7486ebb 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java @@ -44,12 +44,17 @@ import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceInstanceProviderException; import org.x4o.xml.element.ElementObjectPropertyValueException; import org.x4o.xml.io.sax.XMLWriter; -import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageModule; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; +/** + * DefaultX4OWriter can write the xml language. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public class DefaultX4OWriter extends AbstractX4OWriter { public DefaultX4OWriter(X4OLanguageContext elementLanguage) { @@ -115,6 +120,9 @@ public class DefaultX4OWriter extends AbstractX4OWriter { if (m.getName().startsWith("get")==false) { continue; } + if(m.getName().startsWith("getLocationOnScreen")) { + continue; // TODO: rm this + } String name = m.getName().substring(3,4).toLowerCase()+m.getName().substring(4); result.add(name); diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OConnection.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OConnection.java index 5b7e1ba..6507119 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OConnection.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OConnection.java @@ -23,6 +23,12 @@ package org.x4o.xml.io; +/** + * X4OConnection interface for config the io drivers. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public interface X4OConnection { /** diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java index 4f19e03..18bd13b 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java @@ -33,6 +33,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; +/** + * X4OReader can read different input formats. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public interface X4OReader extends X4OConnection { public void addELBeanInstance(String name,Object bean); diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OReaderContext.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OReaderContext.java index 45b3c0c..9bd2204 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OReaderContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OReaderContext.java @@ -35,6 +35,12 @@ import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.phase.X4OPhaseException; import org.xml.sax.SAXException; +/** + * X4OReaderContext is reader with language context. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public interface X4OReaderContext extends X4OReader { void releaseContext(X4OLanguageContext context) throws X4OPhaseException; diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OSchemaWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OSchemaWriter.java index ec0dfdf..3e6c14c 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OSchemaWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OSchemaWriter.java @@ -27,6 +27,12 @@ import java.io.File; import org.x4o.xml.element.ElementException; +/** + * X4OSchemaWriter can write the schema for the language. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public interface X4OSchemaWriter extends X4OConnection { void writeSchema(File basePath) throws ElementException; diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java index 0e578db..f04ab4a 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java @@ -32,6 +32,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; +/** + * X4OWriter can write the xml language. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public interface X4OWriter extends X4OConnection { void write(T object,OutputStream out) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java index 73c65bf..7b12816 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java @@ -33,6 +33,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.x4o.xml.lang.X4OLanguageContext; import org.xml.sax.SAXException; +/** + * X4OWriterContext is writer with language context. + * + * @author Willem Cazander + * @version 1.0 Apr 6, 2013 + */ public interface X4OWriterContext extends X4OWriter { void writeContext(X4OLanguageContext context,OutputStream out) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/XMLConstants.java b/x4o-driver/src/main/java/org/x4o/xml/io/XMLConstants.java index d831cad..c20f46a 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/XMLConstants.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/XMLConstants.java @@ -196,6 +196,18 @@ public final class XMLConstants { return false; } + static public boolean isNameString(String value) { + for (int i=0;i driver = SwiXmlDriver.getInstance(); + X4OReader reader = driver.createReader(); + X4OWriter writer = driver.createWriter(); + + reader.addELBeanInstance(SwiXmlDriver.LANGUAGE_EL_SWING_ENGINE, engine); + Component root = reader.readResource("tests/swixml/swixml-accelerator-3.0.xml"); + writer.writeFile(root, outputFile); + + assertTrue("Debug file does not exists.",outputFile.exists()); + + //String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + //System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath()); + + outputFile.delete(); + } } diff --git a/x4o-driver/src/test/java/org/x4o/xml/test/swixml/SwiXmlDriver.java b/x4o-driver/src/test/java/org/x4o/xml/test/swixml/SwiXmlDriver.java index c702003..84f9464 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/test/swixml/SwiXmlDriver.java +++ b/x4o-driver/src/test/java/org/x4o/xml/test/swixml/SwiXmlDriver.java @@ -29,11 +29,7 @@ import javax.el.ValueExpression; import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriverManager; -import org.x4o.xml.lang.DefaultX4OLanguage; -import org.x4o.xml.lang.DefaultX4OLanguageConfiguration; import org.x4o.xml.lang.X4OLanguageContext; -import org.x4o.xml.lang.X4OLanguage; -import org.x4o.xml.lang.X4OLanguagePropertyKeys; /** * SwiXmlParser works with the SwingEngine to config the UI tree. diff --git a/x4o-driver/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java b/x4o-driver/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java index 459af57..afdf2cd 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java +++ b/x4o-driver/src/test/java/org/x4o/xml/test/swixml/bind/JInternalFrameBindingHandler.java @@ -86,6 +86,9 @@ public class JInternalFrameBindingHandler extends AbstractElementBindingHandler< public void createChilderen(Element parentElement,JInternalFrame parent) throws ElementBindingHandlerException { for (Component c:parent.getComponents()) { if (c instanceof JComponent) { + if (c.getClass().getName().startsWith("javax.swing.plaf")) { + return; + } createChild(parentElement, c); } } diff --git a/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld b/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld index 501d178..eb0ec5a 100644 --- a/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld +++ b/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-2.0.eld @@ -43,6 +43,7 @@ + @@ -128,6 +129,8 @@ + + diff --git a/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld b/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld index ab2cd2b..f858914 100644 --- a/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld +++ b/x4o-driver/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld @@ -39,10 +39,11 @@ - + + @@ -122,6 +123,9 @@ + + +