Updated EL to 2.2 and made code and tests work under java 1.5.

This commit is contained in:
Willem Cazander 2012-09-26 21:49:08 +02:00
parent c38c283fe9
commit 4844df7f84
23 changed files with 215 additions and 178 deletions

View file

@ -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 --

View file

@ -96,9 +96,10 @@
<mockito-all.version>1.9.0</mockito-all.version>
<testng.version>6.3.1</testng.version>
<junit.version>4.10</junit.version>
<xerces.version>2.10.0</xerces.version><!-- Only needed in jdk1.5 -->
<!-- Application lib versions -->
<java.el.version>1.2</java.el.version>
<jasper-el.version>6.0.20</jasper-el.version>
<juel.version>2.1.0</juel.version>
</properties>
<build>

View file

@ -11,14 +11,9 @@
<description>x4o-core</description>
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>${java.el.version}</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-ri</artifactId>
<version>${java.el.version}</version>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper-el</artifactId>
<version>${jasper-el.version}</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
@ -32,6 +27,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -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();

View file

@ -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) {

View file

@ -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);

View file

@ -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;
}

View file

@ -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());
}
}

View file

@ -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<methodes.length;i++) {
Method method = methodes[i];
Class<?>[] 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,61 +117,37 @@ 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<methodes.length;i++) {
Method method = methodes[i];
if (method.getName().equalsIgnoreCase(parameterNameSet)) {
lastMethodFall = method;
if (parameterClass!=null && method.getParameterTypes()[0].isAssignableFrom(parameterClass)) {
logger.finest("Found method type: "+method.getParameterTypes()[0]+" for parameter: "+parameterName);
lastMethod = method;
break;
}
}
}
// old loop is now fallback code
if (lastMethod==null && lastMethodFall!=null) {
lastMethod=lastMethodFall;
}
// find the method for the parameter
Method lastMethod = findMethod(object,parameterName,parameter);
if (lastMethod==null) {
logger.finest("No method found, aborting parameter: "+parameterName);
return;
}
// Special case for null value.
if (parameter==null) {
logger.finest("Found parameter is null Setting method: "+lastMethod.getParameterTypes()[0]+" for parameter: "+parameterName);
try {
lastMethod.invoke(object,new Object[]{parameter});
return;
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
return;
}
// Invoke for class based parameters
if (lastMethod.getParameterTypes()[0].isAssignableFrom(parameter.getClass())) {
logger.finest("Found parameter type: "+lastMethod.getParameterTypes()[0]+" for parameter: "+parameterName+" setting value: "+parameter);
try {
lastMethod.invoke(object,new Object[]{parameter});
return;
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
return;
}
// Invoke for native based types
// not found 2sec try
logger.finest("No corresoning class is found, trying convert manualy");
@ -147,37 +181,6 @@ public class DefaultElementObjectPropertyValue implements ElementObjectPropertyV
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
/*
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Integer.class) ) {
logger.finest("found Integer");
parameter2 = Integer.parseInt(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Long.class) ) {
logger.finest("found Long");
parameter2 = Long.parseLong(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Double.class) ) {
logger.finest("found Double");
parameter2 = Double.parseDouble(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Float.class) ) {
logger.finest("found Float");
parameter2 = Float.parseFloat(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Byte.class) ) {
logger.finest("found Byte");
parameter2 = Byte.parseByte(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Character.class) ) {
logger.finest("found Character");
parameter2 = new Character(parameter.toString().charAt(0));
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Boolean.class) ) {
logger.finest("found Boolean");
// WARNING: this alway returns a boolean :''(
parameter2 = Boolean.parseBoolean(parameter.toString());
}*/
/*
* JAVA NATIVE TYPES:
*
@ -192,37 +195,6 @@ public class DefaultElementObjectPropertyValue implements ElementObjectPropertyV
* double 64
* void n/a
*/
/*
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Boolean.TYPE) ) {
logger.finest("found boolean");
parameter2 = Boolean.parseBoolean(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Integer.TYPE) ) {
logger.finest("found int");
parameter2 = Integer.parseInt(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Long.TYPE) ) {
logger.finest("found long");
parameter2 = Long.parseLong(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Double.TYPE) ) {
logger.finest("found int");
parameter2 = Double.parseDouble(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Float.TYPE) ) {
logger.finest("found float");
parameter2 = Float.parseFloat(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Byte.TYPE) ) {
logger.finest("found byte");
parameter2 = Byte.parseByte(parameter.toString());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Character.TYPE) ) {
logger.finest("found char");
parameter2 = new Character(parameter.toString().charAt(0));
}
*/
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Boolean.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Boolean.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());

View file

@ -71,13 +71,13 @@ public class DefaultX4OLanguageConfiguration implements X4OLanguageConfiguration
if (language==null) {
throw new NullPointerException("language may not be null");
}
if (language.isEmpty()) {
if (language.length()==0) {
throw new IllegalArgumentException("language may not be empty");
}
if (languageVersion==null) {
throw new NullPointerException("languageVersion may not be null");
}
if (languageVersion.isEmpty()) {
if (languageVersion.length()==0) {
throw new IllegalArgumentException("languageVersion may not be empty");
}
languageProperties = new HashMap<X4OLanguageProperty,Object>(20);

View file

@ -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);

View file

@ -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);

View file

@ -200,6 +200,12 @@ public class XMLWriter extends DefaultHandler2 {
if (attributeValue.contains("\"")) {
attributeValue=attributeValue.replaceAll("\"", "&quote;");
}
if (attributeValue.contains("<")) {
attributeValue=attributeValue.replaceAll("<", "&lt;");
}
if (attributeValue.contains(">")) {
attributeValue=attributeValue.replaceAll(">", "&gt;");
}
startElement.append(attributeValue);
startElement.append('"');

View file

@ -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);

View file

@ -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))) {

View file

@ -109,6 +109,7 @@
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.KeyStrokeConverter"/>
<attributeAlias name="Accelerator"/>
</attribute>
<attribute name="mnemonic" runBeanFill="false"/>
<attribute name="Action" runBeanFill="false"/>
<configurator id="menuitem-action" bean.class="org.x4o.xml.test.swixml.SwiXmlActionConfigurator"/>
</element>
@ -118,6 +119,9 @@
<attribute name="orientation">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.JSplitPaneOrientationConverter"/>
</attribute>
<attribute name="dividerLocation">
<conv:integerConverter/>
</attribute>
</element>
<element tag="scrollPane" objectClass="javax.swing.JScrollPane"/>
<element tag="tree" objectClass="javax.swing.JTree"/>

View file

@ -103,6 +103,7 @@
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.KeyStrokeConverter"/>
<attributeAlias name="Accelerator"/>
</attribute>
<attribute name="mnemonic" runBeanFill="false"/>
<attribute name="Action" runBeanFill="false"/>
<configurator id="menuitem-action" bean.class="org.x4o.xml.test.swixml.SwiXmlActionConfigurator"/>
</element>
@ -112,6 +113,9 @@
<attribute name="orientation">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.JSplitPaneOrientationConverter"/>
</attribute>
<attribute name="dividerLocation">
<conv:integerConverter/>
</attribute>
</element>
<element tag="JScrollPane" objectClass="javax.swing.JScrollPane"/>
<element tag="JTree" objectClass="javax.swing.JTree"/>

View file

@ -34,6 +34,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View file

@ -28,6 +28,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View file

@ -51,6 +51,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View file

@ -45,6 +45,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>${xerces.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>