Init commit of full project.

This commit is contained in:
Willem Cazander 2012-09-11 13:15:26 +02:00
parent 130d471bd9
commit 787b1174b0
286 changed files with 27010 additions and 1 deletions

36
x4o-core/.project Normal file
View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>x4o-core</name>
<comment>x4o-core</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

64
x4o-core/pom.xml Normal file
View file

@ -0,0 +1,64 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>x4o</artifactId>
<groupId>org.x4o</groupId>
<version>0.8.2-SNAPSHOT</version>
</parent>
<artifactId>x4o-core</artifactId>
<packaging>jar</packaging>
<name>x4o-core</name>
<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>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel</artifactId>
<version>${juel.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven-site-plugin.version}</version>
<configuration>
<siteDirectory>${project.basedir}/../src/site-child</siteDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,103 @@
/*
* 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.conv;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* AbstractObjectConverter to create ObjectConverters.
*
* @author Willem Cazander
* @version 1.0 Jan 30, 2012
*/
@SuppressWarnings("serial")
abstract public class AbstractObjectConverter implements ObjectConverter {
protected List<ObjectConverter> converters = new ArrayList<ObjectConverter>(5);
abstract public Object convertAfterTo(Object obj, Locale locale) throws ObjectConverterException;
abstract public Object convertAfterBack(Object obj, Locale locale) throws ObjectConverterException;
abstract public ObjectConverter clone() throws CloneNotSupportedException;
protected List<ObjectConverter> cloneConverters() throws CloneNotSupportedException {
List<ObjectConverter> result = new ArrayList<ObjectConverter>(converters.size());
for (ObjectConverter converter:converters) {
result.add(converter.clone());
}
return result;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#convertTo(java.lang.Object, java.util.Locale)
*/
public Object convertTo(Object obj, Locale locale) throws ObjectConverterException {
if (converters.isEmpty()) {
return convertAfterTo(obj,locale);
}
Object result = null;
for (ObjectConverter conv:converters) {
result = conv.convertTo(obj, locale);
}
result = convertAfterTo(obj,locale);
return result;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#convertBack(java.lang.Object, java.util.Locale)
*/
public Object convertBack(Object obj, Locale locale) throws ObjectConverterException {
if (converters.isEmpty()) {
return convertAfterBack(obj,locale);
}
Object result = null;
for (ObjectConverter conv:converters) {
result = conv.convertBack(obj, locale);
}
result = convertAfterBack(obj,locale);
return result;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#getObjectConverters()
*/
public List<ObjectConverter> getObjectConverters() {
return converters;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#addObjectConverter(org.x4o.xml.conv.ObjectConverter)
*/
public void addObjectConverter(ObjectConverter converter) {
converters.add(converter);
}
/**
* @see org.x4o.xml.conv.ObjectConverter#removeObjectConverter(org.x4o.xml.conv.ObjectConverter)
*/
public void removeObjectConverter(ObjectConverter converter) {
converters.remove(converter);
}
}

View file

@ -0,0 +1,58 @@
/*
* 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.conv;
import java.util.Locale;
/**
* AbstractStringObjectConverter to create ObjectConverters which work with strings.
*
* @author Willem Cazander
* @version 1.0 Jan 30, 2012
*/
@SuppressWarnings("serial")
abstract public class AbstractStringObjectConverter extends AbstractObjectConverter {
/**
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassBack()
*/
public Class<?> getObjectClassBack() {
return String.class;
}
public Object convertAfterTo(Object obj, Locale locale) throws ObjectConverterException {
if (obj instanceof String) {
return convertStringTo((String)obj,locale);
} else {
return convertStringTo(obj.toString(),locale);
}
}
public Object convertAfterBack(Object obj, Locale locale) throws ObjectConverterException {
return convertStringBack(obj,locale);
}
abstract public Object convertStringTo(String str, Locale locale) throws ObjectConverterException;
abstract public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException;
}

View file

@ -0,0 +1,100 @@
/*
* 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.conv;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.x4o.xml.conv.text.BooleanConverter;
import org.x4o.xml.conv.text.ByteConverter;
import org.x4o.xml.conv.text.CharacterConverter;
import org.x4o.xml.conv.text.ClassConverter;
import org.x4o.xml.conv.text.DoubleConverter;
import org.x4o.xml.conv.text.FloatConverter;
import org.x4o.xml.conv.text.IntegerConverter;
import org.x4o.xml.conv.text.LongConverter;
import org.x4o.xml.conv.text.URLConverter;
/**
* DefaultObjectConverterProvider.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class DefaultObjectConverterProvider implements ObjectConverterProvider {
private Map<Class<?>,ObjectConverter> converters = null;
/**
* Create new DefaultObjectConverterProvider.
*/
public DefaultObjectConverterProvider() {
converters = new HashMap<Class<?>,ObjectConverter>(20);
}
/**
* Create new DefaultObjectConverterProvider.
* @param addDefaults When true do the addDefaults().
*/
public DefaultObjectConverterProvider(boolean addDefaults) {
this();
if (addDefaults) {
addDefaults();
}
}
/**
* Adds the default converters.
*/
public void addDefaults() {
addObjectConverter(new BooleanConverter());
addObjectConverter(new ByteConverter());
addObjectConverter(new CharacterConverter());
addObjectConverter(new DoubleConverter());
addObjectConverter(new FloatConverter());
addObjectConverter(new IntegerConverter());
addObjectConverter(new LongConverter());
addObjectConverter(new URLConverter());
addObjectConverter(new ClassConverter());
}
/**
* @param converter The converter to add.
*/
public void addObjectConverter(ObjectConverter converter) {
converters.put(converter.getObjectClassTo(), converter);
}
/**
* @see org.x4o.xml.conv.ObjectConverterProvider#getObjectConverterForClass(java.lang.Class)
*/
public ObjectConverter getObjectConverterForClass(Class<?> clazz) {
return converters.get(clazz);
}
protected Collection<ObjectConverter> getObjectConverters() {
return converters.values();
}
}

View file

@ -0,0 +1,88 @@
/*
* 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.conv;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
/**
* The interface to convert objects.
*
* @author Willem Cazander
* @version 1.0 Aug 28, 2008
*/
public interface ObjectConverter extends Cloneable,Serializable {
/**
* @return Returns the class which we can convert to.
*/
Class<?> getObjectClassTo();
/**
* @return Returns the class which we can convert from.
*/
Class<?> getObjectClassBack();
/**
* Convert to the object.
* @param obj The object to convert.
* @param locale The Object convert locale if needed.
* @return Returns the converted object.
* @throws ObjectConverterException
*/
Object convertTo(Object obj,Locale locale) throws ObjectConverterException;
/**
* Convert the object back.
* @param obj The object to convert.
* @param locale The Object convert locale if needed.
* @return Returns the converted object.
* @throws ObjectConverterException
*/
Object convertBack(Object obj,Locale locale) throws ObjectConverterException;
/**
* @return Returns list of child converters.
*/
List<ObjectConverter> getObjectConverters();
/**
* @param converter Adds an child converter.
*/
void addObjectConverter(ObjectConverter converter);
/**
* @param converter Removes this child converter.
*/
void removeObjectConverter(ObjectConverter converter);
/**
* Force impl to have public clone method.
*
* @return An cloned ObjectConverter.
* @throws CloneNotSupportedException If thrown when cloning is not supported.
*/
ObjectConverter clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,64 @@
/*
* 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.conv;
/**
* ObjectConverterException is thrown by an ObjectConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class ObjectConverterException extends Exception {
private static final long serialVersionUID = 1L;
private final ObjectConverter converter;
/**
* Creates an ObjectConverterException.
* @param converter The converter which has the exception.
* @param message The exception message.
*/
public ObjectConverterException(ObjectConverter converter,String message) {
super(message);
this.converter=converter;
}
/**
* Creates an ObjectConverterException.
* @param converter The converter which has the exception.
* @param message The exception message.
* @param exception The parent exception.
*/
public ObjectConverterException(ObjectConverter converter,String message,Exception exception) {
super(message,exception);
this.converter=converter;
}
/**
* @return Returns the ObjectConverter of this exception.
*/
public ObjectConverter getObjectConverter() {
return converter;
}
}

View file

@ -0,0 +1,40 @@
/*
* 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.conv;
/**
* ObjectConverterProvider for class.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public interface ObjectConverterProvider {
/**
* Provides an ObjectConvert based on the converted class result.
* @param clazz The result class we want.
* @return The ObjectConverter which can convert for us.
*/
ObjectConverter getObjectConverterForClass(Class<?> clazz);
}

View file

@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* Provides interfaces for two way object converters.
*
*
* @since 1.0
*/
package org.x4o.xml.conv;

View file

@ -0,0 +1,61 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* BooleanConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class BooleanConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -6641858854858931768L;
public Class<?> getObjectClassTo() {
return Boolean.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
// WARNING: this alway returns a boolean :''(
return new Boolean(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Boolean)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
BooleanConverter result = new BooleanConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* ByteConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class ByteConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -719929830363810123L;
public Class<?> getObjectClassTo() {
return Byte.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Byte(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Byte)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ByteConverter result = new ByteConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* CharacterConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class CharacterConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -5864405229292234565L;
public Class<?> getObjectClassTo() {
return Character.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Character(str.charAt(0));
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Character)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
CharacterConverter result = new CharacterConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,65 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* Converts a String of an className into the the Class object.
*
* @author Willem Cazander
* @version 1.0 Aug 31, 2007
*/
public class ClassConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -1992327327215087127L;
public Class<?> getObjectClassTo() {
return Class.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return X4OLanguageClassLoader.loadClass(str);
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Class<?>)obj).getName();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ClassConverter result = new ClassConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* DoubleConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class DoubleConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 3283317726435306051L;
public Class<?> getObjectClassTo() {
return Double.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Double(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Double)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
DoubleConverter result = new DoubleConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,102 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* Converts Sring of an Enum into the enum value.
*
* @author Willem Cazander
* @version 1.0 Aug 31, 2007
*/
@SuppressWarnings({"rawtypes","unchecked"})
public class EnumConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 8860785472427794548L;
private String enumClass = null;
private Class enumObjectClass = null;
public Class<?> getObjectClassTo() {
return Enum.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
if (getEnumClass()==null) {
throw new ObjectConverterException(this,"enumClass String attribute is not set.");
}
//if (value instanceof Enum) {
// return value;
//}
String v = str; //value.toString();
try {
if (enumObjectClass==null) {
enumObjectClass = (Class<?>)X4OLanguageClassLoader.loadClass(getEnumClass());
}
if (enumObjectClass==null) {
throw new ObjectConverterException(this,"Could not load enumClass");
}
return Enum.valueOf(enumObjectClass, v);
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Enum<?>)obj).name();
}
/**
* @return the enumClass
*/
public String getEnumClass() {
return enumClass;
}
/**
* @param enumClass the enumClass to set
*/
public void setEnumClass(String enumClass) {
this.enumClass = enumClass;
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
EnumConverter result = new EnumConverter();
result.converters=cloneConverters();
result.enumClass=enumClass;
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* FloatConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class FloatConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 8038640125557062170L;
public Class<?> getObjectClassTo() {
return Float.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Float(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Float)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
FloatConverter result = new FloatConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* IntegerConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class IntegerConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 6618552093124468324L;
public Class<?> getObjectClassTo() {
return Integer.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Integer(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Integer)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
IntegerConverter result = new IntegerConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* LongConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class LongConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 25132217809739854L;
public Class<?> getObjectClassTo() {
return Long.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Long(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Long)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
LongConverter result = new LongConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,268 @@
/*
* 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.conv.text;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* StringSplitConverter.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class StringSplitConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 418588893457634317L;
private Class<?> classTo = null;
private String split = null;
private Integer splitSize = null;
private String singleToMethod = null;
private Boolean useNativeType = null;
private List<StringSplitConverterStep> stringSplitConverterSteps = null;
public StringSplitConverter() {
stringSplitConverterSteps = new ArrayList<StringSplitConverterStep>(10);
}
public Class<?> getObjectClassTo() {
return classTo;
}
@SuppressWarnings("rawtypes")
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
if (split==null) {
throw new ObjectConverterException(this,"split is not set.");
}
if (splitSize==null) {
throw new ObjectConverterException(this,"splitSize is not set.");
}
if (classTo==null) {
throw new ObjectConverterException(this,"classTo is not set.");
}
String[] strSplit = str.split(split);
if(strSplit.length!=splitSize) {
throw new ObjectConverterException(this,"Split size is wrong; "+strSplit.length+" need: "+splitSize);
}
List<StringSplitConverterStep> steps = getOrderedSteps(true);
if (steps.size()!=splitSize) {
throw new ObjectConverterException(this,"Step size is wrong; "+steps.size()+" need: "+splitSize);
}
try {
Object[] singleMethodValues = new Object[splitSize];
Object object = X4OLanguageClassLoader.newInstance(classTo);
for (int i=0;i<steps.size();i++) {
StringSplitConverterStep step = steps.get(i);
Object stepObject = strSplit[i];
Object stepValue = step.getObjectConverter().convertTo(stepObject, locale);
if (singleToMethod==null) {
Method m = classTo.getMethod(step.getToMethod(), new Class[] {stepValue.getClass()});
m.invoke(object, stepValue);
} else {
singleMethodValues[i] = stepValue;
}
}
if (singleToMethod!=null) {
List<Class> arguClass = new ArrayList<Class>(singleMethodValues.length);
for (int i=0;i<singleMethodValues.length;i++) {
arguClass.add(singleMethodValues[i].getClass());
}
if (useNativeType!=null && useNativeType) {
arguClass = convertToNative(arguClass);
}
Class[] arguArray = new Class[arguClass.size()];
arguArray = arguClass.toArray(arguArray);
Method m = classTo.getMethod(singleToMethod, arguArray);
List<Object> arguValue = new ArrayList<Object>(singleMethodValues.length);
for (int i=0;i<singleMethodValues.length;i++) {
arguValue.add(singleMethodValues[i]);
}
Object[] valueArray = new Object[arguValue.size()];
valueArray = arguValue.toArray(valueArray);
m.invoke(object, valueArray);
}
return object;
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
public String convertStringBack(Object object,Locale locale) throws ObjectConverterException {
List<StringSplitConverterStep> steps = getOrderedSteps(false);
if (steps.size()!=splitSize) {
throw new ObjectConverterException(this,"Step size is wrong; "+steps.size()+" need: "+splitSize);
}
try {
StringBuffer buf = new StringBuffer(200);
for (int i=0;i<steps.size();i++) {
StringSplitConverterStep step = steps.get(i);
Method m = classTo.getMethod(step.getFromMethod(), new Class[] {});
Object stepValue = m.invoke(object, new Object[] {});
Object stepString = step.getObjectConverter().convertBack(stepValue, locale);
buf.append(stepString.toString());
}
return buf.toString();
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
StringSplitConverter result = new StringSplitConverter();
result.converters=cloneConverters();
return result;
}
private List<StringSplitConverterStep> getOrderedSteps(boolean isTo) {
List<StringSplitConverterStep> result = new ArrayList<StringSplitConverterStep>(stringSplitConverterSteps.size());
result.addAll(stringSplitConverterSteps);
Collections.sort(stringSplitConverterSteps,new StringSplitConverterStepComparator(isTo));
return result;
}
public class StringSplitConverterStepComparator implements Comparator<StringSplitConverterStep> {
boolean isTo = true;
public StringSplitConverterStepComparator(boolean isTo) { this.isTo=isTo; }
public int compare(StringSplitConverterStep e1, StringSplitConverterStep e2) {
if (isTo) {
return e1.getToOrder().compareTo(e2.getToOrder());
} else {
return e1.getFromOrder().compareTo(e2.getFromOrder());
}
}
}
@SuppressWarnings("rawtypes")
private List<Class> convertToNative(List<Class> types) throws ObjectConverterException {
List<Class> result = new ArrayList<Class>(types.size());
for (int i=0;i<types.size();i++) {
Class<?> clazz = types.get(i);
if (clazz.isAssignableFrom(Integer.class)) {
result.add(Integer.TYPE);
} else if (clazz.isAssignableFrom(Long.class)) {
result.add(Long.TYPE);
} else if (clazz.isAssignableFrom(Float.class)) {
result.add(Float.TYPE);
} else if (clazz.isAssignableFrom(Double.class)) {
result.add(Double.TYPE);
} else if (clazz.isAssignableFrom(Boolean.class)) {
result.add(Boolean.TYPE);
} else {
throw new ObjectConverterException(this,"Can't convert type to native; "+clazz);
}
}
return result;
}
/**
* @return the classTo
*/
public Class<?> getClassTo() {
return classTo;
}
/**
* @param classTo the classTo to set
*/
public void setClassTo(Class<?> classTo) {
this.classTo = classTo;
}
/**
* @return the split
*/
public String getSplit() {
return split;
}
/**
* @param split the split to set
*/
public void setSplit(String split) {
this.split = split;
}
/**
* @return the splitSize
*/
public Integer getSplitSize() {
return splitSize;
}
/**
* @param splitSize the splitSize to set
*/
public void setSplitSize(Integer splitSize) {
this.splitSize = splitSize;
}
/**
* @return the singleToMethod
*/
public String getSingleToMethod() {
return singleToMethod;
}
/**
* @param singleToMethod the singleToMethod to set
*/
public void setSingleToMethod(String singleToMethod) {
this.singleToMethod = singleToMethod;
}
/**
* @return the useNativeType
*/
public Boolean getUseNativeType() {
return useNativeType;
}
/**
* @param useNativeType the useNativeType to set
*/
public void setUseNativeType(Boolean useNativeType) {
this.useNativeType = useNativeType;
}
public void addStringSplitConverterStep(StringSplitConverterStep stringSplitConverterStep) {
stringSplitConverterSteps.add(stringSplitConverterStep);
}
public void removeStringSplitConverterStep(StringSplitConverterStep stringSplitConverterStep) {
stringSplitConverterSteps.remove(stringSplitConverterStep);
}
public List<StringSplitConverterStep> getStringSplitConverterSteps() {
return stringSplitConverterSteps;
}
}

View file

@ -0,0 +1,111 @@
/*
* 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.conv.text;
import org.x4o.xml.conv.ObjectConverter;
/**
* StringSplitConverterStep.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class StringSplitConverterStep {
private ObjectConverter objectConverter = null;
private String fromMethod = null;
private Integer fromOrder = null;
private String toMethod = null;
private Integer toOrder = null;
/**
* @return the objectConverter
*/
public ObjectConverter getObjectConverter() {
return objectConverter;
}
/**
* @param objectConverter the objectConverter to set
*/
public void setObjectConverter(ObjectConverter objectConverter) {
this.objectConverter = objectConverter;
}
/**
* @return the fromMethod
*/
public String getFromMethod() {
return fromMethod;
}
/**
* @param fromMethod the fromMethod to set
*/
public void setFromMethod(String fromMethod) {
this.fromMethod = fromMethod;
}
/**
* @return the fromOrder
*/
public Integer getFromOrder() {
return fromOrder;
}
/**
* @param fromOrder the fromOrder to set
*/
public void setFromOrder(Integer fromOrder) {
this.fromOrder = fromOrder;
}
/**
* @return the toMethod
*/
public String getToMethod() {
return toMethod;
}
/**
* @param toMethod the toMethod to set
*/
public void setToMethod(String toMethod) {
this.toMethod = toMethod;
}
/**
* @return the toOrder
*/
public Integer getToOrder() {
return toOrder;
}
/**
* @param toOrder the toOrder to set
*/
public void setToOrder(Integer toOrder) {
this.toOrder = toOrder;
}
}

View file

@ -0,0 +1,78 @@
/*
* 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.conv.text;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* URLConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class URLConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -611843641266301893L;
/**
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
*/
public Class<?> getObjectClassTo() {
return URL.class;
}
/**
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return new URL(str);
} catch (MalformedURLException e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
/**
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((URL)obj).toString();
}
/**
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
URLConverter result = new URLConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,32 @@
/*
* 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.
*/
/**
* Provides default java text converters.
*
*
* @since 1.0
* @see org.x4o.xml.conv
*/
package org.x4o.xml.conv.text;

View file

@ -0,0 +1,76 @@
/*
* 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.core;
import java.util.ArrayList;
import java.util.List;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementLanguage;
/**
* An base class for creating X4OPhaseHandlers.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
abstract public class AbstractX4OPhaseHandler implements X4OPhaseHandler {
protected X4OPhase phase = null;
protected List<X4OPhaseListener> X4OPhaseListeners = null;
public AbstractX4OPhaseHandler() {
X4OPhaseListeners = new ArrayList<X4OPhaseListener>(3);
setX4OPhase();
}
/**
* Is called from constuctor
*/
abstract protected void setX4OPhase();
public X4OPhase getX4OPhase() {
return phase;
}
public List<X4OPhaseListener> getX4OPhaseListeners() {
return X4OPhaseListeners;
}
public void addPhaseListener(X4OPhaseListener listener) {
X4OPhaseListeners.add(listener);
}
public void removePhaseListener(X4OPhaseListener listener) {
X4OPhaseListeners.remove(listener);
}
public boolean isElementPhase() {
return true;
}
abstract public void runElementPhase(Element element) throws X4OPhaseException;
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
}
}

View file

@ -0,0 +1,522 @@
/*
* 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.core;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
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.ElementClassBase;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
/**
* Helps writing the xml debug output of all stuff x4o does.
*
* @author Willem Cazander
* @version 1.0 Jan 15, 2009
*/
public class X4ODebugWriter {
static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output";
protected DefaultHandler2 debugWriter = null;
public X4ODebugWriter(DefaultHandler2 debugWriter) {
this.debugWriter=debugWriter;
}
protected DefaultHandler2 getDebugWriter() {
return debugWriter;
}
public X4OPhaseListener createDebugX4OPhaseListener() {
return new DebugX4OPhaseListener();
}
class DebugX4OPhaseListener implements X4OPhaseListener {
long startTime = 0;
/**
* @throws X4OPhaseException
* @see org.x4o.xml.core.X4OPhaseListener#preRunPhase(org.x4o.xml.element.ElementLanguage)
*/
public void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
startTime = System.currentTimeMillis();
try {
AttributesImpl atts = new AttributesImpl();
if (elementLanguage!=null) {
atts.addAttribute("", "language","","", elementLanguage.getLanguageConfiguration().getLanguage());
}
debugWriter.startElement (DEBUG_URI, "executePhase", "", atts);
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
debugPhase(phase);
}
public void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
long stopTime = System.currentTimeMillis();
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", phase.getX4OPhase().name());
atts.addAttribute ("", "speed", "", "", (stopTime-startTime)+" ms");
debugWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts);
debugWriter.endElement (DEBUG_URI, "executePhaseDone" , "");
debugWriter.endElement (DEBUG_URI, "executePhase" , "");
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
}
}
public void debugLanguageProperties(ElementLanguage ec) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperties", "", atts);
for (X4OLanguageProperty p:X4OLanguageProperty.values()) {
Object value = ec.getLanguageConfiguration().getLanguageProperty(p);
if (value==null) {
continue;
}
AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "uri", "", "", p.toUri());
atts2.addAttribute ("", "value", "", "", value.toString());
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperty", "", atts2);
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperty", "");
}
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperties", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugLanguageDefaultClasses(ElementLanguage ec) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts);
X4OLanguageConfiguration conf = ec.getLanguageConfiguration();
debugLanguageDefaultClass("getDefaultElementNamespaceContext",conf.getDefaultElementNamespaceContext());
debugLanguageDefaultClass("getDefaultElementInterface",conf.getDefaultElementInterface());
debugLanguageDefaultClass("getDefaultElement",conf.getDefaultElement());
debugLanguageDefaultClass("getDefaultElementClass",conf.getDefaultElementClass());
debugLanguageDefaultClass("getDefaultElementClassAttribute",conf.getDefaultElementClassAttribute());
debugLanguageDefaultClass("getDefaultElementLanguageModule",conf.getDefaultElementLanguageModule());
debugLanguageDefaultClass("getDefaultElementBodyComment",conf.getDefaultElementBodyComment());
debugLanguageDefaultClass("getDefaultElementBodyCharacters",conf.getDefaultElementBodyCharacters());
debugLanguageDefaultClass("getDefaultElementBodyWhitespace",conf.getDefaultElementBodyWhitespace());
debugLanguageDefaultClass("getDefaultElementNamespaceInstanceProvider",conf.getDefaultElementNamespaceInstanceProvider());
debugLanguageDefaultClass("getDefaultElementAttributeValueParser",conf.getDefaultElementAttributeValueParser());
debugLanguageDefaultClass("getDefaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue());
debugLanguageDefaultClass("getDefaultElementAttributeHandlerComparator",conf.getDefaultElementAttributeHandlerComparator());
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
private void debugLanguageDefaultClass(String name,Class<?> clazz) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", name);
atts.addAttribute ("", "className", "", "", clazz.getName());
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts);
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", "");
}
public void debugPhaseOrder(List<X4OPhaseHandler> phases) throws X4OPhaseException {
X4OPhaseHandler phase = null;
try {
AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "phaseOrder", "", atts);
for (X4OPhaseHandler phase2:phases) {
phase = phase2;
debugPhase(phase2);
}
debugWriter.endElement(DEBUG_URI, "phaseOrder", "");
} catch (SAXException e) {
// fall back...
if (phase==null) {
if (phases.isEmpty()) {
throw new X4OPhaseException(null,e); /// mmmm
}
phase = phases.get(0);
}
throw new X4OPhaseException(phase,e);
}
}
private void debugPhase(X4OPhaseHandler phase) throws X4OPhaseException {
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", phase.getX4OPhase().name());
atts.addAttribute ("", "runOnce", "", "", phase.getX4OPhase().isRunOnce()+"");
atts.addAttribute ("", "listenersSize", "", "", phase.getX4OPhaseListeners().size()+"");
debugWriter.startElement (DEBUG_URI, "phase", "", atts);
for (X4OPhaseListener l:phase.getX4OPhaseListeners()) {
atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", l.getClass().getName());
debugWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts);
debugWriter.endElement(DEBUG_URI, "X4OPhaseListener", "");
}
debugWriter.endElement(DEBUG_URI, "phase", "");
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
}
public void debugElementLanguageModules(ElementLanguage elementLanguage) throws ElementException {
try {
AttributesImpl attsEmpty = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty);
for (ElementLanguageModule module:elementLanguage.getElementLanguageModules()) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", module.getClass().getName());
atts.addAttribute ("", "name", "", "", module.getName());
atts.addAttribute ("", "providerName", "", "", module.getProviderName());
if (module.getElementLanguageModuleLoader()==null) {
atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", "null");
} else {
atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", module.getElementLanguageModuleLoader().getClass().getName());
}
debugWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts);
//module.getElementAttributeHandlers();
//module.getElementBindingHandlers();
//module.getGlobalElementConfigurators();
//module.getElementInterfaces();
//module.getElementNamespaceContexts();
debugElementConfigurator(module.getGlobalElementConfigurators());
debugElementBindingHandler(module.getElementBindingHandlers());
for (ElementAttributeHandler p:module.getElementAttributeHandlers()) {
atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", p.getAttributeName());
atts.addAttribute ("", "description", "", "", p.getDescription());
atts.addAttribute ("", "className", "", "", p.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementAttributeHandler", "", atts);
for (String para:p.getNextAttributes()) {
atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", para);
debugWriter.startElement (DEBUG_URI, "nextAttribute", "", atts);
debugWriter.endElement(DEBUG_URI, "nextAttribute", "");
}
debugWriter.endElement(DEBUG_URI, "elementAttributeHandler", "");
}
for (ElementInterface elementInterface:module.getElementInterfaces()) {
atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", elementInterface.getClass().getName());
atts.addAttribute ("", "description", "", "", elementInterface.getDescription());
atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName());
debugWriter.startElement (DEBUG_URI, "elementInterface", "", atts);
debugElementBindingHandler(elementInterface.getElementBindingHandlers());
debugElementClassBase(elementInterface);
debugWriter.endElement(DEBUG_URI, "elementInterface", "");
}
for (ElementNamespaceContext enc:module.getElementNamespaceContexts()) {
atts = new AttributesImpl();
atts.addAttribute ("", "uri", "", "", enc.getUri());
atts.addAttribute ("", "description", "", "", enc.getDescription());
atts.addAttribute ("", "schemaUri", "", "", enc.getSchemaUri());
atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource());
atts.addAttribute ("", "className", "", "", enc.getClass().getName());
debugWriter.startElement (DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "", atts);
for (ElementClass ec:enc.getElementClasses()) {
debugElementClass(ec);
}
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", eip.getClass().getName());
debugWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts);
debugWriter.endElement(DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "");
debugWriter.endElement(DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "");
}
debugWriter.endElement(DEBUG_URI, "ElementLanguageModule", "");
}
debugWriter.endElement(DEBUG_URI, "ElementLanguageModules", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElement(Element element) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
// atts.addAttribute ("", "tag", "", "", element.getElementClass().getTag());
atts.addAttribute ("", "objectClass", "", "", ""+element.getElementClass().getObjectClass());
boolean rootElement = element.getParent()==null;
if (rootElement) {
atts.addAttribute ("", "isRootElement", "", "", "true");
}
if (element.getElementObject()==null) {
atts.addAttribute ("", "elementObjectClassName", "", "", "null");
} else {
atts.addAttribute ("", "elementObjectClassName", "", "", element.getElementObject().getClass().getName());
AttributesImpl atts2 = new AttributesImpl();
try {
for (Method m:element.getElementObject().getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
Object value = m.invoke(element.getElementObject());
if (value!=null) {
//atts2.addAttribute ("", m.getName()+".className", "", "", value.getClass().getName());
if (value instanceof String) {
atts2.addAttribute ("", m.getName(), "", "", value.toString());
}
if (value instanceof Number) {
atts2.addAttribute ("", m.getName(), "", "", value.toString());
}
if (value instanceof Collection<?>) {
atts2.addAttribute ("", m.getName()+".size", "", "", ""+((Collection<?>)value).size());
}
if (value instanceof Map<?,?>) {
atts2.addAttribute ("", m.getName()+".size", "", "", ""+((Map<?,?>)value).size());
}
}
}
} catch (Exception e) {
atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage());
}
debugWriter.startElement (DEBUG_URI, "elementObject", "", atts2);
debugWriter.endElement(DEBUG_URI, "elementObject", "");
}
StringBuffer elementPath = getElementPath(element,new StringBuffer());
atts.addAttribute ("", "elementPath", "", "", elementPath.toString());
debugWriter.startElement (DEBUG_URI, "element", "", atts);
debugWriter.endElement(DEBUG_URI, "element", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
/**
* Todo move after xpath support
* @param element
* @param buff
* @return
*/
private StringBuffer getElementPath(Element element,StringBuffer buff) {
if (element.getParent()==null) {
buff.append('/'); // root slash
buff.append(element.getElementClass().getTag());
return buff;
}
buff = getElementPath(element.getParent(),buff);
buff.append('/');
buff.append(element.getElementClass().getTag());
return buff;
}
public void debugPhaseMessage(String message,Class<?> clazz) throws ElementException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", clazz.getName()+"");
try {
debugWriter.startElement (DEBUG_URI, "message", "", atts);
char[] msg = message.toCharArray();
debugWriter.characters(msg,0,msg.length);
debugWriter.endElement(DEBUG_URI, "message", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElementConfigurator(ElementConfigurator ec,Element element) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
atts.addAttribute ("", "configAction", "", "", ec.isConfigAction()+"");
atts.addAttribute ("", "description", "", "", ec.getDescription());
atts.addAttribute ("", "className", "", "", ec.getClass().getName());
debugWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts);
debugElement(element);
debugWriter.endElement(DEBUG_URI, "runElementConfigurator", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElementBindingHandler(ElementBindingHandler ebh,Element element) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
atts.addAttribute ("", "description", "", "", ebh.getDescription());
atts.addAttribute ("", "className", "", "", ebh.getClass().getName()+"");
atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+"");
atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+"");
debugWriter.startElement (DEBUG_URI, "doBind", "", atts);
debugElement(element);
debugWriter.endElement(DEBUG_URI, "doBind", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElementLanguage(ElementLanguage elementLanguage) throws SAXException {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
atts.addAttribute ("", "language", "", "", elementLanguage.getLanguageConfiguration().getLanguage());
atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguageConfiguration().getLanguageVersion());
atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+"");
atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getCurrentX4OPhase().name());
debugWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts);
debugWriter.endElement(DEBUG_URI, "printElementLanguage", "");
}
private void debugElementClass(ElementClass elementClass) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "tag", "", "", elementClass.getTag());
atts.addAttribute ("", "description", "", "", elementClass.getDescription());
atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass());
atts.addAttribute ("", "className", "", "", elementClass.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementClass", "", atts);
for (String phase:elementClass.getSkipPhases()) {
atts = new AttributesImpl();
atts.addAttribute ("", "phase", "", "", ""+phase);
debugWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts);
debugWriter.endElement(DEBUG_URI, "elementSkipPhase", "");
}
debugElementConfigurator(elementClass.getElementConfigurators());
debugElementClassBase(elementClass);
debugWriter.endElement(DEBUG_URI, "elementClass", "");
}
private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementClassBase.getDescription());
atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementClassBase", "", atts);
debugElementConfigurator(elementClassBase.getElementConfigurators());
debugElementClassAttributes(elementClassBase.getElementClassAttributes());
debugWriter.endElement(DEBUG_URI, "elementClassBase", "");
}
private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException {
for (ElementConfigurator elementConfigurator:elementConfigurators) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts);
debugWriter.endElement(DEBUG_URI, "elementConfigurator", "");
}
}
private void debugElementClassAttributes(Collection<ElementClassAttribute> elementClassAttributes) throws SAXException {
for (ElementClassAttribute elementClassAttribute:elementClassAttributes) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", elementClassAttribute.getName());
atts.addAttribute ("", "description", "", "", elementClassAttribute.getDescription());
atts.addAttribute ("", "className", "", "", elementClassAttribute.getClass().getName());
atts.addAttribute ("", "defaultValue", "", "", ""+elementClassAttribute.getDefaultValue());
atts.addAttribute ("", "runBeanFill", "", "", ""+elementClassAttribute.getRunBeanFill());
atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters());
//atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces());
atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL());
debugWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts);
if (elementClassAttribute.getObjectConverter()!=null) {
debugObjectConverter(elementClassAttribute.getObjectConverter());
}
for (String alias:elementClassAttribute.getAttributeAliases()) {
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ""+alias);
debugWriter.startElement(DEBUG_URI, "attributeAlias", "", atts);
debugWriter.endElement(DEBUG_URI, "attributeAlias", "");
}
debugWriter.endElement(DEBUG_URI, "elementClassAttribute", "");
}
}
private void debugObjectConverter(ObjectConverter objectConverter) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "objectClassTo", "", "", objectConverter.getObjectClassTo().getName());
atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName());
atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName());
debugWriter.startElement (DEBUG_URI, "objectConverter", "", atts);
debugWriter.endElement(DEBUG_URI, "objectConverter", "");
}
private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException {
for (ElementBindingHandler bind:elementBindingHandlers) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", bind.getClass().getName());
atts.addAttribute ("", "description", "", "", bind.getDescription());
atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString());
debugWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts);
for (Class<?> clazz:bind.getBindChildClasses()) {
AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "className", "", "", clazz.getName());
debugWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2);
debugWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", "");
}
debugWriter.endElement(DEBUG_URI, "elementBindingHandler", "");
}
}
}

View file

@ -0,0 +1,328 @@
/*
* 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.core;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.sax.XMLWriter;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
/**
* X4ODriver can load language and parse files
*
* @author Willem Cazander
* @version 1.0 Aug 9, 2012
*/
public class X4ODriver implements X4OParserSupport {
/** The logger to log to. */
private Logger logger = null;
/** The ElementLanguage which hold all language config. */
protected ElementLanguage elementLanguage = null;
/** Keep is here for if we want to reuse the parser instance. */
private X4OPhaseManager phaseManager = null;
//private X4OPhaseHandler configOptionalPhase = null;
/** Defines the default version if none is defined. */
public final static String DEFAULT_LANGUAGE_VERSION = "1.0";
/**
* Creates an X4ODriver for this config
*
* @param languageConfig The X4O languageConfig to create this parser for..
*/
public X4ODriver(X4OLanguageConfiguration languageConfig) {
if (languageConfig==null) {
throw new NullPointerException("Can't start with null X4OLanguageConfiguration");
}
elementLanguage = languageConfig.createElementLanguage(); // store also language config
logger = Logger.getLogger(X4OParser.class.getName());
logger.fine("Creating X4O driver for language: "+languageConfig.getLanguage());
}
/**
* Returns the ElementLanguage
* @return returns the ElementLanguage.
*/
public ElementLanguage getElementLanguage() {
return elementLanguage;
}
/**
* Creates and configs an X4OPhaseManager to parse a language.
*
* @return An configured X4OPhaseManager
* @throws X4OPhaseException
*/
protected X4OPhaseManager createX4OPhaseManager() throws X4OPhaseException {
X4OPhaseHandlerFactory factory = new X4OPhaseHandlerFactory(elementLanguage);
X4OPhaseManager manager = new X4OPhaseManager(elementLanguage);
// main startup
//manager.addX4OPhaseHandler(factory.createContextsPhase());
manager.addX4OPhaseHandler(factory.startupX4OPhase());
manager.addX4OPhaseHandler(factory.createLanguagePhase());
manager.addX4OPhaseHandler(factory.createLanguageSiblingsPhase());
manager.addX4OPhaseHandler(factory.parseSAXStreamPhase());
// inject and opt phase
manager.addX4OPhaseHandler(factory.configGlobalElBeansPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
/*
if (configOptionalPhase!=null) {
if (X4OPhase.configOptionalPhase.equals(configOptionalPhase.getX4OPhase())==false) {
throw new X4OPhaseException(configOptionalPhase,new IllegalStateException("createConfigOptionalPhase() did not return an X4OPhase.configOptionalPhase x4o phase."));
}
manager.addX4OPhaseHandler(configOptionalPhase);
}
*/
// meta start point
manager.addX4OPhaseHandler(factory.startX4OPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// config
manager.addX4OPhaseHandler(factory.configElementPhase());
manager.addX4OPhaseHandler(factory.configElementInterfacePhase());
manager.addX4OPhaseHandler(factory.configGlobalElementPhase());
manager.addX4OPhaseHandler(factory.configGlobalAttributePhase());
// run all attribute events
manager.addX4OPhaseHandler(factory.runAttributesPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// templating
manager.addX4OPhaseHandler(factory.fillTemplatingPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// transforming
manager.addX4OPhaseHandler(factory.transformPhase());
manager.addX4OPhaseHandler(factory.runDirtyElementPhase(manager));
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// binding elements
manager.addX4OPhaseHandler(factory.bindElementPhase());
// runing and releasing
manager.addX4OPhaseHandler(factory.runPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
manager.addX4OPhaseHandler(factory.runDirtyElementLastPhase(manager));
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// after release phase Element Tree is not avible anymore
manager.addX4OPhaseHandler(factory.releasePhase());
// Add debug phase listener to all phases
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
for (X4OPhaseHandler h:manager.getPhases()) {
h.addPhaseListener(elementLanguage.getLanguageConfiguration().getX4ODebugWriter().createDebugX4OPhaseListener());
}
}
// We are done we the manager
return manager;
}
protected X4OPhaseManager createX4OPhaseManagerSupport() throws X4OPhaseException {
X4OPhaseHandlerFactory factory = new X4OPhaseHandlerFactory(elementLanguage);
X4OPhaseManager manager = new X4OPhaseManager(elementLanguage);
manager.addX4OPhaseHandler(factory.createLanguagePhase());
manager.addX4OPhaseHandler(factory.createLanguageSiblingsPhase());
manager.addX4OPhaseHandler(factory.configGlobalElBeansPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
return manager;
}
/**
* Parses the input stream as a X4O document.
*/
public void parseInput() throws ParserConfigurationException,SAXException,IOException {
if (elementLanguage.getLanguageConfiguration().getLanguage()==null) {
throw new ParserConfigurationException("parserConfig is broken getLanguage() returns null.");
}
// init debugWriter if enabled
boolean startedDebugWriter = false;
Object debugOutputHandler = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER);
Object debugOutputStream = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM);
if (elementLanguage.getLanguageConfiguration().getX4ODebugWriter()==null) {
DefaultHandler2 xmlDebugWriter = null;
if (debugOutputHandler instanceof DefaultHandler2) {
xmlDebugWriter = (DefaultHandler2)debugOutputHandler;
} else if (debugOutputStream instanceof OutputStream) {
xmlDebugWriter = new XMLWriter((OutputStream)debugOutputStream);
}
if (xmlDebugWriter!=null) {
xmlDebugWriter.startDocument();
xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI);
X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter);
elementLanguage.getLanguageConfiguration().setX4ODebugWriter(debugWriter);
startedDebugWriter = true;
}
}
// debug language
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "language", "", "", elementLanguage.getLanguageConfiguration().getLanguage());
atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+"");
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "", atts);
}
// start parsing language
try {
if (phaseManager==null) {
phaseManager = createX4OPhaseManager();
}
phaseManager.runPhases();
} catch (Exception e) {
// also debug exceptions
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "message", "", "", e.getMessage());
if (e instanceof X4OPhaseException) {
atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getX4OPhase().name());
}
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts);
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
printer.append('\n');
if (e.getCause()==null) {
e.printStackTrace(printer);
} else {
e.getCause().printStackTrace(printer);
}
char[] stack = writer.getBuffer().toString().toCharArray();
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length);
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
} catch (Exception ee) {
ee.printStackTrace();
}
}
// unwrap exception
if (e.getCause() instanceof ParserConfigurationException) {
throw (ParserConfigurationException)e.getCause();
}
if (e.getCause() instanceof SAXException) {
throw (SAXException)e.getCause();
}
if (e.getCause() instanceof IOException) {
throw (IOException)e.getCause();
}
if (e.getCause()==null) {
throw new SAXException(e);
} else {
throw new SAXException((Exception)e.getCause());
}
} finally {
// close all our resources.
//if (inputStream!=null) {
// inputStream.close();
//}
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
}
if (startedDebugWriter && elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endPrefixMapping("debug");
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endDocument();
if (debugOutputStream instanceof OutputStream) {
OutputStream outputStream = (OutputStream)debugOutputStream;
outputStream.flush();
outputStream.close(); // need this here ?
}
}
}
}
/**
* Loads the language and returns the ElementLanguage.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
try {
X4OPhaseManager loadLanguageManager = createX4OPhaseManagerSupport();
loadLanguageManager.runPhases();
return elementLanguage;
} catch (Exception e) {
throw new X4OParserSupportException(e);
}
}
/**
* Run a manual release phase to clean the parsing object tree.
*
* @throws X4OPhaseException
*/
public void doReleasePhaseManual() throws X4OPhaseException {
if (phaseManager==null) {
throw new IllegalStateException("Can't release with null phaseManager.");
}
phaseManager.doReleasePhaseManual();
}
/**
* Sets an X4O Language property.
* @param key The key of the property to set.
* @param value The vlue of the property to set.
*/
public void setProperty(String key,Object value) {
if (phaseManager!=null) {
throw new IllegalStateException("Can't set property after phaseManager is created.");
}
elementLanguage.getLanguageConfiguration().setLanguageProperty(X4OLanguageProperty.valueByUri(key), value);
}
/**
* Returns the value an X4O Language property.
* @param key The key of the property to get the value for.
* @return Returns null or the value of the property.
*/
public Object getProperty(String key) {
return elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.valueByUri(key));
}
}

View file

@ -0,0 +1,167 @@
/*
* 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.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* X4OEntityResolver resolves internel entities and proxy to external defined ones.
*
* Resolve order;
* 1) validation base path dir
* 2) external resolver
* 3) lookup for language in classpath.
* 4) throw exception
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class X4OEntityResolver implements EntityResolver {
private Logger logger = null;
private URL basePath = null;
private ElementLanguage elementLanguage = null;
private Map<String,String> schemaResources = null;
private Map<String,String> schemaPathResources = null;
protected X4OEntityResolver(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't provide entities with null ElementLanguage.");
}
this.logger=Logger.getLogger(X4OEntityResolver.class.getName());
this.elementLanguage=elementLanguage;
this.basePath=(URL)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_BASE_PATH);
this.schemaResources=new HashMap<String,String>(20);
this.schemaPathResources=new HashMap<String,String>(20);
for (ElementLanguageModule mod:elementLanguage.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
if (ns.getSchemaUri()==null) {
continue;
}
if (ns.getSchemaResource()==null) {
continue;
}
StringBuffer buf = new StringBuffer(30);
buf.append(elementLanguage.getLanguageConfiguration().getLanguageResourcePathPrefix());
buf.append('/');
buf.append(elementLanguage.getLanguageConfiguration().getLanguage());
buf.append('/');
buf.append(ns.getSchemaResource());
schemaResources.put( ns.getSchemaUri(), buf.toString() );
buf = new StringBuffer(30);
buf.append(elementLanguage.getLanguageConfiguration().getLanguage());
buf.append(File.separatorChar);
buf.append(ns.getSchemaResource());
schemaPathResources.put( ns.getSchemaUri(), buf.toString() );
}
}
}
public InputSource resolveEntity(String publicId, String systemId) throws IOException,SAXException {
logger.finer("Fetch sysId: "+systemId+" pubId: "+publicId);
// Check if other resolver has resource
EntityResolver resolver = (EntityResolver)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.CONFIG_ENTITY_RESOLVER);
if (resolver!=null) {
InputSource result = resolver.resolveEntity(publicId, systemId);
if (result!=null) {
return result;
}
}
// Check if we have it on user defined schema base path
if (schemaPathResources.containsKey(systemId)) {
File schemaBasePath = (File)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.VALIDATION_SCHEMA_PATH);
if (schemaBasePath!=null && schemaBasePath.exists()) {
String schemeResource = schemaResources.get(systemId);
File schemaFile = new File(schemaBasePath.getAbsolutePath()+File.separatorChar+schemeResource);
if (schemaFile.exists()) {
if (schemaFile.canRead()==false) {
throw new SAXException("Can't read schema file: "+schemaFile);
}
try {
InputSource in = new InputSource(new FileInputStream(schemaFile));
in.setPublicId(publicId);
in.setSystemId(systemId);
return in;
} catch (IOException e) {
throw new IOException("Could not open: "+schemaFile+" error: "+e.getMessage(),e);
}
}
}
}
// Check if we have it on the classpath.
if (schemaResources.containsKey(systemId)) {
String schemeResource = schemaResources.get(systemId);
ClassLoader cl = X4OLanguageClassLoader.getClassLoader();
URL resource = cl.getResource(schemeResource);
if (resource!=null) {
try {
InputSource in = new InputSource(resource.openStream());
in.setPublicId(publicId);
in.setSystemId(systemId);
return in;
} catch (IOException e) {
throw new IOException("Could not open: "+resource+" error: "+e.getMessage(),e);
}
}
}
if (basePath!=null && systemId!=null) {
if (systemId.startsWith(basePath.toExternalForm())) {
logger.finer("Base reference basePath: "+basePath+" systemId: "+systemId);
try {
InputSource in = new InputSource(new URL(systemId).openStream());
in.setPublicId(publicId);
in.setSystemId(systemId);
return in;
} catch (IOException e) {
throw new IOException("Could not open: "+systemId+" error: "+e.getMessage(),e);
}
}
}
// always throw to remove all network fetches.
throw new SAXException("SystemId not found: "+systemId);
}
}

View file

@ -0,0 +1,124 @@
/*
* 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.core;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* X4OErrorHandler prints the SAX2 Errors and Warsnings when parsing xml.
*
* @author Willem Cazander
* @version 1.0 Feb 8, 2007
*/
public class X4OErrorHandler implements ErrorHandler {
private ElementLanguage elementLanguage = null;
private ErrorHandler errorHandler = null;
/**
* Construct a new SAXErrorPrinter
* @param elementLanguage The elementLanguage to get errors to.
*/
public X4OErrorHandler(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't debug and proxy errors with null elementLanguage.");
}
this.elementLanguage=elementLanguage;
this.errorHandler=(ErrorHandler)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.CONFIG_ERROR_HANDLER);
}
/**
* Prints the error message to debug output.
*/
private void printError(boolean isError, SAXParseException exception) throws SAXException {
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()==false) {
return;
}
String message = printErrorString(isError,exception);
try {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().debugPhaseMessage(message, X4OErrorHandler.class);
} catch (ElementException e) {
throw new SAXException(e);
}
}
/**
* Prints the error message to string.
*/
private String printErrorString(boolean isError, SAXParseException exception) {
StringBuffer buf = new StringBuffer(50);
buf.append(exception.getSystemId());
buf.append(":");
buf.append(exception.getLineNumber());
buf.append(":");
buf.append(exception.getColumnNumber());
buf.append(" ");
buf.append((isError?"Error: ":"Warning: "));
buf.append(exception.getMessage());
return buf.toString();
}
// ========= ErrorHandler
/**
* Receive notification of a SAX warning.
*/
public void warning(SAXParseException exception) throws SAXException {
printError(false, exception);
if (errorHandler!=null) {
errorHandler.warning(exception);
} else {
throw new SAXException(printErrorString(false,exception));
}
}
/**
* Receive notification of a SAX recoverable error.
*/
public void error(SAXParseException exception) throws SAXException {
printError(true, exception);
if (errorHandler!=null) {
errorHandler.error(exception);
} else {
throw new SAXException(printErrorString(true,exception));
}
}
/**
* Receive notification of a SAX non-recoverable error.
*/
public void fatalError(SAXParseException exception) throws SAXException {
printError(true, exception);
if (errorHandler!=null) {
errorHandler.fatalError(exception);
} else {
throw new SAXException(printErrorString(true,exception));
}
}
}

View file

@ -0,0 +1,143 @@
/*
* 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.core;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.core.config.X4OLanguagePropertyKeys;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.impl.config.DefaultX4OLanguageConfiguration;
import org.x4o.xml.sax.AbstractXMLParser;
import org.xml.sax.SAXException;
/**
* This is the starting point of the XML X4O parsing.
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
public class X4OParser extends AbstractXMLParser implements X4OParserSupport {
private X4ODriver driver = null;
/**
* Creates an X4OParser object.
*
* @param language The X4O language to create this parser for..
*/
public X4OParser(String language) {
this(language,X4ODriver.DEFAULT_LANGUAGE_VERSION);
}
public X4OParser(String language,String languageVersion) {
this(new DefaultX4OLanguageConfiguration(language,languageVersion));
}
protected X4OParser(X4OLanguageConfiguration config) {
this(new X4ODriver(config));
}
protected X4OParser(X4ODriver driver) {
if (driver==null) {
throw new NullPointerException("Can't start X4OParser with null X4ODriver.");
}
this.driver = driver;
}
protected X4ODriver getDriver() {
return driver;
}
/**
* @see org.x4o.xml.sax.AbstractXMLParser#parse(java.io.InputStream,java.lang.String,java.net.URL)
*/
@Override
public void parse(InputStream input,String systemId,URL basePath) throws ParserConfigurationException,SAXException, IOException {
driver.setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_STREAM, input);
driver.setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_SYSTEM_ID, systemId);
driver.setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_BASE_PATH, basePath);
driver.parseInput();
}
/**
* Run a manual release phase to clean the parsing object tree.
*
* @throws X4OPhaseException
*/
public void doReleasePhaseManual() throws X4OPhaseException {
driver.doReleasePhaseManual();
}
/**
* Sets an X4O Language property.
* @param key The key of the property to set.
* @param value The vlue of the property to set.
*/
public void setProperty(String key,Object value) {
driver.setProperty(key, value);
}
/**
* Returns the value an X4O Language property.
* @param key The key of the property to get the value for.
* @return Returns null or the value of the property.
*/
public Object getProperty(String key) {
return driver.getProperty(key);
}
/**
* Loads the support ElementLanguage from the driver.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
return driver.loadElementLanguageSupport();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void addELBeanInstance(String name,Object bean) {
if (name==null) {
throw new NullPointerException("Can't add null name.");
}
if (name.isEmpty()) {
throw new NullPointerException("Can't add empty name.");
}
if (bean==null) {
throw new NullPointerException("Can't add null bean.");
}
Map map = (Map)getProperty(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP);
if (map==null) {
map = new HashMap<String,Object>(20);
setProperty(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP, map);
}
map.put(name,bean);
}
}

View file

@ -0,0 +1,43 @@
/*
* 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.core;
import org.x4o.xml.element.ElementLanguage;
/**
* X4OParserSupport is interface for language features without integration with parsing code.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public interface X4OParserSupport {
/**
* Loads the language ElementLanguage to provide support.
*
* @return Returns the ElementLanguage.
* @throws X4OParserSupportException
*/
ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException;
}

View file

@ -0,0 +1,68 @@
/*
* 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.core;
/**
* X4OParserSupportException is exception when executing an language supporting feature.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class X4OParserSupportException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10L;
/**
* Constructs an X4OWriteSchemaException without a detail message.
*/
public X4OParserSupportException() {
super();
}
/**
* Constructs an X4OWriteSchemaException with a detail message.
* @param message The message of this Exception
*/
public X4OParserSupportException(String message) {
super(message);
}
/**
* Creates an X4OWriteSchemaException from a parent exception.
* @param e The error exception.
*/
public X4OParserSupportException(Exception e) {
super(e);
}
/**
* Constructs an X4OWriteSchemaException with a detail message.
* @param message The message of this Exception
* @param e The error exception.
*/
public X4OParserSupportException(String message,Exception e) {
super(message,e);
}
}

View file

@ -0,0 +1,124 @@
/*
* 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.core;
/**
* Defines the different phases of the x4o xml parser.
*
* @author Willem Cazander
* @version 1.0 Sep 1, 2008
*/
public enum X4OPhase {
/** Defines this meta startup phase */
startupX4OPhase(true),
/** Load all meta info of the language we are creating. */
createLanguagePhase(true),
/** Load all siblings languages. */
createLanguageSiblingsPhase(true),
/** Parse the xml from sax events. */
parseSAXStreamPhase(true),
/** Optional extra config phase for injecting bean instances into the EL context. */
configGlobalElBeansPhase(true),
/** emty meta phase to refer to that sax is ready and element s are waiting for processing */
startX4OPhase(true),
/** re runnable phases which config xml to beans and binds them together */
configElementPhase,
configElementInterfacePhase,
configGlobalElementPhase,
configGlobalAttributePhase,
/** Fill the bean attributes from the Element xml attributes. */
runAttributesPhase,
/** Fill in the x4o templating objects. */
fillTemplatingPhase,
/** transform phase , modifies the Element Tree. */
transformPhase,
/** Run the phases which needs to be runned again from a phase. */
runDirtyElementPhase(true),
/** Binds objects together */
bindElementPhase,
/** Run action stuff, we are ready with it. */
runPhase(true),
/** Rerun all needed phases for all element that requested it. */
runDirtyElementLastPhase,
/** Releases all Elements, which clears attributes and childeren etc.. */
releasePhase(true),
/** write all phases and stuff to debug sax stream */
debugPhase;
/** Defines which phase we start, when context is created. */
public static final X4OPhase FIRST_PHASE = startupX4OPhase;
/** The order in which the phases are executed */
static final X4OPhase[] PHASE_ORDER = { startupX4OPhase,
createLanguagePhase,createLanguageSiblingsPhase,
parseSAXStreamPhase,configGlobalElBeansPhase,
startX4OPhase,
configElementPhase,configElementInterfacePhase,configGlobalElementPhase,
configGlobalAttributePhase,runAttributesPhase,fillTemplatingPhase,
transformPhase,runDirtyElementPhase,bindElementPhase,
runPhase,runDirtyElementLastPhase,
releasePhase
};
/** Boolean indicating that this phase only may be run'ed once. */
private boolean runOnce = false;
/**
* Creates an X4O Phase
*/
private X4OPhase() {
}
/**
* Creates an X4O Phase
* @param runOnce Flag indicating that this phase is runnable multiple times.
*/
private X4OPhase(boolean runOnce) {
this.runOnce=runOnce;
}
/**
* Returns a flag indicating that this phase is runnable multiple times.
* @return True if phase is restricted to run once.
*/
public boolean isRunOnce() {
return runOnce;
}
}

View file

@ -0,0 +1,77 @@
/*
* 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.core;
/**
* Is throw when there is en Exception within an Element.
*
* @author Willem Cazander
* @version 1.0 Jan 1, 2009
*/
public class X4OPhaseException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10l;
private X4OPhaseHandler exceptionPhase = null;
/**
* Creates an ElementException from a parent exception.
* @param exceptionPhase The handler which throwed.
* @param e The Exception.
*/
public X4OPhaseException(X4OPhaseHandler exceptionPhase,Exception e) {
super(e);
this.exceptionPhase=exceptionPhase;
}
/**
* Creates an ElementException from a parent exception.
* @param exceptionPhase The handler which throwed.
* @param message The message of the error.
*/
public X4OPhaseException(X4OPhaseHandler exceptionPhase,String message) {
super(message);
this.exceptionPhase=exceptionPhase;
}
/**
* Creates an ElementException from a parent exception.
* @param exceptionPhase The handler which throwed.
* @param message The message of the error.
* @param e The Exception.
*/
public X4OPhaseException(X4OPhaseHandler exceptionPhase,String message,Exception e) {
super(message,e);
this.exceptionPhase=exceptionPhase;
}
/**
* Returns the X4OPhaseHandler which created this Exception
* @return An X4OPhaseHandler
*/
public X4OPhaseHandler getX4OPhaseHandler() {
return exceptionPhase;
}
}

View file

@ -0,0 +1,85 @@
/*
* 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.core;
import java.util.List;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementLanguage;
/**
* This is the starting point of the XML X4O parsing.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
public interface X4OPhaseHandler {
/**
* Returns the X4OPhase for which this handler was written.
* @return Returns the phase for which this handler works.
*/
X4OPhase getX4OPhase();
/**
* Runs this phase.
* @param elementLanguage
* @throws X4OPhaseException
*/
void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException;
/**
* Returns all X4OPhaseListeners which where added.
* @return All X4OPhaseListeners.
*/
List<X4OPhaseListener> getX4OPhaseListeners();
/**
* Adds an X4OPhaseListener
* @param listener
*/
void addPhaseListener(X4OPhaseListener listener);
/**
* Removes an X4OPhaseListener
* @param listener
*/
void removePhaseListener(X4OPhaseListener listener);
/**
* runPhase is called but should do nothig.
* When elementPhase is enables x4o tries to merge all element phases so
* we don't need to loop element tree to often.
* @return True if to run in config.
*/
boolean isElementPhase();
/**
* Run this phase for this Element.
* @param element
* @throws X4OPhaseException
*/
void runElementPhase(Element element) throws X4OPhaseException;
}

View file

@ -0,0 +1,951 @@
/*
* 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.core;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.el.ValueExpression;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.core.config.X4OLanguageLoader;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementAttributeValueParser;
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.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementLanguageModuleLoaderSibling;
import org.x4o.xml.element.ElementNamespaceContext;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* Factory which can create X4OPhaseHandlers for all the predefined phases used in default x4o language parsing.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
public class X4OPhaseHandlerFactory {
private Logger logger = null;
private ElementLanguage elementLanguage = null;
private List<RunConfigurator> runConf = null;
public X4OPhaseHandlerFactory(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't start factory with null elementLanguage.");
}
this.elementLanguage=elementLanguage;
logger = Logger.getLogger(X4OPhaseHandlerFactory.class.getName());
runConf = new ArrayList<RunConfigurator>(10);
}
class RunConfigurator {
Element element;
ElementConfigurator elementConfigurator;
RunConfigurator(Element element,ElementConfigurator elementConfigurator) {
this.element=element;
this.elementConfigurator=elementConfigurator;
}
}
private void runElementConfigurators(List<ElementConfigurator> ecs,Element e,X4OPhaseHandler phase) throws X4OPhaseException {
int size = ecs.size();
for (int i=0;i<size;i++) {
ElementConfigurator ec = ecs.get(i);
if (ec.isConfigAction()) {
runConf.add(new RunConfigurator(e,ec));
return;
}
try {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementConfigurator(ec,e);
}
ec.doConfigElement(e);
// may request rerun of config
if (ec.isConfigAction()) {
runConf.add(new RunConfigurator(e,ec));
}
} catch (ElementException ee) {
throw new X4OPhaseException(phase,ee);
}
}
}
private void debugPhaseMessage(String message,X4OPhaseHandler phaseHandler) throws X4OPhaseException {
if (hasX4ODebugWriter()) {
try {
getX4ODebugWriter().debugPhaseMessage(message,phaseHandler.getClass());
} catch (ElementException ee) {
throw new X4OPhaseException(phaseHandler,ee);
}
}
}
private boolean hasX4ODebugWriter() {
return elementLanguage.getLanguageConfiguration().hasX4ODebugWriter();
}
private X4ODebugWriter getX4ODebugWriter() {
return elementLanguage.getLanguageConfiguration().getX4ODebugWriter();
}
/**
* Creates the startupX4OPhase which is a empty meta phase.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler startupX4OPhase() {
class CreateStartX4OPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.startupX4OPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
// print the properties and classes for this language/config
if (hasX4ODebugWriter()) {
try {
getX4ODebugWriter().debugLanguageProperties(elementLanguage);
getX4ODebugWriter().debugLanguageDefaultClasses(elementLanguage);
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}
}
}
};
X4OPhaseHandler result = new CreateStartX4OPhase();
return result;
}
/**
* Loads all the modules a language.
* Then creates the ElementProviders
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler createLanguagePhase() {
class CreateLanguagePhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.createLanguagePhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
debugPhaseMessage("Loading main language: "+elementLanguage.getLanguageConfiguration().getLanguage(),this);
X4OLanguageLoader loader = (X4OLanguageLoader)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultX4OLanguageLoader());
loader.loadLanguage(elementLanguage,elementLanguage.getLanguageConfiguration().getLanguage(),elementLanguage.getLanguageConfiguration().getLanguageVersion());
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementLanguageModules(elementLanguage);
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new CreateLanguagePhase();
return result;
}
/**
* Loads all sibling languages.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler createLanguageSiblingsPhase() {
class CreateLanguageSiblingsPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.createLanguageSiblingsPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
List<ElementLanguageModuleLoaderSibling> siblingLoaders = new ArrayList<ElementLanguageModuleLoaderSibling>(3);
for (ElementLanguageModule module:elementLanguage.getElementLanguageModules()) {
if (module.getElementLanguageModuleLoader() instanceof ElementLanguageModuleLoaderSibling) {
siblingLoaders.add((ElementLanguageModuleLoaderSibling)module.getElementLanguageModuleLoader());
}
}
if (siblingLoaders.isEmpty()==false) {
X4OLanguageLoader loader = (X4OLanguageLoader)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultX4OLanguageLoader());
for (ElementLanguageModuleLoaderSibling siblingLoader:siblingLoaders) {
debugPhaseMessage("Loading sibling langauge loader: "+siblingLoader,this);
siblingLoader.loadLanguageSibling(elementLanguage, loader);
}
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementLanguageModules(elementLanguage);
}
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new CreateLanguageSiblingsPhase();
return result;
}
/**
* Parses the xml resource(s) and creates an Element tree.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler parseSAXStreamPhase() {
class CreateSAXStreamPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.parseSAXStreamPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
//XMLParserConfiguration config = new XIncludeAwareParserConfiguration();
//config.setProperty("http://apache.org/xml/properties/internal/grammar-pool",myFullGrammarPool);
//SAXParser parser = new SAXParser(config);
// Create Sax parser with x4o tag handler
X4OTagHandler xth = new X4OTagHandler(elementLanguage);
XMLReader saxParser = XMLReaderFactory.createXMLReader();
saxParser.setErrorHandler(new X4OErrorHandler(elementLanguage));
saxParser.setEntityResolver(new X4OEntityResolver(elementLanguage));
saxParser.setContentHandler(xth);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
// Set properties and optional
Map<String,Object> saxParserProperties = elementLanguage.getLanguageConfiguration().getSAXParserProperties();
for (Map.Entry<String,Object> entry:saxParserProperties.entrySet()) {
String name = entry.getKey();
Object value= entry.getValue();
saxParser.setProperty(name, value);
debugPhaseMessage("Set SAX property: "+name+" to: "+value,this);
}
Map<String,Object> saxParserPropertiesOptional = elementLanguage.getLanguageConfiguration().getSAXParserPropertiesOptional();
for (Map.Entry<String,Object> entry:saxParserPropertiesOptional.entrySet()) {
String name = entry.getKey();
Object value= entry.getValue();
try {
saxParser.setProperty(name, value);
debugPhaseMessage("Set SAX optional property: "+name+" to: "+value,this);
} catch (SAXException e) {
debugPhaseMessage("Could not set optional SAX property: "+name+" to: "+value+" error: "+e.getMessage(),this);
}
}
// Set sax features and optional
Map<String, Boolean> features = elementLanguage.getLanguageConfiguration().getSAXParserFeatures();
for (String key:features.keySet()) {
Boolean value=features.get(key);
saxParser.setFeature(key, value);
debugPhaseMessage("Set SAX feature: "+key+" to: "+value,this);
}
Map<String, Boolean> featuresOptional = elementLanguage.getLanguageConfiguration().getSAXParserFeaturesOptional();
for (String key:featuresOptional.keySet()) {
Boolean value=featuresOptional.get(key);
try {
saxParser.setFeature(key, value);
debugPhaseMessage("Set SAX optional feature: "+key+" to: "+value,this);
} catch (SAXException e) {
debugPhaseMessage("Could not set optional SAX feature: "+key+" to: "+value+" error: "+e.getMessage(),this);
}
}
// check for required features
List<String> requiredFeatures = elementLanguage.getLanguageConfiguration().getSAXParserFeaturesRequired();
for (String requiredFeature:requiredFeatures) {
debugPhaseMessage("Checking required SAX feature: "+requiredFeature,this);
if (saxParser.getFeature(requiredFeature)==false) {
Exception e = new IllegalStateException("Missing required feature: "+requiredFeature);
throw new X4OPhaseException(this,e);
}
}
// Finally start parsing the xml input stream
Object requestInputSource = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_OBJECT);
InputSource input = null;
InputStream inputStream = null;
if (requestInputSource instanceof InputSource) {
input = (InputSource)requestInputSource;
} else {
inputStream = (InputStream)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_STREAM);
input = new InputSource(inputStream);
}
Object requestInputEncoding = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_ENCODING);
if (requestInputEncoding!=null && requestInputEncoding instanceof String) {
input.setEncoding(requestInputEncoding.toString());
}
Object requestSystemId = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_SYSTEM_ID);
if (requestSystemId!=null && requestSystemId instanceof String) {
input.setSystemId(requestSystemId.toString());
}
try {
saxParser.parse(input);
} finally {
if (inputStream!=null) {
inputStream.close();
}
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new CreateSAXStreamPhase();
return result;
}
/**
* Creates the startX4OPhase which is a empty meta phase.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler startX4OPhase() {
class CreateStartX4OPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.startX4OPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
// empty because this is a meta phase.
}
};
X4OPhaseHandler result = new CreateStartX4OPhase();
return result;
}
/**
* Creates the configGlobalElBeansPhase which adds beans to the el context.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configGlobalElBeansPhase() {
class ConfigGlobalElBeansPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configGlobalElBeansPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
@SuppressWarnings("rawtypes")
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
Map beanMap = (Map)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (beanMap==null) {
return;
}
for (Object elName:beanMap.keySet()) {
Object o = beanMap.get(elName);
ValueExpression ve = elementLanguage.getExpressionFactory().createValueExpression(elementLanguage.getELContext(),"${"+elName+"}", o.getClass());
ve.setValue(elementLanguage.getELContext(), o);
debugPhaseMessage("Setting el bean: ${"+elName+"} to: "+o.getClass().getName(),this);
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new ConfigGlobalElBeansPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configElementPhase() {
class ConfigElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// First phase is to rename attributes, maybe move so sax phase
for (ElementClassAttribute eca:element.getElementClass().getElementClassAttributes()) {
List<String> aliases = eca.getAttributeAliases();
if (aliases.isEmpty()) {
continue;
}
for (String alias:aliases) {
if (element.getAttributes().containsKey(alias)) {
String attributeValue = element.getAttributes().get(alias);
element.getAttributes().put(eca.getName(), attributeValue);
element.getAttributes().remove(alias);
}
}
}
logger.finest("Do ElementClass Config Configurators: "+element.getElementClass().getElementConfigurators().size());
runElementConfigurators(element.getElementClass().getElementConfigurators(),element,this);
}
};
X4OPhaseHandler result = new ConfigElementPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configElementInterfacePhase() {
class ConfigElementInterfacePhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configElementInterfacePhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.getElementObject()==null) {
logger.finest("Null elementObject skipping, interfaces");
return;
}
for (ElementInterface ei:element.getElementLanguage().findElementInterfaces(element.getElementObject())) {
logger.finest("Do ElementInterface Config Configurators: "+element.getElementClass().getElementConfigurators().size());
runElementConfigurators(ei.getElementConfigurators(),element,this);
}
}
};
X4OPhaseHandler result = new ConfigElementInterfacePhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configGlobalElementPhase() {
class ConfigGlobalElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configGlobalElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
for (ElementLanguageModule mod:element.getElementLanguage().getElementLanguageModules()) {
logger.finest("Do Element Config Global Configurators: "+mod.getGlobalElementConfigurators().size());
runElementConfigurators(mod.getGlobalElementConfigurators(),element,this);
}
}
};
X4OPhaseHandler result = new ConfigGlobalElementPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configGlobalAttributePhase() {
class ConfigGlobalAttributePhase extends AbstractX4OPhaseHandler {
Comparator<ElementAttributeHandler> elementAttributeHandlerComparator = null;
protected void setX4OPhase() {
phase = X4OPhase.configGlobalAttributePhase;
}
@SuppressWarnings("unchecked")
public void runElementPhase(Element element) throws X4OPhaseException {
if (elementAttributeHandlerComparator==null) {
try {
elementAttributeHandlerComparator = (Comparator<ElementAttributeHandler>)X4OLanguageClassLoader.newInstance(element.getElementLanguage().getLanguageConfiguration().getDefaultElementAttributeHandlerComparator());
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
// do global parameters
logger.finest("Do Element Global AttributeHandlers.");
List<ElementAttributeHandler> handlers = new ArrayList<ElementAttributeHandler>();
for (ElementLanguageModule mod:element.getElementLanguage().getElementLanguageModules()) {
for (ElementAttributeHandler global:mod.getElementAttributeHandlers()) {
String attribute = element.getAttributes().get(global.getAttributeName());
if (attribute!=null) {
handlers.add(global);
}
}
}
Collections.sort(handlers,elementAttributeHandlerComparator);
List<ElementConfigurator> handlers2 = new ArrayList<ElementConfigurator>(handlers.size());
handlers2.addAll(handlers);
runElementConfigurators(handlers2,element,this);
}
};
X4OPhaseHandler result = new ConfigGlobalAttributePhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runAttributesPhase() {
class RunAttributesPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.runAttributesPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// we only can config ElementObjects
if (element.getElementObject()==null) {
return;
}
// do config
Map<String,String> attr = element.getAttributes();
ElementAttributeValueParser attrParser = element.getElementLanguage().getElementAttributeValueParser();
Boolean autoAttributes = element.getElementClass().getAutoAttributes();
if (autoAttributes==null) {
autoAttributes = true;
}
try {
for (String name:attr.keySet()) {
String valueString = (String)attr.get(name);
if (valueString==null) {
continue;
}
Object value = valueString;
ElementClassAttribute attrClass = element.getElementClass().getElementClassAttributeByName(name);
if (attrClass!=null) {
if (attrClass.getRunResolveEL()==null || attrClass.getRunResolveEL()) {
if (attrParser.isELParameter(name, valueString, element)) {
value = attrParser.getELParameterValue(valueString, element);
}
}
if (attrClass.getRunConverters()==null || attrClass.getRunConverters()) {
value = attrParser.getConvertedParameterValue(name, value, element);
}
if (attrClass.getRunBeanFill()==null || attrClass.getRunBeanFill()) {
element.getElementLanguage().getElementObjectPropertyValue().setProperty(element.getElementObject(), name, value);
}
} else if (autoAttributes) {
value = attrParser.getParameterValue(name,valueString,element);
element.getElementLanguage().getElementObjectPropertyValue().setProperty(element.getElementObject(), name, value);
} else {
continue; // skip all non auto attribute non attribute defined xml attributes, or throw exception ?
}
}
// check for defaults
for (ElementClassAttribute attrClass:element.getElementClass().getElementClassAttributes()) {
if (attrClass.getDefaultValue()!=null && attr.containsKey(attrClass.getName())==false) {
Object value = null;
if (attrClass.getDefaultValue() instanceof String) {
value = attrParser.getParameterValue(attrClass.getName(),(String)attrClass.getDefaultValue(),element);
} else {
value = attrClass.getDefaultValue();
}
if (attrClass.getRunBeanFill()==null || attrClass.getRunBeanFill()) {
element.getElementLanguage().getElementObjectPropertyValue().setProperty(element.getElementObject(), attrClass.getName(), value);
}
}
}
} catch (ObjectConverterException oce) {
throw new X4OPhaseException(this,"Error while converting parameters: "+oce.getMessage(),oce);
} catch (ElementException e) {
throw new X4OPhaseException(this,"Error while setting parameters: "+e.getMessage(),e);
}
}
};
X4OPhaseHandler result = new RunAttributesPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler fillTemplatingPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.fillTemplatingPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
};
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler transformPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.transformPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.isTransformingTree()==false) {
return;
}
try {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElement(element);
}
element.doElementRun();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}
}
};
return result;
}
/**
*
* @param manager The phasemanager.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runDirtyElementPhase(final X4OPhaseManager manager) {
class RunDirtyElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.runDirtyElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
Map<Element,X4OPhase> dirtyElements = element.getElementLanguage().getDirtyElements();
if (dirtyElements.isEmpty()) {
return;
}
debugPhaseMessage("Dirty elements: "+dirtyElements.size(), this);
for (Element e:dirtyElements.keySet()) {
X4OPhase p = dirtyElements.get(e);
manager.runPhasesForElement(e, p);
}
element.getElementLanguage().getDirtyElements().clear();
}
};
X4OPhaseHandler result = new RunDirtyElementPhase();
return result;
}
/**
*
* @param manager The phasemanager.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runDirtyElementLastPhase(final X4OPhaseManager manager) {
class RunDirtyElementLastPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.runDirtyElementLastPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
Map<Element,X4OPhase> dirtyElements = element.getElementLanguage().getDirtyElements();
if (dirtyElements.isEmpty()) {
return;
}
debugPhaseMessage("Dirty elements last: "+dirtyElements.size(), this);
for (Element e:dirtyElements.keySet()) {
X4OPhase p = dirtyElements.get(e);
manager.runPhasesForElement(e, p);
}
element.getElementLanguage().getDirtyElements().clear();
}
};
X4OPhaseHandler result = new RunDirtyElementLastPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler bindElementPhase() {
class BindElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.bindElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
Element parentElement = element.getParent();
if(parentElement==null) {
logger.finest("No parent element, so no binding needed.");
return;
}
Object parentObject = parentElement.getElementObject();
if(parentObject==null) {
logger.finest("No parent object, so no binding needed.");
return;
}
Object childObject = element.getElementObject();
if (childObject==null) {
logger.finest("No child object, so no binding needed.");
return;
}
List<ElementBindingHandler> binds = element.getElementLanguage().findElementBindingHandlers(parentObject, childObject);
logger.finest("Calling bindings handlers; "+binds.size());
try {
for (ElementBindingHandler binding:binds) {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementBindingHandler(binding,element);
}
binding.doBind(parentObject,childObject,element);
}
} catch (ElementException e) {
throw new X4OPhaseException(this,"Error while binding",e);
}
}
};
X4OPhaseHandler result = new BindElementPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.runPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.isTransformingTree()) {
return; // has already runned.
}
try {
//if (parser.hasX4ODebugWriter()) {
// parser.getX4ODebugWriter().debugElement(element);
//}
element.doElementRun();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}
}
};
class RunConfiguratorPhaseListener implements X4OPhaseListener {
/**
* @see org.x4o.xml.core.X4OPhaseListener#preRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
}
/**
* @see org.x4o.xml.core.X4OPhaseListener#endRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
for (RunConfigurator conf:runConf) {
try {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementConfigurator(conf.elementConfigurator,conf.element);
}
conf.elementConfigurator.doConfigElement(conf.element);
} catch (ElementException e) {
throw new X4OPhaseException(phase,e);
}
}
}
}
result.addPhaseListener(new RunConfiguratorPhaseListener());
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler releasePhase() {
// for debug output
class ReleasePhaseListener implements X4OPhaseListener {
private int elementsReleased = 0;
/**
* @see org.x4o.xml.core.X4OPhaseListener#preRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
elementsReleased=0;
}
/**
* @see org.x4o.xml.core.X4OPhaseListener#endRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
if (hasX4ODebugWriter()==false) {
return;
}
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "elements", "", "", elementsReleased+"");
getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts);
getX4ODebugWriter().getDebugWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , "");
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
}
public void addReleasedElement() {
elementsReleased++;
}
}
final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.releasePhase;
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
}
public void runElementPhase(Element element) throws X4OPhaseException {
try {
element.release();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
} finally {
releaseCounter.addReleasedElement();
}
}
};
result.addPhaseListener(releaseCounter);
return result;
}
/**
* Creates an debug phase
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler debugPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.debugPhase;
// safety check
if (hasX4ODebugWriter()==false) {
throw new NullPointerException("Use debugPhase only when X4OParser.debugWriter is filled.");
}
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
//atts.addAttribute ("", "verbose", "", "", "true");
getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts);
startedPrefix.clear();
printXML(elementLanguage.getRootElement());
for (String prefix:startedPrefix) {
getX4ODebugWriter().getDebugWriter().endPrefixMapping(prefix);
}
getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "printElementTree", "");
getX4ODebugWriter().debugElementLanguage(elementLanguage);
} catch (SAXException e) {
throw new X4OPhaseException(this,e);
}
}
List<String> startedPrefix = new ArrayList<String>(10);
// note: slow version
private String getNamespaceForElement(Element e) {
for (ElementLanguageModule mod:e.getElementLanguage().getElementLanguageModules()) {
for (ElementNamespaceContext enc:mod.getElementNamespaceContexts()) {
List<ElementClass> l = enc.getElementClasses();
if (l.contains(e.getElementClass())) {
return enc.getUri();
}
}
}
return null;
}
private void printXML(Element element) throws SAXException {
if (element==null) {
throw new SAXException("Can't print debug xml of null element.");
}
DefaultHandler2 handler = getX4ODebugWriter().getDebugWriter();
if (element.getElementType().equals(Element.ElementType.comment)) {
char[] msg = ((String)element.getElementObject()).toCharArray();
handler.comment(msg,0,msg.length);
return;
}
if (element.getElementType().equals(Element.ElementType.characters)) {
char[] msg = ((String)element.getElementObject()).toCharArray();
handler.characters(msg,0,msg.length);
return;
}
if (element.getElementClass()==null) {
throw new SAXException("Element without ElementClass is not valid: "+element+" obj: "+element.getElementObject());
}
AttributesImpl atts = new AttributesImpl();
for (String key:element.getAttributes().keySet()) {
String value = element.getAttributes().get(key);
//uri, localName, xml1.0name, type, value
atts.addAttribute ("", key, "", "", value);
}
String nameSpace = getNamespaceForElement(element);
String prefix = element.getElementLanguage().findElementNamespaceContext(nameSpace).getPrefixMapping();
if (startedPrefix.contains(prefix)==false) {
handler.startPrefixMapping(prefix, nameSpace);
startedPrefix.add(prefix);
}
handler.startElement (nameSpace, element.getElementClass().getTag(), "", atts);
for (Element e:element.getAllChilderen()) {
printXML(e);
}
handler.endElement (nameSpace, element.getElementClass().getTag(), "");
}
};
return result;
}
}

View file

@ -0,0 +1,53 @@
/*
* 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.core;
import org.x4o.xml.element.ElementLanguage;
/**
* An X4OPhaseListener can be placed on an X4OPhaseHandler and is called
* before and after the phase has runned.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
public interface X4OPhaseListener {
/**
* Gets called before the X4OPhaseHandler is run.
* @param phase The phase to be run.
* @param elementLanguage The elementLanguage of the driver.
* @throws X4OPhaseException Is throws when listeners has error.
*/
void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException;
/**
* Gets called after the X4OPhaseHandler is runned.
* @param phase The phase just run.
* @param elementLanguage The elementLanguage of the driver.
* @throws X4OPhaseException Is throws when listeners has error.
*/
void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException;
}

View file

@ -0,0 +1,291 @@
/*
* 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.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementLanguage;
/**
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order
* and will execute the phases when runPhases is called.
*
* @author Willem Cazander
* @version 1.0 Jan 6, 2008
*/
public class X4OPhaseManager {
/** The X4OPhaseHandler */
private List<X4OPhaseHandler> x4oPhases = null;
private ElementLanguage elementLanguage = null;
private X4OPhase stopPhase = null;
private boolean skipReleasePhase = false;
private boolean skipRunPhase = false;
private boolean skipSiblingsPhase = false;
/**
* Local package constuctor
*/
public X4OPhaseManager(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't manage phases with null elementLanguage in constuctor.");
}
x4oPhases = new ArrayList<X4OPhaseHandler>(15);
this.elementLanguage = elementLanguage;
// Manual
skipReleasePhase = elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RELEASE);
skipRunPhase = elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RUN);
skipSiblingsPhase = elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_SIBLINGS);
// Check if we need to stop after a certain phase
Object stopPhaseObject = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.PHASE_STOP_AFTER);
if (stopPhaseObject instanceof X4OPhase) {
stopPhase = (X4OPhase)stopPhaseObject;
}
}
/**
* Adds an X4OPhaseHandler.
* @param phase The X4OPhaseHandler to add.
*/
public void addX4OPhaseHandler(X4OPhaseHandler phase) {
if (phase==null) {
throw new NullPointerException("Can't add null phase handler.");
}
// context is created in first phase.
if (X4OPhase.FIRST_PHASE.equals(elementLanguage.getCurrentX4OPhase())==false) {
throw new IllegalStateException("Can't add new phases after first phase is completed.");
}
x4oPhases.add(phase);
}
/**
* Returns all the X4OPhaseHandlers.
* @return Returns all X4OPhaseHandlers.
*/
protected List<X4OPhaseHandler> getPhases() {
return x4oPhases;
}
/**
* Returns all the X4OPhaseHandlers in ordered list.
* @return Returns all X4OPhaseHandler is order.
*/
protected List<X4OPhaseHandler> getOrderedPhases() {
List<X4OPhaseHandler> result = new ArrayList<X4OPhaseHandler>(x4oPhases);
Collections.sort(result,new X4OPhaseHandlerComparator());
return result;
}
/**
* Runs all the phases in the right order.
* @throws X4OPhaseException
*/
public void runPhases() throws X4OPhaseException {
// sort for the order
List<X4OPhaseHandler> x4oPhasesOrder = getOrderedPhases();
// debug output
if (elementLanguage.getLanguageConfiguration().getX4ODebugWriter()!=null) {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().debugPhaseOrder(x4oPhases);
}
// run the phases in ordered order
for (X4OPhaseHandler phaseHandler:x4oPhasesOrder) {
if (skipReleasePhase && X4OPhase.releasePhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip always release phase when requested by property
}
if (skipRunPhase && X4OPhase.runPhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip run phase on request
}
if (skipSiblingsPhase && X4OPhase.createLanguageSiblingsPhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip loading sibling languages
}
// debug output
elementLanguage.setCurrentX4OPhase(phaseHandler.getX4OPhase());
// run listeners
for (X4OPhaseListener l:phaseHandler.getX4OPhaseListeners()) {
l.preRunPhase(phaseHandler, elementLanguage);
}
// always run endRunPhase for valid debug xml
try {
// do the run interface
phaseHandler.runPhase(elementLanguage);
// run the element phase if possible
executePhaseElement(phaseHandler);
} finally {
// run the listeners again
for (X4OPhaseListener l:phaseHandler.getX4OPhaseListeners()) {
l.endRunPhase(phaseHandler, elementLanguage);
}
}
if (stopPhase!=null && stopPhase.equals(phaseHandler.getX4OPhase())) {
return; // we are done
}
}
}
public void runPhasesForElement(Element e,X4OPhase p) throws X4OPhaseException {
// sort for the order
List<X4OPhaseHandler> x4oPhasesOrder = getOrderedPhases();
for (X4OPhaseHandler phaseHandler:x4oPhasesOrder) {
if (phaseHandler.getX4OPhase().equals(p)==false) {
continue; // we start running all phases from specified phase
}
if (X4OPhase.releasePhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip always release phase in dirty extra runs.
}
if (skipRunPhase && X4OPhase.runPhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip run phase on request
}
// set phase
elementLanguage.setCurrentX4OPhase(phaseHandler.getX4OPhase());
// do the run interface
phaseHandler.runPhase(elementLanguage);
// run the element phase if possible
executePhaseElement(phaseHandler);
if (stopPhase!=null && stopPhase.equals(phaseHandler.getX4OPhase())) {
return; // we are done
}
}
}
public void doReleasePhaseManual() throws X4OPhaseException {
if (skipReleasePhase==false) {
throw new IllegalStateException("No manual release requested.");
}
if (elementLanguage.getRootElement()==null) {
return; // no root element , empty xml document ?
}
if (elementLanguage.getRootElement().getElementClass()==null) {
throw new IllegalStateException("Release phase has already been runned.");
}
X4OPhaseHandler h = null;
for (X4OPhaseHandler phase:x4oPhases) {
if (phase.getX4OPhase().equals(X4OPhase.releasePhase)) {
h = phase;
break;
}
}
if (h==null) {
throw new IllegalStateException("No release phase found in manager to run.");
}
// set phase
elementLanguage.setCurrentX4OPhase(h.getX4OPhase());
// do the run interface
h.runPhase(elementLanguage);
// run the element phase if possible
executePhaseElement(h);
}
class X4OPhaseHandlerComparator implements Comparator<X4OPhaseHandler> {
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(X4OPhaseHandler e1, X4OPhaseHandler e2) {
X4OPhase p1 = e1.getX4OPhase();
X4OPhase p2 = e2.getX4OPhase();
if (p1==p2) {
return 0;
}
if (p1==X4OPhase.debugPhase) {
return 0;
}
if (p2==X4OPhase.debugPhase) {
return 0;
}
int i1 = phaseOrder(p1);
int i2 = phaseOrder(p2);
if (i1>i2) {
return 1;
}
if (i1<i2) {
return -1;
}
return 0;
}
private int phaseOrder(X4OPhase check) {
int result=0;
for (X4OPhase p:X4OPhase.PHASE_ORDER) {
if (p==check) {
return result;
}
result++;
}
return -1;
}
}
private void executePhaseElement(X4OPhaseHandler phase) throws X4OPhaseException {
if (elementLanguage.getRootElement()==null) {
return;
}
executePhaseTree(elementLanguage.getRootElement(),phase);
}
/**
* todo: rewrite to itterator for big deep trees
*
* @param element
* @param phase
* @throws X4OPhaseException
*/
private void executePhaseTree(Element element,X4OPhaseHandler phase) throws X4OPhaseException {
if (element.getElementClass().getSkipPhases().contains(phase.getX4OPhase().name())==false) {
phase.runElementPhase(element);
}
for (Element e:element.getChilderen()) {
executePhaseTree(e,phase);
}
}
}

View file

@ -0,0 +1,294 @@
/*
* 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.core;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.Element.ElementType;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.sax.AttributeMap;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.ext.DefaultHandler2;
import java.util.Map;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* This class handels all the X4O tags.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public class X4OTagHandler extends DefaultHandler2 {
/** The logger to log to */
private Logger logger = null;
private boolean loggerFinest = false;
/** The Locator for parse errors */
private Locator locator = null;
/** The element Stack */
private Stack<Element> elementStack = null;
/** The elememtContext */
private ElementLanguage elementLanguage = null;
/** Store the override element */
private Element overrideSaxElement = null;
/** Store the override element handler */
private DefaultHandler2 overrideSaxHandler = null;
/**
* Creates an X4OTagHandler
* which can receice sax xml events and converts them into the Element* interfaces events.
*/
public X4OTagHandler(ElementLanguage elementLanguage) {
logger = Logger.getLogger(X4OTagHandler.class.getName());
loggerFinest = logger.isLoggable(Level.FINEST);
elementStack = new Stack<Element>();
this.elementLanguage = elementLanguage;
}
/**
* @see org.xml.sax.helpers.DefaultHandler#setDocumentLocator(org.xml.sax.Locator)
*/
@Override
public void setDocumentLocator(Locator locator) {
this.locator=locator;
}
/**
* @see org.xml.sax.helpers.DefaultHandler#startPrefixMapping(java.lang.String, java.lang.String)
*/
@Override
public void startPrefixMapping(String prefix, String namespaceUri) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.startPrefixMapping(prefix, namespaceUri);
return;
}
if ("http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri)) {
return; // skip schema ns if non validating
}
if ("http://www.w3.org/2001/XInclude".equals(namespaceUri)) {
return; // skip xinclude ns.
}
ElementNamespaceContext enc = elementLanguage.findElementNamespaceContext(namespaceUri);
if (enc==null) {
throw new SAXException("Can't find namespace uri: "+namespaceUri+" in language: "+elementLanguage.getLanguageConfiguration().getLanguage());
}
enc.setPrefixMapping(prefix);
}
/**
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(String namespaceUri, String tag, String qName,Attributes attributes) throws SAXException {
if (loggerFinest) {
logger.finest("XMLTAG-START: "+namespaceUri+":"+tag);
}
if (overrideSaxHandler!=null) {
overrideSaxHandler.startElement(namespaceUri, tag, qName, attributes);
return;
}
ElementNamespaceContext enc = elementLanguage.findElementNamespaceContext(namespaceUri);
if (enc==null) {
if ("".equals(namespaceUri)) {
String configEmptryUri = (String)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_EMPTY_NAMESPACE_URI);
if (configEmptryUri!=null) {
namespaceUri = configEmptryUri;
enc = elementLanguage.findElementNamespaceContext(namespaceUri);
}
if (enc==null) {
throw new SAXParseException("No ElementNamespaceContext found for empty namespace.",locator);
}
enc.setPrefixMapping("");
}
if (enc==null) {
throw new SAXParseException("No ElementProvider found for namespace: "+namespaceUri,locator);
}
}
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
Element element = null;
try {
element = eip.createElementInstance(tag);
} catch (Exception e) {
throw new SAXParseException("Error while creating element: "+e.getMessage(),locator,e);
}
enc.addElementClass(element.getElementClass());
// next bind them togeter.
if (elementStack.empty()) {
elementLanguage.setRootElement(element); // root element !!
} else {
Element parent = elementStack.peek();
element.setParent(parent); // set parent element
parent.addChild(element);
}
// create attribute map
Map<String,String> map = new AttributeMap<String,String>(attributes);
element.getAttributes().putAll(map);
elementStack.push(element);
try {
element.doElementStart();
} catch (ElementException ee) {
throw new SAXParseException("Error while configing element: "+ee.getMessage(),locator,ee);
}
if (ElementType.overrideSax.equals(element.getElementType())) {
overrideSaxElement = element;
overrideSaxHandler = (DefaultHandler2)element.getElementObject();
}
}
/**
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void endElement(String namespaceUri, String tag,String qName) throws SAXException {
if (loggerFinest) {
logger.finest("XMLTAG-END: "+namespaceUri+":"+tag);
}
if (overrideSaxHandler!=null) {
if (overrideSaxElement.getElementClass().getTag().equals(tag)) {
overrideSaxHandler.endDocument();
overrideSaxHandler = null;
overrideSaxElement = null; // elementStack code make sure doElementEnd is runned on override element.
} else {
overrideSaxHandler.endElement(namespaceUri, tag, qName);
return;
}
}
if (elementStack.empty()) {
return;
}
Element element = elementStack.pop();
try {
element.doElementEnd();
} catch (ElementException ee) {
throw new SAXParseException("Error while configing element: '"+tag+"' "+ee.getMessage(),locator,ee);
}
}
/**
* Gets called to pass the text between XML-tags and converts it to a String.
* When this string is 0 length then nothing is done.
* If there are no element on the stact noting is done.
*
* @see org.xml.sax.helpers.DefaultHandler#characters(char[],int,int)
*/
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.characters(ch, start, length);
return;
}
if (length==0) {
return; // no text
}
String text = new String(ch,start,length);
if (text.isEmpty()) {
return; // no text
}
if (elementStack.empty()) {
return; // no element
}
Element e = elementStack.peek();
try {
e.doCharacters(text);
} catch (ElementException ee) {
throw new SAXParseException("Error while doCharacters element: '"+e.getElementClass().getTag()+"' "+ee.getMessage(),locator,ee);
}
}
/**
* @see org.xml.sax.helpers.DefaultHandler#ignorableWhitespace(char[], int, int)
*/
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.ignorableWhitespace(ch, start, length);
return;
}
String text = new String(ch);
text = text.substring(start, start + length);
if (text.length()==0) {
return; // no text
}
if (elementStack.empty()) {
return; // no element
}
Element e = elementStack.peek();
try {
e.doIgnorableWhitespace(text);
} catch (ElementException ee) {
throw new SAXParseException("Error while doIgnorableWhitespace element: '"+e.getElementClass().getTag()+"' "+ee.getMessage(),locator,ee);
}
}
/**
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
*/
@Override
public void comment(char[] ch, int start, int length) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.comment(ch, start, length);
return;
}
String text = new String(ch);
text = text.substring(start, start + length);
if (text.length()==0) {
return; // no text
}
if (elementStack.empty()) {
return; // no element
}
Element e = elementStack.peek();
try {
e.doComment(text);
} catch (ElementException ee) {
throw new SAXParseException("Error while doComment element: '"+e.getElementClass().getTag()+"' "+ee.getMessage(),locator,ee);
}
}
/**
* @see org.xml.sax.helpers.DefaultHandler#processingInstruction(java.lang.String, java.lang.String)
*/
@Override
public void processingInstruction(String target, String data) throws SAXException {
logger.fine("Skipping process instuctions: "+target+" data: "+data);
}
}

View file

@ -0,0 +1,80 @@
/*
* 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.core.config;
/**
* X4OLanguageClassLoader is short hand for safe class loading.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public class X4OLanguageClassLoader {
/**
* Gets the thread classloader or the normal classloader.
* @return Returns the ClassLoader.
*/
public static ClassLoader getClassLoader() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = X4OLanguageClassLoader.class.getClassLoader();
}
return cl;
}
/**
* Loads a Class from the ContextClassLoader and if that is not set, then
* uses the class of the String className instance.
*
* @param className The class name to load
* @return The loaded class
* @throws ClassNotFoundException if class not loaded.
*/
public static Class<?> loadClass(String className) throws ClassNotFoundException {
return getClassLoader().loadClass(className);
}
/**
* Creates new instance of clazz.
* @param clazz The class to make object from.
* @return The object of the clazz.
* @throws InstantiationException When className has no default constructor.
* @throws IllegalAccessException When class loading has security error.
*/
public static Object newInstance(Class<?> clazz) throws InstantiationException, IllegalAccessException {
return clazz.newInstance();
}
/**
* Creates new instance of className.
* @param className The className to create object from.
* @return The object of the className.
* @throws ClassNotFoundException When className is not found.
* @throws InstantiationException When className has no default constructor.
* @throws IllegalAccessException When class loading has security error.
*/
public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return newInstance(loadClass(className));
}
}

View file

@ -0,0 +1,147 @@
/*
* 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.core.config;
import java.util.List;
import java.util.Map;
import org.x4o.xml.core.X4ODebugWriter;
import org.x4o.xml.element.ElementLanguage;
/**
* X4OLanguageConfiguration first used interface in x4o parser which does the hard config of the x4o xml parsing.
*
* @author Willem Cazander
* @version 1.0 27 Oct 2009
*/
public interface X4OLanguageConfiguration {
/** Prefix where we load all language definitions from. */
public final static String DEFAULT_LANG_PATH_PREFIX = "META-INF";
/** The modules file to startup the language definition process. */
public final static String DEFAULT_LANG_MODULES_FILE = "-modules.xml";
/**
* Returns the language for which this ElementLanguage is created.
* @return Returns the language.
*/
String getLanguage();
/**
* @return Returns the languageVersion of the parsing of this language.
*/
String getLanguageVersion();
/**
* @return Returns the path prefix for loading language resources.
*/
String getLanguageResourcePathPrefix();
/**
* @return Returns the filename (postfix) of the modules definition file.
*/
String getLanguageResourceModulesFileName();
Object getLanguageProperty(X4OLanguageProperty property);
void setLanguageProperty(X4OLanguageProperty property,Object object);
boolean getLanguagePropertyBoolean(X4OLanguageProperty property);
int getLanguagePropertyInteger(X4OLanguageProperty property);
// Core interfaces are also in class for text reference without instance
public Class<?> getDefaultElementNamespaceContext();
public Class<?> getDefaultElementInterface();
public Class<?> getDefaultElement();
public Class<?> getDefaultElementClass();
public Class<?> getDefaultElementClassAttribute();
// Other needed interfaces in class form also
public Class<?> getDefaultElementLanguageModule();
public Class<?> getDefaultElementBodyComment();
public Class<?> getDefaultElementBodyCharacters();
public Class<?> getDefaultElementBodyWhitespace();
public Class<?> getDefaultElementNamespaceInstanceProvider();
public Class<?> getDefaultElementAttributeValueParser();
public Class<?> getDefaultElementObjectPropertyValue();
public Class<?> getDefaultElementAttributeHandlerComparator();
/**
* @return Returns the X4OLanguageVersionFilter which filters the best version to use.
*/
public Class<?> getDefaultX4OLanguageVersionFilter();
/**
* @return Returns the X4OLanguageLoader which loads languages into the element context.
*/
public Class<?> getDefaultX4OLanguageLoader();
/**
* Creates and filles the inital element language used to store the language.
* @return The newly created ElementLanguage.
*/
public ElementLanguage createElementLanguage();
/**
* @return Returns Map of SAX properties which are set.
*/
public Map<String,Object> getSAXParserProperties();
/**
* @return Returns Map of SAX properties which are optional set.
*/
public Map<String,Object> getSAXParserPropertiesOptional();
/**
* @return Returns Map of SAX features which are set on the xml parser.
*/
public Map<String,Boolean> getSAXParserFeatures();
/**
* @return Returns Map of SAX features which are optional set.
*/
public Map<String, Boolean> getSAXParserFeaturesOptional();
/**
* @return Returns List of SAX features which are required for xml parsing.
*/
public List<String> getSAXParserFeaturesRequired();
/**
* @return Returns null or an X4ODebugWriter to write parsing steps and debug data to.
*/
public X4ODebugWriter getX4ODebugWriter();
/**
* @return Returns true if this config has a debug writer.
*/
public boolean hasX4ODebugWriter();
/**
* @param debugWriter The debug writer to set
*/
public void setX4ODebugWriter(X4ODebugWriter debugWriter);
}

View file

@ -0,0 +1,44 @@
/*
* 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.core.config;
import org.x4o.xml.element.ElementLanguage;
/**
* Loads the language into the contexts.
*
* @author Willem Cazander
* @version 1.0 28 Oct 2009
*/
public interface X4OLanguageLoader {
/**
* Loads the language modules.
* @param elementLanguage The elementLanguage to load the module in.
* @param language The language to load.
* @param languageVersion The language version to load.
* @throws X4OLanguageLoaderException When there is an error.
*/
void loadLanguage(ElementLanguage elementLanguage,String language,String languageVersion) throws X4OLanguageLoaderException;
}

View file

@ -0,0 +1,68 @@
/*
* 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.core.config;
/**
* Is throw when there is en Exception within an Element.
*
* @author Willem Cazander
* @version 1.0 Oct 28, 2009
*/
public class X4OLanguageLoaderException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10L;
/**
* Constructs an X4OLanguageLoaderException without a detail message.
*/
public X4OLanguageLoaderException() {
super();
}
/**
* Constructs an X4OLanguageLoaderException with a detail message.
* @param message The message of this Exception
*/
public X4OLanguageLoaderException(String message) {
super(message);
}
/**
* Creates an X4OLanguageLoaderException from a parent exception.
* @param e The exception.
*/
public X4OLanguageLoaderException(Exception e) {
super(e);
}
/**
* Constructs an X4OLanguageLoaderException with a detail message.
* @param message The message of this Exception
* @param e The exception.
*/
public X4OLanguageLoaderException(String message,Exception e) {
super(message,e);
}
}

View file

@ -0,0 +1,224 @@
/*
* 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.core.config;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Map;
import javax.el.ExpressionFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.ext.DefaultHandler2;
/**
* X4OLanguageProperty holds the language parser properties keys
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public enum X4OLanguageProperty {
/** Read-Only property returning the language we are working with. */
LANGUAGE_NAME("language/name"),
/** Read-Only property returning the version of the language. */
LANGUAGE_VERSION("language/version"),
/** When set to OutputStream xml debug is written to it. note: when output-handler is set this property is ignored. */
DEBUG_OUTPUT_STREAM("debug/output-stream",OutputStream.class),
/** When set to DefaultHandler2 xml debug events are fired to the object. */
DEBUG_OUTPUT_HANDLER("debug/output-handler",DefaultHandler2.class),
/** When set to true print also phases for parsing eld files. */
DEBUG_OUTPUT_ELD_PARSER("debug/output-eld-parser",Boolean.class,false),
/** When set to true print full element tree per phase. */
//DEBUG_OUTPUT_TREE_PER_PHASE("debug/output-tree-per-phase",Boolean.class),
/** SAX parser input buffer size: 512-16k defaults to 8k. */
INPUT_BUFFER_SIZE("input/buffer-size",Integer.class,4096*2),
/** When set it allows parsing of non-namespace aware documents. */
INPUT_EMPTY_NAMESPACE_URI("input/empty-namespace-uri"),
/** The input stream to parse, note is skipped when object is set. */
INPUT_SOURCE_STREAM("input/source/stream",InputStream.class),
/** When set it overrides automatic encoding detection of sax parser. */
INPUT_SOURCE_ENCODING("input/source/encoding"),
/** When set use this InputSource instance for parsing. */
INPUT_SOURCE_OBJECT("input/source/object",InputSource.class),
/** Sets the system-id to the input source. */
INPUT_SOURCE_SYSTEM_ID("input/source/system-id",String.class),
/** Sets the base path to resolve external input sources. */
INPUT_SOURCE_BASE_PATH("input/source/base-path",URL.class),
/** Set for custom handling of validation errors. */
CONFIG_ERROR_HANDLER("config/error-handler",ErrorHandler.class),
/** Resolve more entities from local sources. */
CONFIG_ENTITY_RESOLVER("config/entity-resolver",EntityResolver.class),
//CONFIG_CACHE_HANDLER("config/cache-handler"),
//CONFIG_MODULE_PROVIDER("config/module-provider"),
//CONFIG_LOCK_PROPERTIES("config/lock-properties"),
/** The beans in this map are set into the EL context for reference. */
EL_BEAN_INSTANCE_MAP("el/bean-instance-map",Map.class),
//EL_CONTEXT_INSTANCE("el/context-instance"),
/** When set this instance is used in ElementLanguage. */
EL_FACTORY_INSTANCE("el/factory-instance",ExpressionFactory.class),
//EL_INSTANCE_FACTORY("phase/skip-elb-init",Boolean.class),
/** When set to an X4OPhase then parsing stops after completing the set phase. */
PHASE_STOP_AFTER("phase/stop-after",Boolean.class),
/** When set to true skip the release phase. */
PHASE_SKIP_RELEASE("phase/skip-release",Boolean.class,false),
/** When set to true skip the run phase. */
PHASE_SKIP_RUN("phase/skip-run",Boolean.class,false),
/** When set to true skip the load siblings language phase. */
PHASE_SKIP_SIBLINGS("phase/skip-siblings",Boolean.class,false),
/** When set this path is searched for xsd schema files in the language sub directory. */
VALIDATION_SCHEMA_PATH("validation/schema-path",File.class),
/** When set to true then input xml is validated. */
VALIDATION_INPUT("validation/input",Boolean.class,false),
/** When set to true then input xsd xml grammer is validated. */
VALIDATION_INPUT_XSD("validation/input/xsd",Boolean.class,false),
/** When set to true then eld xml is validated. */
VALIDATION_ELD("validation/eld",Boolean.class,false),
/** When set to true than eld xsd xml grammer is also validated. */
VALIDATION_ELD_XSD("validation/eld/xsd",Boolean.class,false);
private final static String URI_PREFIX = "http://language.x4o.org/xml/properties/";
private final String uriName;
private final Class<?>[] classTypes;
private final Object defaultValue;
private X4OLanguageProperty(String uriName) {
this(uriName,String.class);
}
private X4OLanguageProperty(String uriName,Class<?> classType) {
this(uriName,new Class[]{classType},null);
}
private X4OLanguageProperty(String uriName,Class<?> classType,Object defaultValue) {
this(uriName,new Class[]{classType},defaultValue);
}
private X4OLanguageProperty(String uriName,Class<?>[] classTypes,Object defaultValue) {
this.uriName=URI_PREFIX+uriName;
this.classTypes=classTypes;
this.defaultValue=defaultValue;
}
/**
* Returns the uri defined by this property.
* @return The uri defined by this property.
*/
public String toUri() {
return uriName;
}
/**
* Returns the default value for this property.
* @return The default value for this property.
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* Checks if the object is valid to set on this property.
* This is done by checking the allowed class types if they are assignable from the value class.
* @param value The object to check.
* @return Returns true when Object value is allowed to be set.
*/
public boolean isValueValid(Object value) {
if (LANGUAGE_NAME.equals(this) | LANGUAGE_VERSION.equals(this)) {
return false; // read only are not valid to set.
}
if (value==null) {
return true;
}
Class<?> valueClass = value.getClass();
for (Class<?> c:classTypes) {
if (c.isAssignableFrom(valueClass)) {
return true;
}
}
return false;
}
/**
* Search the enum for the value defined by the given uri.
* @param uri The uri to search for.
* @return Return the property for the given uri.
* @throws IllegalArgumentException when uri is not found.
*/
static public X4OLanguageProperty valueByUri(String uri) {
if (uri==null) {
throw new NullPointerException("Can't search null uri.");
}
if (uri.isEmpty()) {
throw new IllegalArgumentException("Can't search empty uri.");
}
if (uri.startsWith(URI_PREFIX)==false) {
throw new IllegalArgumentException("Can't search for other name local prefix: "+URI_PREFIX+" found: "+uri);
}
for (X4OLanguageProperty p:values()) {
if (uri.equals(p.toUri())) {
return p;
}
}
throw new IllegalArgumentException("Could not find language property for uri key: "+uri);
}
}

View file

@ -0,0 +1,66 @@
/*
* 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.core.config;
/**
* X4OLanguagePropertyKeys is shortcut to the the properties by uri.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public class X4OLanguagePropertyKeys {
public final static String LANGUAGE_NAME = X4OLanguageProperty.LANGUAGE_NAME.toUri();
public final static String LANGUAGE_VERSION = X4OLanguageProperty.LANGUAGE_VERSION.toUri();
public final static String DEBUG_OUTPUT_STREAM = X4OLanguageProperty.DEBUG_OUTPUT_STREAM.toUri();
public final static String DEBUG_OUTPUT_HANDLER = X4OLanguageProperty.DEBUG_OUTPUT_HANDLER.toUri();
public final static String DEBUG_OUTPUT_ELD_PARSER = X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER.toUri();
public final static String INPUT_BUFFER_SIZE = X4OLanguageProperty.INPUT_BUFFER_SIZE.toUri();
public final static String INPUT_EMPTY_NAMESPACE_URI = X4OLanguageProperty.INPUT_EMPTY_NAMESPACE_URI.toUri();
public final static String INPUT_SOURCE_STREAM = X4OLanguageProperty.INPUT_SOURCE_STREAM.toUri();
public final static String INPUT_SOURCE_ENCODING = X4OLanguageProperty.INPUT_SOURCE_ENCODING.toUri();
public final static String INPUT_SOURCE_OBJECT = X4OLanguageProperty.INPUT_SOURCE_OBJECT.toUri();
public final static String INPUT_SOURCE_SYSTEM_ID = X4OLanguageProperty.INPUT_SOURCE_SYSTEM_ID.toUri();
public final static String INPUT_SOURCE_BASE_PATH = X4OLanguageProperty.INPUT_SOURCE_BASE_PATH.toUri();
public final static String CONFIG_ERROR_HANDLER = X4OLanguageProperty.CONFIG_ERROR_HANDLER.toUri();
public final static String CONFIG_ENTITY_RESOLVER = X4OLanguageProperty.CONFIG_ENTITY_RESOLVER.toUri();
public final static String EL_BEAN_INSTANCE_MAP = X4OLanguageProperty.EL_BEAN_INSTANCE_MAP.toUri();
public final static String EL_FACTORY_INSTANCE = X4OLanguageProperty.EL_FACTORY_INSTANCE.toUri();
public final static String PHASE_STOP_AFTER = X4OLanguageProperty.PHASE_STOP_AFTER.toUri();
public final static String PHASE_SKIP_RELEASE = X4OLanguageProperty.PHASE_SKIP_RELEASE.toUri();
public final static String PHASE_SKIP_RUN = X4OLanguageProperty.PHASE_SKIP_RUN.toUri();
public final static String PHASE_SKIP_SIBLINGS = X4OLanguageProperty.PHASE_SKIP_SIBLINGS.toUri();
public final static String VALIDATION_SCHEMA_PATH = X4OLanguageProperty.VALIDATION_SCHEMA_PATH.toUri();
public final static String VALIDATION_INPUT = X4OLanguageProperty.VALIDATION_INPUT.toUri();
public final static String VALIDATION_INPUT_XSD = X4OLanguageProperty.VALIDATION_INPUT_XSD.toUri();
public final static String VALIDATION_ELD = X4OLanguageProperty.VALIDATION_ELD.toUri();
public final static String VALIDATION_ELD_XSD = X4OLanguageProperty.VALIDATION_ELD_XSD.toUri();
}

View file

@ -0,0 +1,44 @@
/*
* 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.core.config;
import java.util.List;
/**
* X4OLanguageVersionFilter fitlers the best version to use of the modules to load.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public interface X4OLanguageVersionFilter {
/**
* Finds the version to load or returns null if no match is found.
*
* @param languageVersion The languageVersion to requested.
* @param versions The versions provided by the module.
* @return The version to load.
*/
String filterVersion(String languageVersion,List<String> versions);
}

View file

@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* The core config interfaces and key definitions.
*
*
* @since 1.0
*/
package org.x4o.xml.core.config;

View file

@ -0,0 +1,30 @@
/*
* 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.
*/
/**
* The core classes which startup the language.
*
* @since 1.0
*/
package org.x4o.xml.core;

View file

@ -0,0 +1,66 @@
/*
* 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.eld;
import java.util.logging.Logger;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementLanguageModuleLoader;
import org.x4o.xml.element.ElementLanguageModuleLoaderException;
/**
* De default X4OElementConfigurator.
*
* @author Willem Cazander
* @version 1.0 Aug 17, 2005
*/
public class EldModuleLoader implements ElementLanguageModuleLoader {
private Logger logger = null;
private String eldResource = null;
private boolean isEldCore = false;
public EldModuleLoader(String eldResource,boolean isEldCore) {
if (eldResource==null) {
throw new NullPointerException("Can't load null eld resource.");
}
logger = Logger.getLogger(EldModuleLoader.class.getName());
this.eldResource=eldResource;
this.isEldCore=isEldCore;
}
/**
* @see org.x4o.xml.element.ElementLanguageModuleLoader#loadLanguageModule(org.x4o.xml.element.ElementLanguage, org.x4o.xml.element.ElementLanguageModule)
*/
public void loadLanguageModule(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) throws ElementLanguageModuleLoaderException {
logger.fine("Loading name eld file from resource: "+eldResource);
try {
EldParser parser = new EldParser(elementLanguage,elementLanguageModule,isEldCore);
parser.parseResource(eldResource);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
}
}
}

View file

@ -0,0 +1,285 @@
/*
* 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.eld;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.x4o.xml.conv.text.ClassConverter;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.eld.lang.BeanElement;
import org.x4o.xml.eld.lang.DescriptionElement;
import org.x4o.xml.eld.lang.ElementClassAddParentElement;
import org.x4o.xml.eld.lang.ElementClassAttributeBindingHandler;
import org.x4o.xml.eld.lang.ElementClassBindingHandler;
import org.x4o.xml.eld.lang.ElementInterfaceBindingHandler;
import org.x4o.xml.eld.lang.ElementModuleBindingHandler;
import org.x4o.xml.eld.lang.ElementNamespaceContextBindingHandler;
import org.x4o.xml.eld.lang.ModuleElement;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementLanguageModuleLoader;
import org.x4o.xml.element.ElementLanguageModuleLoaderException;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.impl.DefaultElementClass;
/**
* EldModuleLoaderCore provides a few basic elements for the core eld x4o language.
*
* @author Willem Cazander
* @version 1.0 Jan 11, 2009
*/
public class EldModuleLoaderCore implements ElementLanguageModuleLoader {
private Logger logger = null;
private static final String _CEL_XMLNS = "http://cel.x4o.org/xml/ns/";
private static final String _CEL_CORE = "cel-core";
private static final String _CEL_ROOT = "cel-root";
private static final String _CEL_XSD_FILE = "-1.0.xsd";
private static final String CEL_CORE_URI = _CEL_XMLNS+_CEL_CORE;
private static final String CEL_ROOT_URI = _CEL_XMLNS+_CEL_ROOT;
private static final String CEL_CORE_XSD_URI = CEL_CORE_URI+_CEL_XSD_FILE;
private static final String CEL_ROOT_XSD_URI = CEL_ROOT_URI+_CEL_XSD_FILE;
private static final String CEL_CORE_XSD_FILE = _CEL_CORE+_CEL_XSD_FILE;
private static final String CEL_ROOT_XSD_FILE = _CEL_ROOT+_CEL_XSD_FILE;
public EldModuleLoaderCore() {
logger = Logger.getLogger(EldModuleLoaderCore.class.getName());
}
/**
* @see org.x4o.xml.element.ElementLanguageModuleLoader#loadLanguageModule(org.x4o.xml.element.ElementLanguage, org.x4o.xml.element.ElementLanguageModule)
*/
public void loadLanguageModule(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) throws ElementLanguageModuleLoaderException {
elementLanguageModule.setId("cel-module");
elementLanguageModule.setName("Core Element Languag Module");
elementLanguageModule.setProviderName("cel.x4o.org");
List<ElementClass> elementClassList = new ArrayList<ElementClass>(10);
elementClassList.add(new DefaultElementClass("attribute",elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute()));
elementClassList.add(new DefaultElementClass("classConverter",ClassConverter.class));
createElementClasses(elementClassList,elementLanguage); // adds all meta info
ElementClassAttribute attr;
DefaultElementClass ns = new DefaultElementClass("namespace",elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceContext());
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("uri");
attr.setRequired(true);
ns.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ns);
DefaultElementClass dec = new DefaultElementClass("element",elementLanguage.getLanguageConfiguration().getDefaultElementClass());
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("objectClass");
attr.setObjectConverter(new ClassConverter());
dec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("elementClass");
attr.setObjectConverter(new ClassConverter());
dec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(dec);
DefaultElementClass ec = new DefaultElementClass("elementInterface",elementLanguage.getLanguageConfiguration().getDefaultElementInterface());
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("interfaceClass");
attr.setObjectConverter(new ClassConverter());
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
logger.finer("Creating eldcore namespace.");
ElementNamespaceContext namespace;
try {
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceContext());
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setUri(CEL_CORE_URI);
namespace.setSchemaUri(CEL_CORE_XSD_URI);
namespace.setSchemaResource(CEL_CORE_XSD_FILE);
namespace.setSchemaPrefix(_CEL_CORE);
logger.finer("Loading elementClassList size: "+elementClassList.size());
for (ElementClass ecL:elementClassList) {
namespace.addElementClass(ecL);
}
addBindingHandler("cel-class-bind",new ElementClassBindingHandler(),elementLanguageModule);
addBindingHandler("cel-module-bind",new ElementModuleBindingHandler(),elementLanguageModule);
addBindingHandler("cel-class-attr-bind",new ElementClassAttributeBindingHandler(),elementLanguageModule);
addBindingHandler("cel-interface-bind",new ElementInterfaceBindingHandler(),elementLanguageModule);
addBindingHandler("cel-namespace-bind",new ElementNamespaceContextBindingHandler(),elementLanguageModule);
try {
namespace.getElementNamespaceInstanceProvider().start(elementLanguage, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(namespace);
// And define root
try {
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceContext());
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setUri(CEL_ROOT_URI);
namespace.setSchemaUri(CEL_ROOT_XSD_URI);
namespace.setSchemaResource(CEL_ROOT_XSD_FILE);
namespace.setSchemaPrefix(_CEL_ROOT);
namespace.addElementClass(new DefaultElementClass("module",elementLanguage.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class));
namespace.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
try {
namespace.getElementNamespaceInstanceProvider().start(elementLanguage, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(namespace);
}
/**
* Adds only Element class beans which need extra meta info for schema.
*
* @param elementClassList The list to fill.
* @throws ElementLanguageModuleLoaderException
*/
private void createElementClasses(List<ElementClass> elementClassList,ElementLanguage elementLanguage) throws ElementLanguageModuleLoaderException {
ElementClass ec = null;
ElementClassAttribute attr = null;
ec = new DefaultElementClass("bindingHandler",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "elementInterface");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("id");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
ec = new DefaultElementClass("attributeHandler",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);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
ec = new DefaultElementClass("configurator",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "elementInterface");
ec.addElementParent("", "element");
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");
ec.addElementParent("", "attributeHandler");
ec.addElementParent("", "bindingHandler");
ec.addElementParent("", "configurator");
ec.addElementParent("", "elementInterface");
ec.addElementParent("", "element");
elementClassList.add(ec);
ec = new DefaultElementClass("elementParent",null,ElementClassAddParentElement.class);
ec.addElementParent("", "element");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("tag");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("uri");
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
}
private void addBindingHandler(String id,ElementBindingHandler handler,ElementLanguageModule elementLanguageModule) {
handler.setId(id);
elementLanguageModule.addElementBindingHandler(handler);
}
}

View file

@ -0,0 +1,94 @@
/*
* 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.eld;
import org.x4o.xml.core.X4ODriver;
import org.x4o.xml.core.X4OParser;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
/**
* An Element Language Definition X4O parser.
* This eld parser config parent x4o parser with the eld x4o parser.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public class EldParser extends X4OParser {
/** Defines the identifier of the ELD x4o language. */
public static final String ELD_VERSION = X4ODriver.DEFAULT_LANGUAGE_VERSION;
/** Defines the identifier of the 'Element Language Description' language. */
public static final String ELD_LANGUAGE = "eld";
/** Defines the identifier of the 'Core Element Language' language. */
public static final String CEL_LANGUAGE = "cel";
protected EldParser() {
this(false);
}
protected EldParser(boolean isEldCore) {
super(isEldCore?CEL_LANGUAGE:ELD_LANGUAGE,ELD_VERSION);
}
/**
* getDriver for unit tests
*/
protected X4ODriver getDriver() {
return super.getDriver();
}
/**
* Start the second x4o parsing for eld files.
* @param elementLanguage The elementLanguage to fill.
* @param elementLanguageModule The elementLanguageModule from to fill.
*/
public EldParser(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) {
this(false);
if (elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
getDriver().getElementLanguage().getLanguageConfiguration().setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter()); // move to ..
}
addELBeanInstance(PARENT_LANGUAGE_CONFIGURATION, elementLanguage.getLanguageConfiguration());
addELBeanInstance(PARENT_LANGUAGE_ELEMENT_LANGUAGE, elementLanguage);
addELBeanInstance(PARENT_ELEMENT_LANGUAGE_MODULE, elementLanguageModule);
}
public EldParser(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule,boolean isEldCore) {
this(isEldCore);
if (elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
getDriver().getElementLanguage().getLanguageConfiguration().setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter());
}
addELBeanInstance(PARENT_LANGUAGE_CONFIGURATION, elementLanguage.getLanguageConfiguration());
addELBeanInstance(PARENT_LANGUAGE_ELEMENT_LANGUAGE, elementLanguage);
addELBeanInstance(PARENT_ELEMENT_LANGUAGE_MODULE, elementLanguageModule);
}
public final static String PARENT_LANGUAGE_CONFIGURATION = "parentLanguageConfiguration";
public final static String PARENT_ELEMENT_LANGUAGE_MODULE = "parentElementLanguageModule";
public final static String PARENT_LANGUAGE_ELEMENT_LANGUAGE = "parentLanguageElementLanguage";
}

View file

@ -0,0 +1,47 @@
/*
* 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.eld;
import org.x4o.xml.core.X4OParserSupport;
import org.x4o.xml.core.X4OParserSupportException;
import org.x4o.xml.element.ElementLanguage;
/**
* EldParserSupport can write the eld schema.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class EldParserSupport implements X4OParserSupport {
/**
* Loads the ElementLanguage of this language parser for support.
* @return The loaded ElementLanguage.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
EldParser parser = new EldParser(false);
return parser.loadElementLanguageSupport();
}
}

View file

@ -0,0 +1,47 @@
/*
* 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.eld;
import org.x4o.xml.core.X4OParserSupport;
import org.x4o.xml.core.X4OParserSupportException;
import org.x4o.xml.element.ElementLanguage;
/**
* EldParserSupportCore can write the cel schema.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class EldParserSupportCore implements X4OParserSupport {
/**
* Loads the ElementLanguage of this language parser for support.
* @return The loaded ElementLanguage.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
EldParser parser = new EldParser(true);
return parser.loadElementLanguageSupport();
}
}

View file

@ -0,0 +1,53 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementException;
/**
* AttributeAliasElement add the defines alias to the parent element attribute.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2006
*/
public class AttributeAliasElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
String alias = getAttributes().get("name");
if (alias==null) {
throw new ElementException("'name' attribute is not set on: "+getElementClass().getTag());
}
if (getParent().getElementObject() instanceof ElementClassAttribute) {
((ElementClassAttribute)getParent().getElementObject()).addAttributeAlias(alias);
} else {
throw new ElementException("Wrong parent class is not ElementClassAttribute but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,111 @@
/*
* 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.eld.lang;
import java.util.List;
import org.x4o.xml.element.AbstractElementConfigurator;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.Element.ElementType;
import org.x4o.xml.element.ElementConfiguratorException;
/**
* AttributeFromBodyConfigurator sets the body as attribute.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class AttributeFromBodyConfigurator extends AbstractElementConfigurator {
private String name = null;
private String bodyType = null;
/**
* @see org.x4o.xml.element.ElementConfigurator#doConfigElement(org.x4o.xml.element.Element)
*/
public void doConfigElement(Element element) throws ElementConfiguratorException {
if (name==null) {
throw new ElementConfiguratorException(this,"name attribute is not set.");
}
if (name.isEmpty()) {
throw new ElementConfiguratorException(this,"name attribute is empty.");
}
if (bodyType==null) {
bodyType = "characters";
}
String value = null;
if ("characters".equals(bodyType)) {
value = fetchBodyType(element,ElementType.characters);
} else if ("comment".equals(bodyType)) {
value = fetchBodyType(element,ElementType.comment);
} else if ("ignorableWhitespace".equals(bodyType)) {
value = fetchBodyType(element,ElementType.ignorableWhitespace);
} else {
throw new ElementConfiguratorException(this,"bodyType attribute value is unknown; "+bodyType);
}
if (value.isEmpty()) {
return;
}
element.getAttributes().put(name, value);
}
private String fetchBodyType(Element element,ElementType elementType) {
StringBuffer buf = new StringBuffer(300);
List<Element> childsAll = element.getAllChilderen();
List<Element> childs = ElementType.filterElements(childsAll, elementType);
for (int i=0;i<childs.size();i++) {
Element e = childs.get(i);
buf.append(e.getElementObject().toString());
}
return buf.toString();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the bodyType
*/
public String getBodyType() {
return bodyType;
}
/**
* @param bodyType the bodyType to set
*/
public void setBodyType(String bodyType) {
this.bodyType = bodyType;
}
}

View file

@ -0,0 +1,74 @@
/*
* 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.eld.lang;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
/**
* An BeanElement.<br>
* This BeanElement fills it elementObject from source with the bean.class attribute.
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class BeanElement extends AbstractElement {
private List<Object> constructorArguments = null;
public BeanElement() {
constructorArguments = new ArrayList<Object>(3);
}
@Override
public void doElementStart() throws ElementException {
String className = getAttributes().get("bean.class");
if("".equals(className) | className==null) { throw new ElementException("Set the bean.class attribute"); }
try {
Class<?> beanClass = X4OLanguageClassLoader.loadClass(className);
if (constructorArguments.isEmpty()) {
setElementObject(beanClass.newInstance());
} else {
Class<?>[] arguClass = new Class<?>[constructorArguments.size()];
constructorArguments.toArray(arguClass);
Constructor<?> c = beanClass.getConstructor(arguClass);
setElementObject(c.newInstance(constructorArguments));
}
} catch (Exception e) {
throw new ElementException(e);
}
}
public void addConstuctorArgument(Object argu) {
if (argu==null) {
throw new NullPointerException("Can't add null argument for constructor.");
}
constructorArguments.add(argu);
}
}

View file

@ -0,0 +1,76 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementMetaBase;
import org.x4o.xml.element.ElementException;
/**
* Fills all the ElementDescription which the description
*
*
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class DescriptionElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementStart()
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()==null) {
throw new ElementException("can't be a root tag");
}
if (getParent().getElementObject() instanceof ElementMetaBase == false) {
throw new ElementException("Wrong parent class is not ElementDescription");
}
}
/**
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
*/
@Override
public void doCharacters(String characters) throws ElementException {
super.doCharacters(characters);
setElementObject(characters);
}
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
if (getElementObject()==null) {
throw new ElementException("description is not set.");
}
if (getParent().getElementObject() instanceof ElementMetaBase) {
((ElementMetaBase)getParent().getElementObject()).setDescription(getElementObject().toString());
} else {
throw new ElementException("Wrong parent class is not ElementClass");
}
}
}

View file

@ -0,0 +1,57 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementException;
/**
* ElementClassAddParentElement adds an parent tag to ElementClass for xsd.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementClassAddParentElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
String tag = getAttributes().get("tag");
if (tag==null) {
throw new ElementException("'tag' attribute is not set on: "+getElementClass().getTag());
}
String namespaceUri = getAttributes().get("uri");
if (namespaceUri==null) {
namespaceUri = ""; // current namespace ?
}
if (getParent().getElementObject() instanceof ElementClass) {
((ElementClass)getParent().getElementObject()).addElementParent(namespaceUri,tag);
} else {
throw new ElementException("Wrong parent class is not ElementClass but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,68 @@
/*
* 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.eld.lang;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClassAttribute;
/**
* ElementClassAttributeBindingHandler adds the object converter.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementClassAttributeBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ObjectConverter.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementClassAttribute.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementClassAttribute parent = (ElementClassAttribute)parentObject;
if (childObject instanceof ObjectConverter) {
parent.setObjectConverter((ObjectConverter)childObject);
}
}
}

View file

@ -0,0 +1,73 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
/**
* This ElementBindingHandler adds the ElementClassAttributeConverter and the
* ElementConfigurator to the ElementClass.
*
* @author Willem Cazander
* @version 1.0 Jan 31, 2007
*/
public class ElementClassBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClassAttribute.class,
ElementConfigurator.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementClass.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementClass parent = (ElementClass)parentObject;
if (childObject instanceof ElementClassAttribute) {
parent.addElementClassAttribute((ElementClassAttribute)childObject);
}
if (childObject instanceof ElementConfigurator) {
parent.addElementConfigurators((ElementConfigurator)childObject);
}
}
}

View file

@ -0,0 +1,77 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementInterface;
/**
* ElementInterfaceBindingHandler binds all childs into the interface.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementInterfaceBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClassAttribute.class,
ElementConfigurator.class,
ElementBindingHandler.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementInterface.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementInterface parent = (ElementInterface)parentObject;
if (childObject instanceof ElementBindingHandler) {
parent.addElementBindingHandler((ElementBindingHandler)childObject);
}
if (childObject instanceof ElementClassAttribute) {
parent.addElementClassAttribute((ElementClassAttribute)childObject);
}
if (childObject instanceof ElementConfigurator) {
parent.addElementConfigurators((ElementConfigurator)childObject);
}
}
}

View file

@ -0,0 +1,134 @@
/*
* 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.eld.lang;
import java.util.Map;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.eld.EldParser;
import org.x4o.xml.element.AbstractElementBindingHandler;
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.ElementLanguage;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
/**
* An ParentLanguageElementConfigurator.
*
* This binds the main interfaces of the ELD language to an other Element
*
* @author Willem Cazander
* @version 1.0 Jan 19, 2007
*/
public class ElementModuleBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementInterface.class,
ElementNamespaceContext.class,
ElementBindingHandler.class,
ElementAttributeHandler.class,
ElementConfigurator.class,
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementLanguageModule.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
@SuppressWarnings("rawtypes")
Map m = (Map)childElement.getElementLanguage().getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (m==null) {
return;
}
ElementLanguage x4oParsingContext = (ElementLanguage)m.get(EldParser.PARENT_LANGUAGE_ELEMENT_LANGUAGE);
//ElementLanguageModule elementLanguageModule = (ElementLanguageModule)m.get(EldParser.PARENT_ELEMENT_LANGUAGE_MODULE);
ElementLanguageModule elementLanguageModule = (ElementLanguageModule)parentObject;
if (x4oParsingContext==null) {
return;
}
if (elementLanguageModule==null) {
return;
}
if (childObject instanceof ElementInterface) {
ElementInterface elementInterface = (ElementInterface)childObject;
elementLanguageModule.addElementInterface(elementInterface);
return;
}
if (childObject instanceof ElementNamespaceContext) {
ElementNamespaceContext elementNamespaceContext = (ElementNamespaceContext)childObject;
try {
elementNamespaceContext.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(childElement.getElementLanguage().getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementBindingHandlerException("Error loading: "+e.getMessage(),e);
}
try {
elementNamespaceContext.getElementNamespaceInstanceProvider().start(x4oParsingContext, elementNamespaceContext);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementBindingHandlerException("Error starting: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(elementNamespaceContext);
return;
}
if (childObject instanceof ElementBindingHandler) {
ElementBindingHandler elementBindingHandler = (ElementBindingHandler)childObject;
elementLanguageModule.addElementBindingHandler(elementBindingHandler);
return;
}
if (childObject instanceof ElementAttributeHandler) {
ElementAttributeHandler elementAttributeHandler = (ElementAttributeHandler)childObject;
elementLanguageModule.addElementAttributeHandler(elementAttributeHandler);
return;
}
if (childObject instanceof ElementConfigurator) {
ElementConfigurator elementConfigurator = (ElementConfigurator)childObject;
elementLanguageModule.addGlobalElementConfigurator(elementConfigurator);
return;
}
}
}

View file

@ -0,0 +1,68 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementNamespaceContext;
/**
* ElementNamespaceContextBindingHandler binds ElementClass into namespace.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementNamespaceContextBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClass.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementNamespaceContext.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementNamespaceContext parent = (ElementNamespaceContext)parentObject;
if (childObject instanceof ElementClass) {
parent.addElementClass((ElementClass)childObject);
}
return;
}
}

View file

@ -0,0 +1,120 @@
/*
* 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.eld.lang;
import java.lang.reflect.Method;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* Binds to objects together with a method found by reflection.
*
* @author Willem Cazander
* @version 1.0 Nov 21, 2007
*/
public class ElementRefectionBindingHandler extends AbstractElementBindingHandler {
private Class<?> parentClass = null;
private Class<?> childClass = null;
private String method = null;
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return parentClass;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return new Class[] {childClass};
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException {
if (parentClass==null | childClass==null | method==null) {
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" method="+method+".");
}
Method[] ms = parentObject.getClass().getMethods();
for (Method m:ms) {
if (method.equalsIgnoreCase(m.getName())) {
try {
m.invoke(parentObject, childObject);
} catch (Exception e) {
throw new ElementBindingHandlerException("Error in binding beans: "+e.getMessage(),e);
}
return;
}
}
}
/**
* @return the parentClass
*/
public Class<?> getParentClass() {
return parentClass;
}
/**
* @param parentClass the parentClass to set
*/
public void setParentClass(Class<?> parentClass) {
this.parentClass = parentClass;
}
/**
* @return the childClass
*/
public Class<?> getChildClass() {
return childClass;
}
/**
* @param childClass the childClass to set
*/
public void setChildClass(Class<?> childClass) {
this.childClass = childClass;
}
/**
* @return the method
*/
public String getMethod() {
return method;
}
/**
* @param method the method to set
*/
public void setMethod(String method) {
this.method = method;
}
}

View file

@ -0,0 +1,59 @@
/*
* 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.eld.lang;
import java.util.Map;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.eld.EldParser;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementLanguageModule;
/**
* ModuleElement put in an instance from parent language module.
*
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2012
*/
public class ModuleElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementStart()
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()!=null) {
throw new ElementException("Need to be root tag");
}
@SuppressWarnings("rawtypes")
Map m = (Map)getElementLanguage().getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (m==null) {
return;
}
ElementLanguageModule elementLanguageModule = (ElementLanguageModule)m.get(EldParser.PARENT_ELEMENT_LANGUAGE_MODULE);
setElementObject(elementLanguageModule);
}
}

View file

@ -0,0 +1,54 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementException;
/**
* NextAttributeElement.<br>
* Parses the attributeName and adds it to the ElementClass
*
* @author Willem Cazander
* @version 1.0 Feb 19, 2007
*/
public class NextAttributeElement extends AbstractElement {
@Override
public void doElementRun() throws ElementException {
String param = getAttributes().get("attributeName");
if (param==null) {
throw new ElementException("attributeName may not be null");
}
if (getParent()==null) {
throw new ElementException("can't be a root tag");
}
if (getParent().getElementObject() instanceof ElementAttributeHandler) {
((ElementAttributeHandler)getParent().getElementObject()).addNextAttribute(param);
} else {
throw new ElementException("Wrong parent class");
}
}
}

View file

@ -0,0 +1,53 @@
/*
* 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.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementException;
/**
* SkipPhaseElement add skip phases to elements.
*
* @author Willem Cazander
* @version 1.0 Aug 26, 2012
*/
public class SkipPhaseElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
String phase = getAttributes().get("name");
if (phase==null) {
throw new ElementException("'name' attribute is not set on: "+getElementClass().getTag());
}
if (getParent().getElementObject() instanceof ElementClass) {
((ElementClass)getParent().getElementObject()).addSkipPhase(phase);
} else {
throw new ElementException("Wrong parent class is not ElementClassAttribute but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,68 @@
/*
* 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.eld.lang;
import org.x4o.xml.conv.text.StringSplitConverter;
import org.x4o.xml.conv.text.StringSplitConverterStep;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* StringSplitConverterBindingHandler binds the string split converter step to parent.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class StringSplitConverterBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
StringSplitConverterStep.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return StringSplitConverter.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
StringSplitConverter parent = (StringSplitConverter)parentObject;
if (childObject instanceof StringSplitConverterStep) {
parent.addStringSplitConverterStep((StringSplitConverterStep)childObject);
}
}
}

View file

@ -0,0 +1,68 @@
/*
* 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.eld.lang;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.text.StringSplitConverterStep;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* StringSplitConverterStepBindingHandler binds the object converter to the step.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class StringSplitConverterStepBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ObjectConverter.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return StringSplitConverterStep.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
StringSplitConverterStep parent = (StringSplitConverterStep)parentObject;
if (childObject instanceof ObjectConverter) {
parent.setObjectConverter((ObjectConverter)childObject);
}
}
}

View file

@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* The X4O ELD Language x4o classes.
*
*
* @since 1.0
*/
package org.x4o.xml.eld.lang;

View file

@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* The X4O Element Language Definition parser.
*
*
* @since 1.0
*/
package org.x4o.xml.eld;

View file

@ -0,0 +1,115 @@
/*
* 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.eld.xsd;
import java.io.File;
import java.io.FileOutputStream;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.sax.XMLWriter;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
/**
* EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2012
*/
public class EldXsdXmlGenerator {
private ElementLanguage context = null;
public EldXsdXmlGenerator(ElementLanguage context) {
this.context=context;
}
private void checkNamespace(ElementNamespaceContext ns) {
if (ns.getSchemaResource()==null) {
throw new NullPointerException("Can't generate xsd for namespace without schemaResource uri: "+ns.getUri());
}
if (ns.getSchemaResource().isEmpty()) {
throw new NullPointerException("Can't generate xsd for namespace with empty schemaResource uri: "+ns.getUri());
}
}
public void writeSchema(File basePath,String namespace) throws ElementException {
try {
if (namespace!=null) {
ElementNamespaceContext ns = context.findElementNamespaceContext(namespace);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespace);
}
checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try {
XMLWriter out = new XMLWriter(fio);
generateSchema(ns.getUri(), out);
} finally {
fio.close();
}
return;
}
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try {
XMLWriter out = new XMLWriter(fio);
generateSchema(ns.getUri(), out);
} finally {
fio.close();
}
}
}
} catch (Exception e) {
throw new ElementException(e); // todo rm
}
}
public void generateSchema(String namespaceUri,DefaultHandler2 xmlWriter) throws SAXException {
ElementNamespaceContext ns = context.findElementNamespaceContext(namespaceUri);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespaceUri);
}
EldXsdXmlWriter xsdWriter = new EldXsdXmlWriter(xmlWriter,context);
xsdWriter.startNamespaces(namespaceUri);
xsdWriter.startSchema(ns,context);
for (ElementClass ec:ns.getElementClasses()) {
xsdWriter.writeElementClass(ec,ns);
}
for (ElementClass ec:ns.getElementClasses()) {
xsdWriter.writeElement(ec,ns);
}
xsdWriter.endSchema();
}
}

View file

@ -0,0 +1,442 @@
/*
* 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.eld.xsd;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
/**
* EldXsdXmlWriter Creates the schema from an eld resource.
*
* Note: this is still writing a bit quick and hacky.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2012
*/
public class EldXsdXmlWriter {
static public final String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
protected ElementLanguage context = null;
protected DefaultHandler2 xmlWriter = null;
protected String writeNamespace = null;
protected Map<String, String> namespaces = null;
public EldXsdXmlWriter(DefaultHandler2 xmlWriter,ElementLanguage context) {
this.xmlWriter=xmlWriter;
this.context=context;
this.namespaces=new HashMap<String,String>(10);
}
private void startNamespace(String uri,String prefixNamespace) {
String prefix = namespaces.get(uri);
if (prefix!=null) {
return;
}
if (uri.equals(writeNamespace)) {
namespaces.put(uri, "this");
return;
}
if (prefixNamespace!=null) {
namespaces.put(uri, prefixNamespace); // let user define it
return;
}
StringBuilder buf = new StringBuilder(20);
for (char c:uri.toLowerCase().toCharArray()) {
if (Character.isLetter(c)) {
buf.append(c);
}
if (Character.isDigit(c)) {
buf.append(c);
}
}
prefix = buf.toString();
if (prefix.startsWith("http")) {
prefix = prefix.substring(4);
}
if (prefix.startsWith("uri")) {
prefix = prefix.substring(3);
}
if (prefix.startsWith("url")) {
prefix = prefix.substring(3);
}
namespaces.put(uri, prefix);
}
public void startNamespaces(String namespaceUri) {
this.writeNamespace=namespaceUri;
this.namespaces.clear();
// redo this mess, add nice find for binding handlers
for (ElementLanguageModule modContext:context.getElementLanguageModules()) {
for (ElementNamespaceContext nsContext:modContext.getElementNamespaceContexts()) {
for (ElementClass ec:nsContext.getElementClasses()) {
Class<?> objectClass = null;
if (ec.getObjectClass()!=null) {
objectClass = ec.getObjectClass();
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
for (ElementClass checkClass:ns.getElementClasses()) {
if (checkClass.getObjectClass()==null) {
continue;
}
Class<?> checkObjectClass = checkClass.getObjectClass();
List<ElementBindingHandler> b = context.findElementBindingHandlers(objectClass,checkObjectClass);
if (b.isEmpty()==false) {
startNamespace(ns.getUri(),ns.getSchemaPrefix());
}
}
}
}
}
}
}
}
}
private static final String COMMENT_SEPERATOR = " ==================================================================== ";
private static final String COMMENT_TEXT = "=====";
public void startSchema(ElementNamespaceContext ns,ElementLanguage elementLanguage) throws SAXException {
xmlWriter.startDocument();
// this is a mess;
char[] msg;
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
msg = COMMENT_SEPERATOR.toCharArray();
xmlWriter.comment(msg,0,msg.length);
String desc = "Automatic generated schema for language: "+elementLanguage.getLanguageConfiguration().getLanguage();
int space = COMMENT_SEPERATOR.length()-desc.length()-(2*COMMENT_TEXT.length())-4;
StringBuffer b = new StringBuffer(COMMENT_SEPERATOR.length());
b.append(" ");
b.append(COMMENT_TEXT);
b.append(" ");
b.append(desc);
for (int i=0;i<space;i++) {
b.append(' ');
}
b.append(COMMENT_TEXT);
b.append(" ");
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
msg = b.toString().toCharArray();
xmlWriter.comment(msg,0,msg.length);
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
msg = COMMENT_SEPERATOR.toCharArray();
xmlWriter.comment(msg,0,msg.length);
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
ElementLanguageModule module = null;
for (ElementLanguageModule elm:elementLanguage.getElementLanguageModules()) {
ElementNamespaceContext s = elm.getElementNamespaceContext(ns.getUri());
if (s!=null) {
module = elm;
break;
}
}
b = new StringBuffer(COMMENT_SEPERATOR.length());
b.append("\n\tProviderName:\t");
b.append(module.getProviderName());
b.append("\n\tModuleName:\t\t");
b.append(module.getName());
b.append("\n\tNamespaces:\t\t");
b.append(module.getElementNamespaceContexts().size());
b.append("\n\tNamespace:\t\t");
b.append(ns.getUri());
b.append("\n\tCreated on:\t\t");
b.append(new Date());
b.append("\n");
msg = b.toString().toCharArray();
xmlWriter.comment(msg,0,msg.length);
xmlWriter.startPrefixMapping("", SCHEMA_URI);
for (String uri:namespaces.keySet()) {
String prefix = namespaces.get(uri);
xmlWriter.startPrefixMapping(prefix, uri);
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "version", "", "", "1.0");
atts.addAttribute ("", "elementFormDefault", "", "", "qualified");
atts.addAttribute ("", "attributeFormDefault", "", "", "unqualified");
atts.addAttribute ("", "targetNamespace", "", "", ns.getUri());
xmlWriter.startElement (SCHEMA_URI, "schema", "", atts);
for (String uri:namespaces.keySet()) {
if (ns.getUri().equals(uri)) {
continue;
}
ElementNamespaceContext nsContext = context.findElementNamespaceContext(uri);
atts = new AttributesImpl();
atts.addAttribute ("", "namespace", "", "", nsContext.getUri());
atts.addAttribute ("", "schemaLocation", "", "", nsContext.getSchemaResource());
xmlWriter.startElement (SCHEMA_URI, "import", "", atts);
xmlWriter.endElement (SCHEMA_URI, "import", "");
}
}
public void endSchema() throws SAXException {
xmlWriter.endElement (SCHEMA_URI, "schema" , "");
xmlWriter.endDocument();
}
public void writeElementClass(ElementClass ec,ElementNamespaceContext nsWrite) throws SAXException {
AttributesImpl atts = new AttributesImpl();
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
atts.addAttribute ("", "name", "", "", ec.getTag());
xmlWriter.startElement (SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
atts = new AttributesImpl();
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
} else {
atts.addAttribute ("", "name", "", "", ec.getTag()+"Type");
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
}
if (ec.getSchemaContentBase()!=null) {
atts = new AttributesImpl();
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
if (ec.getSchemaContentMixed()!=null && ec.getSchemaContentMixed()) {
atts.addAttribute ("", "mixed", "", "", "true");
}
xmlWriter.startElement (SCHEMA_URI, "complexContent", "", atts);
} else {
xmlWriter.startElement (SCHEMA_URI, "simpleContent", "", atts);
}
atts = new AttributesImpl();
atts.addAttribute ("", "base", "", "", ec.getSchemaContentBase());
xmlWriter.startElement (SCHEMA_URI, "extension", "", atts);
}
if (ec.getSchemaContentBase()==null) {
atts = new AttributesImpl();
atts.addAttribute ("", "minOccurs", "", "", "0"); // 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);
}
}
xmlWriter.endElement(SCHEMA_URI, "choice", "");
}
List<String> attrNames = new ArrayList<String>(30);
for (ElementClassAttribute eca:ec.getElementClassAttributes()) {
attrNames.add(eca.getName());
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eca.getName());
atts.addAttribute ("", "type", "", "", "string");
if (eca.getRequired()!=null && eca.getRequired()) {
atts.addAttribute ("", "use", "", "", "required");
}
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
}
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementAttributeHandler eah:mod.getElementAttributeHandlers()) {
attrNames.add(eah.getAttributeName());
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eah.getAttributeName());
atts.addAttribute ("", "type", "", "", "string");
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
}
}
if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) {
// oke
} else {
if (ec.getObjectClass()!=null) {
for (Method m:ec.getObjectClass().getMethods()) {
if (m.getName().startsWith("set")) {
String n = m.getName().substring(3);
if (m.getParameterTypes().length==0) {
continue; // set without parameters
}
if (n.length()<2) {
continue;
}
n = n.substring(0,1).toLowerCase()+n.substring(1,n.length());
if (attrNames.contains(n)) {
continue;
}
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", n);
Class<?> type = m.getParameterTypes()[0]; // TODO make full list for auto attribute type resolving.
if (type.equals(Object.class)) {
atts.addAttribute ("", "type", "", "", "string");// object is always string because is always assignable
} else if (type.isAssignableFrom(Boolean.class) | type.isAssignableFrom(Boolean.TYPE)) {
atts.addAttribute ("", "type", "", "", "boolean");
} else if (type.isAssignableFrom(Integer.class) | type.isAssignableFrom(Integer.TYPE)) {
atts.addAttribute ("", "type", "", "", "integer");
} else if (type.isAssignableFrom(Long.class) | type.isAssignableFrom(Long.TYPE)) {
atts.addAttribute ("", "type", "", "", "long");
} else if (type.isAssignableFrom(Float.class) | type.isAssignableFrom(Float.TYPE)) {
atts.addAttribute ("", "type", "", "", "float");
} else if (type.isAssignableFrom(Double.class) | type.isAssignableFrom(Double.TYPE)) {
atts.addAttribute ("", "type", "", "", "double");
} else {
atts.addAttribute ("", "type", "", "", "string");
}
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
}
}
} else {
atts = new AttributesImpl();
xmlWriter.startElement (SCHEMA_URI, "anyAttribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "anyAttribute", "");
}
}
if (ec.getSchemaContentBase()!=null) {
xmlWriter.endElement(SCHEMA_URI, "extension", "");
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
xmlWriter.endElement(SCHEMA_URI, "complexContent", "");
} else {
xmlWriter.endElement(SCHEMA_URI, "simpleContent", "");
}
}
xmlWriter.endElement(SCHEMA_URI, "complexType", "");
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
xmlWriter.endElement(SCHEMA_URI, "element", "");
}
}
private void writeElementClassNamespaces(ElementClass ec,ElementNamespaceContext nsWrite,ElementNamespaceContext ns) throws SAXException {
AttributesImpl atts = new AttributesImpl();
List<String> refElements = new ArrayList<String>(20);
for (ElementClass checkClass:ns.getElementClasses()) {
List<String> parents = checkClass.getElementParents(nsWrite.getUri());
if (parents!=null) {
if (parents!=null) {
if (parents.contains(ec.getTag())) {
refElements.add(checkClass.getTag());
}
}
}
if (nsWrite.getUri().equals(ns.getUri())) {
parents = checkClass.getElementParents("");
if (parents!=null) {
if (parents.contains(ec.getTag())) {
refElements.add(checkClass.getTag());
}
}
}
if (ec.getObjectClass()==null) {
continue;
}
if (checkClass.getObjectClass()==null) {
continue;
}
Class<?> objectClass = ec.getObjectClass();
Class<?> checkObjectClass = checkClass.getObjectClass();
List<ElementBindingHandler> b = context.findElementBindingHandlers(objectClass,checkObjectClass);
if (b.isEmpty()==false) {
refElements.add(checkClass.getTag());
}
}
if (refElements.isEmpty()==false) {
Set<String> s = new HashSet<String>(refElements.size());
s.addAll(refElements);
List<String> r = new ArrayList<String>(s.size());
r.addAll(s);
Collections.sort(r);
String prefix = namespaces.get(ns.getUri());
for (String refElement:r) {
atts = new AttributesImpl();
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
atts.addAttribute ("", "ref", "", "", prefix+":"+refElement);
} else if (nsWrite.getUri().equals(ns.getUri())==false) {
atts.addAttribute ("", "ref", "", "", prefix+":"+refElement);
} else {
atts.addAttribute ("", "name", "", "", refElement);
atts.addAttribute ("", "type", "", "", prefix+":"+refElement+"Type");
}
xmlWriter.startElement (SCHEMA_URI, "element", "", atts);
xmlWriter.endElement (SCHEMA_URI, "element", "");
}
}
}
public void writeElement(ElementClass ec,ElementNamespaceContext nsWrite) throws SAXException {
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
return; // is done in writeElementClass
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ec.getTag());
atts.addAttribute ("", "type", "", "", "this:"+ec.getTag()+"Type");
xmlWriter.startElement(SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
if (ec.getDescription()!=null) {
atts = new AttributesImpl();
xmlWriter.startElement(SCHEMA_URI, "annotation", "", atts);
atts = new AttributesImpl();
atts.addAttribute ("", "xml:lang", "", "", "en");
xmlWriter.startElement(SCHEMA_URI, "documentation", "", atts);
char[] msg = ec.getDescription().toCharArray();
xmlWriter.characters(msg,0,msg.length);
xmlWriter.endElement(SCHEMA_URI, "documentation", "");
xmlWriter.endElement(SCHEMA_URI, "annotation", "");
}
xmlWriter.endElement(SCHEMA_URI, "element", "");
}
}

View file

@ -0,0 +1,167 @@
/*
* 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.eld.xsd;
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.x4o.xml.core.X4OParserSupport;
import org.x4o.xml.core.X4OParserSupportException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
/**
* X4OLanguageSchemaWriter is support class to write schema files from eld.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class X4OLanguageEldXsdWriter {
private Class<?> languageParserSupport = null;
private String languageNamespaceUri = null;
private File basePath;
@SuppressWarnings("unchecked")
static public void main(String argu[]) {
X4OLanguageEldXsdWriter languageSchema = new X4OLanguageEldXsdWriter();
List<String> arguList = Arrays.asList(argu);
Iterator<String> arguIterator = arguList.iterator();
while (arguIterator.hasNext()) {
String arg = arguIterator.next();
if ("-path".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.out.println("No argument for -path given.");
System.exit(1);
return;
}
File schemaBasePath = new File(arguIterator.next());
if (schemaBasePath.exists()==false) {
System.out.println("path does not exists; "+schemaBasePath);
System.exit(1);
return;
}
languageSchema.setBasePath(schemaBasePath);
continue;
}
if ("-uri".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.out.println("No argument for -uri given.");
System.exit(1);
return;
}
languageSchema.setLanguageNamespaceUri(arguIterator.next());
continue;
}
if ("-class".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.out.println("No argument for -class given.");
System.exit(1);
return;
}
String apiClass = arguIterator.next();
try {
languageSchema.setLanguageParserSupport((Class<X4OParserSupport>) X4OLanguageClassLoader.loadClass(apiClass));
} catch (ClassNotFoundException e) {
System.out.println("Schema api class is not found: "+apiClass);
System.exit(1);
return;
}
continue;
}
}
try {
languageSchema.execute();
} catch (X4OParserSupportException e) {
System.out.println("Error while schema writing: "+e.getMessage());
e.printStackTrace();
System.exit(1);
return;
}
}
public void execute() throws X4OParserSupportException {
try {
// Get the support context
X4OParserSupport languageSupport = (X4OParserSupport)getLanguageParserSupport().newInstance();
ElementLanguage context = languageSupport.loadElementLanguageSupport();
// Start xsd generator
EldXsdXmlGenerator xsd = new EldXsdXmlGenerator(context);
xsd.writeSchema(getBasePath(), getLanguageNamespaceUri());
} catch (InstantiationException e) {
throw new X4OParserSupportException(e);
} catch (IllegalAccessException e) {
throw new X4OParserSupportException(e);
} catch (ElementException e) {
throw new X4OParserSupportException(e);
}
}
/**
* @return the languageParserSupport
*/
public Class<?> getLanguageParserSupport() {
return languageParserSupport;
}
/**
* @param languageParserSupport the languageParserSupport to set
*/
public void setLanguageParserSupport(Class<?> languageParserSupport) {
this.languageParserSupport = languageParserSupport;
}
/**
* @return the languageNamespaceUri
*/
public String getLanguageNamespaceUri() {
return languageNamespaceUri;
}
/**
* @param languageNamespaceUri the languageNamespaceUri to set
*/
public void setLanguageNamespaceUri(String languageNamespaceUri) {
this.languageNamespaceUri = languageNamespaceUri;
}
/**
* @return the basePath
*/
public File getBasePath() {
return basePath;
}
/**
* @param basePath the basePath to set
*/
public void setBasePath(File basePath) {
this.basePath = basePath;
}
}

View file

@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* The X4O ELD to XSD Schema generator classes.
*
*
* @since 1.0
*/
package org.x4o.xml.eld.xsd;

View file

@ -0,0 +1,243 @@
/*
* 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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* An AbstractElement.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2005
*/
abstract public class AbstractElement implements Element {
/** The parent Element */
private Element parent = null;
/** The config object */
private Object elementObject = null;
/** The language parsing context */
private ElementLanguage elementLanguage = null;
/** The ElementClass */
private ElementClass elementClass = null;
/** The attributes */
private Map<String,String> attributes = new HashMap<String,String>(10);
/** The Childeren */
private List<Element> childeren = new ArrayList<Element>(10);
/** All Childeren */
private List<Element> allChilderen = new ArrayList<Element>(10);
/**
* @see Element#doElementStart()
*/
public void doElementStart() throws ElementException {
}
/**
* @see Element#doElementEnd()
*/
public void doElementEnd() throws ElementException {
}
/**
* @see Element#doElementRun()
*/
public void doElementRun() throws ElementException {
}
/**
* @see Element#setParent(Element)
*/
public void setParent(Element element) {
parent = element;
}
/**
* @see Element#getParent()
*/
public Element getParent() {
return parent;
}
/**
* Cleans the attributes and elements(class) and context.
* @see Element#release()
*/
public void release() throws ElementException {
getAttributes().clear();
setElementClass(null);
setParent(null);
setElementLanguage(null);
attributes.clear();
childeren.clear(); // we do not release childeren, x4o does that
allChilderen.clear();
}
/**
* @see Element#getElementObject()
*/
public Object getElementObject() {
return elementObject;
}
/**
* @see Element#setElementObject(Object)
*/
public void setElementObject(Object object) {
elementObject=object;
}
/**
* @see Element#setElementLanguage(ElementLanguage)
*/
public void setElementLanguage(ElementLanguage elementLanguage) {
this.elementLanguage=elementLanguage;
}
/**
* @see Element#getElementLanguage()
*/
public ElementLanguage getElementLanguage() {
return elementLanguage;
}
/**
* @see org.x4o.xml.element.Element#doCharacters(java.lang.String)
*/
public void doCharacters(String characters) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getElementLanguage().getLanguageConfiguration().getDefaultElementBodyCharacters());
e.setElementObject(characters);
addChild(e);
} catch (Exception exception) {
throw new ElementException(exception);
}
}
/**
* @see org.x4o.xml.element.Element#doComment(java.lang.String)
*/
public void doComment(String comment) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getElementLanguage().getLanguageConfiguration().getDefaultElementBodyComment());
e.setElementObject(comment);
addChild(e);
} catch (Exception exception) {
throw new ElementException(exception);
}
}
/**
* @see org.x4o.xml.element.Element#doIgnorableWhitespace(java.lang.String)
*/
public void doIgnorableWhitespace(String space) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getElementLanguage().getLanguageConfiguration().getDefaultElementBodyWhitespace());
e.setElementObject(space);
addChild(e);
} catch (Exception exception) {
throw new ElementException(exception);
}
}
/**
* @see org.x4o.xml.element.Element#setElementClass(ElementClass)
*/
public void setElementClass(ElementClass elementClass) {
this.elementClass=elementClass;
}
/**
* @see org.x4o.xml.element.Element#getElementClass()
*/
public ElementClass getElementClass() {
return elementClass;
}
/**
* @see org.x4o.xml.element.Element#getAttributes()
*/
public Map<String, String> getAttributes() {
return attributes;
}
/**
* @see org.x4o.xml.element.Element#setAttribute(java.lang.String, java.lang.String)
*/
public void setAttribute(String name,String value) {
attributes.put(name, value);
}
/**
* @see org.x4o.xml.element.Element#getChilderen()
*/
public List<Element> getChilderen() {
return childeren;
}
/**
* @see org.x4o.xml.element.Element#addChild(Element)
*/
public void addChild(Element element) {
allChilderen.add(element);
if (ElementType.element.equals(element.getElementType())) {
childeren.add(element);
}
}
/**
* @see org.x4o.xml.element.Element#removeChild(Element)
*/
public void removeChild(Element element) {
childeren.remove(element);
allChilderen.remove(element);
}
/**
* @see org.x4o.xml.element.Element#getAllChilderen()
*/
public List<Element> getAllChilderen() {
return allChilderen;
}
/**
* @see org.x4o.xml.element.Element#getElementType()
*/
public ElementType getElementType() {
return ElementType.element;
}
/**
* Defaults to false.
* @see org.x4o.xml.element.Element#isTransformingTree()
*/
public boolean isTransformingTree() {
return false;
}
}

View file

@ -0,0 +1,80 @@
/*
* 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;
import java.util.ArrayList;
import java.util.List;
/**
* An AbstractElementAttributeHandler.
*
* @author Willem Cazander
* @version 1.0 Aug 10, 2006
*/
abstract public class AbstractElementAttributeHandler extends AbstractElementConfigurator implements ElementAttributeHandler {
private String attributeName = null;
private List<String> nextAttributes = new ArrayList<String>(2);
/**
* @see org.x4o.xml.element.ElementAttributeHandler#addNextAttribute(java.lang.String)
*/
public void addNextAttribute(String attribute) {
if (attribute==null) {
throw new NullPointerException("Can add null attribute for loading.");
}
nextAttributes.add(attribute);
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#removeNextAttribute(java.lang.String)
*/
public void removeNextAttribute(String attribute) {
if (attribute==null) {
throw new NullPointerException("Can remove null attribute for loading.");
}
nextAttributes.remove(attribute);
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#getNextAttributes()
*/
public List<String> getNextAttributes() {
return nextAttributes;
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#getAttributeName()
*/
public String getAttributeName() {
return attributeName;
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#setAttributeName(java.lang.String)
*/
public void setAttributeName(String attributeName) {
this.attributeName=attributeName;
}
}

View file

@ -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;
/**
* An AbstractElementBindingHandler.<br>
* Does nothing.
*
* @author Willem Cazander
* @version 1.0 Apr 16, 2006
*/
abstract public class AbstractElementBindingHandler extends AbstractElementMetaBase implements ElementBindingHandler {
}

View file

@ -0,0 +1,202 @@
/*
* 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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* An AbstractElementClass.
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
abstract public class AbstractElementClass extends AbstractElementClassBase implements ElementClass {
private String tag = null;
private Class<?> objectClass = null;
private Class<?> elementClass = null;
private Boolean autoAttributes = true;
private Map<String,List<String>> elementParents = null;
private String schemaContentBase = null;
private Boolean schemaContentComplex = null;
private Boolean schemaContentMixed = null;
private List<String> skipPhases = null;
public AbstractElementClass() {
elementParents = new HashMap<String,List<String>>(5);
skipPhases = new ArrayList<String>(3);
}
/**
* @see ElementClass#getTag()
*/
public String getTag() {
return tag;
}
/**
* @see ElementClass#setTag(String)
*/
public void setTag(String tag) {
this.tag = tag;
}
/**
* @see ElementClass#getElementClass()
*/
public Class<?> getElementClass() {
return elementClass;
}
/**
* @see ElementClass#setElementClass(Class)
*/
public void setElementClass(Class<?> elementClass) {
this.elementClass = elementClass;
}
/**
* @see ElementClass#getObjectClass()
*/
public Class<?> getObjectClass() {
return objectClass;
}
/**
* @see ElementClass#setObjectClass(Class)
*/
public void setObjectClass(Class<?> objectClass) {
this.objectClass = objectClass;
}
/**
* @return the autoAttributes
*/
public Boolean getAutoAttributes() {
return autoAttributes;
}
/**
* @param autoAttributes the autoAttributes to set
*/
public void setAutoAttributes(Boolean autoAttributes) {
this.autoAttributes = autoAttributes;
}
/**
* @see org.x4o.xml.element.ElementClass#addElementParent(java.lang.String,java.lang.String)
*/
public void addElementParent(String namespaceUri,String tag) {
List<String> tags = elementParents.get(namespaceUri);
if (tags==null) {
tags = new ArrayList<String>(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<String> tags = elementParents.get(namespaceUri);
if (tags==null) {
return;
}
tags.remove(tag);
}
/**
* @see org.x4o.xml.element.ElementClass#getElementParents(java.lang.String)
*/
public List<String> getElementParents(String namespaceUri) {
return elementParents.get(namespaceUri);
}
/**
* @return the schemaContentBase
*/
public String getSchemaContentBase() {
return schemaContentBase;
}
/**
* @param schemaContentBase the schemaContentBase to set
*/
public void setSchemaContentBase(String schemaContentBase) {
this.schemaContentBase = schemaContentBase;
}
/**
* @return the schemaContentComplex
*/
public Boolean getSchemaContentComplex() {
return schemaContentComplex;
}
/**
* @param schemaContentComplex the schemaContentComplex to set
*/
public void setSchemaContentComplex(Boolean schemaContentComplex) {
this.schemaContentComplex = schemaContentComplex;
}
/**
* @return the schemaContentMixed
*/
public Boolean getSchemaContentMixed() {
return schemaContentMixed;
}
/**
* @param schemaContentMixed the schemaContentMixed to set
*/
public void setSchemaContentMixed(Boolean schemaContentMixed) {
this.schemaContentMixed = schemaContentMixed;
}
/**
* @see org.x4o.xml.element.ElementClass#addSkipPhase(java.lang.String)
*/
public void addSkipPhase(String phase) {
skipPhases.add(phase);
}
/**
* @see org.x4o.xml.element.ElementClass#removeSkipPhase(java.lang.String)
*/
public void removeSkipPhase(String phase) {
skipPhases.remove(phase);
}
/**
* @see org.x4o.xml.element.ElementClass#getSkipPhases()
*/
public List<String> getSkipPhases() {
return skipPhases;
}
}

View file

@ -0,0 +1,171 @@
/*
* 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;
import java.util.ArrayList;
import java.util.List;
import org.x4o.xml.conv.ObjectConverter;
/**
* An AbstractElementClassAttribute.
*
* @author Willem Cazander
* @version 1.0 Jan 19, 2012
*/
abstract public class AbstractElementClassAttribute extends AbstractElementMetaBase implements ElementClassAttribute {
private String name = null;
private ObjectConverter objectConverter = null;
private Object defaultValue = null;
private List<String> attributeAliases = null;
private Boolean required = null;
private Boolean runResolveEL = null;
//private Boolean runInterfaces = null;
private Boolean runConverters = null;
private Boolean runBeanFill = null;
public AbstractElementClassAttribute() {
attributeAliases = new ArrayList<String>(3);
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#getName()
*/
public String getName() {
return name;
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#setName(java.lang.String)
*/
public void setName(String name) {
this.name=name;
}
/**
* @return the objectConverter
*/
public ObjectConverter getObjectConverter() {
return objectConverter;
}
/**
* @param objectConverter the objectConverter to set
*/
public void setObjectConverter(ObjectConverter objectConverter) {
this.objectConverter = objectConverter;
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#setDefaultValue(java.lang.Object)
*/
public void setDefaultValue(Object defaultValue) {
this.defaultValue=defaultValue;
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#getDefaultValue()
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#addAttributeAlias(java.lang.String)
*/
public void addAttributeAlias(String alias) {
attributeAliases.add(alias);
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#removeAttributeAlias(java.lang.String)
*/
public void removeAttributeAlias(String alias) {
attributeAliases.remove(alias);
}
/**
* @see org.x4o.xml.element.ElementClassAttribute#getAttributeAliases()
*/
public List<String> getAttributeAliases() {
return attributeAliases;
}
/**
* @return the required
*/
public Boolean getRequired() {
return required;
}
/**
* @param required the required to set
*/
public void setRequired(Boolean required) {
this.required = required;
}
/**
* @return the runResolveEL
*/
public Boolean getRunResolveEL() {
return runResolveEL;
}
/**
* @param runResolveEL the runResolveEL to set
*/
public void setRunResolveEL(Boolean runResolveEL) {
this.runResolveEL = runResolveEL;
}
/**
* @return the runConverters
*/
public Boolean getRunConverters() {
return runConverters;
}
/**
* @param runConverters the runConverters to set
*/
public void setRunConverters(Boolean runConverters) {
this.runConverters = runConverters;
}
/**
* @return the runBeanFill
*/
public Boolean getRunBeanFill() {
return runBeanFill;
}
/**
* @param runBeanFill the runBeanFill to set
*/
public void setRunBeanFill(Boolean runBeanFill) {
this.runBeanFill = runBeanFill;
}
}

View file

@ -0,0 +1,80 @@
/*
* 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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* An AbstractElementClassBase.
*
* @author Willem Cazander
* @version 1.0 Jan 19, 2012
*/
abstract public class AbstractElementClassBase extends AbstractElementMetaBase implements ElementClassBase {
private Map<String,ElementClassAttribute> elementClassAttributes = null;
private List<ElementConfigurator> elementConfigurators = null;
public AbstractElementClassBase() {
elementConfigurators = new ArrayList<ElementConfigurator>(5);
elementClassAttributes = new HashMap<String,ElementClassAttribute>(15);
}
/**
* @see ElementClass#getElementConfigurators()
*/
public List<ElementConfigurator> getElementConfigurators() {
return elementConfigurators;
}
/**
* @see ElementClass#addElementConfigurators(ElementConfigurator)
*/
public void addElementConfigurators(ElementConfigurator elementConfigurator) {
elementConfigurators.add(elementConfigurator);
}
/**
*/
public void addElementClassAttribute(ElementClassAttribute elementClassAttribute) {
elementClassAttributes.put(elementClassAttribute.getName(),elementClassAttribute);
}
/**
*/
public Collection<ElementClassAttribute> getElementClassAttributes() {
return elementClassAttributes.values();
}
/**
*/
public ElementClassAttribute getElementClassAttributeByName(String attributeName) {
return elementClassAttributes.get(attributeName);
}
}

View file

@ -0,0 +1,53 @@
/*
* 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;
/**
* An AbstractElementConfigurator.<br>
* Does nothing.
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2007
*/
abstract public class AbstractElementConfigurator extends AbstractElementMetaBase implements ElementConfigurator {
/** Flag indicating that this is an config action and should run in runPhase */
private boolean configAction = false;
/**
* Defaults to false.
* @see org.x4o.xml.element.ElementConfigurator#isConfigAction()
*/
public boolean isConfigAction() {
return configAction;
}
/**
* Sets the configAction
* @param configAction The configAction to set.
*/
public void setConfigAction(boolean configAction) {
this.configAction=configAction;
}
}

View file

@ -0,0 +1,71 @@
/*
* 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;
import java.util.ArrayList;
import java.util.List;
/**
* An AbstractElement.
*
* @author Willem Cazander
* @version 1.0 Apr 15, 2008
*/
abstract public class AbstractElementInterface extends AbstractElementClassBase implements ElementInterface {
private Class<?> interfaceClass = null;
private List<ElementBindingHandler> elementBindingHandlers = null;
public AbstractElementInterface() {
elementBindingHandlers = new ArrayList<ElementBindingHandler>(4);
}
/**
* @see org.x4o.xml.element.ElementInterface#addElementBindingHandler(org.x4o.xml.element.ElementBindingHandler)
*/
public void addElementBindingHandler(ElementBindingHandler elementBindingHandler) {
elementBindingHandlers.add(elementBindingHandler);
}
/**
* @see org.x4o.xml.element.ElementInterface#getElementBindingHandlers()
*/
public List<ElementBindingHandler> getElementBindingHandlers() {
return elementBindingHandlers;
}
/**
* @see org.x4o.xml.element.ElementInterface#getInterfaceClass()
*/
public Class<?> getInterfaceClass() {
return interfaceClass;
}
/**
* @see org.x4o.xml.element.ElementInterface#setInterfaceClass(java.lang.Class)
*/
public void setInterfaceClass(Class<?> interfaceClass) {
this.interfaceClass=interfaceClass;
}
}

View file

@ -0,0 +1,304 @@
/*
* 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;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.logging.Logger;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import org.x4o.xml.core.X4OPhase;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.element.ElementBindingHandler;
/**
* An AbstractElementLanguage.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
abstract public class AbstractElementLanguage implements ElementLanguageLocal {
private Logger logger = null;
private ExpressionFactory expressionFactory = null;
private ELContext eLContext = null;
private ElementAttributeValueParser elementAttributeValueParser = null;
private ElementObjectPropertyValue elementObjectPropertyValue = null;
private X4OPhase currentX4OPhase = null;
private Map<Element, X4OPhase> dirtyElements = null;
private Element rootElement = null;
private X4OLanguageConfiguration languageConfiguration = null;
private List<ElementLanguageModule> elementLanguageModules = null;
/**
* Creates a new empty ElementLanguage.
*/
public AbstractElementLanguage() {
logger = Logger.getLogger(AbstractElementLanguage.class.getName());
logger.finest("Creating new ParsingContext");
elementLanguageModules = new ArrayList<ElementLanguageModule>(20);
currentX4OPhase = X4OPhase.FIRST_PHASE;
dirtyElements = new HashMap<Element, X4OPhase>(40);
}
/**
* @see org.x4o.xml.element.ElementLanguage#getELContext()
*/
public ELContext getELContext() {
return eLContext;
}
/**
* @see org.x4o.xml.element.ElementLanguageLocal#setELContext(javax.el.ELContext)
*/
public void setELContext(ELContext context) {
if (eLContext!=null) {
throw new IllegalStateException("Can only set elContext once.");
}
eLContext = context;
}
/**
* @see org.x4o.xml.element.ElementLanguage#getExpressionFactory()
*/
public ExpressionFactory getExpressionFactory() {
return expressionFactory;
}
/**
* @see org.x4o.xml.element.ElementLanguageLocal#setExpressionFactory(javax.el.ExpressionFactory)
*/
public void setExpressionFactory(ExpressionFactory expressionFactory) {
if (this.expressionFactory!=null) {
throw new IllegalStateException("Can only set expressionFactory once.");
}
this.expressionFactory = expressionFactory;
}
/**
* @return the elementAttributeValueParser
*/
public ElementAttributeValueParser getElementAttributeValueParser() {
return elementAttributeValueParser;
}
/**
* @param elementAttributeValueParser the elementAttributeValueParser to set
*/
public void setElementAttributeValueParser(ElementAttributeValueParser elementAttributeValueParser) {
if (this.elementAttributeValueParser!=null) {
throw new IllegalStateException("Can only set elementAttributeValueParser once.");
}
this.elementAttributeValueParser = elementAttributeValueParser;
}
/**
* @return the elementObjectPropertyValue
*/
public ElementObjectPropertyValue getElementObjectPropertyValue() {
return elementObjectPropertyValue;
}
/**
* @param elementObjectPropertyValue the elementObjectPropertyValue to set
*/
public void setElementObjectPropertyValue(ElementObjectPropertyValue elementObjectPropertyValue) {
if (this.elementObjectPropertyValue!=null) {
throw new IllegalStateException("Can only set elementObjectPropertyValue once.");
}
this.elementObjectPropertyValue = elementObjectPropertyValue;
}
/**
* @see org.x4o.xml.element.ElementLanguage#getCurrentX4OPhase()
*/
public X4OPhase getCurrentX4OPhase() {
return currentX4OPhase;
}
/**
* @see org.x4o.xml.element.ElementLanguage#setCurrentX4OPhase(org.x4o.xml.core.X4OPhase)
*/
public void setCurrentX4OPhase(X4OPhase currentX4OPhase) {
this.currentX4OPhase = currentX4OPhase;
}
/**
* @see org.x4o.xml.element.ElementLanguage#addDirtyElement(org.x4o.xml.element.Element, org.x4o.xml.core.X4OPhase)
*/
public void addDirtyElement(Element element, X4OPhase phase) {
if (dirtyElements.containsKey(element)) {
throw new IllegalArgumentException("Can't add an element twice.");
}
dirtyElements.put(element,phase);
}
/**
* @see org.x4o.xml.element.ElementLanguage#getDirtyElements()
*/
public Map<Element, X4OPhase> getDirtyElements() {
return dirtyElements;
}
/**
* @see org.x4o.xml.element.ElementLanguage#getRootElement()
*/
public Element getRootElement() {
return rootElement;
}
/**
* @see org.x4o.xml.element.ElementLanguage#setRootElement(org.x4o.xml.element.Element)
*/
public void setRootElement(Element element) {
if (element==null) {
throw new NullPointerException("May not set rootElement to null");
}
// allowed for reusing this context in multiple parse sessions.
//if (rootElement!=null) {
// throw new IllegalStateException("Can't set rootElement when it is already set.");
//}
rootElement=element;
}
/**
* @return the languageConfiguration
*/
public X4OLanguageConfiguration getLanguageConfiguration() {
return languageConfiguration;
}
/**
* @param languageConfiguration the languageConfiguration to set
*/
public void setLanguageConfiguration(X4OLanguageConfiguration languageConfiguration) {
this.languageConfiguration = languageConfiguration;
}
/**
* @see org.x4o.xml.element.ElementLanguage#addElementLanguageModule(org.x4o.xml.element.ElementLanguageModule)
*/
public void addElementLanguageModule(ElementLanguageModule elementLanguageModule) {
if (elementLanguageModule.getId()==null) {
throw new NullPointerException("Can't add module without id.");
}
elementLanguageModules.add(elementLanguageModule);
}
/**
* @see org.x4o.xml.element.ElementLanguage#getElementLanguageModules()
*/
public List<ElementLanguageModule> getElementLanguageModules() {
return elementLanguageModules;
}
/**
* @see org.x4o.xml.element.ElementLanguage#findElementBindingHandlers(java.lang.Object,java.lang.Object)
*/
public List<ElementBindingHandler> findElementBindingHandlers(Object parent,Object child) {
List<ElementBindingHandler> result = new ArrayList<ElementBindingHandler>(50);
for (int i=0;i<elementLanguageModules.size();i++) {
ElementLanguageModule module = elementLanguageModules.get(i);
findElementBindingHandlerInList(parent,child,result,module.getElementBindingHandlers());
}
for (ElementInterface ei:findElementInterfaces(parent)) {
findElementBindingHandlerInList(parent,child,result,ei.getElementBindingHandlers());
}
return result;
}
private void findElementBindingHandlerInList(Object parent,Object child,List<ElementBindingHandler> result,List<ElementBindingHandler> checkList) {
for (ElementBindingHandler binding:checkList) {
boolean parentBind = false;
if (parent instanceof Class) {
parentBind = binding.getBindParentClass().isAssignableFrom((Class<?>)parent);
} else {
parentBind = binding.getBindParentClass().isInstance(parent);
}
if (parentBind==false) {
continue;
}
boolean childBind = false;
for (Class<?> childClass:binding.getBindChildClasses()) {
if (child instanceof Class && childClass.isAssignableFrom((Class<?>)child)) {
childBind=true;
break;
} else if (childClass.isInstance(child)) {
childBind=true;
break;
}
}
if (parentBind & childBind) {
result.add(binding);
}
}
}
/**
* @see org.x4o.xml.element.ElementLanguage#findElementInterfaces(java.lang.Object)
*/
public List<ElementInterface> findElementInterfaces(Object elementObject) {
if (elementObject==null) {
throw new NullPointerException("Can't search for null object.");
}
List<ElementInterface> result = new ArrayList<ElementInterface>(50);
for (int i=0;i<elementLanguageModules.size();i++) {
ElementLanguageModule module = elementLanguageModules.get(i);
for (ElementInterface ei:module.getElementInterfaces()) {
Class<?> eClass = ei.getInterfaceClass();
logger.finest("Checking interface handler: "+ei+" for class: "+eClass);
if (elementObject instanceof Class && eClass.isAssignableFrom((Class<?>)elementObject)) {
logger.finer("Found interface match from class; "+elementObject);
result.add(ei);
} else if (eClass.isInstance(elementObject)) {
logger.finer("Found interface match from object; "+elementObject);
result.add(ei);
}
}
}
return result;
}
/**
* @see org.x4o.xml.element.ElementLanguage#findElementNamespaceContext(java.lang.String)
*/
public ElementNamespaceContext findElementNamespaceContext(String namespaceUri) {
// TODO: refactor so no search for every tag !!
ElementNamespaceContext result = null;
for (int i=0;i<elementLanguageModules.size();i++) {
ElementLanguageModule module = elementLanguageModules.get(i);
result = module.getElementNamespaceContext(namespaceUri);
if (result!=null) {
return result;
}
}
return result;
}
}

View file

@ -0,0 +1,270 @@
/*
* 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;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementLanguage;
/**
* An AbstractElementLanguageModule.
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2012
*/
abstract public class AbstractElementLanguageModule extends AbstractElementMetaBase implements ElementLanguageModule {
private Logger logger = null;
private String name=null;
private String providerName=null;
private String sourceResource = null;
/** The globalAttribute handlers */
private List<ElementAttributeHandler> elementAttributeHandlers = null;
/** The binding rules */
private List<ElementBindingHandler> elementBindingHandlers = null;
private List<ElementConfigurator> globalElementConfigurators = null;
private List<ElementInterface> elementInterfaces = null;
private Map<String,ElementNamespaceContext> elementNamespaceContexts = null;
private ElementLanguageModuleLoader elementLanguageModuleLoader = null;
/**
* Creates a new empty ElementLanguage.
*/
public AbstractElementLanguageModule() {
logger = Logger.getLogger(AbstractElementLanguage.class.getName());
logger.finest("Creating new ParsingContext");
elementAttributeHandlers = new ArrayList<ElementAttributeHandler>(4);
elementBindingHandlers = new ArrayList<ElementBindingHandler>(4);
globalElementConfigurators = new ArrayList<ElementConfigurator>(4);
elementInterfaces = new ArrayList<ElementInterface>(20);
elementNamespaceContexts = new HashMap<String,ElementNamespaceContext>(10);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the providerName
*/
public String getProviderName() {
return providerName;
}
/**
* @param providerName the providerName to set
*/
public void setProviderName(String providerName) {
this.providerName = providerName;
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#addElementAttributeHandler(ElementAttributeHandler)
*/
public void addElementAttributeHandler(ElementAttributeHandler elementAttributeHandler) {
if (elementAttributeHandler==null) {
throw new NullPointerException("Can't add null object");
}
if (elementAttributeHandler.getId()==null) {
throw new NullPointerException("Can't add with null id property.");
}
logger.finer("Adding ElementAttributeHandler: "+elementAttributeHandler.getAttributeName());
elementAttributeHandlers.add(elementAttributeHandler);
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#getElementAttributeHandlers()
*/
public List<ElementAttributeHandler> getElementAttributeHandlers() {
return elementAttributeHandlers;
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#addElementBindingHandler(ElementBindingHandler)
*/
public void addElementBindingHandler(ElementBindingHandler elementBindingHandler) {
if (elementBindingHandler.getId()==null) {
throw new NullPointerException("Can't add with null id property.");
}
logger.finer("Adding ElementBindingHandler: "+elementBindingHandler);
elementBindingHandlers.add(elementBindingHandler);
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#getElementBindingHandlers()
*/
public List<ElementBindingHandler> getElementBindingHandlers() {
return elementBindingHandlers;
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#addGlobalElementConfigurator(ElementConfigurator)
*/
public void addGlobalElementConfigurator(ElementConfigurator 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);
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#getGlobalElementConfigurators()
*/
public List<ElementConfigurator> getGlobalElementConfigurators() {
return globalElementConfigurators;
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#addElementInterface(org.x4o.xml.element.ElementInterface)
*/
public void addElementInterface(ElementInterface elementInterface) {
if (elementInterface==null) {
throw new NullPointerException("Can't add null.");
}
if (elementInterface.getId()==null) {
throw new NullPointerException("Can't add with null id property.");
}
if (elementInterface.getInterfaceClass()==null) {
throw new NullPointerException("ElementInterface not correctly configured getInterfaceClass returns null.");
}
elementInterfaces.add(elementInterface);
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#getElementInterfaces()
*/
public List<ElementInterface> getElementInterfaces() {
return elementInterfaces;
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#addElementNamespaceContext(org.x4o.xml.element.ElementNamespaceContext)
*/
public void addElementNamespaceContext(ElementNamespaceContext elementNamespaceContext) {
if (elementNamespaceContext==null) {
throw new NullPointerException("Can't add null.");
}
if (elementNamespaceContext.getUri()==null) {
throw new NullPointerException("Can add ElementNamespaceContext without uri.");
}
if (elementNamespaceContext.getId()==null) {
StringBuffer buf = new StringBuffer(30);
for (char c:elementNamespaceContext.getUri().toLowerCase().toCharArray()) {
if (Character.isLetter(c)) {buf.append(c);}
if (Character.isDigit(c)) {buf.append(c);}
}
String id = buf.toString();
if (id.startsWith("http")) {id = id.substring(4);}
elementNamespaceContext.setId(id);
}
// TODO: no language here so move to EL default on eld attribute tag
//if (elementNamespaceContext.getSchemaUri()==null) {
// elementNamespaceContext.setSchemaUri(elementNamespaceContext.getUri()+elementNamespaceContext.)
//}
logger.fine("Adding namespaceUri: "+elementNamespaceContext.getUri());
elementNamespaceContexts.put(elementNamespaceContext.getUri(), elementNamespaceContext);
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#getElementNamespaceContext(java.lang.String)
*/
public ElementNamespaceContext getElementNamespaceContext(String namespaceUri) {
return elementNamespaceContexts.get(namespaceUri);
}
/**
* @see org.x4o.xml.element.ElementLanguageModule#getElementNamespaceContexts()
*/
public List<ElementNamespaceContext> getElementNamespaceContexts() {
return new ArrayList<ElementNamespaceContext>(elementNamespaceContexts.values());
}
/**
* @return the elementLanguageModuleLoader
*/
public ElementLanguageModuleLoader getElementLanguageModuleLoader() {
return elementLanguageModuleLoader;
}
/**
* @param elementLanguageModuleLoader the elementLanguageModuleLoader to set
*/
public void setElementLanguageModuleLoader(ElementLanguageModuleLoader elementLanguageModuleLoader) {
this.elementLanguageModuleLoader = elementLanguageModuleLoader;
}
/**
* @return the sourceResource
*/
public String getSourceResource() {
return sourceResource;
}
/**
* @param sourceResource the sourceResource to set
*/
public void setSourceResource(String sourceResource) {
this.sourceResource = sourceResource;
}
/**
* Reloads the module, experiment !!
*/
public void reloadModule(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) throws ElementLanguageModuleLoaderException {
elementAttributeHandlers.clear();
elementBindingHandlers.clear();
elementInterfaces.clear();
elementNamespaceContexts.clear();
getElementLanguageModuleLoader().loadLanguageModule(elementLanguage, elementLanguageModule);
}
}

View file

@ -0,0 +1,68 @@
/*
* 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;
/**
* AbstractElementMetaBase stores the id and description.
*
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2009
*/
abstract public class AbstractElementMetaBase implements ElementMetaBase {
/** The description */
private String id = null;
/** The description */
private String description = null;
/**
* @see org.x4o.xml.element.ElementMetaBase#setId(java.lang.String)
*/
public void setId(String id) {
this.id=id;
}
/**
* @see org.x4o.xml.element.ElementMetaBase#getId()
*/
public String getId() {
return id;
}
/**
* @see org.x4o.xml.element.ElementConfigurator#getDescription()
*/
public String getDescription() {
return description;
}
/**
* @see org.x4o.xml.element.ElementConfigurator#setDescription(java.lang.String)
*/
public void setDescription(String description) {
this.description=description;
}
}

View file

@ -0,0 +1,187 @@
/*
* 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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The abstract verion of ElementNamespaceContext
* @author Willem Cazander
* @version 1.0 Oct 28, 2009
*/
abstract public class AbstractElementNamespaceContext extends AbstractElementMetaBase implements ElementNamespaceContext {
private ElementNamespaceInstanceProvider elementNamespaceInstanceProvider = null;
private String prefixMapping = null;
private Map<String,ElementClass> elementClasses = null;
private String uri = null;
private String name = null;
private String schemaUri = null;
private String schemaResource = null;
private String schemaPrefix = null;
private Boolean languageRoot = null;
public AbstractElementNamespaceContext() {
elementClasses = new HashMap<String,ElementClass>(100);
}
/**
* @see org.x4o.xml.element.ElementNamespaceContext#getPrefixMapping()
*/
public String getPrefixMapping() {
return prefixMapping;
}
/**
* @return the elementNamespaceInstanceProvider
*/
public ElementNamespaceInstanceProvider getElementNamespaceInstanceProvider() {
return elementNamespaceInstanceProvider;
}
/**
* @param elementNamespaceInstanceProvider the elementNamespaceInstanceProvider to set
*/
public void setElementNamespaceInstanceProvider(ElementNamespaceInstanceProvider elementNamespaceInstanceProvider) {
this.elementNamespaceInstanceProvider = elementNamespaceInstanceProvider;
}
/**
* @see org.x4o.xml.element.ElementNamespaceContext#setPrefixMapping(java.lang.String)
*/
public void setPrefixMapping(String prefixMapping) {
this.prefixMapping=prefixMapping;
}
/**
* @see org.x4o.xml.element.ElementNamespaceContext#addElementClass(org.x4o.xml.element.ElementClass)
*/
public void addElementClass(ElementClass elementClass) {
if (elementClass.getTag()==null) {
throw new NullPointerException("ElementClass not correctly configured getTag is null.");
}
elementClasses.put(elementClass.getTag(), elementClass);
}
/**
* @see org.x4o.xml.element.ElementNamespaceContext#getElementClass(java.lang.String)
*/
public ElementClass getElementClass(String tag) {
return elementClasses.get(tag);
}
/**
* @see org.x4o.xml.element.ElementNamespaceContext#getElementClasses()
*/
public List<ElementClass> getElementClasses() {
return new ArrayList<ElementClass>(elementClasses.values());
}
/**
* @return the uri
*/
public String getUri() {
return uri;
}
/**
* @param uri the namespace uri to set
*/
public void setUri(String uri) {
this.uri = uri;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the schemaUri
*/
public String getSchemaUri() {
return schemaUri;
}
/**
* @param schemaUri the schemaUri to set
*/
public void setSchemaUri(String schemaUri) {
this.schemaUri = schemaUri;
}
/**
* @return the schemaResource
*/
public String getSchemaResource() {
return schemaResource;
}
/**
* @param schemaResource the schemaResource to set
*/
public void setSchemaResource(String schemaResource) {
this.schemaResource = schemaResource;
}
/**
* @return the languageRoot
*/
public Boolean getLanguageRoot() {
return languageRoot;
}
/**
* @param languageRoot the languageRoot to set
*/
public void setLanguageRoot(Boolean languageRoot) {
this.languageRoot = languageRoot;
}
/**
* @return the schemaPrefix
*/
public String getSchemaPrefix() {
return schemaPrefix;
}
/**
* @param schemaPrefix the schemaPrefix to set
*/
public void setSchemaPrefix(String schemaPrefix) {
this.schemaPrefix = schemaPrefix;
}
}

View file

@ -0,0 +1,218 @@
/*
* 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;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Defines an XML element with an object.<br>
* <br>
* The main function is to store the ElementObject.<br>
* Also we can configure the ElementObject from differted events hooks.
* from the attibutes or parent (object)element.
*
* @author Willem Cazander
* @version 1.0 01/02/2005
*/
public interface Element {
/**
* The ElementTypes which are possible.
*/
public enum ElementType {
/** The normale ElementType, which is mostly bound to an object. */
element,
/** Extra meta characters in xml. */
characters,
/** The xml comments in xml. */
comment,
/** ignorableWhitespace in xml */
ignorableWhitespace,
/** Receive raw sax event on elementObject */
overrideSax;
static public List<Element> filterElements(List<Element> elements,ElementType elementType) {
List<Element> result = new ArrayList<Element>(3);
for (int i=0;i<elements.size();i++) {
Element element = elements.get(i);
if (elementType == element.getElementType()) {
result.add(element);
}
}
return result;
}
}
/**
* This method is fired when the end xml tag is parsed.
*/
void doElementEnd() throws ElementException;
/**
* This method is fired when the start of xml tag is parsed.
*/
void doElementStart() throws ElementException;
/**
* This method is fired only once in the run phase.
*/
void doElementRun() throws ElementException;
/**
* Set the parent Element.
* @param element The paraent Element to set.
*/
void setParent(Element element);
/**
* Returns the parent Element.<br>
* Or null when there is no parent Element.
*
* @return Returns the parent Element
*/
Element getParent();
/**
* This method get called when this Element object is not needed anymore.<br>
* Can be used to close resources.
*/
void release() throws ElementException;
/**
* Gives back the object this Element has made and configed.<br>
* So other elements can do stuff to that object.<br>
*
* @return An Object.
*/
Object getElementObject();
/**
* Sets the object which we control.
* @param object The object to configed by this element.
*/
void setElementObject(Object object);
/**
* Sets the ElementLanguage.
* @param elementLanguage The ElementLanguage to set.
*/
void setElementLanguage(ElementLanguage elementLanguage);
/**
* Gets the ElementLanguage.
* @return Returns the ElementLanguage.
*/
ElementLanguage getElementLanguage();
/**
* Sets the body texts on an event based system.
* @param body The body text.
*/
void doCharacters(String body) throws ElementException;
/**
* Sets the comment texts on an event based system.
* @param comment The comment text.
*/
void doComment(String comment) throws ElementException;
/**
* Is called when there is whitespace in xml.
* @param space The space.
* @throws ElementException
*/
void doIgnorableWhitespace(String space) throws ElementException;
/**
* Sets the ElementClass.
* @param elementClass The ElementClass to set.
*/
void setElementClass(ElementClass elementClass);
/**
* Gets the ElementClass.
* @return Returns the ElementClass.
*/
ElementClass getElementClass();
/**
* Sets the xml attributes.
* @param name The name to set.
* @param value The value to set.
*/
void setAttribute(String name,String value);
/**
* Gets the xml attributes.
* @return Returns the xml attributes.
*/
Map<String,String> getAttributes();
/**
* Gets the childeren elements.
* @return Returns the childeren.
*/
List<Element> getChilderen();
/**
* Gets the childeren elements including those which are comment and white space. (text)
* @return Returns all the childeren.
*/
List<Element> getAllChilderen();
/**
* Adds an Elment as child of this element.
* @param element The child to add.
*/
void addChild(Element element);
/**
* Removes an Elment as child of this element.
* @param element The child to remove.
*/
void removeChild(Element element);
/**
* Gets the Element type.
* @return Returns the ElementType.
*/
ElementType getElementType();
/**
* Returns if this elements transforms the tree.
* if true the the doElementRun is runned in the transform phase insteat of the run phase.
*
* You need to add those new or modified Elements to the DirtyElement for reparsering.
*
* @return Returns true if transforming tree.
*/
boolean isTransformingTree();
}

View file

@ -0,0 +1,66 @@
/*
* 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;
import java.util.List;
/**
* Handlers attributes for xml attributes of all elements processed.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public interface ElementAttributeHandler extends ElementConfigurator {
/**
* Gets the attribute name this attribute handler handles.
* @return Returns the attributes name of this attribute handler.
*/
String getAttributeName();
/**
* Sets the attribute name this attribute handler handles.
* @param attributeName
*/
void setAttributeName(String attributeName);
/**
* Adds an NextAttribute.
* There next attributes will defines the order in which the ElementAttributeHandlers are executed.
* @param attribute
*/
void addNextAttribute(String attribute);
/**
* Removes an next attribute
* @param attribute
*/
void removeNextAttribute(String attribute);
/**
* Get all next attributes
* @return Returns the list of all next attributes.
*/
List<String> getNextAttributes();
}

View file

@ -0,0 +1,76 @@
/*
* 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;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.element.Element;
/**
* Helper interface for setting properties.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public interface ElementAttributeValueParser {
/**
* Checks if the value is an EL parameter.
* @param name The name of the attribute.
* @param value The value of the attribute.
* @param element The element of the attribute.
* @return Returns true if value is EL parameter.
*/
boolean isELParameter(String name,String value,Element element);
/**
* Returns the object which is stored in the ELContext
* @param value The attribute value.
* @param element The element of the attribute.
* @return Returns the resolved el parameter value.
* @throws ElementParameterException
* @throws ElementObjectPropertyValueException
*/
Object getELParameterValue(String value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
/**
* Convert the value into a new value genereted by parameterConverters.
* @param name The name of the attribute.
* @param value The value of the attribute.
* @param element The element of the attribute.
* @return Returns the converted attribute value.
* @throws ElementParameterException
*/
Object getConvertedParameterValue(String name,Object value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
/**
* Does is all, Checks if value is EL parameter and lookups the object.
* and converts to new object via parameter converter and return value.
* @param name The name of the attribute.
* @param value The value of the attribute.
* @param element The element of the attribute.
* @return Returns the attribute value.
* @throws ElementParameterException
*/
Object getParameterValue(String name,String value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
}

View file

@ -0,0 +1,47 @@
/*
* 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;
/**
* ElementAttributeValueParserException.<br>
*
*
*
* @author Willem Cazander
* @version 1.0 Jan 2, 2008
*/
@SuppressWarnings("serial")
public class ElementAttributeValueParserException extends ElementException {
/*
public ElementAttributeValueParserException(ElementAttributeConverter converter,String message) {
super(message);
}
public ElementAttributeValueParserException(ElementAttributeConverter converter,String message,Exception exception) {
super(message,exception);
}
*/
}

View file

@ -0,0 +1,58 @@
/*
* 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;
import org.x4o.xml.element.Element;
/**
* Bind ElementObjects together.
*
* This interface is used to bind a parent and child ElementObject together.
* For example; when both objects are an JComponent then we can add the child to the parent
* with the method: ((JComponent)parent).add((JComponent)child);
*
*
* @author Willem Cazander
* @version 1.0 Aug 17, 2005
*/
public interface ElementBindingHandler extends ElementMetaBase {
/**
* @return Returns the parent classes which this binding handler can do.
*/
Class<?> getBindParentClass();
/**
* @return Returns array of child classes which this binding handler can do.
*/
Class<?>[] getBindChildClasses();
/**
* Do the binding of this child to the parent object.
* @param parentObject The parentObject of this childElement.
* @param childObject The childObject of this childElement.
* @param childElement The child element to bind to the parent.
*/
void doBind(Object parentObject,Object childObject,Element childElement) throws ElementBindingHandlerException;
}

View file

@ -0,0 +1,54 @@
/*
* 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;
/**
* ElementBindingException.<br>
* Is throw with there is a exception in binding the objects
*
*
* @author Willem Cazander
* @version 1.0 Apr 15, 2008
*/
@SuppressWarnings("serial")
public class ElementBindingHandlerException extends ElementException {
/**
* Creates binding exception.
* @param message The error message.
*/
public ElementBindingHandlerException(String message) {
super(message);
}
/**
* Creates binding exception.
* @param message The error message.
* @param exception The error exception.
*/
public ElementBindingHandlerException(String message,Exception exception) {
super(message,exception);
}
}

View file

@ -0,0 +1,151 @@
/*
* 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;
import java.util.List;
/**
* The ElementClass stores all parse information to config the Element.
*
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
public interface ElementClass extends ElementClassBase {
/**
* Gets the xml tag the Element should handle.
* @return the tag
*/
String getTag();
/**
* Sets the XML tag the Element should handle.
* @param tag the tag to set
*/
void setTag(String tag);
/**
* Gets the ElementClass.
* @return the elementClass
*/
Class<?> getElementClass();
/**
* Sets the ElementClass.
* @param elementClass the elementClass to set.
*/
void setElementClass(Class<?> elementClass);
/**
* @return the objectClass.
*/
Class<?> getObjectClass();
/**
* @param objectClass the objectClass to set.
*/
void setObjectClass(Class<?> objectClass);
/**
* @return the autoAttributes.
*/
Boolean getAutoAttributes();
/**
* @param autoAttributes the autoAttributes to set.
*/
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<String> getElementParents(String namespaceUri);
/**
* @return the schemaContentBase
*/
String getSchemaContentBase();
/**
* @param schemaContentBase the schemaContentBase to set
*/
void setSchemaContentBase(String schemaContentBase);
/**
* @return the schemaContentComplex
*/
Boolean getSchemaContentComplex();
/**
* @param schemaContentComplex the schemaContentComplex to set
*/
void setSchemaContentComplex(Boolean schemaContentComplex);
/**
* @return the schemaContentMixed
*/
Boolean getSchemaContentMixed();
/**
* @param schemaContentMixed the schemaContentMixed to set
*/
void setSchemaContentMixed(Boolean schemaContentMixed);
/**
* Add an skip phase for this element.
* @param phase The phase name.
*/
void addSkipPhase(String phase);
/**
* Removes an skip phase for this element.
* @param phase The phase name.
*/
void removeSkipPhase(String phase);
/**
* Get all the skip phases for this element.
* @return The defined phases.
*/
List<String> getSkipPhases();
}

View file

@ -0,0 +1,128 @@
/*
* 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;
import java.util.List;
import org.x4o.xml.conv.ObjectConverter;
/**
* The ElementClass stores all parse information to config the Element.
*
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
public interface ElementClassAttribute extends ElementMetaBase {
/**
* Gets the attribute name which this ElementAttributeConverter handlers
*/
String getName();
/**
* Sets the attribute name which this ElementAttributeConverter handlers
*/
void setName(String name);
/**
* Gets the ObjectConverter
*/
ObjectConverter getObjectConverter();
/**
* Add the ObjectConverter whichs converts
*/
void setObjectConverter(ObjectConverter objectConverter);
/**
* Sets the defaultValue of this attribute
* @param defaultValue The defaultValue to set.
*/
void setDefaultValue(Object defaultValue);
/**
* Gets the default value.
* @return Returns the default value if any.
*/
Object getDefaultValue();
/**
* Add an attribute alias for this attribute.
* @param alias The alias.
*/
void addAttributeAlias(String alias);
/**
* Removes an attribute alias.
* @param alias The alias.
*/
void removeAttributeAlias(String alias);
/**
* Get all the aliases for this attribute.
* @return The defined aliases.
*/
List<String> getAttributeAliases();
/**
* @return the required
*/
Boolean getRequired();
/**
* @param required the required to set
*/
void setRequired(Boolean required);
/**
* @return the runResolveEL
*/
Boolean getRunResolveEL();
/**
* @param runResolveEL the runResolveEL to set
*/
void setRunResolveEL(Boolean runResolveEL);
/**
* @return the runConverters
*/
Boolean getRunConverters();
/**
* @param runConverters the runConverters to set
*/
void setRunConverters(Boolean runConverters);
/**
* @return the runBeanFill
*/
Boolean getRunBeanFill();
/**
* @param runBeanFill the runBeanFill to set
*/
void setRunBeanFill(Boolean runBeanFill);
}

View file

@ -0,0 +1,44 @@
/*
* 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;
import java.util.Collection;
import java.util.List;
/**
* The ElementClassBase is for all higher instances the base config of an ElementClass config structure.
*
*
* @author Willem Cazander
* @version 1.0 Jan 19, 2012
*/
public interface ElementClassBase extends ElementMetaBase {
List<ElementConfigurator> getElementConfigurators();
void addElementConfigurators(ElementConfigurator elementConfigurator);
Collection<ElementClassAttribute> getElementClassAttributes();
ElementClassAttribute getElementClassAttributeByName(String attributeName);
void addElementClassAttribute(ElementClassAttribute elementClassAttribute);
}

View file

@ -0,0 +1,50 @@
/*
* 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) more.
*
*
* @author Willem Cazanders
* @version 1.0 Jan 18, 2007
*/
public interface ElementConfigurator extends ElementMetaBase {
/**
* Gets called for configuring the given Element.
* @param element The element to config.
* @throws ElementConfiguratorException Is thrown which error is done.
*/
void doConfigElement(Element element) throws ElementConfiguratorException;
/**
* Return if this ElementConfigurator is an Action.
* which means is is executed in the runPhase in the end.
* So all magic is done, and we can access the fully finnisched object and toss it around.
* @return Returns true if need to run in config phase.
*/
boolean isConfigAction();
}

View file

@ -0,0 +1,64 @@
/*
* 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;
/**
* ElementConfiguratorException.<br>
*
* @author Willem Cazander
* @version 1.0 Aug 28, 2008
*/
@SuppressWarnings("serial")
public class ElementConfiguratorException extends ElementException {
/**
* Creates an configurator exception.
* @param config The ElementConfigurator.
* @param message The error message.
*/
public ElementConfiguratorException(ElementConfigurator config,String message) {
super(message);
}
/**
* Creates an configurator exception.
* @param config The ElementConfigurator.
* @param message The error message.
* @param exception The error exception.
*/
public ElementConfiguratorException(ElementConfigurator config,String message,Exception exception) {
super(message,exception);
}
/**
* Creates an configurator exception.
* @param config The ElementConfigurator.
* @param message The error message.
* @param exception The wrapped element error exception.
*/
public ElementConfiguratorException(ElementConfigurator config,String message,ElementException exception) {
super(message,exception);
}
}

View file

@ -0,0 +1,68 @@
/*
* 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;
/**
* Is throw when there is en Exception within an Element.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2005
*/
public class ElementException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10L;
/**
* Constructs an ElementException without a detail message.
*/
public ElementException() {
super();
}
/**
* Constructs an ElementException with a detail message.
* @param message The message of this Exception
*/
public ElementException(String message) {
super(message);
}
/**
* Creates an ElementException from a parent exception.
* @param e The error exception.
*/
public ElementException(Exception e) {
super(e);
}
/**
* Constructs an ElementException with a detail message.
* @param message The message of this Exception
* @param e The error exception.
*/
public ElementException(String message,Exception e) {
super(message,e);
}
}

View file

@ -0,0 +1,59 @@
/*
* 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;
import java.util.List;
/**
* Defines an ElementInterface.
*
* @author Willem Cazander
* @version 1.0 Apr 15, 2008
*/
public interface ElementInterface extends ElementClassBase {
/**
* Gets this class of the interface to match this converters/etc/ to.
* @return the tag.
*/
Class<?> getInterfaceClass();
/**
* Sets the interface class.
* @param interfaceClass the interfaceClass to set.
*/
void setInterfaceClass(Class<?> interfaceClass);
/**
* Adds an ElementBindingHanlder.
* @param elementBindingHandler The ElementBindingHandler to add.
*/
void addElementBindingHandler(ElementBindingHandler elementBindingHandler);
/**
* Gets all ElementBindingHandlers.
* @return Returns all the ElementBindingHandlers.
*/
List<ElementBindingHandler> getElementBindingHandlers();
}

View file

@ -0,0 +1,142 @@
/*
* 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;
import java.util.List;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import org.x4o.xml.core.X4OPhase;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
/**
* ElementLanguage is the central store of the defined element language.
*
* @author Willem Cazander
* @version 1.0 Feb 14, 2007
*/
public interface ElementLanguage {
/**
* Gets all ElementBindingHandlers.
* @param parent The parent element object or class to search for.
* @param child The parent element object or class to search for.
* @return Returns an List with all ElementBindingHandler for the search pair.
*/
List<ElementBindingHandler> findElementBindingHandlers(Object parent,Object child);
/**
* Returns list of ElementInterfaces for an element.
* @param object The element object or class to search for.
* @return The list of elementInterfaces.
*/
List<ElementInterface> findElementInterfaces(Object object);
/**
* Returns the namespace context for an namespace uri.
* @param namespaceUri the namespace uri.
* @return The ElementNamespaceContext.
*/
ElementNamespaceContext findElementNamespaceContext(String namespaceUri);
/**
* Gets the EL Context.
* @return Returns the ELContext.
*/
ELContext getELContext();
/**
* Gets the ExpressionFactory.
* @return Returns the ExpressionFactory.
*/
ExpressionFactory getExpressionFactory();
/**
* @return Returns the ElementAttributeValueParser.
*/
ElementAttributeValueParser getElementAttributeValueParser();
/**
* @return Returns the ElementObjectPropertyValue.
*/
ElementObjectPropertyValue getElementObjectPropertyValue();
/**
* Returns the current X4OPhase of the parser.
* @return Returns the current phase.
*/
X4OPhase getCurrentX4OPhase();
/**
* Sets the phase of the context.
* TODO: Do never call this, methode sould be moved to local interface.
* @param phase The current phase to set.
*/
void setCurrentX4OPhase(X4OPhase phase);
/**
* Marks an (new) Element as dirty and run the phases from this start phase.
*
* @param element The Element which needs the magic.
* @param phase May be null, then it should defualt to configElementPhase
*/
void addDirtyElement(Element element,X4OPhase phase);
/**
* Get all Dirty Elements.
* @return Returns Map with dirty elements.
*/
Map<Element,X4OPhase> getDirtyElements();
/**
* Returns the root Element which starts the xml tree.
* @return Returns the root element of the document instance we parse.
*/
Element getRootElement();
/**
* Sets the root element.
* @param element The root element to set.
*/
void setRootElement(Element element);
/**
* @return the languageConfiguration.
*/
X4OLanguageConfiguration getLanguageConfiguration();
/**
* Adds an ElementLanguageModule to this language.
* @param elementLanguageModule The element language module to add.
*/
void addElementLanguageModule(ElementLanguageModule elementLanguageModule);
/**
* @return Returns a list of element language modules in this defined and loaded language.
*/
List<ElementLanguageModule> getElementLanguageModules();
}

View file

@ -0,0 +1,67 @@
/*
* 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;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
/**
* ElementLanguageLocal is the local set interface for ElementLanguage.
*
* @author Willem Cazander
* @version 1.0 Oct 28, 2009
*/
public interface ElementLanguageLocal extends ElementLanguage {
/**
* Sets the EL Context.
* @param context The ELContext to set.
*/
void setELContext(ELContext context);
/**
* Sets the ExpressionFactory.
* @param expressionFactory The ExpressionFactory to set.
*/
void setExpressionFactory(ExpressionFactory expressionFactory);
/**
* @param elementAttributeValueParser The elementAttributeValueParser to set.
*/
void setElementAttributeValueParser(ElementAttributeValueParser elementAttributeValueParser);
/**
* @param elementObjectPropertyValue The elementObjectPropertyValue to set.
*/
void setElementObjectPropertyValue(ElementObjectPropertyValue elementObjectPropertyValue);
/**
* @param parserConfiguration The parserConfiguration to set.
*/
void setLanguageConfiguration(X4OLanguageConfiguration parserConfiguration);
}

Some files were not shown because too many files have changed in this diff Show more