From 4844df7f8472e5bfdaff933b1112c4dcfdc2f7a6 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Wed, 26 Sep 2012 21:49:08 +0200 Subject: [PATCH] Updated EL to 2.2 and made code and tests work under java 1.5. --- build.txt | 14 +- pom.xml | 5 +- x4o-core/pom.xml | 19 +- .../org/x4o/xml/core/X4OEntityResolver.java | 7 +- .../main/java/org/x4o/xml/core/X4OParser.java | 2 +- .../java/org/x4o/xml/core/X4OTagHandler.java | 4 +- .../xml/core/config/X4OLanguageProperty.java | 2 +- .../lang/AttributeFromBodyConfigurator.java | 4 +- .../lang/ElementRefectionBindingHandler.java | 11 +- .../x4o/xml/eld/xsd/EldXsdXmlGenerator.java | 2 +- .../DefaultElementObjectPropertyValue.java | 262 ++++++++---------- .../DefaultX4OLanguageConfiguration.java | 4 +- .../impl/config/DefaultX4OLanguageLoader.java | 2 +- .../org/x4o/xml/impl/el/X4OELResolver.java | 2 +- .../main/java/org/x4o/xml/sax/XMLWriter.java | 6 + .../java/org/x4o/xml/core/EmptyXmlTest.java | 7 +- .../xml/test/swixml/conv/ColorConverter.java | 2 +- .../META-INF/swixml/swixml-lang-2.0.eld | 6 +- .../META-INF/swixml/swixml-lang-3.0.eld | 6 +- x4o-elddoc/pom.xml | 6 + x4o-meta/pom.xml | 8 +- x4o-plugin/x4o-plugin-ant-elddoc/pom.xml | 6 + x4o-plugin/x4o-plugin-ant-schema/pom.xml | 6 + 23 files changed, 215 insertions(+), 178 deletions(-) diff --git a/build.txt b/build.txt index 3f6edf1..9a606d0 100644 --- a/build.txt +++ b/build.txt @@ -2,10 +2,22 @@ Building X4O You need a few software packages; -- java sdk 1.5 or higher. +- java 1.5 or higher. - maven 3 or higher. +-- Run multi jvm test -- + +todo make maven like; +note2: this does need maven 3.0.3++ in 3.0.1 there is some java6 classes. + +export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/;mvn clean test +export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/;mvn clean test +export JAVA_HOME=/usr/lib/jvm/j2sdk1.6-oracle/;mvn clean test +export JAVA_HOME=/usr/lib/jvm/j2sdk1.7-oracle/;mvn clean test +export JAVA_HOME=/usr/lib/jvm/jdk1.5.0_22/;~/bin/mvn3/apache-maven-3.0.3/bin/mvn clean test +#not working; +#export JAVA_HOME=/usr/lib/jvm/java-1.5.0-gcj-4.7/;~/bin/mvn3/apache-maven-3.0.3/bin/mvn clean test -- Create package -- diff --git a/pom.xml b/pom.xml index 9163f59..4774867 100644 --- a/pom.xml +++ b/pom.xml @@ -96,9 +96,10 @@ 1.9.0 6.3.1 4.10 + 2.10.0 - 1.2 + 6.0.20 2.1.0 @@ -414,6 +415,6 @@ - + diff --git a/x4o-core/pom.xml b/x4o-core/pom.xml index 0390b1b..fab4f6a 100644 --- a/x4o-core/pom.xml +++ b/x4o-core/pom.xml @@ -11,14 +11,9 @@ x4o-core - javax.el - el-api - ${java.el.version} - - - javax.el - el-ri - ${java.el.version} + org.apache.tomcat + jasper-el + ${jasper-el.version} de.odysseus.juel @@ -31,7 +26,13 @@ junit ${junit.version} test - + + + xerces + xercesImpl + ${xerces.version} + test + diff --git a/x4o-core/src/main/java/org/x4o/xml/core/X4OEntityResolver.java b/x4o-core/src/main/java/org/x4o/xml/core/X4OEntityResolver.java index de33d0e..7063c8a 100644 --- a/x4o-core/src/main/java/org/x4o/xml/core/X4OEntityResolver.java +++ b/x4o-core/src/main/java/org/x4o/xml/core/X4OEntityResolver.java @@ -124,7 +124,8 @@ public class X4OEntityResolver implements EntityResolver { in.setSystemId(systemId); return in; } catch (IOException e) { - throw new IOException("Could not open: "+schemaFile+" error: "+e.getMessage(),e); + // note; IOException(String,Exception) is java6 + throw new SAXException("Could not open: "+schemaFile+" error: "+e.getMessage(),e); } } } @@ -142,7 +143,7 @@ public class X4OEntityResolver implements EntityResolver { in.setSystemId(systemId); return in; } catch (IOException e) { - throw new IOException("Could not open: "+resource+" error: "+e.getMessage(),e); + throw new SAXException("Could not open: "+resource+" error: "+e.getMessage(),e); } } } @@ -155,7 +156,7 @@ public class X4OEntityResolver implements EntityResolver { in.setSystemId(systemId); return in; } catch (IOException e) { - throw new IOException("Could not open: "+systemId+" error: "+e.getMessage(),e); + throw new SAXException("Could not open: "+systemId+" error: "+e.getMessage(),e); } } diff --git a/x4o-core/src/main/java/org/x4o/xml/core/X4OParser.java b/x4o-core/src/main/java/org/x4o/xml/core/X4OParser.java index be64a49..ed02e62 100644 --- a/x4o-core/src/main/java/org/x4o/xml/core/X4OParser.java +++ b/x4o-core/src/main/java/org/x4o/xml/core/X4OParser.java @@ -127,7 +127,7 @@ public class X4OParser extends AbstractXMLParser implements X4OParserSupport { if (name==null) { throw new NullPointerException("Can't add null name."); } - if (name.isEmpty()) { + if (name.length()==0) { throw new NullPointerException("Can't add empty name."); } if (bean==null) { diff --git a/x4o-core/src/main/java/org/x4o/xml/core/X4OTagHandler.java b/x4o-core/src/main/java/org/x4o/xml/core/X4OTagHandler.java index d8bd3a4..e0deb86 100644 --- a/x4o-core/src/main/java/org/x4o/xml/core/X4OTagHandler.java +++ b/x4o-core/src/main/java/org/x4o/xml/core/X4OTagHandler.java @@ -220,10 +220,10 @@ public class X4OTagHandler extends DefaultHandler2 { return; // no text } String text = new String(ch,start,length); - if (text.isEmpty()) { + if (text.length()==0) { return; // no text } - if (elementStack.empty()) { + if (elementStack.isEmpty()) { return; // no element } Element e = elementStack.peek(); diff --git a/x4o-core/src/main/java/org/x4o/xml/core/config/X4OLanguageProperty.java b/x4o-core/src/main/java/org/x4o/xml/core/config/X4OLanguageProperty.java index d169255..b0aff2d 100644 --- a/x4o-core/src/main/java/org/x4o/xml/core/config/X4OLanguageProperty.java +++ b/x4o-core/src/main/java/org/x4o/xml/core/config/X4OLanguageProperty.java @@ -208,7 +208,7 @@ public enum X4OLanguageProperty { if (uri==null) { throw new NullPointerException("Can't search null uri."); } - if (uri.isEmpty()) { + if (uri.length()==0) { throw new IllegalArgumentException("Can't search empty uri."); } if (uri.startsWith(URI_PREFIX)==false) { diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java b/x4o-core/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java index c3740e0..2b50c12 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java @@ -48,7 +48,7 @@ public class AttributeFromBodyConfigurator extends AbstractElementConfigurator { if (name==null) { throw new ElementConfiguratorException(this,"name attribute is not set."); } - if (name.isEmpty()) { + if (name.length()==0) { throw new ElementConfiguratorException(this,"name attribute is empty."); } if (bodyType==null) { @@ -64,7 +64,7 @@ public class AttributeFromBodyConfigurator extends AbstractElementConfigurator { } else { throw new ElementConfiguratorException(this,"bodyType attribute value is unknown; "+bodyType); } - if (value.isEmpty()) { + if (value.length()==0) { return; } element.getAttributes().put(name, value); diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java b/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java index 3cb36df..00df63a 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/lang/ElementRefectionBindingHandler.java @@ -65,11 +65,18 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle } Method[] ms = parentObject.getClass().getMethods(); for (Method m:ms) { - if (method.equalsIgnoreCase(m.getName())) { + Class[] types = m.getParameterTypes(); + if (types.length == 0) { + continue; + } + if (types.length > 1) { + continue; + } + if (types[0].isAssignableFrom(childClass)) { try { m.invoke(parentObject, childObject); } catch (Exception e) { - throw new ElementBindingHandlerException("Error in binding beans: "+e.getMessage(),e); + throw new ElementBindingHandlerException("Error invoke binding method of: "+getId()+" error: "+e.getMessage(),e); } return; } diff --git a/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlGenerator.java b/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlGenerator.java index d3f4b4e..519479c 100644 --- a/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlGenerator.java +++ b/x4o-core/src/main/java/org/x4o/xml/eld/xsd/EldXsdXmlGenerator.java @@ -54,7 +54,7 @@ public class EldXsdXmlGenerator { if (ns.getSchemaResource()==null) { throw new NullPointerException("Can't generate xsd for namespace without schemaResource uri: "+ns.getUri()); } - if (ns.getSchemaResource().isEmpty()) { + if (ns.getSchemaResource().length()==0) { throw new NullPointerException("Can't generate xsd for namespace with empty schemaResource uri: "+ns.getUri()); } } diff --git a/x4o-core/src/main/java/org/x4o/xml/impl/DefaultElementObjectPropertyValue.java b/x4o-core/src/main/java/org/x4o/xml/impl/DefaultElementObjectPropertyValue.java index c9a56b9..9b413fe 100644 --- a/x4o-core/src/main/java/org/x4o/xml/impl/DefaultElementObjectPropertyValue.java +++ b/x4o-core/src/main/java/org/x4o/xml/impl/DefaultElementObjectPropertyValue.java @@ -46,6 +46,64 @@ public class DefaultElementObjectPropertyValue implements ElementObjectPropertyV private static final long serialVersionUID = 1L; + private Logger logger = Logger.getLogger(DefaultElementObjectPropertyValue.class.getName()); + + private Method findMethod(Object object,String parameterName,Object parameter) { + + // Get class but can be null. + Class parameterClass = null; + if(parameter!=null) { + parameterClass=parameter.getClass(); + } + logger.finer("Trying value: pn="+parameterName+" o="+object+" p="+parameter+"("+parameterClass+")"); + String parameterNameSet = "set"+parameterName; + Method[] methodes = object.getClass().getMethods(); + Method lastMethodFall = null; + for (int i=0;i[] types = method.getParameterTypes(); + if (types.length == 0) { + continue; + } + if (types.length > 1) { + continue; + } + if (method.getName().equalsIgnoreCase(parameterNameSet)) { + lastMethodFall = method; + if (parameterClass!=null) { + // Check for class based parameters. + if (types[0].isAssignableFrom(parameterClass)) { + logger.finest("Found method type: "+method.getParameterTypes()[0]+" for parameter: "+parameterName); + return method; + } + // Check the native parameter types. + if (parameterClass.isAssignableFrom(Boolean.class) && types[0].isAssignableFrom(Boolean.TYPE) ) { + return method; + } + if (parameterClass.isAssignableFrom(Integer.class) && types[0].isAssignableFrom(Integer.TYPE) ) { + return method; + } + if (parameterClass.isAssignableFrom(Long.class) && types[0].isAssignableFrom(Long.TYPE) ) { + return method; + } + if (parameterClass.isAssignableFrom(Double.class) && types[0].isAssignableFrom(Double.TYPE) ) { + return method; + } + if (parameterClass.isAssignableFrom(Float.class) && types[0].isAssignableFrom(Float.TYPE) ) { + return method; + } + if (parameterClass.isAssignableFrom(Byte.class) && types[0].isAssignableFrom(Byte.TYPE) ) { + return method; + } + if (parameterClass.isAssignableFrom(Character.class) && types[0].isAssignableFrom(Character.TYPE) ) { + return method; + } + } + } + } + return lastMethodFall; + } + /** * TODO: this function is not completed !! * @@ -59,60 +117,36 @@ public class DefaultElementObjectPropertyValue implements ElementObjectPropertyV */ public void setProperty(Object object,String parameterName,Object parameter) throws ElementObjectPropertyValueException { - // a bit hackie - Class parameterClass = null; - if(parameter!=null) { - parameterClass=parameter.getClass(); - } - - Logger logger = Logger.getLogger(DefaultElementObjectPropertyValue.class.getName()); - - logger.finer("Trying value: pn="+parameterName+" o="+object+" p="+parameter+"("+parameterClass+")"); - String parameterNameSet = "set"+parameterName; - Method[] methodes = object.getClass().getMethods(); - Method lastMethod = null; - Method lastMethodFall = null; - - for (int i=0;i(20); diff --git a/x4o-core/src/main/java/org/x4o/xml/impl/config/DefaultX4OLanguageLoader.java b/x4o-core/src/main/java/org/x4o/xml/impl/config/DefaultX4OLanguageLoader.java index 0c1cbf1..13e8b6b 100644 --- a/x4o-core/src/main/java/org/x4o/xml/impl/config/DefaultX4OLanguageLoader.java +++ b/x4o-core/src/main/java/org/x4o/xml/impl/config/DefaultX4OLanguageLoader.java @@ -251,7 +251,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader { @Override public void characters(char[] ch, int start, int length) throws SAXException { String text = new String(ch,start,length).trim(); - if (text.isEmpty()) { + if (text.length()==0) { return; } buf.append(text); diff --git a/x4o-core/src/main/java/org/x4o/xml/impl/el/X4OELResolver.java b/x4o-core/src/main/java/org/x4o/xml/impl/el/X4OELResolver.java index 058fa67..fa1206c 100644 --- a/x4o-core/src/main/java/org/x4o/xml/impl/el/X4OELResolver.java +++ b/x4o-core/src/main/java/org/x4o/xml/impl/el/X4OELResolver.java @@ -67,7 +67,7 @@ public class X4OELResolver extends ELResolver { } @Override - @SuppressWarnings("rawtypes") + @SuppressWarnings({ "rawtypes", "unchecked" }) public Iterator getFeatureDescriptors(ELContext context,Object base) { base = checkBase(base); return delegate.getFeatureDescriptors(context, base); diff --git a/x4o-core/src/main/java/org/x4o/xml/sax/XMLWriter.java b/x4o-core/src/main/java/org/x4o/xml/sax/XMLWriter.java index f4796ee..558f4cf 100644 --- a/x4o-core/src/main/java/org/x4o/xml/sax/XMLWriter.java +++ b/x4o-core/src/main/java/org/x4o/xml/sax/XMLWriter.java @@ -200,6 +200,12 @@ public class XMLWriter extends DefaultHandler2 { if (attributeValue.contains("\"")) { attributeValue=attributeValue.replaceAll("\"", ""e;"); } + if (attributeValue.contains("<")) { + attributeValue=attributeValue.replaceAll("<", "<"); + } + if (attributeValue.contains(">")) { + attributeValue=attributeValue.replaceAll(">", ">"); + } startElement.append(attributeValue); startElement.append('"'); diff --git a/x4o-core/src/test/java/org/x4o/xml/core/EmptyXmlTest.java b/x4o-core/src/test/java/org/x4o/xml/core/EmptyXmlTest.java index 922564c..71498f3 100644 --- a/x4o-core/src/test/java/org/x4o/xml/core/EmptyXmlTest.java +++ b/x4o-core/src/test/java/org/x4o/xml/core/EmptyXmlTest.java @@ -91,7 +91,12 @@ public class EmptyXmlTest extends TestCase { try { parser.parseResource("tests/empty-xml/empty-xml.xml"); } catch (SAXException e) { - assertEquals(true,e.getMessage().contains("Premature end of file.")); + boolean hasError = e.getMessage().contains("Premature end of file."); + if (System.getProperty("java.version").startsWith("1.5")) { + hasError = e.getMessage().contains("A well-formed document requires a root element."); + } + + assertEquals(true,hasError); return; } assertEquals(true,false); diff --git a/x4o-core/src/test/java/org/x4o/xml/test/swixml/conv/ColorConverter.java b/x4o-core/src/test/java/org/x4o/xml/test/swixml/conv/ColorConverter.java index f85bc7d..89df632 100644 --- a/x4o-core/src/test/java/org/x4o/xml/test/swixml/conv/ColorConverter.java +++ b/x4o-core/src/test/java/org/x4o/xml/test/swixml/conv/ColorConverter.java @@ -50,7 +50,7 @@ public class ColorConverter extends AbstractStringObjectConverter { public Object convertStringTo(String str, Locale locale) throws ObjectConverterException { try { - if (str.isEmpty()) { + if (str.length()==0) { throw new ObjectConverterException(this,"Can't convert empty color."); } if (Character.isDigit(str.charAt(0))) { 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 be14379..da2bc52 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 @@ -39,7 +39,7 @@ - + @@ -109,6 +109,7 @@ + @@ -118,6 +119,9 @@ + + + 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 87c9eff..e16bc2e 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 @@ -39,7 +39,7 @@ - + @@ -103,6 +103,7 @@ + @@ -112,6 +113,9 @@ + + + diff --git a/x4o-elddoc/pom.xml b/x4o-elddoc/pom.xml index 0d7bfce..ebbeb53 100644 --- a/x4o-elddoc/pom.xml +++ b/x4o-elddoc/pom.xml @@ -34,6 +34,12 @@ test-jar test + + xerces + xercesImpl + ${xerces.version} + test + diff --git a/x4o-meta/pom.xml b/x4o-meta/pom.xml index ee84f4d..ea4c557 100644 --- a/x4o-meta/pom.xml +++ b/x4o-meta/pom.xml @@ -27,7 +27,13 @@ junit ${junit.version} test - + + + xerces + xercesImpl + ${xerces.version} + test + diff --git a/x4o-plugin/x4o-plugin-ant-elddoc/pom.xml b/x4o-plugin/x4o-plugin-ant-elddoc/pom.xml index 76d539c..526605a 100644 --- a/x4o-plugin/x4o-plugin-ant-elddoc/pom.xml +++ b/x4o-plugin/x4o-plugin-ant-elddoc/pom.xml @@ -51,6 +51,12 @@ test-jar test + + xerces + xercesImpl + ${xerces.version} + test + diff --git a/x4o-plugin/x4o-plugin-ant-schema/pom.xml b/x4o-plugin/x4o-plugin-ant-schema/pom.xml index 6a0136f..28b0a03 100644 --- a/x4o-plugin/x4o-plugin-ant-schema/pom.xml +++ b/x4o-plugin/x4o-plugin-ant-schema/pom.xml @@ -45,6 +45,12 @@ test-jar test + + xerces + xercesImpl + ${xerces.version} + test +