Easter cleaning

This commit is contained in:
Willem Cazander 2025-05-07 21:46:32 +02:00
commit 9e36078b2e
1862 changed files with 270281 additions and 0 deletions

33
nx01-x4o-driver/pom.xml Normal file
View file

@ -0,0 +1,33 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>love.distributedrebirth.nx01</groupId>
<artifactId>nx01</artifactId>
<version>〇一。壬寅。一〄-SNAPSHOT</version>
</parent>
<artifactId>nx01-x4o-driver</artifactId>
<dependencies>
<dependency>
<groupId>love.distributedrebirth.nx01</groupId>
<artifactId>nx01-x4o-sax3</artifactId>
</dependency>
<dependency>
<groupId>love.distributedrebirth.nx01</groupId>
<artifactId>nx01-x4o-fc18</artifactId>
</dependency>
<dependency>
<groupId>love.distributedrebirth.nx01</groupId>
<artifactId>nx01-x4o-maisdoc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper-el</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,177 @@
/*
* Copyright (c) 2004-2014, 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;
import java.util.List;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.DefaultX4OWriter;
import org.x4o.xml.io.X4OReader;
import org.x4o.xml.io.X4OReaderSession;
import org.x4o.xml.io.X4OWriter;
import org.x4o.xml.io.X4OWriterSession;
import org.x4o.xml.lang.X4OLanguageConfiguration;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.phase.X4OPhaseManager;
import org.x4o.xml.lang.task.X4OLanguageTask;
/**
* X4ODriver Is the x4o language driver to interact with xml.
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
public abstract class X4ODriver<T> {
/** Defines the default version if none is defined. */
public final static String DEFAULT_LANGUAGE_VERSION = "1.0";
/**
* marker constructor.
*/
public X4ODriver(/*X4ODriverManager.ConstructorMarker marker*/) {
}
/**
* @return Returns the langauge name of this driver.
*/
abstract public String getLanguageName();
/**
* @return Returns the supported language versions for this driver.
*/
abstract public String[] getLanguageVersions();
// =============== build methods to override
protected X4OLanguage buildLanguage(String version) {
return X4ODriverManager.getDefaultBuildLanguage(this, version);
}
protected X4OPhaseManager buildPhaseManager() {
return X4ODriverManager.getDefaultBuildPhaseManager();
}
protected X4OLanguageConfiguration buildLanguageConfiguration() {
return X4ODriverManager.getDefaultBuildLanguageConfiguration();
}
// =============== Reader
public X4OReader<T> createReader() {
return createReaderSession();
}
public X4OReader<T> createReader(String version) {
return createReaderSession(version);
}
public X4OReaderSession<T> createReaderSession() {
return createReaderSession(getLanguageVersionDefault());
}
public X4OReaderSession<T> createReaderSession(String version) {
return new DefaultX4OReader<T>(createLanguage(version));
}
// =============== Writer
public X4OWriter<T> createWriter() {
return createWriterSession();
}
public X4OWriter<T> createWriter(String version) {
return createWriterSession(version);
}
public X4OWriterSession<T> createWriterSession() {
return createWriterSession(getLanguageVersionDefault());
}
public X4OWriterSession<T> createWriterSession(String version) {
return new DefaultX4OWriter<T>(createLanguage(version));
}
// =============== Language
/**
* Returns the default language which is the latest version.
* @return The default language version.
*/
final public String getLanguageVersionDefault() {
return X4ODriverManager.getDefaultLanguageVersion(getLanguageVersions());
}
/**
* Creates the X4OLanguage for the specified version.
* @param version The language version to create.
* @return The created X4OLanguage.
*/
final public X4OLanguage createLanguage(String version) {
return buildLanguage(version);
}
/**
* Creates the X4OLanguage for the default version.
* @return The created X4OLanguage.
*/
final public X4OLanguage createLanguage() {
return buildLanguage(getLanguageVersionDefault());
}
/*
* Creates the X4OLanguageSession for the default language version.
* @return The created X4OLanguageSession.
*
final public X4OLanguageSession createLanguageSession() {
return createLanguageSession(getLanguageVersionDefault());
}
*
* Creates the X4OLanguageSession for the specified version.
* @param version The language version to create the context for.
* @return The created X4OLanguageSession.
*
final public X4OLanguageSession createLanguageSession(String version) {
return createLanguage(version).createLanguageSession();
}*/
// =============== Language Tasks
final public X4OLanguageTask getLanguageTask(String taskId) {
return X4ODriverManager.getX4OLanguageTask(taskId);
}
final public List<X4OLanguageTask> getLanguageTasks() {
return X4ODriverManager.getX4OLanguageTasks();
}
}

View file

@ -0,0 +1,338 @@
/*
* Copyright (c) 2004-2014, 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;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.x4o.xml.lang.DefaultX4OLanguage;
import org.x4o.xml.lang.DefaultX4OLanguageConfiguration;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageConfiguration;
import org.x4o.xml.lang.phase.DefaultX4OPhaseManager;
import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseLanguageInit;
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
import org.x4o.xml.lang.phase.X4OPhaseLanguageWrite;
import org.x4o.xml.lang.phase.X4OPhaseManager;
import org.x4o.xml.lang.phase.X4OPhaseType;
import org.x4o.xml.lang.task.X4OLanguageTask;
import org.xml.sax.Attributes;
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.XMLReaderFactory;
/**
* X4ODriverManager controls all the x4o driver and languages loaded in the classpath.
*
* @author Willem Cazander
* @version 1.0 Apr 6, 2013
*/
public final class X4ODriverManager {
public final static String X4O_DRIVERS_RESOURCE = "META-INF/x4o-drivers.xml";
private final static X4ODriverManager instance;
private Logger logger = null;
private volatile boolean reloadDrivers = true;
private Map<String,String> classdrivers = null;
private Map<String,String> defaultDrivers = null;
private Map<String,X4ODriver<?>> drivers = null;
private Map<String,X4OLanguageTask> languageTasks = null;
private X4ODriverManager() {
logger = Logger.getLogger(X4ODriverManager.class.getName());
classdrivers = new HashMap<String,String>(10);
defaultDrivers = new HashMap<String,String>(10);
drivers = new HashMap<String,X4ODriver<?>>(10);
languageTasks = new HashMap<String,X4OLanguageTask>(10);
}
static {
instance = new X4ODriverManager();
}
private void registerX4OLanguageTask(String className) {
try {
X4OLanguageTask task = (X4OLanguageTask)X4OLanguageClassLoader.newInstance(className);
if (languageTasks.containsKey(task.getId())) {
throw new RuntimeException("Can't add duplicate language task: "+task.getId());
}
languageTasks.put(task.getId(), task);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e.getMessage(),e);
} catch (InstantiationException e) {
throw new IllegalStateException(e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e.getMessage(),e);
}
}
static public X4OLanguageTask getX4OLanguageTask(String taskId) {
instance.lazyInit(); // fixme
return instance.languageTasks.get(taskId);
}
static public List<X4OLanguageTask> getX4OLanguageTasks() {
instance.lazyInit(); // fixme
return new ArrayList<X4OLanguageTask>(instance.languageTasks.values());
}
static protected String getDefaultLanguageVersion(String[] languages) {
if (languages==null || languages.length==0) {
return X4ODriver.DEFAULT_LANGUAGE_VERSION;
}
String languageVersion = languages[languages.length-1];
return languageVersion;
}
static protected X4OPhaseManager getDefaultBuildPhaseManager() {
DefaultX4OPhaseManager manager = new DefaultX4OPhaseManager();
new X4OPhaseLanguageInit().createPhases(manager);
new X4OPhaseLanguageRead().createPhases(manager);
new X4OPhaseLanguageWrite().createPhases(manager);
return manager;
}
static protected X4OLanguage getDefaultBuildLanguage(X4ODriver<?> driver,String version) {
if (version==null) {
version = driver.getLanguageVersionDefault();
}
DefaultX4OLanguage result = new DefaultX4OLanguage(
driver.buildLanguageConfiguration(),
driver.buildPhaseManager(),
driver.getLanguageName(),
version
);
try {
result.getPhaseManager().runPhases(result.createLanguageSession(), X4OPhaseType.INIT); // TODO: fix phase to interface T
} catch (X4OPhaseException e) {
throw new RuntimeException(e); //TODO: change layer
}
return result;
}
static protected X4OLanguageConfiguration getDefaultBuildLanguageConfiguration() {
DefaultX4OLanguageConfiguration config = new DefaultX4OLanguageConfiguration();
config.fillDefaults();
X4OLanguageConfiguration result = config.createProxy();
return result;
}
/*
static public void setGlobalProperty(X4ODriver<?> driver,String key,Object value) {
Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName());
if (driverProperties==null) {
driverProperties = new HashMap<String,Object>(20);
instance.globalProperties.put(driver.getLanguageName(), driverProperties);
}
String keyLimits[] = driver.getGlobalPropertyKeySet();
for (int i=0;i<keyLimits.length;i++) {
String keyLimit = keyLimits[i];
if (keyLimit.equals(key)) {
driverProperties.put(key,value);
return;
}
}
throw new IllegalArgumentException("Property with key: "+key+" is protected by key limit.");
}
*/
static public void registerX4ODriver(X4ODriver<?> driver) {
if (driver==null) {
throw new NullPointerException("Can't register null driver.");
}
if (driver.getLanguageName()==null) {
throw new NullPointerException("Error in driver impl languageName is null in: "+driver.getClass());
}
if (driver.getLanguageName().length()==0) {
throw new IllegalArgumentException("Error in driver impl languageName is empty in: "+driver.getClass());
}
if (driver.getLanguageVersions()==null) {
throw new NullPointerException("Error in driver impl languageVersions is null in: "+driver.getClass());
}
if (driver.getLanguageVersions().length==0) {
throw new IllegalArgumentException("Error in driver impl languageVersions is empty in: "+driver.getClass());
}
instance.drivers.put(driver.getLanguageName(), driver);
}
static public void deregisterX4ODriver(X4ODriver<?> driver) {
if (driver==null) {
throw new NullPointerException("Can't deregister null driver.");
}
if (driver.getLanguageName()==null) {
throw new NullPointerException("Error in driver impl languageName is null in: "+driver.getClass());
}
instance.drivers.remove(driver.getLanguageName());
}
static public X4ODriver<?> getX4ODriver(String language) {
if (language==null) {
throw new NullPointerException("Can't provider driver for null language.");
}
if (language.length()==0) {
throw new IllegalArgumentException("Can't provider driver for empty language.");
}
if (instance.drivers.containsKey(language)) {
return instance.drivers.get(language);
}
instance.lazyInit();
X4ODriver<?> result = instance.createX4ODriver(language);
if (result==null) {
throw new IllegalArgumentException("Can't find driver for language: "+language);
}
return result;
}
static public List<String> getX4OLanguages() {
instance.lazyInit();
List<String> result = new ArrayList<String>(10);
result.addAll(instance.classdrivers.keySet());
result.addAll(instance.defaultDrivers.keySet());
Collections.sort(result);
return result;
}
private void lazyInit() {
if (reloadDrivers==false) {
return;
}
instance.loadLanguageDrivers();
reloadDrivers = false;
}
private X4ODriver<?> createX4ODriver(String language) {
String driverClassName = null;
if (classdrivers.containsKey(language)) {
driverClassName = classdrivers.get(language);
} else if (defaultDrivers.containsKey(language)) {
driverClassName = defaultDrivers.get(language);
}
if (driverClassName==null) {
return null;
}
try {
Class<?> driverClass = X4OLanguageClassLoader.loadClass(driverClassName);
//Constructor<?> markedConstructor = driverClass.getDeclaredConstructor(new Class[]{ConstructorMarker.class});
//X4ODriver<?> driver = (X4ODriver<?>)markedConstructor.newInstance(new Object[]{new ConstructorMarker()});
X4ODriver<?> driver = (X4ODriver<?>)driverClass.newInstance();
registerX4ODriver(driver);
return driver;
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e.getMessage(),e);
} catch (InstantiationException e) {
throw new IllegalStateException(e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e.getMessage(),e);
}
}
/*
* Class to make sure all driver instances are created by this manager instance.
final public class ConstructorMarker {
private ConstructorMarker() {
}
}*/
/**
* Loads all defined language drivers in classpath.
*/
private void loadLanguageDrivers() {
logger.finer("loading x4o drivers from: "+X4O_DRIVERS_RESOURCE);
try {
Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources(X4O_DRIVERS_RESOURCE);
while(e.hasMoreElements()) {
URL u = e.nextElement();
loadDriversXml(u.openStream());
}
e = Thread.currentThread().getContextClassLoader().getResources("/"+X4O_DRIVERS_RESOURCE);
while(e.hasMoreElements()) {
URL u = e.nextElement();
loadDriversXml(u.openStream());
}
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(),e);
}
}
/**
* Parser xml inputstream and add into drivers and defaultDrivers lists.
* @param in The inputstream to parser.
* @throws IOException
* @throws SAXException
*/
private void loadDriversXml(InputStream in) throws IOException, SAXException {
if (in==null) {
throw new NullPointerException("Can't parse null input stream");
}
DriversTagHandler xth = new DriversTagHandler();
XMLReader saxParser = XMLReaderFactory.createXMLReader();
saxParser.setContentHandler(xth);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
try {
saxParser.parse(new InputSource(in));
} finally {
in.close();
}
}
private class DriversTagHandler extends DefaultHandler2 {
@Override
public void startElement(String namespaceUri, String tag, String qName,Attributes attr) throws SAXException {
if ("drivers".equals(tag)) {
String version = attr.getValue("version");
logger.finest("Version attribute: "+version);
} else if ("driver".equals(tag)) {
String language = attr.getValue("language");
String className = attr.getValue("className");
logger.finest("Driver className: "+className+" for language: "+language);
if (classdrivers.containsKey(className)==false) {
classdrivers.put(language,className);
}
} else if ("defaultDriver".equals(tag)) {
String language = attr.getValue("language");
logger.finest("DefaultDriver language: "+language);
if (defaultDrivers.containsKey(language)==false) {
defaultDrivers.put(language,language);
}
} else if ("languageTask".equals(tag)) {
String className = attr.getValue("className");
logger.finest("Language task className: "+className);
X4ODriverManager.instance.registerX4OLanguageTask(className);
}
}
}
}

View file

@ -0,0 +1,102 @@
/*
* Copyright (c) 2004-2014, 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,57 @@
/*
* Copyright (c) 2004-2014, 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,104 @@
/*
* Copyright (c) 2004-2014, 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 holds the defined converts.
*
* @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)
* @param clazz The Class to search an ObjectConverter for.
* @return The ObjectConverter or null for the class.
*/
public ObjectConverter getObjectConverterForClass(Class<?> clazz) {
return converters.get(clazz);
}
/**
* @return Returns all ObjectConverted stored in this class.
*/
protected Collection<ObjectConverter> getObjectConverters() {
return converters.values();
}
}

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2004-2014, 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 When the conversion failes.
*/
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 When the conversion failes.
*/
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,63 @@
/*
* Copyright (c) 2004-2014, 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,39 @@
/*
* Copyright (c) 2004-2014, 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,30 @@
/*
* Copyright (c) 2004-2014, 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 interfaces for two way object converters.
*
*
* @since 1.0
*/
package org.x4o.xml.conv;

View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Boolean.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
// WARNING: this alway returns a boolean :''(
return Boolean.valueOf(str);
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Boolean)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
BooleanConverter result = new BooleanConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Byte.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Byte(str);
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Byte)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ByteConverter result = new ByteConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Character.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Character(str.charAt(0));
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Character)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
CharacterConverter result = new CharacterConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,93 @@
/*
* Copyright (c) 2004-2014, 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.lang.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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Class.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return X4OLanguageClassLoader.loadClass(str);
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Class<?>)obj).getName();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ClassConverter result = new ClassConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Double.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Double(str);
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Double)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
DoubleConverter result = new DoubleConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,129 @@
/*
* Copyright (c) 2004-2014, 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.lang.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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Enum.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
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);
}
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
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;
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
EnumConverter result = new EnumConverter();
result.converters=cloneConverters();
result.enumClass=enumClass;
return result;
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Float.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Float(str);
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Float)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
FloatConverter result = new FloatConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Integer.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Integer(str);
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Integer)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
IntegerConverter result = new IntegerConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return Long.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Long(str);
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Long)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
LongConverter result = new LongConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,296 @@
/*
* Copyright (c) 2004-2014, 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.lang.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);
}
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return classTo;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
@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);
}
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param object The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
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 {
StringBuilder buf = new StringBuilder(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);
}
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@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,110 @@
/*
* Copyright (c) 2004-2014, 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,94 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Returns the convert to class.
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
* @return The class to convert to.
*/
public Class<?> getObjectClassTo() {
return URL.class;
}
/**
* Converts string into object.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
* @param str The string to convert to object.
* @param locale The locale to convert the string from.
* @return The object converted from the string.
* @throws ObjectConverterException When conversion fails.
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return new URL(str);
} catch (MalformedURLException e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
/**
* Converts object into string.
*
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
* @param obj The object to convert to string.
* @param locale The locale to convert the object from.
* @return The string converted from the object.
* @throws ObjectConverterException When conversion fails.
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((URL)obj).toString();
}
/**
* Clone this ObjectConverter.
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
* @return The cloned ObjectConverter.
* @throws CloneNotSupportedException When cloning fails.
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
URLConverter result = new URLConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004-2014, 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 default implementations to convert text to objects.
*
*
* @since 1.0
* @see org.x4o.xml.conv
*/
package org.x4o.xml.conv.text;

View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 2004-2014, 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.el;
import java.util.HashMap;
import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
import javax.el.CompositeELResolver;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.FunctionMapper;
import javax.el.ListELResolver;
import javax.el.MapELResolver;
import javax.el.VariableMapper;
/**
* X4OELFunctionMapper simple EL context.
*
* @author Willem Cazander
* @version 1.0 Sep 14, 2010
*/
public class X4OELContext extends ELContext {
private ELResolver elResolver = null;
private FunctionMapper functionMapper = null;
private VariableMapper variableMapper = null;
/**
* Creates a X4OELContext.
*/
public X4OELContext() {
CompositeELResolver compositeELResolver = new CompositeELResolver();
compositeELResolver.add(new X4OELResolver(new HashMap<Object, Object>(100)));
compositeELResolver.add(new ArrayELResolver());
compositeELResolver.add(new ListELResolver());
compositeELResolver.add(new BeanELResolver());
compositeELResolver.add(new MapELResolver());
elResolver = compositeELResolver;
functionMapper = new X4OELFunctionMapper();
variableMapper = new X4OELVariableMapper();
}
/**
* Returns the ELResolver.
* @return The ELResolver.
* @see javax.el.ELContext#getELResolver()
*/
@Override
public ELResolver getELResolver() {
return elResolver;
}
/**
* Returns the FunctionMapper.
* @return The FunctionMapper.
* @see javax.el.ELContext#getFunctionMapper()
*/
@Override
public FunctionMapper getFunctionMapper() {
return functionMapper;
}
/**
* Returns the VariableMapper.
* @return The VariableMapper.
* @see javax.el.ELContext#getVariableMapper()
*/
@Override
public VariableMapper getVariableMapper() {
return variableMapper;
}
}

View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 2004-2014, 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.el;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import javax.el.FunctionMapper;
/**
* X4OELFunctionMapper simple EL function mapper.
*
* @author Willem Cazander
* @version 1.0 Sep 14, 2010
*/
public class X4OELFunctionMapper extends FunctionMapper {
/**
* Stores the el to method function mapping.
*/
private Map<String,Method> functionMap = null;
/**
* Creates a X4OELFunctionMapper.
*/
public X4OELFunctionMapper() {
functionMap = new HashMap<String,Method>(50);
}
/**
* Resolves method el functions.
* @param prefix The function prefix.
* @param localName The local name of function.
* @return The resolved function or null is not found.
*/
@Override
public Method resolveFunction(String prefix, String localName) {
String key = prefix + ":" + localName;
return functionMap.get(key);
}
/**
* Add an static method to the function mapper.
* @param prefix The function prefix.
* @param localName The local name of function.
* @param method The method to execute on.
*/
public void addFunction(String prefix, String localName, Method method) {
if(prefix==null || localName==null || method==null) {
throw new NullPointerException();
}
int modifiers = method.getModifiers();
if(!Modifier.isPublic(modifiers)) {
throw new IllegalArgumentException("method not public");
}
if(!Modifier.isStatic(modifiers)) {
throw new IllegalArgumentException("method not static");
}
Class<?> retType = method.getReturnType();
if(retType == Void.TYPE) {
throw new IllegalArgumentException("method returns void");
}
String key = prefix + ":" + localName;
functionMap.put(key, method);
}
}

View file

@ -0,0 +1,101 @@
/*
* Copyright (c) 2004-2014, 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.el;
import java.util.Iterator;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.MapELResolver;
/**
* X4OELResolver simple EL resolver.
*
* @author Willem Cazander
* @version 1.0 Sep 14, 2010
*/
public class X4OELResolver extends ELResolver {
private ELResolver delegate = null;
private Map<Object,Object> objectStore = null;
/**
* Creates X4OELResolver which is backed by the objectStore.
* @param objectStore The objectStore.
*/
public X4OELResolver(Map<Object, Object> objectStore) {
this.objectStore = objectStore;
delegate = new MapELResolver();
}
/**
* Checks if base object is null and else return objectStore.
* @param base The base object to check.
* @return Returns the base object or objectStore.
*/
private Object checkBase(Object base) {
if (base==null) {
return objectStore;
}
return base;
}
@Override
public Object getValue(ELContext context, Object base, Object property) {
base = checkBase(base);
return delegate.getValue(context, base, property);
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
base = checkBase(base);
return delegate.getCommonPropertyType(context, base);
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Iterator getFeatureDescriptors(ELContext context,Object base) {
base = checkBase(base);
return delegate.getFeatureDescriptors(context, base);
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
base = checkBase(base);
return delegate.getType(context, base, property);
}
@Override
public boolean isReadOnly(ELContext context, Object base, Object property) {
base = checkBase(base);
return delegate.isReadOnly(context, base, property);
}
@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
base = checkBase(base);
delegate.setValue(context, base, property, value);
}
}

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2004-2014, 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.el;
import java.util.HashMap;
import java.util.Map;
import javax.el.ValueExpression;
import javax.el.VariableMapper;
/**
* X4OELVariableMapper simple EL variable mapper.
*
* @author Willem Cazander
* @version 1.0 Sep 14, 2010
*/
public class X4OELVariableMapper extends VariableMapper {
/** Map to hold all the expressions used. */
private Map<String, ValueExpression> expressions = null;
/**
* Creates the X4OELVariableMapper.
*/
public X4OELVariableMapper() {
expressions = new HashMap<String, ValueExpression>();
}
/**
* @see javax.el.VariableMapper#resolveVariable(java.lang.String)
* @param var Resolve this var to an ValueExpression.
* @return The resolved ValueExpression of the var.
*/
@Override
public ValueExpression resolveVariable(String var) {
return expressions.get(var);
}
/**
* @see javax.el.VariableMapper#setVariable(java.lang.String, javax.el.ValueExpression)
* @param var Resolve this var to an ValueExpression.
* @param expression The ValueExpression of the var.
* @return The ValueExpression being set.
*/
@Override
public ValueExpression setVariable(String var, ValueExpression expression) {
return expressions.put(var, expression);
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2004-2014, 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.el;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import org.x4o.xml.lang.X4OLanguageClassLoader;
/**
* X4OExpressionFactory finds and loads the needed impl.
*
* @author Willem Cazander
* @version 1.0 Apr 7, 2013
*/
public class X4OExpressionFactory {
static public final String EL_FACTORY_IMPL_APACHE = "org.apache.el.ExpressionFactoryImpl";
static public final String EL_FACTORY_IMPL_ODYSSEUS = "de.odysseus.el.ExpressionFactoryImpl";
static public ExpressionFactory createExpressionFactory() {
ExpressionFactory result = null;
try {
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_APACHE);
result = (ExpressionFactory) expressionFactoryClass.newInstance();
} catch (Exception e) {
try {
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_ODYSSEUS);
result = (ExpressionFactory) expressionFactoryClass.newInstance();
} catch (Exception ee) {
throw new RuntimeException("Could not load ExpressionFactory tried: "+EL_FACTORY_IMPL_APACHE+" and "+EL_FACTORY_IMPL_ODYSSEUS+" but could not load one of them.");
}
}
return result;
}
static public ELContext createELContext(Class<?> elContextClass) {
ELContext result = null;
try {
result = (ELContext)X4OLanguageClassLoader.newInstance(elContextClass);
} catch (Exception e) {
throw new RuntimeException("Could not create instance of ELContext: "+e.getMessage(),e);
}
return result;
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2014, 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 Expression Language classes.
*
*
* @since 1.0
*/
package org.x4o.xml.el;

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2004-2014, 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.X4ODriver;
import org.x4o.xml.lang.X4OLanguageModule;
/**
* CelDriver is the Core Element Language driver.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public class CelDriver extends X4ODriver<X4OLanguageModule> {
/** Defines the identifier of the 'Core Element Language' language. */
public static final String LANGUAGE_NAME = "cel";
/** Defines the versions this langauge knowns. */
public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
@Override
public String getLanguageName() {
return LANGUAGE_NAME;
}
@Override
public String[] getLanguageVersions() {
return LANGUAGE_VERSIONS;
}
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2004-2014, 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.X4ODriver;
import org.x4o.xml.lang.X4OLanguageModule;
/**
* 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 EldDriver extends X4ODriver<X4OLanguageModule> {
/** Defines the identifier of the 'Element Language Description' language. */
public static final String LANGUAGE_NAME = "eld";
/** Defines the identifier of the ELD x4o language. */
public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
@Override
public String getLanguageName() {
return LANGUAGE_NAME;
}
@Override
public String[] getLanguageVersions() {
return LANGUAGE_VERSIONS;
}
}

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2004-2014, 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.io.IOException;
import java.util.logging.Logger;
import javax.el.ValueExpression;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
import org.x4o.xml.io.X4OConnectionException;
import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageModuleLocal;
import org.x4o.xml.lang.X4OLanguageSession;
import org.x4o.xml.lang.X4OLanguageModuleLoader;
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
import org.x4o.xml.lang.X4OLanguageLocal;
import org.xml.sax.SAXException;
/**
* EldModuleLoader loads the child eld language and proxies the parent language into the child so to the parent langauge is configured.
*
* @author Willem Cazander
* @version 1.0 Aug 17, 2005
*/
public class EldModuleLoader implements X4OLanguageModuleLoader {
private Logger logger = null;
private String eldResource = null;
private boolean isEldCore = false;
/** The EL key to access the parent language module. */
public static final String EL_PARENT_LANGUAGE_MODULE = "parentLanguageModule";
/** The EL key to access the parent language element langauge. */
public static final String EL_PARENT_LANGUAGE = "parentLanguage";
/**
* Creates an ELD/CEL module loader.
* @param eldResource The resource to load.
* @param isEldCore If true then load CEL else load ELD.
*/
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;
}
/**
* Loads the ELD language into the module.
* @param language The langauge to load for.
* @param languageModule The module to load it in.
* @throws X4OLanguageModuleLoaderException When eld language could not be loaded.
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModuleLocal)
*/
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
logger.fine("Loading name eld file from resource: "+eldResource);
try {
X4ODriver<?> driver = null;
if (isEldCore) {
driver = X4ODriverManager.getX4ODriver(CelDriver.LANGUAGE_NAME);
} else {
driver = X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
}
X4OReader<?> reader = driver.createReader();
//X4OLanguageSession eldLang = driver.createLanguageSession(driver.getLanguageVersionDefault());
//X4OReader<?> reader = new DefaultX4OReader<Object>(eldLang);
reader.addELBeanInstance(EL_PARENT_LANGUAGE, language);
reader.addELBeanInstance(EL_PARENT_LANGUAGE_MODULE, languageModule);
//TODO: if (language.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
// eldLang.setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter());
// }
reader.readResource(eldResource);
} catch (X4OConnectionException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} catch (SAXException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} catch (IOException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
}
}
public static X4OLanguage getLanguage(X4OLanguageSession context) {
ValueExpression ee = context.getExpressionLanguageFactory().createValueExpression(context.getExpressionLanguageContext(),"${"+EL_PARENT_LANGUAGE+"}", X4OLanguage.class);
return (X4OLanguage)ee.getValue(context.getExpressionLanguageContext());
}
public static X4OLanguageModule getLanguageModule(X4OLanguageSession context) {
ValueExpression ee = context.getExpressionLanguageFactory().createValueExpression(context.getExpressionLanguageContext(),"${"+EL_PARENT_LANGUAGE_MODULE+"}", X4OLanguageModule.class);
return (X4OLanguageModule)ee.getValue(context.getExpressionLanguageContext());
}
}

View file

@ -0,0 +1,291 @@
/*
* Copyright (c) 2004-2014, 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.conv.ObjectConverter;
import org.x4o.xml.conv.text.ClassConverter;
import org.x4o.xml.eld.lang.AttributeAliasElement;
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.ElementNamespaceBindingHandler;
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.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageLocal;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageModuleLoader;
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
import org.x4o.xml.lang.X4OLanguageModuleLocal;
/**
* 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 X4OLanguageModuleLoader {
private Logger logger = null;
private static final String PP_CEL_PROVIDER_HOST = "cel.x4o.org";
private static final String PP_CEL_XMLNS = "http://"+PP_CEL_PROVIDER_HOST+"/xml/ns/";
private static final String PP_CEL_XSD_FILE = "-1.0.xsd";
private static final String CEL_CORE = "cel-core";
private static final String CEL_ROOT = "cel-root";
private static final String CEL_CORE_XSD_FILE = CEL_CORE+PP_CEL_XSD_FILE;
private static final String CEL_ROOT_XSD_FILE = CEL_ROOT+PP_CEL_XSD_FILE;
/** The cel core namespace uri. */
public static final String CEL_CORE_URI = PP_CEL_XMLNS+CEL_CORE;
/** The cel root namespace uri. */
public static final String CEL_ROOT_URI = PP_CEL_XMLNS+CEL_ROOT;
/** The cel core schema namespace uri. */
public static final String CEL_CORE_XSD_URI = CEL_CORE_URI+PP_CEL_XSD_FILE;
/** The cel root schema namespace uri. */
public static final String CEL_ROOT_XSD_URI = CEL_ROOT_URI+PP_CEL_XSD_FILE;
/**
* Creates the CEL module loader.
*/
public EldModuleLoaderCore() {
logger = Logger.getLogger(EldModuleLoaderCore.class.getName());
}
/**
* Loads the CEL language into the module.
* @param language The langauge to load for.
* @param languageModule The module to load it in.
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModuleLocald)
*/
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModuleLocal languageModule) throws X4OLanguageModuleLoaderException {
// Config module meta data
configLanguageModule(languageModule);
// Config language
addBindingHandler(languageModule,new ElementClassBindingHandler(),"cel-class-bind","Binds the ElementClass childeren.");
addBindingHandler(languageModule,new ElementModuleBindingHandler(),"cel-module-bind","Binds the LanguageModule childeren.");
addBindingHandler(languageModule,new ElementClassAttributeBindingHandler(),"cel-class-attr-bind","Binds the ElementClassAttribute childeren.");
addBindingHandler(languageModule,new ElementInterfaceBindingHandler(),"cel-interface-bind","Binds the ElementInterface childeren.");
addBindingHandler(languageModule,new ElementNamespaceBindingHandler(),"cel-namespace-bind","Binds the Namespace childeren.");
// Create cel-lang namespace in language
ElementNamespace namespace = createNamespaceContext(language,CEL_CORE,CEL_CORE_URI,CEL_CORE_XSD_URI,CEL_CORE_XSD_FILE,CEL_CORE);
configElementClasses(language,namespace);
startAndAddNamespace(language,languageModule,namespace);
// Create cel-root namespace in language for schema support
ElementNamespace namespaceRoot = createNamespaceContext(language,CEL_ROOT,CEL_ROOT_URI,CEL_ROOT_XSD_URI,CEL_ROOT_XSD_FILE,CEL_ROOT);
namespaceRoot.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
ElementClass rootElement = createElementClass(language,"module",language.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class,"The module tag is the root xml element for ELD language.");
rootElement.addElementClassAttribute(createElementClassAttribute(language,"id",true,null));
rootElement.addElementClassAttribute(createElementClassAttribute(language,"providerHost",true,null));
namespaceRoot.addElementClass(rootElement);
startAndAddNamespace(language,languageModule,namespaceRoot);
}
/**
* Adds only Element class beans which need extra meta info for schema.
* @param namespace The namespace to config.
* @param language The language to config for.
* @throws X4OLanguageModuleLoaderException
*/
private void configElementClasses(X4OLanguage language,ElementNamespace namespace) throws X4OLanguageModuleLoaderException {
ElementClass ec = null;
namespace.addElementClass(createElementClass(language,"attribute",language.getLanguageConfiguration().getDefaultElementClassAttribute(),null,"Defines xml element attribute."));
ec = createElementClass(language,"attributeAlias",null,AttributeAliasElement.class,"Adds an attribute alias.");
ec.addElementClassAttribute(createElementClassAttribute(language,"name",true,null));
ec.addElementParent(CEL_CORE_URI, "attribute");
namespace.addElementClass(ec);
namespace.addElementClass(createElementClass(language,"classConverter",ClassConverter.class,null,"Converts string attribute to java class instance."));
ec = createElementClass(language,"namespace",language.getLanguageConfiguration().getDefaultElementNamespace(),null,"Defines an xml namespace.");
ec.addElementClassAttribute(createElementClassAttribute(language,"uri",true,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"element",language.getLanguageConfiguration().getDefaultElementClass(),null,"Defines xml element tag.");
ec.addElementClassAttribute(createElementClassAttribute(language,"objectClass",false,new ClassConverter()));
ec.addElementClassAttribute(createElementClassAttribute(language,"elementClass",false,new ClassConverter()));
namespace.addElementClass(ec);
ec = createElementClass(language,"elementInterface",language.getLanguageConfiguration().getDefaultElementInterface(),null,"Defines element interface class.");
ec.addElementClassAttribute(createElementClassAttribute(language,"interfaceClass",false,new ClassConverter()));
namespace.addElementClass(ec);
ec = createElementClass(language,"bindingHandler",null,BeanElement.class,"Defines generic binding handler for languge.");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementClassAttribute(createElementClassAttribute(language,"id",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"namespaceAttribute",null,BeanElement.class,"Defines generic namespace attribute for language.");
ec.addElementParent(CEL_CORE_URI, "namespace");
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"configurator",null,BeanElement.class,"Define generic configurator for language.");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"configAction",false,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"configuratorGlobal",null,BeanElement.class,"Define generic global configuator for languge.");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"configAction",false,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"description",null,DescriptionElement.class,"Adds description as text on all eld elements.");
ec.setSchemaContentBase("string");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent(CEL_CORE_URI, "namespace");
ec.addElementParent(CEL_CORE_URI, "namespaceAttribute");
ec.addElementParent(CEL_CORE_URI, "bindingHandler");
ec.addElementParent(CEL_CORE_URI, "configurator");
ec.addElementParent(CEL_CORE_URI, "configuratorGlobal");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "attribute");
namespace.addElementClass(ec);
ec = createElementClass(language,"elementParent",null,ElementClassAddParentElement.class,"Added (meta) element parent.");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementClassAttribute(createElementClassAttribute(language,"tag",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"uri",false,null));
namespace.addElementClass(ec);
}
private void configLanguageModule(X4OLanguageModuleLocal languageModule) {
languageModule.setId("cel-module");
languageModule.setProviderName("Core Element Languag Module");
languageModule.setProviderHost(PP_CEL_PROVIDER_HOST);
languageModule.setDescription("Core Element Language Module Loader");
}
private void startAndAddNamespace(X4OLanguageLocal language,X4OLanguageModuleLocal languageModule,ElementNamespace namespace) throws X4OLanguageModuleLoaderException {
try {
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
languageModule.addElementNamespace(namespace);
}
private ElementNamespace createNamespaceContext(X4OLanguageLocal language,String id,String uri,String schemaUri,String schemaResource,String schemaPrefix) throws X4OLanguageModuleLoaderException {
logger.finer("Creating "+language.getLanguageName()+" namespace.");
ElementNamespace namespace;
try {
namespace = (ElementNamespace)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespace());
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)
X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider())
);
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setId(id);
namespace.setUri(uri);
namespace.setSchemaUri(schemaUri);
namespace.setSchemaResource(schemaResource);
namespace.setSchemaPrefix(schemaPrefix);
return namespace;
}
private ElementClass createElementClass(X4OLanguage language,String tag,Class<?> objectClass,Class<?> elementClass,String description) throws X4OLanguageModuleLoaderException {
try {
ElementClass result = (ElementClass)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClass());
result.setId(tag);
result.setObjectClass(objectClass);
result.setElementClass(elementClass);
result.setDescription(description);
return result;
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
}
/**
* Creates new configed ElementClassAttribute instance.
* @param language The X4OLanguage to create from.
* @param name The name of the attribute.
* @param required Is the attribute required.
* @param converter The converter for the attribute.
* @return The new ElementClassAttribute instance.
* @throws X4OLanguageModuleLoaderException When class could not be created.
*/
private ElementClassAttribute createElementClassAttribute(X4OLanguage language,String name,boolean required,ObjectConverter converter) throws X4OLanguageModuleLoaderException {
try {
ElementClassAttribute result = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClassAttribute());
result.setId(name);
if (required) {
result.setRequired(required);
}
if (converter!=null) {
result.setObjectConverter(converter);
}
return result;
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
}
/**
* Adds binding handler to module.
* @param languageModule The language module.
* @param handler The handler to add the the module.
* @param id The handler id.
* @param description The handler descripion.
*/
private void addBindingHandler(X4OLanguageModuleLocal languageModule,ElementBindingHandler handler,String id,String description) {
handler.setId(id);
handler.setDescription(description);
languageModule.addElementBindingHandler(handler);
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import org.x4o.sax3.io.SAX3PropertyConfig;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.task.AbstractX4OLanguageTask;
import org.x4o.xml.lang.task.X4OLanguageTaskException;
import org.x4o.xml.lang.task.X4OLanguageTaskExecutor;
/**
* X4OWriteLanguageDoc is support class to write html documentation from the eld.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class EldDocLanguageTask extends AbstractX4OLanguageTask {
public static final String TASK_ID = "eld-doc";
private static final String TASK_NAME = "ELD DOC Writer Task";
private static final String TASK_DESC = "Writes out the documentation of the language elements.";
public EldDocLanguageTask() {
super(TASK_ID,TASK_NAME,TASK_DESC,EldDocWriter.DEFAULT_PROPERTY_CONFIG);
}
/**
* Executes this language task.
*/
protected X4OLanguageTaskExecutor createTaskExecutorChecked(final SAX3PropertyConfig config) {
return new X4OLanguageTaskExecutor() {
public void execute(X4OLanguage language) throws X4OLanguageTaskException {
try {
new EldDocWriter(language,config).writeDocumentation();
} catch (ElementException e) {
throw new X4OLanguageTaskException(config,e.getMessage(),e);
}
}
};
}
}

View file

@ -0,0 +1,319 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import org.x4o.maisdoc.flake.MaisDocGenerator;
import org.x4o.maisdoc.flake.DefaultPageWriterHelp;
import org.x4o.maisdoc.flake.DefaultPageWriterIndexAll;
import org.x4o.maisdoc.flake.DefaultPageWriterTree;
import org.x4o.maisdoc.model.MaisDoc;
import org.x4o.maisdoc.model.MaisDocConcept;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocRemoteClass;
import org.x4o.sax3.SAX3WriterXml;
import org.x4o.sax3.io.SAX3PropertyConfig;
import org.x4o.sax3.io.SAX3PropertyConfig.PropertyConfigItem;
import org.x4o.xml.element.ElementNamespaceAttribute;
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.ElementConfiguratorGlobal;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageSession;
import org.xml.sax.SAXException;
/**
* EldDocWriter writes the x4o eld documentation.
*
* @author Willem Cazander
* @version 1.0 Aug 26, 2010
*/
public class EldDocWriter {
private final static String DEFAULT_NAME = "X4O ELD DOC";
private final static String DEFAULT_DESCRIPTION = "X4O Meta Language Documentation.";
// Core concepts
private static final String[] C_CONTEXT = {"language","Overview","All language modules.","The loaded language modules.."};
private static final String[] C_MODULE = {"module","Module","The Language Modules.","The language is build by the modules and provides the namespaces."};
private static final String[] C_INTERFACE = {"interface","Interface","The element interface.","The element interface."};
private static final String[] C_NAMESPACE = {"namespace","Namespace","The Language Namespace.","The language namespace holds all the xml elements."};
private static final String[] C_ELEMENT = {"element","Element","The Language Element.","The xml language element description."};
// Child concepts
private static final String[] CC_ATTRIBUTE_H = {"attribute-handler","Attribute Handler","The attribute handler.","The attribute handler."};
private static final String[] CC_ATTRIBUTE = {"attribute","Attribute","The attribute config.","The attribute config."};
private static final String[] CC_CONFIGURATOR = {"configurator","Configurator","The element configurator.","The element configurator."};
private static final String[] CC_CONFIGURATOR_G = {"configurator-global","ConfiguratorGlobal","The global configurator.","The global configurator."};
private static final String[] CC_BINDING = {"binding","Binding","The element binding.","The element binding."};
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"eld-doc/";
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path";
public final static String DOC_NAME = PROPERTY_CONTEXT_PREFIX+"doc/name";
public final static String DOC_DESCRIPTION = PROPERTY_CONTEXT_PREFIX+"doc/description";
public final static String DOC_ABOUT = PROPERTY_CONTEXT_PREFIX+"doc/about";
public final static String DOC_COPYRIGHT = PROPERTY_CONTEXT_PREFIX+"doc/copyright";
public final static String DOC_PAGE_SUB_TITLE = PROPERTY_CONTEXT_PREFIX+"doc/page-sub-title";
public final static String META_KEYWORDS = PROPERTY_CONTEXT_PREFIX+"meta/keywords";
public final static String META_STYLESHEET = PROPERTY_CONTEXT_PREFIX+"meta/stylesheet";
public final static String META_STYLESHEET_THEMA = PROPERTY_CONTEXT_PREFIX+"meta/stylesheet-thema";
public final static String JAVADOC_LINK = PROPERTY_CONTEXT_PREFIX+"javadoc/link";
public final static String JAVADOC_LINK_OFFLINE = PROPERTY_CONTEXT_PREFIX+"javadoc/link-offline";
public final static String PAGE_PRINT_TREE = PROPERTY_CONTEXT_PREFIX+"page/print-tree";
public final static String PAGE_PRINT_XTREE = PROPERTY_CONTEXT_PREFIX+"page/print-xtree";
public final static String PAGE_PRINT_INDEX_ALL = PROPERTY_CONTEXT_PREFIX+"page/print-index-all";
public final static String PAGE_PRINT_HELP = PROPERTY_CONTEXT_PREFIX+"page/print-help";
static {
DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true,SAX3WriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(true,OUTPUT_PATH,File.class),
new PropertyConfigItem(false,DOC_NAME,String.class),
new PropertyConfigItem(false,DOC_DESCRIPTION,String.class),
new PropertyConfigItem(false,DOC_ABOUT,String.class),
new PropertyConfigItem(false,DOC_COPYRIGHT,String.class),
new PropertyConfigItem(false,DOC_PAGE_SUB_TITLE,String.class),
new PropertyConfigItem(false,META_KEYWORDS,List.class),
new PropertyConfigItem(false,META_STYLESHEET,File.class),
new PropertyConfigItem(false,META_STYLESHEET_THEMA,String.class),
new PropertyConfigItem(false,JAVADOC_LINK,List.class),
new PropertyConfigItem(false,JAVADOC_LINK_OFFLINE,Map.class),
new PropertyConfigItem(PAGE_PRINT_TREE,Boolean.class,true),
new PropertyConfigItem(PAGE_PRINT_XTREE,Boolean.class,true),
new PropertyConfigItem(PAGE_PRINT_INDEX_ALL,Boolean.class,true),
new PropertyConfigItem(PAGE_PRINT_HELP,Boolean.class,true)
);
}
/** The config of this writer. */
private final SAX3PropertyConfig propertyConfig;
/** The language to write doc over. */
private final X4OLanguage language;
/**
* Creates an EldDocGenerator for this langauge context.
* @param language The language to generate doc for.
*/
public EldDocWriter(X4OLanguage language,SAX3PropertyConfig parentConfig) {
this.language=language;
this.propertyConfig=new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
this.propertyConfig.copyParentProperties(parentConfig);
}
/**
* Writes the language documentation to the base path.
* @throws ElementException Is thrown when error is done.
*/
public void writeDocumentation() throws ElementException {
try {
File basePath = propertyConfig.getPropertyFile(OUTPUT_PATH);
MaisDocGenerator writer = new MaisDocGenerator();
MaisDoc doc = buildLanguageDoc();
writer.write(doc, basePath);
} catch (IOException e) {
throw new ElementException(e);
}
}
/**
* Creates a fully configured ApiDco object.
* @return The ApiDoc configured to write eld documentation.
*/
private MaisDoc buildLanguageDoc() {
// Generic config
MaisDoc doc = new MaisDoc();
doc.setName( propertyConfig.getPropertyString(DOC_NAME, DEFAULT_NAME));
doc.setDescription( propertyConfig.getPropertyString(DOC_DESCRIPTION, DEFAULT_DESCRIPTION));
doc.setDocAbout( propertyConfig.getPropertyString(DOC_ABOUT, createLanguageAbout()));
doc.setDocCopyright( propertyConfig.getPropertyString(DOC_COPYRIGHT, createLanguageCopyright()));
doc.setDocPageSubTitle( propertyConfig.getPropertyString(DOC_PAGE_SUB_TITLE, createPageSubTitle()));
doc.setMetaStyleSheetThema( propertyConfig.getPropertyString(META_STYLESHEET_THEMA));
doc.setMetaStyleSheet( propertyConfig.getPropertyFile(META_STYLESHEET));
List<String> keywords = propertyConfig.getPropertyList(META_KEYWORDS);
if (keywords==null) {
keywords = createLanguageKeywords();
}
doc.addMetaKeywordAll(keywords);
doc.setNoFrameAllName("All Elements");
doc.setFrameNavPrintParent(true);
doc.setFrameNavPrintParentId(true);
doc.setGroupTypeName("summary", "Summary",1);
doc.setGroupTypeName("overview", "Overview",2);
// Javadoc linking config
List<String> javadocLinkList = propertyConfig.getPropertyList(JAVADOC_LINK);
Map<String,String> javadocLinkOfflineMap = propertyConfig.getPropertyMap(JAVADOC_LINK_OFFLINE);
if (javadocLinkList!=null) {
for (String javadocUrl:javadocLinkList) {
doc.addRemoteClass(new MaisDocRemoteClass(javadocUrl));
}
}
if (javadocLinkOfflineMap!=null) {
for (Map.Entry<String,String> offlineLink:javadocLinkOfflineMap.entrySet()) {
doc.addRemoteClass(new MaisDocRemoteClass(offlineLink.getKey(),offlineLink.getValue()));
}
}
// Tree and navagation config
doc.setFrameNavConceptClass(ElementClass.class);
doc.addTreeNodePageModeClass(X4OLanguageSession.class);
doc.addTreeNodePageModeClass(X4OLanguageModule.class);
doc.addTreeNodePageModeClass(ElementInterface.class);
doc.addTreeNodePageModeClass(ElementNamespace.class);
doc.addAnnotatedClasses(EldDocWriterLanguage.class);
doc.addAnnotatedClasses(EldDocWriterLanguageModule.class);
doc.addAnnotatedClasses(EldDocWriterElementClass.class);
doc.addAnnotatedClasses(EldDocWriterElementNamespace.class);
doc.addAnnotatedClasses(EldDocWriterElementInterface.class);
MaisDocConcept adcRoot = doc.addConcept(new MaisDocConcept(null,C_CONTEXT,X4OLanguage.class));
MaisDocConcept adcMod = doc.addConcept(new MaisDocConcept(adcRoot,C_MODULE,X4OLanguageModule.class));
MaisDocConcept adcIface = doc.addConcept(new MaisDocConcept(adcMod,C_INTERFACE,ElementInterface.class));
MaisDocConcept adcNs = doc.addConcept(new MaisDocConcept(adcMod,C_NAMESPACE,ElementNamespace.class));
MaisDocConcept adcEc = doc.addConcept(new MaisDocConcept(adcNs,C_ELEMENT,ElementClass.class));
// mm maybe redo something here
adcMod.addChildConcepts(new MaisDocConcept(adcMod,CC_ATTRIBUTE_H,ElementNamespaceAttribute.class));
adcMod.addChildConcepts(new MaisDocConcept(adcMod,CC_CONFIGURATOR_G,ElementConfiguratorGlobal.class));
adcMod.addChildConcepts(new MaisDocConcept(adcMod,CC_BINDING,ElementBindingHandler.class));
adcIface.addChildConcepts(new MaisDocConcept(adcMod,CC_ATTRIBUTE,ElementClassAttribute.class));
adcIface.addChildConcepts(new MaisDocConcept(adcMod,CC_CONFIGURATOR,ElementConfigurator.class));
adcEc.addChildConcepts(new MaisDocConcept(adcEc,CC_CONFIGURATOR,ElementConfigurator.class));
adcEc.addChildConcepts(new MaisDocConcept(adcEc,CC_ATTRIBUTE,ElementClassAttribute.class));
// Non-tree pages config
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_XTREE)) { doc.addDocPage(EldDocXTreePageWriter.createDocPage()); }
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_TREE)) { doc.addDocPage(DefaultPageWriterTree.createDocPage()); }
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_INDEX_ALL)) { doc.addDocPage(DefaultPageWriterIndexAll.createDocPage()); }
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_HELP)) { doc.addDocPage(DefaultPageWriterHelp.createDocPage()); }
// Doc tree config
MaisDocNode rootNode = new MaisDocNode(language,"language",getLanguageNameUpperCase()+" Language","The X4O "+getLanguageNameUpperCase()+" Language");
doc.setRootNode(rootNode);
for (X4OLanguageModule mod:language.getLanguageModules()) { MaisDocNode modNode = rootNode.addNode(createNodeLanguageModule(mod));
for (ElementBindingHandler bind:mod.getElementBindingHandlers()) { modNode.addNode(createNodeElementBindingHandler(bind)); }
for (ElementConfiguratorGlobal conf:mod.getElementConfiguratorGlobals()) { modNode.addNode(createNodeElementConfiguratorGlobal(conf)); }
for (ElementInterface iface:mod.getElementInterfaces()) { MaisDocNode ifaceNode = modNode.addNode(createNodeElementInterface(iface));
for (ElementClassAttribute eca:iface.getElementClassAttributes()) { ifaceNode.addNode(createNodeElementClassAttribute(eca)); }
for (ElementConfigurator conf:iface.getElementConfigurators()) { ifaceNode.addNode(createNodeElementConfigurator(conf)); } }
for (ElementNamespace ns:mod.getElementNamespaces()) { MaisDocNode nsNode = modNode.addNode(createNodeElementNamespace(ns));
for (ElementNamespaceAttribute attr:ns.getElementNamespaceAttributes()) { nsNode.addNode(createNodeElementNamespaceAttribute(attr)); }
for (ElementClass ec:ns.getElementClasses()) { MaisDocNode ecNode = nsNode.addNode(createNodeElementClass(ec));
for (ElementClassAttribute eca:ec.getElementClassAttributes()) { ecNode.addNode(createNodeElementClassAttribute(eca)); }
for (ElementConfigurator conf:ec.getElementConfigurators()) { ecNode.addNode(createNodeElementConfigurator(conf)); } } }
}
return doc;
}
private MaisDocNode createNodeElementBindingHandler(ElementBindingHandler bind) {
return new MaisDocNode(bind,bind.getId(),bind.getId(),bind.getDescription());
}
private MaisDocNode createNodeElementNamespaceAttribute(ElementNamespaceAttribute attr) {
return new MaisDocNode(attr,attr.getId(),attr.getId(),attr.getDescription());
}
private MaisDocNode createNodeElementConfiguratorGlobal(ElementConfiguratorGlobal conf) {
return new MaisDocNode(conf,conf.getId(),conf.getId(),conf.getDescription());
}
private MaisDocNode createNodeElementConfigurator(ElementConfigurator conf) {
return new MaisDocNode(conf,conf.getId(),conf.getId(),conf.getDescription());
}
private MaisDocNode createNodeLanguageModule(X4OLanguageModule mod) {
return new MaisDocNode(mod,mod.getId(),mod.getId(),mod.getDescription());
}
private MaisDocNode createNodeElementInterface(ElementInterface iface) {
return new MaisDocNode(iface,iface.getId(),iface.getId(),iface.getDescription());
}
private MaisDocNode createNodeElementNamespace(ElementNamespace ns) {
return new MaisDocNode(ns,ns.getId(),ns.getUri(),ns.getDescription());
}
private MaisDocNode createNodeElementClass(ElementClass ec) {
return new MaisDocNode(ec,ec.getId(),ec.getId(),ec.getDescription());
}
private MaisDocNode createNodeElementClassAttribute(ElementClassAttribute eca) {
return new MaisDocNode(eca,eca.getId(),eca.getId(),eca.getDescription());
}
private String createPageSubTitle() {
StringBuilder buf = new StringBuilder(100);
buf.append(language.getLanguageName());
buf.append(" ");// note use real space as 'html/header/title' will not always escape entities. TODO: add to html writer
buf.append(language.getLanguageVersion());
buf.append(" API");
return buf.toString();
}
private String createLanguageAbout() {
StringBuilder buf = new StringBuilder(100);
buf.append("XML X4O Language\n");
buf.append(language.getLanguageName().toUpperCase());
buf.append("&trade;&nbsp;");
buf.append(language.getLanguageVersion());
return buf.toString();
}
private String createLanguageCopyright() {
Calendar calendar = Calendar.getInstance();
StringBuilder buf = new StringBuilder(100);
buf.append("Copyright&nbsp;&#x00a9;&nbsp;");
buf.append(calendar.get(Calendar.YEAR));
buf.append("&nbsp;");
buf.append(getLanguageNameUpperCase());
buf.append("&nbsp;");
buf.append("All Rights Reserved.");
return buf.toString();
}
private List<String> createLanguageKeywords() {
List<String> keywords = new ArrayList<String>(10);
keywords.add(language.getLanguageName());
keywords.add("x4o");
keywords.add("eld");
keywords.add("xml");
keywords.add("xsd");
keywords.add("schema");
keywords.add("language");
keywords.add("documentation");
return keywords;
}
private String getLanguageNameUpperCase() {
return language.getLanguageName().toUpperCase();
}
}

View file

@ -0,0 +1,179 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import java.io.IOException;
import java.util.List;
import org.x4o.maisdoc.flake.MaisDocContentPrinter;
import org.x4o.maisdoc.flake.MaisDocContentWriter;
import org.x4o.maisdoc.flake.MaisDocNodeDataConfiguratorMethod;
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
import org.x4o.maisdoc.model.MaisDoc;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocNodeBody;
import org.x4o.maisdoc.model.MaisDocNodeData;
import org.x4o.maisdoc.model.MaisDocWriteEvent;
import org.x4o.sax3.SAX3WriterHtml.Tag;
import org.x4o.xml.eld.doc.EldDocXTreePageWriter.TreeNode;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageModule;
/**
* EldDocWriterElementClass writer all content parts for the ElementClass.
*
* @author Willem Cazander
* @version 1.0 May 29, 2013
*/
public class EldDocWriterElementClass implements MaisDocContentPrinter {
@MaisDocNodeDataConfiguratorMethod(targetClasses={ElementClass.class})
public void configNavBar(MaisDoc doc,MaisDocNode node,MaisDocNodeData data) {
/*
ElementClass ec = (ElementClass)node.getUserData();
Collection<ElementClassAttribute> list = ec.getElementClassAttributes();
if (list.isEmpty()) {
clearHrefContentGroupAlways(doc,"summary","attribute");
}
*/
clearHrefContentGroup(doc,node,"summary","attribute",ElementClassAttribute.class);
clearHrefContentGroup(doc,node,"summary","configurator",ElementConfigurator.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={1},contentGroup="element",contentGroupType="summary")
public void writeElementX4OSummary(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
printApiTableBean(event, "Element", "class","id","description");
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary")
public void writeElementClassAttribute(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
printApiTable(event,"Element Class Attribute Summary",ElementClassAttribute.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={3},contentGroup="configurator",contentGroupType="summary")
public void writeElementConfigurator(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
printApiTable(event,"Element Configurator Summary",ElementConfigurator.class);
}
/*
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary")
public void writeElementX4OAttributeSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
ElementClass ec = (ElementClass)event.getEventObject().getUserData();
Collection<ElementClassAttribute> list = ec.getElementClassAttributes();
if (list.isEmpty()) {
return;
}
ApiDocContentWriter writer = event.getWriter();
writer.docTableStart("Element X4O Attributes", "All Element X4O Attributes Overview",ApiDocContentCss.overviewSummary);
writer.docTableHeader("URI", "Name");
for (ElementClassAttribute attr:list) {
writer.docTableRow(attr.getId(),attr.getDescription());
}
writer.docTableEnd();
}
*/
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={10},contentGroup="bean",contentGroupType="summary")
public void writeElementObjectPropertiesSummary(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
ElementClass ec = (ElementClass)event.getEventObject().getUserData();
Class<?> beanClass = ec.getObjectClass();
if (beanClass==null) {
return;
}
printApiTableBeanClass(event, beanClass, "Object");
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.DESCRIPTION_LINKS,targetClasses={ElementClass.class})
public void writeElementRelationLinks(MaisDocWriteEvent<MaisDocNode> event) throws IOException {
MaisDocContentWriter writer = event.getWriter();
ElementClass ec = (ElementClass)event.getEventObject().getUserData();
ElementNamespace ns = (ElementNamespace)event.getEventObject().getParent().getUserData();
X4OLanguageModule mod = (X4OLanguageModule)event.getEventObject().getParent().getParent().getUserData();
X4OLanguage language = (X4OLanguage)event.getEventObject().getParent().getParent().getParent().getUserData();
// TODO: this is hacky
EldDocXTreePageWriter xtree = (EldDocXTreePageWriter)event.getDoc().findDocPageById("overview-xtree").getPageWriters().get(0);
TreeNode node = xtree.new TreeNode();
node.language=language;
node.module=mod;
node.namespace=ns;
node.elementClass=ec;
String pathPrefix = "../../../../language/";
List<TreeNode> parents = xtree.findParents(node);
writer.printTagStart(Tag.dl);
writer.printTagCharacters(Tag.dt,"All Element Parents:");
writer.printTagStart(Tag.dd);
if (parents.isEmpty()) {
writer.printCharacters("No parent.");
}
for (int i=0;i<parents.size();i++) {
TreeNode n = parents.get(i);
String uri = toElementUri(pathPrefix, n.module, n.namespace, n.elementClass);
writer.printHref(uri, n.namespace.getId()+":"+n.elementClass.getId());
if (i<parents.size()-1) {
writer.printCharacters(",&nbsp;");
}
}
writer.printTagEnd(Tag.dd);
writer.printTagEnd(Tag.dl);
List<TreeNode> childs = xtree.findChilderen(node);
writer.printTagStart(Tag.dl);
writer.printTagCharacters(Tag.dt,"All Element Childeren:");
writer.printTagStart(Tag.dd);
if (childs.isEmpty()) {
writer.printCharacters("No childeren.");
}
for (int i=0;i<childs.size();i++) {
TreeNode n = childs.get(i);
String uri = toElementUri(pathPrefix, n.module, n.namespace, n.elementClass);
writer.printHref(uri, n.namespace.getId()+":"+n.elementClass.getId());
if (i<childs.size()-1) {
writer.printCharacters(",&nbsp;");
}
}
writer.printTagEnd(Tag.dd);
writer.printTagEnd(Tag.dl);
}
private String toElementUri(String pathPrefix,X4OLanguageModule mod,ElementNamespace namespace,ElementClass ec) {
StringBuilder buf = new StringBuilder(100);
if (pathPrefix!=null) {
buf.append(pathPrefix);
}
buf.append(MaisDocContentWriter.toSafeUri(mod.getId()));
buf.append("/");
buf.append(MaisDocContentWriter.toSafeUri(namespace.getId()));
buf.append("/");
buf.append(MaisDocContentWriter.toSafeUri(ec.getId()));
buf.append("/index.html");
return buf.toString();
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import java.io.IOException;
import org.x4o.maisdoc.flake.MaisDocContentPrinter;
import org.x4o.maisdoc.flake.MaisDocNodeDataConfiguratorMethod;
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
import org.x4o.maisdoc.model.MaisDoc;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocNodeBody;
import org.x4o.maisdoc.model.MaisDocNodeData;
import org.x4o.maisdoc.model.MaisDocWriteEvent;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementInterface;
import org.xml.sax.SAXException;
/**
* EldDocWriterElementInterface writers all content parts for the x4o element interface.
*
* @author Willem Cazander
* @version 1.0 Aug 17, 2013
*/
public class EldDocWriterElementInterface implements MaisDocContentPrinter {
@MaisDocNodeDataConfiguratorMethod(targetClasses={ElementInterface.class})
public void configNavBar(MaisDoc doc,MaisDocNode node,MaisDocNodeData data) {
clearHrefContentGroup(doc,node,"summary","attribute",ElementClassAttribute.class);
clearHrefContentGroup(doc,node,"summary","binding",ElementBindingHandler.class);
clearHrefContentGroup(doc,node,"summary","configurator",ElementConfigurator.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={1},contentGroup="interface",contentGroupType="summary")
public void writeElementNamespaceBeanProperties(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTableBean(event,"Interface","description");
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary")
public void writeElementClassAttribute(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Element Class Attribute Summary",ElementClassAttribute.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={3},contentGroup="binding",contentGroupType="summary")
public void writeElementBindingHandler(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Element Binding Handler Summary",ElementBindingHandler.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={4},contentGroup="configurator",contentGroupType="summary")
public void writeElementConfigurator(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Element Configurator Summary",ElementConfigurator.class);
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import java.io.IOException;
import org.x4o.maisdoc.flake.MaisDocContentPrinter;
import org.x4o.maisdoc.flake.MaisDocNodeDataConfiguratorMethod;
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
import org.x4o.maisdoc.model.MaisDoc;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocNodeBody;
import org.x4o.maisdoc.model.MaisDocNodeData;
import org.x4o.maisdoc.model.MaisDocWriteEvent;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementNamespace;
import org.xml.sax.SAXException;
/**
* EldDocWriterElementNamespace writers all content parts for the x4o element namespace context.
*
* @author Willem Cazander
* @version 1.0 Aug 14, 2013
*/
public class EldDocWriterElementNamespace implements MaisDocContentPrinter {
@MaisDocNodeDataConfiguratorMethod(targetClasses={ElementNamespace.class})
public void configNavBar(MaisDoc doc,MaisDocNode node,MaisDocNodeData data) {
clearHrefContentGroup(doc,node,"summary","element",ElementClass.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementNamespace.class},nodeBodyOrders={1},contentGroup="namespace",contentGroupType="summary")
public void writeElementNamespaceBeanProperties(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTableBean(event,"Namespace","description","elementClasses","elementNamespaceInstanceProvider","prefixMapping");
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementNamespace.class},nodeBodyOrders={2},contentGroup="element",contentGroupType="summary")
public void writeElementNamespaceElements(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Element Summary",ElementClass.class);
}
//@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementNamespace.class},nodeBodyOrders={2})
//public void writeElementNamespaceAttributes(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
// printApiTable(event,"Element Summary",ElementClass.class);
//}
}

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import java.io.IOException;
import org.x4o.maisdoc.flake.MaisDocContentCss;
import org.x4o.maisdoc.flake.MaisDocContentPrinter;
import org.x4o.maisdoc.flake.MaisDocContentWriter;
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocNodeBody;
import org.x4o.maisdoc.model.MaisDocWriteEvent;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageModule;
import org.xml.sax.SAXException;
/**
* EldDocWriterLanguage writer all content parts for the x4o language.
*
* @author Willem Cazander
* @version 1.0 May 29, 2013
*/
public class EldDocWriterLanguage implements MaisDocContentPrinter {
// TODO move
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementBindingHandler.class})
public void writeElementBindingHandlerBean(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTableBean(event,"BindingHandler","description");
}
// TODO move
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementConfigurator.class})
public void writeElementConfiguratorBean(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTableBean(event,"Configurator","description");
}
// TODO move
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={ElementClassAttribute.class})
public void writeElementClassAttributeBean(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTableBean(event,"Element Class Attribute","description");
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguage.class},nodeBodyOrders={1})
public void writeLanguageSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
MaisDocContentWriter writer = event.getWriter();
MaisDocNode node = event.getEventObject();
X4OLanguage language = (X4OLanguage)node.getUserData();
int attrHandlers = 0;
int bindHandlers = 0;
int interFaces = 0;
int eleConfigs = 0;
int elements = 0;
int namespaces = 0;
for (X4OLanguageModule mod:language.getLanguageModules()) {
bindHandlers += mod.getElementBindingHandlers().size();
interFaces += mod.getElementInterfaces().size();
eleConfigs += mod.getElementConfiguratorGlobals().size();
for (ElementNamespace ns:mod.getElementNamespaces()) {
namespaces++;
elements += ns.getElementClasses().size();
attrHandlers += ns.getElementNamespaceAttributes().size();
}
}
writer.docTableStart("Language Summary", "Language Stats Summary.",MaisDocContentCss.overviewSummary);
writer.docTableHeader("Name", "Value");
writer.docTableRow("LanguageName:", ""+language.getLanguageName(), null);
writer.docTableRow("LanguageVersion:",""+language.getLanguageVersion(),null);
writer.docTableRow("Modules:",""+language.getLanguageModules().size(),null);
writer.docTableRow("Elements:",""+elements,null);
writer.docTableRow("ElementNamespaces:",""+namespaces,null);
writer.docTableRow("ElementNamespaceAttribute:",""+attrHandlers,null);
writer.docTableRow("ElementInterfaces:",""+interFaces,null);
writer.docTableRow("ElementBindingHandlers:",""+bindHandlers,null);
writer.docTableRow("ElementConfigurators:",""+eleConfigs,null);
writer.docTableEnd();
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguage.class},nodeBodyOrders={2})
public void writeModulesSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Module Summary",X4OLanguageModule.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguage.class},nodeBodyOrders={3})
public void writeNamespaceSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
MaisDocContentWriter writer = event.getWriter();
MaisDocNode node = event.getEventObject();
X4OLanguage language = (X4OLanguage)node.getUserData();
writer.docTableStart("Namespace Summary", "All Language Namespaces Overview",MaisDocContentCss.overviewSummary);
writer.docTableHeader("ID", "URI");
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
writer.docTableRowLink("language/"+MaisDocContentWriter.toSafeUri(mod.getId())+"/"+MaisDocContentWriter.toSafeUri(ns.getId())+"/index.html",ns.getId(),ns.getUri());
}
}
writer.docTableEnd();
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import org.x4o.xml.element.ElementNamespaceAttribute;
import java.io.IOException;
import org.x4o.maisdoc.flake.MaisDocContentPrinter;
import org.x4o.maisdoc.flake.MaisDocNodeDataConfiguratorMethod;
import org.x4o.maisdoc.flake.MaisDocNodeWriterMethod;
import org.x4o.maisdoc.model.MaisDoc;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocNodeBody;
import org.x4o.maisdoc.model.MaisDocNodeData;
import org.x4o.maisdoc.model.MaisDocWriteEvent;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.lang.X4OLanguageModule;
import org.xml.sax.SAXException;
/**
* EldDocWriterLanguageModukle writers all content parts for the x4o language module.
*
* @author Willem Cazander
* @version 1.0 Aug 10, 2013
*/
public class EldDocWriterLanguageModule implements MaisDocContentPrinter {
@MaisDocNodeDataConfiguratorMethod(targetClasses={X4OLanguageModule.class})
public void configNavBar(MaisDoc doc,MaisDocNode node,MaisDocNodeData data) {
clearHrefContentGroup(doc,node,"summary","interface",ElementInterface.class);
clearHrefContentGroup(doc,node,"summary","binding",ElementBindingHandler.class);
clearHrefContentGroup(doc,node,"summary","attribute",ElementNamespaceAttribute.class);
clearHrefContentGroup(doc,node,"summary","configurator",ElementConfigurator.class);
clearHrefContentGroup(doc,node,"summary","namespace",ElementNamespace.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={1},contentGroup="interface",contentGroupType="summary")
public void writeInterfaceSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Interface Summary",ElementInterface.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={2},contentGroup="binding",contentGroupType="summary")
public void writeBindingSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Binding Summary",ElementBindingHandler.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={3},contentGroup="attribute",contentGroupType="summary")
public void writeAttributeSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Attribute Summary",ElementNamespaceAttribute.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={4},contentGroup="configurator",contentGroupType="summary")
public void writeConfigutorSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Configurator Summary",ElementConfigurator.class);
}
@MaisDocNodeWriterMethod(nodeBody=MaisDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={5},contentGroup="namespace",contentGroupType="summary")
public void writeNamespaceSummary(MaisDocWriteEvent<MaisDocNode> event) throws SAXException, IOException {
printApiTable(event,"Namespace Summary",ElementNamespace.class);
}
}

View file

@ -0,0 +1,332 @@
/*
* Copyright (c) 2004-2014, 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.doc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.x4o.maisdoc.flake.MaisDocContentWriter;
import org.x4o.maisdoc.flake.DefaultPageWriterTree;
import org.x4o.maisdoc.model.MaisDoc;
import org.x4o.maisdoc.model.MaisDocNode;
import org.x4o.maisdoc.model.MaisDocPage;
import org.x4o.maisdoc.model.MaisDocPageWriter;
import org.x4o.maisdoc.model.MaisDocWriteEvent;
import org.x4o.sax3.SAX3WriterHtml.Tag;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageModule;
/**
* EldDocXTreePageWriter for dom overview of tree but as seperate page.
*
* @author Willem Cazander
* @version 1.0 May 29, 2013
*/
public class EldDocXTreePageWriter extends DefaultPageWriterTree implements MaisDocPageWriter {
public static MaisDocPage createDocPage() {
return new MaisDocPage("overview-xtree","XTree","XTree of dom elements.",new EldDocXTreePageWriter());
}
// TODO: rm this old tree code;
private void walkTree(TreeNode node,MaisDocContentWriter writer,String pathPrefix) throws IOException {
String href = toElementUri(pathPrefix,node.module,node.namespace,node.elementClass);
writer.printTagStart(Tag.ul);
writer.printTagStart(Tag.li,"",null,"circle");
writer.printCharacters(node.namespace.getId());
writer.printCharacters(":");
writer.printHref(href, node.elementClass.getId(), node.elementClass.getId(), "strong");
writer.printTagEnd(Tag.li);
List<TreeNode> childs = findChilderen(node);
for (TreeNode child:childs) {
walkTree(child,writer,pathPrefix);
}
writer.printTagEnd(Tag.ul);
}
/**
* TODO: remove this
* @see org.x4o.maisdoc.flake.DefaultPageWriterTree#writePageContent(org.x4o.maisdoc.model.MaisDocWriteEvent)
*/
@Override
public void writePageContent(MaisDocWriteEvent<MaisDocPage> e) throws IOException {
//selectRootNode(e.getDoc()); // create
MaisDoc doc = e.getDoc();
X4OLanguage language = (X4OLanguage)doc.getRootNode().getUserData();
String pathPrefix = "language/";
// temp print old way
List<TreeNode> rootNodes = new ArrayList<TreeNode>(3);
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
if (ns.getLanguageRoot()!=null && ns.getLanguageRoot()) {
// found language root elements.
for (ElementClass ec:ns.getElementClasses()) {
TreeNode node = new TreeNode();
node.language=language;
node.module=mod;
node.namespace=ns;
node.elementClass=ec;
rootNodes.add(node);
}
}
}
}
Collections.sort(rootNodes,new TreeNodeComparator());
for (TreeNode rootNode:rootNodes) {
walkTree(rootNode,e.getWriter(),pathPrefix);
}
}
private String toElementUri(String pathPrefix,X4OLanguageModule mod,ElementNamespace namespace,ElementClass ec) {
StringBuilder buf = new StringBuilder(100);
if (pathPrefix!=null) {
buf.append(pathPrefix);
}
buf.append(MaisDocContentWriter.toSafeUri(mod.getId()));
buf.append("/");
buf.append(MaisDocContentWriter.toSafeUri(namespace.getId()));
buf.append("/");
buf.append(MaisDocContentWriter.toSafeUri(ec.getId()));
buf.append("/index.html");
return buf.toString();
}
/**
* Overrided to select the dom view of the tree.
* @see org.x4o.maisdoc.flake.DefaultPageWriterTree#selectRootNode(org.x4o.maisdoc.model.MaisDoc)
*/
@Override
protected MaisDocNode selectRootNode(MaisDoc doc) {
try {
return createXTree(doc);
} catch (IOException e) {
throw new IllegalStateException("Could not create XTree for: "+doc.getName()+" error: "+e.getMessage(),e);
}
}
private MaisDocNode createXTree(MaisDoc doc) throws IOException {
X4OLanguage language = (X4OLanguage)doc.getRootNode().getUserData();
MaisDocNode root = new MaisDocNode(language,"root","Root","Language root");
List<TreeNode> rootNodes = new ArrayList<TreeNode>(3);
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
if (ns.getLanguageRoot()!=null && ns.getLanguageRoot()) {
// found language root elements.
for (ElementClass ec:ns.getElementClasses()) {
TreeNode node = new TreeNode();
node.language=language;
node.module=mod;
node.namespace=ns;
node.elementClass=ec;
rootNodes.add(node);
}
}
}
}
Collections.sort(rootNodes,new TreeNodeComparator());
for (TreeNode rootNode:rootNodes) {
walkTree(rootNode,"../");
}
return root;
}
private void walkTree(TreeNode node,String pathPrefix) throws IOException {
//String href = toElementUri(pathPrefix,node.module,node.namespace,node.elementClass);
List<TreeNode> childs = findChilderen(node);
for (TreeNode child:childs) {
walkTree(child,pathPrefix);
}
}
class TreeNode {
X4OLanguage language;
X4OLanguageModule module;
ElementNamespace namespace;
ElementClass elementClass;
TreeNode parent;
int indent = 0;
}
public List<TreeNode> findChilderen(TreeNode node) {
List<TreeNode> result = new ArrayList<TreeNode>(10);
if (node.indent>20) {
return result; // hard fail limit
}
for (X4OLanguageModule mod:node.language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
for (ElementClass ec:ns.getElementClasses()) {
TreeNode n=null;
List<String> tags = ec.getElementParents(node.namespace.getUri());
if (tags!=null && tags.contains(node.elementClass.getId())) {
n = new TreeNode();
n.language=node.language;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
} else {
if (ec.getObjectClass()==null) {
continue;
}
// Check interfaces of parent , and see if child tag is there.
for (ElementInterface ei:node.language.findElementInterfaces(ec.getObjectClass())) {
List<String> eiTags = ei.getElementParents(node.namespace.getUri());
if (eiTags!=null && eiTags.contains(node.elementClass.getId())) {
n = new TreeNode();
n.language=node.language;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
break;
}
}
if (node.elementClass.getObjectClass()==null) {
continue;
}
List<ElementBindingHandler> binds = node.language.findElementBindingHandlers(node.elementClass.getObjectClass(), ec.getObjectClass());
if (binds.isEmpty()==false) {
n = new TreeNode();
n.language=node.language;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
}
}
if (n!=null && isInTree(node,n)==false) {
result.add(n);
}
}
}
}
Collections.sort(result,new TreeNodeComparator());
return result;
}
private boolean isInTree(TreeNode node,TreeNode checkNode) {
if ( node.namespace.getUri().equals(checkNode.namespace.getUri()) &&
node.elementClass.getId().equals(checkNode.elementClass.getId())
) {
return true;
}
if (node.parent!=null) {
return isInTree(node.parent,checkNode);
}
return false;
}
public List<TreeNode> findParents(TreeNode node) {
List<TreeNode> result = new ArrayList<TreeNode>(10);
TreeNode n=null;
for (X4OLanguageModule mod:node.language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
List<String> tags = node.elementClass.getElementParents(ns.getUri());
if (tags!=null) {
for (ElementClass ec:ns.getElementClasses()) {
if (tags.contains(ec.getId())) {
n = new TreeNode();
n.language=node.language;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
result.add(n);
}
}
}
for (ElementClass ec:ns.getElementClasses()) {
// Check interfaces of parent , and see if child tag is there.
if (node.elementClass.getObjectClass()!=null) {
for (ElementInterface ei:node.language.findElementInterfaces(node.elementClass.getObjectClass())) {
List<String> eiTags = ei.getElementParents(ns.getUri());
if (eiTags!=null && eiTags.contains(ec.getId())) {
n = new TreeNode();
n.language=node.language;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
result.add(n);
break;
}
}
}
if (ec.getObjectClass()==null) {
continue;
}
if (node.elementClass.getObjectClass()==null) {
continue;
}
List<ElementBindingHandler> binds = node.language.findElementBindingHandlers(ec.getObjectClass(),node.elementClass.getObjectClass());
if (binds.isEmpty()==false) {
n = new TreeNode();
n.language=node.language;
n.module=mod;
n.namespace=ns;
n.elementClass=ec;
n.indent=node.indent+1;
n.parent=node;
if (isInTree(node,n)==false) {
result.add(n);
}
}
}
}
}
Collections.sort(result,new TreeNodeComparator());
return result;
}
class TreeNodeComparator implements Comparator<TreeNode> {
public int compare(TreeNode o1,TreeNode o2) {
return o1.elementClass.getId().compareTo(o2.elementClass.getId());
}
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2014, 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 documentation classes.
*
* @author Willem Cazander
* @since 1.0 Aug 26, 2010
*/
package org.x4o.xml.eld.doc;

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2004-2014, 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 {
/**
* Add the xml attribute 'name' to ElementClassAttribute as attribute alias.
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
* @throws ElementException When name attribute is not set or when parent element object is not ElementClassAttribute interface.
*/
@Override
public void doElementEnd() throws ElementException {
String alias = getAttributes().get("name");
if (alias==null) {
throw new ElementException("'name' attribute is not set on: "+getElementClass().getId());
}
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,113 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* Config an element body as attribute of parent elememt.
* @param element The element to config.
* @throws ElementConfiguratorException Is thrown when object tree is non valid.
* @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.length()==0) {
throw new ElementConfiguratorException(this,"name attribute is empty.");
}
if (bodyType==null) {
bodyType = ElementType.characters.name();
}
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.trim().length()==0) {
return;
}
element.getAttributes().put(name, value);
}
private String fetchBodyType(Element element,ElementType elementType) {
StringBuilder buf = new StringBuilder(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,94 @@
/*
* Copyright (c) 2004-2014, 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.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.lang.X4OLanguageClassLoader;
/**
* 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;
/**
* Creates a BeanElement.
*/
public BeanElement() {
constructorArguments = new ArrayList<Object>(3);
}
/**
* On start of element create the element object, filled from the bean.class attribute.
* @throws ElementException When bean could not be created.
*/
@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 (ClassNotFoundException e) {
throw new ElementException(e);
} catch (InstantiationException e) {
throw new ElementException(e);
} catch (IllegalAccessException e) {
throw new ElementException(e);
} catch (NoSuchMethodException e) {
throw new ElementException(e);
} catch (IllegalArgumentException e) {
throw new ElementException(e);
} catch (InvocationTargetException e) {
throw new ElementException(e);
}
}
/**
* Add bean constructor arguments.
* @param argu The argument to add to constructor.
*/
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,80 @@
/*
* Copyright (c) 2004-2014, 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 {
/**
* Starts the description element and validates that it is not root and parent is meta base.
* @throws ElementException When parent element object is not meta base object.
* @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");
}
}
/**
* The description elememt body characters are stored as element object.
* @param characters The text of the description.
* @throws ElementException When super has error.
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
*/
@Override
public void doCharacters(String characters) throws ElementException {
super.doCharacters(characters);
setElementObject(characters);
}
/**
* Ends the description element and sets the description on the parent.
* @throws ElementException When parent element object is not meta base object.
* @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-2014, 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.ElementClassBase;
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()
* @throws ElementException When parent is not ElementClassBase.
*/
@Override
public void doElementEnd() throws ElementException {
String tag = getAttributes().get("tag");
if (tag==null) {
throw new ElementException("'tag' attribute is not set on: "+getElementClass().getId());
}
String namespaceUri = getAttributes().get("uri");
if (namespaceUri==null) {
namespaceUri = getParent().getParent().getAttributes().get("uri"); // copy uri from namespace element.
}
if (getParent().getElementObject() instanceof ElementClassBase) {
((ElementClassBase)getParent().getElementObject()).addElementParent(namespaceUri,tag);
} else {
throw new ElementException("Wrong parent class is not ElementClassBase but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2004-2014, 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<ElementClassAttribute> {
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.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,ElementClassAttribute parentObject,Object childObject) throws ElementBindingHandlerException {
if (childObject instanceof ObjectConverter) {
parentObject.setObjectConverter((ObjectConverter)childObject);
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
public void createChilderen(Element parentElement,ElementClassAttribute parentObject) throws ElementBindingHandlerException {
createChild(parentElement, parentObject.getObjectConverter());
}
}

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2004-2014, 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<ElementClass> {
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.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,ElementClass parent, Object childObject) throws ElementBindingHandlerException {
if (childObject instanceof ElementClassAttribute) {
parent.addElementClassAttribute((ElementClassAttribute)childObject);
}
if (childObject instanceof ElementConfigurator) {
parent.addElementConfigurators((ElementConfigurator)childObject);
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
public void createChilderen(Element parentElement,ElementClass parent) throws ElementBindingHandlerException {
for (ElementClassAttribute child:parent.getElementClassAttributes()) {
createChild(parentElement, child);
}
for (ElementConfigurator child:parent.getElementConfigurators()) {
createChild(parentElement, child);
}
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2004-2014, 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.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<ElementInterface> {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClassAttribute.class,
ElementConfigurator.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.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,ElementInterface parent, Object childObject) throws ElementBindingHandlerException {
if (childObject instanceof ElementClassAttribute) {
parent.addElementClassAttribute((ElementClassAttribute)childObject);
}
if (childObject instanceof ElementConfigurator) {
parent.addElementConfigurators((ElementConfigurator)childObject);
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
public void createChilderen(Element parentElement,ElementInterface parent) throws ElementBindingHandlerException {
for (ElementClassAttribute child:parent.getElementClassAttributes()) {
createChild(parentElement, child);
}
for (ElementConfigurator child:parent.getElementConfigurators()) {
createChild(parentElement, child);
}
}
}

View file

@ -0,0 +1,176 @@
/*
* Copyright (c) 2004-2014, 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.eld.EldModuleLoader;
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.ElementConfiguratorGlobal;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageModuleLocal;
/**
* 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<X4OLanguageModuleLocal> {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementInterface.class,
ElementNamespace.class,
ElementBindingHandler.class,
ElementConfiguratorGlobal.class,
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return X4OLanguageModuleLocal.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,X4OLanguageModuleLocal languageModule, Object childObject) throws ElementBindingHandlerException {
X4OLanguage x4oParsingContext = EldModuleLoader.getLanguage(childElement.getLanguageSession());
if (x4oParsingContext==null) {
return;
}
if (languageModule==null) {
return;
}
if (childObject instanceof ElementInterface) {
ElementInterface elementInterface = (ElementInterface)childObject;
languageModule.addElementInterface(elementInterface);
return;
}
if (childObject instanceof ElementNamespace) {
ElementNamespace elementNamespace = (ElementNamespace)childObject;
if (elementNamespace.getId()==null) {
throw new NullPointerException("Can add elementNamespace without id.");
}
// TODO: no language here so move to EL default on eld attribute tag
if (elementNamespace.getId()!=null) {
StringBuilder buf = new StringBuilder(30);
for (char c:elementNamespace.getId().toLowerCase().toCharArray()) {
if (Character.isLetter(c)) {buf.append(c);}
if (Character.isDigit(c)) {buf.append(c);}
if ('-'==c) {buf.append(c);}
}
String id = buf.toString();
elementNamespace.setId(id);
}
if (elementNamespace.getUri()==null) {
elementNamespace.setUri(
"http://"+languageModule.getProviderHost()+
"/xml/ns/"+x4oParsingContext.getLanguageName()+
"-"+elementNamespace.getId());
}
if (elementNamespace.getSchemaUri()==null) {
elementNamespace.setSchemaUri(
"http://"+languageModule.getProviderHost()+
"/xml/ns/"+x4oParsingContext.getLanguageName()+
"-"+elementNamespace.getId()+
"-"+x4oParsingContext.getLanguageVersion()+
".xsd"
);
}
if (elementNamespace.getSchemaResource()==null) {
elementNamespace.setSchemaResource(
x4oParsingContext.getLanguageName()+
"-"+elementNamespace.getId()+
"-"+x4oParsingContext.getLanguageVersion()+
".xsd"
);
}
if (elementNamespace.getSchemaPrefix()==null) {
elementNamespace.setSchemaPrefix(elementNamespace.getId());
}
try {
elementNamespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(childElement.getLanguageSession().getLanguage().getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementBindingHandlerException("Error loading: "+e.getMessage(),e);
}
try {
elementNamespace.getElementNamespaceInstanceProvider().start(x4oParsingContext, elementNamespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementBindingHandlerException("Error starting: "+e.getMessage(),e);
}
languageModule.addElementNamespace(elementNamespace);
return;
}
if (childObject instanceof ElementBindingHandler) {
ElementBindingHandler elementBindingHandler = (ElementBindingHandler)childObject;
languageModule.addElementBindingHandler(elementBindingHandler);
return;
}
if (childObject instanceof ElementConfiguratorGlobal) {
ElementConfiguratorGlobal elementConfigurator = (ElementConfiguratorGlobal)childObject;
languageModule.addElementConfiguratorGlobal(elementConfigurator);
return;
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
public void createChilderen(Element parentElement,X4OLanguageModuleLocal parent) throws ElementBindingHandlerException {
for (ElementInterface child:parent.getElementInterfaces()) {
createChild(parentElement, child);
}
for (ElementNamespace child:parent.getElementNamespaces()) {
createChild(parentElement, child);
}
for (ElementBindingHandler child:parent.getElementBindingHandlers()) {
createChild(parentElement, child);
}
for (ElementConfiguratorGlobal child:parent.getElementConfiguratorGlobals()) {
createChild(parentElement, child);
}
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2014, 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.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceAttribute;
/**
* ElementNamespaceBindingHandler binds ElementClass into namespace.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementNamespaceBindingHandler extends AbstractElementBindingHandler<ElementNamespace> {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClass.class,
ElementNamespaceAttribute.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementNamespace.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,ElementNamespace parent, Object childObject) throws ElementBindingHandlerException {
if (childObject instanceof ElementClass) {
ElementClass elementClass = (ElementClass)childObject;
if (elementClass.getId()==null && elementClass.getObjectClass()!=null) {
elementClass.setId(elementClass.getObjectClass().getSimpleName()); // TODO: move to defaults layer
}
parent.addElementClass(elementClass);
}
if (childObject instanceof ElementNamespaceAttribute) {
ElementNamespaceAttribute elementNamespaceAttribute = (ElementNamespaceAttribute)childObject;
parent.addElementNamespaceAttribute(elementNamespaceAttribute);
return;
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
public void createChilderen(Element parentElement,ElementNamespace parent) throws ElementBindingHandlerException {
for (ElementClass child:parent.getElementClasses()) {
createChild(parentElement, child);
}
for (ElementNamespaceAttribute child:parent.getElementNamespaceAttributes()) {
createChild(parentElement, child);
}
}
}

View file

@ -0,0 +1,286 @@
/*
* Copyright (c) 2004-2014, 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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementObjectPropertyValueException;
/**
* Binds to objects together with a method found by reflection.
*
* @author Willem Cazander
* @version 1.0 Nov 21, 2007
*/
public class ElementRefectionBindingHandler extends AbstractElementBindingHandler<Object> {
private Class<?> parentClass = null;
private Class<?> childClass = null;
private String property = null;
private String addMethod = null;
private String getMethod = null;
private String skipChilderenClassRegex = 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.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
@SuppressWarnings(value = {"unchecked", "rawtypes"})
public void bindChild(Element childElement, Object parentObject, Object childObject) throws ElementBindingHandlerException {
if (parentClass==null | childClass==null) {
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" addMethod="+addMethod+".");
}
if (property != null) { // Tmp hanky code here...
try {
String pop = property.substring(0,1).toUpperCase() + property.substring(1);
Method propType = parentObject.getClass().getMethod("get" + pop);
if (List.class.isAssignableFrom(propType.getReturnType())) {
Object data = childElement.getLanguageSession().getElementObjectPropertyValue().getProperty(parentObject, property);
if (data == null) {
// TODO: redo wrong type, add accesser object return from ElementObjectPropertyValue !!
childElement.getLanguageSession().getElementObjectPropertyValue().setProperty(parentObject, property, new ArrayList<>());
data = childElement.getLanguageSession().getElementObjectPropertyValue().getProperty(parentObject, property);
}
if (data instanceof Collection) {
Collection dataCollection = (Collection)data;
dataCollection.add(childObject);
return;
}
throw new ElementBindingHandlerException("Unhandled property collection type: "+data.getClass()+" on: "+parentObject.getClass()+" id:"+getId());
}
childElement.getLanguageSession().getElementObjectPropertyValue().setProperty(parentObject, property, childObject);
return;
} catch (/*ElementObjectPropertyValueException |*/ Exception e) {
throw new ElementBindingHandlerException(getId() + " error " + e.getMessage(), e);
}
}
// TODO: remove old...
Method[] ms = parentObject.getClass().getMethods();
for (Method m:ms) {
Class<?>[] types = m.getParameterTypes();
if (types.length == 0) {
continue;
}
if (types.length > 1) {
continue;
}
if (addMethod.equalsIgnoreCase(m.getName())==false) {
continue;
}
if (types[0].isAssignableFrom(childClass)) {
try {
m.invoke(parentObject, childObject);
} catch (Exception e) {
throw new ElementBindingHandlerException("Error invoke binding method of: "+getId()+" error: "+e.getMessage(),e);
}
return;
}
}
throw new ElementBindingHandlerException("Could not find method: "+addMethod+" on: "+parentObject.getClass()+" id:"+getId());
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
public void createChilderen(Element parentElement,Object parentObject) throws ElementBindingHandlerException {
if (parentClass==null | childClass==null) {
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" getMethod="+getMethod+".");
}
if (property != null) {
try {
Object data = parentElement.getLanguageSession().getElementObjectPropertyValue().getProperty(parentObject, property);
createSafeChildLoop(parentElement, data);
} catch (ElementObjectPropertyValueException e) {
throw new ElementBindingHandlerException(e.getMessage(), e);
}
return;
}
Method[] ms = parentObject.getClass().getMethods();
for (Method m:ms) {
Class<?>[] types = m.getParameterTypes();
if (types.length != 0) {
continue;
}
if (getMethod.equalsIgnoreCase(m.getName())==false) {
continue;
}
Object result;
try {
result = m.invoke(parentObject, new Object[]{});
} catch (Exception e) {
throw new ElementBindingHandlerException("Invoke error: "+e.getMessage()+" from: "+getMethod+" on: "+parentObject+" id:"+getId(),e);
}
createSafeChildLoop(parentElement, result);
return;
}
throw new ElementBindingHandlerException("Could not find method: "+getMethod+" on: "+parentObject.getClass()+" id:"+getId());
}
@SuppressWarnings("rawtypes")
protected void createSafeChildLoop(Element parentElement,Object result) throws ElementBindingHandlerException {
if (result==null) {
return; // null is no childeren
}
if (result instanceof List) {
for (Object o:(List)result) {
createSafeChild(parentElement, o);
}
return;
} else if (result instanceof Collection) {
for (Object o:(Collection)result) {
createSafeChild(parentElement, o);
}
return;
} else if (result.getClass().isArray()) {
for (Object o:(Object[])result) {
createSafeChild(parentElement, o);
}
return;
} else if (childClass.isAssignableFrom(result.getClass())) {
createSafeChild(parentElement, result);
return;
} else {
throw new ElementBindingHandlerException("Unsupported return type: "+result.getClass()+" need: "+childClass+" from: "+getMethod+" on: "+parentElement.getElementObject().getClass()+" id:"+getId());
}
}
/**
* Only create child when class matches and regex doesn't exclude it.
* @param parentElement The element to create childeren for.
* @param childObject The childObject.
*/
protected void createSafeChild(Element parentElement,Object childObject) {
if (childClass.isAssignableFrom(childObject.getClass())==false) {
return;
}
if (skipChilderenClassRegex!=null && childObject.getClass().getName().matches(skipChilderenClassRegex)) {
return; // skip
}
createChild(parentElement,childObject);
}
/**
* @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 addMethod
*/
public String getAddMethod() {
return addMethod;
}
/**
* @param addMethod the addMethod to set
*/
public void setAddMethod(String addMethod) {
this.addMethod = addMethod;
}
/**
* @return the getMethod
*/
public String getGetMethod() {
return getMethod;
}
/**
* @param getMethod the getMethod to set
*/
public void setGetMethod(String getMethod) {
this.getMethod = getMethod;
}
/**
* @return the property
*/
public String getProperty() {
return property;
}
/**
* @param property the property to set
*/
public void setProperty(String property) {
this.property = property;
}
/**
* @return the skipChilderenClassRegex
*/
public String getSkipChilderenClassRegex() {
return skipChilderenClassRegex;
}
/**
* @param skipChilderenClassRegex the skipChilderenClassRegex to set
*/
public void setSkipChilderenClassRegex(String skipChilderenClassRegex) {
this.skipChilderenClassRegex = skipChilderenClassRegex;
}
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2004-2014, 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.eld.EldModuleLoader;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.lang.X4OLanguageModule;
/**
* 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()
* @throws ElementException When module element is used and non-root element.
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()!=null) {
throw new ElementException("Need to be root tag");
}
X4OLanguageModule elementLanguageModule = EldModuleLoader.getLanguageModule(getLanguageSession());
setElementObject(elementLanguageModule);
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2014, 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.ElementNamespaceAttribute;
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 ElementNamespaceAttribute) {
((ElementNamespaceAttribute)getParent().getElementObject()).addNextAttribute(param);
} else {
throw new ElementException("Wrong parent class");
}
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2014, 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()
* @throws ElementException Gets thrown when name is not set or element object is not an element class instance.
*/
@Override
public void doElementEnd() throws ElementException {
String phase = getAttributes().get("name");
if (phase==null) {
throw new ElementException("'name' attribute is not set on: "+getElementClass().getId());
}
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,76 @@
/*
* Copyright (c) 2004-2014, 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<StringSplitConverter> {
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.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,StringSplitConverter parent, Object childObject) throws ElementBindingHandlerException {
if (childObject instanceof StringSplitConverterStep) {
parent.addStringSplitConverterStep((StringSplitConverterStep)childObject);
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
@Override
public void createChilderen(Element parentElement,StringSplitConverter parentObject) throws ElementBindingHandlerException {
for (StringSplitConverterStep child:parentObject.getStringSplitConverterSteps()) {
createChild(parentElement, child);
}
}
}

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2004-2014, 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<StringSplitConverterStep> {
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.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement,StringSplitConverterStep parent, Object childObject) throws ElementBindingHandlerException {
if (childObject instanceof ObjectConverter) {
parent.setObjectConverter((ObjectConverter)childObject);
}
}
/**
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
*/
@Override
public void createChilderen(Element parentElement,StringSplitConverterStep parentObject) throws ElementBindingHandlerException {
createChild(parentElement, parentObject.getObjectConverter());
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2014, 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 Element Language Definition language elements.
*
*
* @since 1.0
*/
package org.x4o.xml.eld.lang;

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2014, 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 Element Language Definition drivers.
*
*
* @since 1.0
*/
package org.x4o.xml.eld;

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2004-2014, 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.IOException;
import org.x4o.sax3.io.SAX3PropertyConfig;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.task.AbstractX4OLanguageTask;
import org.x4o.xml.lang.task.X4OLanguageTaskException;
import org.x4o.xml.lang.task.X4OLanguageTaskExecutor;
import org.xml.sax.SAXException;
/**
* EldXsdLanguageTask is support class to write schema files from eld.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class EldXsdLanguageTask extends AbstractX4OLanguageTask {
public static final String TASK_ID = "eld-xsd";
private static final String TASK_NAME = "ELD XSD Writer Task";
private static final String TASK_DESC = "Writes out the schema of the language elements.";
public EldXsdLanguageTask() {
super(TASK_ID,TASK_NAME,TASK_DESC,EldXsdWriter.DEFAULT_PROPERTY_CONFIG);
}
/**
* Executes this language task.
*/
protected X4OLanguageTaskExecutor createTaskExecutorChecked(final SAX3PropertyConfig config) {
return new X4OLanguageTaskExecutor() {
public void execute(X4OLanguage language) throws X4OLanguageTaskException {
try {
new EldXsdWriter(language,config).writeSchema();
} catch (SAXException e) {
throw new X4OLanguageTaskException(config,e.getMessage(),e);
} catch (IOException e) {
throw new X4OLanguageTaskException(config,e.getMessage(),e);
}
}
};
}
}

View file

@ -0,0 +1,166 @@
/*
* Copyright (c) 2004-2014, 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 java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.x4o.sax3.SAX3WriterXml;
import org.x4o.sax3.SAX3WriterXsd;
import org.x4o.sax3.io.SAX3PropertyConfig;
import org.x4o.sax3.io.SAX3PropertyConfig.PropertyConfigItem;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage;
import org.xml.sax.SAXException;
/**
* EldXsdWriter creates XML Schema files from a x4o language.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2012
*/
public class EldXsdWriter {
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"eld-xsd/";
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path";
public final static String OUTPUT_DOCUMENTATION = PROPERTY_CONTEXT_PREFIX+"output/documentation";
public final static String FILTER_NAMESPACE = PROPERTY_CONTEXT_PREFIX+"filter/namespace";
public final static String FILTER_ELEMENT = PROPERTY_CONTEXT_PREFIX+"filter/element";
public final static String PROLOG_SEPERATOR_LINE = PROPERTY_CONTEXT_PREFIX+"prolog/seperator-line";
public final static String PROLOG_SEPERATOR_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/seperator-enable";
public final static String PROLOG_GENERATED_VERSION = PROPERTY_CONTEXT_PREFIX+"prolog/generated-version";
public final static String PROLOG_GENERATED_BY = PROPERTY_CONTEXT_PREFIX+"prolog/generated-by";
public final static String PROLOG_GENERATED_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/generated-enable";
public final static String PROLOG_XMLNS_INFO_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/xmlns-info-enable";
public final static String PROLOG_XMLNS_DESC_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/xmlns-desc-enable";
private static final String DEFAULT_PROLOG_SEPERATOR = " ===================================================================== ";
static {
DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true,SAX3WriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(true,OUTPUT_PATH, File.class ),
new PropertyConfigItem(OUTPUT_DOCUMENTATION, Boolean.class, true),
new PropertyConfigItem(FILTER_NAMESPACE, String.class ),
new PropertyConfigItem(FILTER_ELEMENT, String.class ),
new PropertyConfigItem(PROLOG_SEPERATOR_LINE, String.class, DEFAULT_PROLOG_SEPERATOR),
new PropertyConfigItem(PROLOG_SEPERATOR_ENABLE, Boolean.class, true),
new PropertyConfigItem(PROLOG_GENERATED_VERSION, String.class ),
new PropertyConfigItem(PROLOG_GENERATED_BY, String.class ),
new PropertyConfigItem(PROLOG_GENERATED_ENABLE, Boolean.class, true),
new PropertyConfigItem(PROLOG_XMLNS_INFO_ENABLE, Boolean.class, true),
new PropertyConfigItem(PROLOG_XMLNS_DESC_ENABLE, Boolean.class, true)
);
}
private final X4OLanguage language;
private final SAX3PropertyConfig propertyConfig;
public EldXsdWriter(X4OLanguage language,SAX3PropertyConfig parentConfig) {
this.language=language;
this.propertyConfig=new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
this.propertyConfig.copyParentProperties(parentConfig);
}
private void checkNamespace(ElementNamespace ns) {
if (ns.getSchemaResource()==null) {
throw new NullPointerException("Can't generate xsd for namespace without schemaResource uri: "+ns.getUri());
}
if (ns.getSchemaResource().length()==0) {
throw new NullPointerException("Can't generate xsd for namespace with empty schemaResource uri: "+ns.getUri());
}
}
public void writeSchema() throws SAXException, IOException {
File basePath = propertyConfig.getPropertyFile(OUTPUT_PATH);
String encoding = propertyConfig.getPropertyString(SAX3WriterXml.OUTPUT_ENCODING);
String namespace = propertyConfig.getPropertyString(FILTER_NAMESPACE);
if (basePath==null) {
throw new NullPointerException("Can't write schema to null output path.");
}
if (!basePath.exists()) {
basePath.mkdirs();
}
if (namespace!=null) {
ElementNamespace ns = language.findElementNamespace(namespace);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespace);
}
checkNamespace(ns);
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
try {
SAX3WriterXsd xsdWriter = new SAX3WriterXsd(wr,encoding);
xsdWriter.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), xsdWriter);
} finally {
wr.close();
}
return;
}
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
checkNamespace(ns);
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
try {
SAX3WriterXsd xsdWriter = new SAX3WriterXsd(wr,encoding);
xsdWriter.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), xsdWriter);
} finally {
wr.close();
}
}
}
}
private void generateSchema(String namespaceUri,SAX3WriterXsd xsdWriter) throws IOException {
ElementNamespace ns = language.findElementNamespace(namespaceUri);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespaceUri);
}
String filterElement = propertyConfig.getPropertyString(FILTER_ELEMENT);
EldXsdWriterElement xsdWriterElement = new EldXsdWriterElement(xsdWriter,language,propertyConfig);
xsdWriterElement.startNamespaces(namespaceUri);
xsdWriterElement.startSchema(ns);
for (ElementClass ec:ns.getElementClasses()) {
if (filterElement!=null && !ec.getId().equals(filterElement)) {
continue;
}
xsdWriterElement.writeElementClass(ec,ns);
}
for (ElementClass ec:ns.getElementClasses()) {
if (filterElement!=null && !ec.getId().equals(filterElement)) {
continue;
}
xsdWriterElement.writeElement(ec,ns);
}
xsdWriterElement.endSchema();
}
}

View file

@ -0,0 +1,474 @@
/*
* Copyright (c) 2004-2014, 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.IOException;
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.sax3.SAX3WriterXml;
import org.x4o.sax3.SAX3WriterXsd;
import org.x4o.sax3.SAX3WriterXsd.Tag;
import org.x4o.sax3.io.SAX3PropertyConfig;
import org.x4o.sax3.io.SAX3XMLConstants;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementMetaBase;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceAttribute;
import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage;
import org.xml.sax.SAXException;
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 EldXsdWriterElement {
private SAX3PropertyConfig propertyConfig;
protected X4OLanguage language = null;
protected SAX3WriterXsd xsdWriter = null;
protected String writeNamespace = null;
protected Map<String, String> namespaces = null;
public EldXsdWriterElement(SAX3WriterXsd xsdWriter,X4OLanguage language,SAX3PropertyConfig propertyConfig) {
this.xsdWriter=xsdWriter;
this.language=language;
this.propertyConfig=propertyConfig;
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 (X4OLanguageModule modContext:language.getLanguageModules()) {
for (ElementNamespace nsContext:modContext.getElementNamespaces()) {
for (ElementClass ec:nsContext.getElementClasses()) {
Class<?> objectClass = null;
if (ec.getObjectClass()!=null) {
objectClass = ec.getObjectClass();
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
for (ElementClass checkClass:ns.getElementClasses()) {
if (checkClass.getObjectClass()==null) {
continue;
}
Class<?> checkObjectClass = checkClass.getObjectClass();
List<ElementBindingHandler> b = language.findElementBindingHandlers(objectClass,checkObjectClass);
if (b.isEmpty()==false) {
startNamespace(ns.getUri(),ns.getSchemaPrefix());
}
}
}
}
for (ElementInterface ei:language.findElementInterfaces(objectClass)) {
List<String> eiTags = ei.getElementParents(namespaceUri);
if (eiTags!=null) {
startNamespace(nsContext.getUri(),nsContext.getSchemaPrefix());
}
}
}
}
}
}
}
private static final String COMMENT_FORMAT = "%1$-20s %2$s";
private void prologWriteGenerator() throws IOException {
if (propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_SEPERATOR_ENABLE)) {
xsdWriter.printComment(propertyConfig.getPropertyString(EldXsdWriter.PROLOG_SEPERATOR_LINE));
}
if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_GENERATED_ENABLE)) {
return;
}
String chEnter = propertyConfig.getPropertyString(SAX3WriterXml.OUTPUT_CHAR_NEWLINE);
String chTab = propertyConfig.getPropertyString(SAX3WriterXml.OUTPUT_CHAR_TAB);
String generatedBy = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_GENERATED_BY, EldXsdWriter.class.getSimpleName());
String generatedVersion = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_GENERATED_VERSION);
StringBuilder b = new StringBuilder();
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"GeneratedBy:",generatedBy));
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"GeneratedDate:",new Date()));
if (generatedVersion != null && !generatedVersion.isEmpty()) {
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"GeneratedVersion:",generatedVersion));
}
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"LanguageName:",language.getLanguageName()));
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"LanguageVersion:",language.getLanguageVersion()));
b.append(chEnter);
xsdWriter.printComment(b.toString());
}
private void prologWriteNSMeta(ElementNamespace ns) throws IOException {
String chEnter = propertyConfig.getPropertyString(SAX3WriterXml.OUTPUT_CHAR_NEWLINE);
String chTab = propertyConfig.getPropertyString(SAX3WriterXml.OUTPUT_CHAR_TAB);
if (propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_XMLNS_INFO_ENABLE)) {
StringBuilder b = new StringBuilder();
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"NSId:",ns.getId()));
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"NSName:",ns.getName()));
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"NSUri:",ns.getUri()));
b.append(chEnter + chTab + String.format(COMMENT_FORMAT,"NSUriSchema:",ns.getSchemaUri()));
b.append(chEnter);
xsdWriter.printComment(b.toString());
}
boolean printDesc = false;
if (propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_XMLNS_DESC_ENABLE)) {
if (ns.getDescription() != null && !ns.getDescription().isEmpty()) {
printDesc = true;
}
}
if (printDesc && propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_SEPERATOR_ENABLE)) {
xsdWriter.printComment(propertyConfig.getPropertyString(EldXsdWriter.PROLOG_SEPERATOR_LINE));
}
if (printDesc) {
StringBuilder buf = new StringBuilder();
for (String line : ns.getDescription().split("\n")) {
buf.append(chEnter);
buf.append(chTab);
buf.append(line);
}
buf.append(chEnter);
xsdWriter.printComment(buf.toString());
}
}
public void startSchema(ElementNamespace ns) throws IOException {
xsdWriter.startDocument();
prologWriteGenerator();
prologWriteNSMeta(ns);
for (String uri:namespaces.keySet()) {
String prefix = namespaces.get(uri);
try {
xsdWriter.getContentWriterWrapped().startPrefixMapping(prefix, uri);
} catch (SAXException e) {
throw new IOException(e);
}
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "version", "", "", "1.0");
atts.addAttribute ("", "elementFormDefault", "", "", "qualified");
atts.addAttribute ("", "attributeFormDefault", "", "", "unqualified");
atts.addAttribute ("", "targetNamespace", "", "", ns.getUri());
xsdWriter.printTagStart(Tag.schema, atts);
for (String uri:namespaces.keySet()) {
if (ns.getUri().equals(uri)) {
continue;
}
ElementNamespace nsContext = language.findElementNamespace(uri);
xsdWriter.printXsdImport(nsContext.getUri(), nsContext.getSchemaResource());
}
writeNamespaceAttributes(ns);
}
public void endSchema() throws IOException {
xsdWriter.printTagEnd(Tag.schema);
try {
xsdWriter.getContentWriterWrapped().ignorableWhitespace(SAX3XMLConstants.CHAR_NEWLINE);
} catch (SAXException e) {
throw new IOException(e);
}
xsdWriter.endDocument();
}
private void writeNamespaceAttributes(ElementNamespace ns) throws IOException {
for (ElementNamespaceAttribute eah:ns.getElementNamespaceAttributes()) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eah.getAttributeName());
atts.addAttribute ("", "type", "", "", "string");
writeElementAttribute(eah,atts);
}
}
public void writeElementClass(ElementClass ec,ElementNamespace nsWrite) throws IOException {
AttributesImpl atts = new AttributesImpl();
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
atts.addAttribute ("", "name", "", "", ec.getId());
xsdWriter.printTagStart(Tag.element, atts);// Only in the language root xsd there is an element.
atts = new AttributesImpl();
xsdWriter.printTagStart(Tag.complexType, atts);
} else {
atts.addAttribute ("", "name", "", "", ec.getId()+"Type");
xsdWriter.printTagStart(Tag.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");
}
xsdWriter.printTagStart(Tag.complexContent, atts);
} else {
xsdWriter.printTagStart(Tag.simpleContent, atts);
}
atts = new AttributesImpl();
atts.addAttribute ("", "base", "", "", ec.getSchemaContentBase());
xsdWriter.printTagStart(Tag.extension, atts);
}
if (ec.getSchemaContentBase()==null) {
atts = new AttributesImpl();
atts.addAttribute ("", "minOccurs", "", "", "0"); // TODO: make unordered elements
atts.addAttribute ("", "maxOccurs", "", "", "unbounded");
xsdWriter.printTagStart(Tag.choice, atts);
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
writeElementClassNamespaces(ec,nsWrite,ns);
}
}
xsdWriter.printTagEnd(Tag.choice);
}
List<String> attrNames = new ArrayList<String>(30);
for (ElementClassAttribute eca:ec.getElementClassAttributes()) {
attrNames.add(eca.getId());
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eca.getId());
atts.addAttribute ("", "type", "", "", "string");
if (eca.getRequired()!=null && eca.getRequired()) {
atts.addAttribute ("", "use", "", "", "required");
}
writeElementAttribute(eca,atts);
for (String alias:eca.getAttributeAliases()) {
attrNames.add(alias);
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", alias);
atts.addAttribute ("", "type", "", "", "string");
writeElementAttribute(null,atts);
}
}
if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) {
// oke, reverse this if and rm whitespace.
try {
xsdWriter.getContentWriterWrapped().ignorableWhitespace(' ');
} catch (SAXException e) {
throw new IOException(e);
}
} 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;
}
attrNames.add(n);
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");
}
xsdWriter.printTagStartEnd(Tag.attribute, atts);
}
}
} else {
atts = new AttributesImpl();
xsdWriter.printTagStartEnd(Tag.anyAttribute, atts);
}
}
if (ec.getSchemaContentBase()!=null) {
xsdWriter.printTagEnd(Tag.extension);
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
xsdWriter.printTagEnd(Tag.complexContent);
} else {
xsdWriter.printTagEnd(Tag.simpleContent);
}
}
xsdWriter.printTagEnd(Tag.complexType);
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
xsdWriter.printTagEnd(Tag.element);
}
}
private void writeElementClassNamespaces(ElementClass ecWrite,ElementNamespace nsWrite,ElementNamespace ns) throws IOException {
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 && parents.contains(ecWrite.getId())) {
refElements.add(checkClass.getId());
continue;
}
if (checkClass.getObjectClass()==null) {
continue;
}
for (ElementInterface ei:language.findElementInterfaces(checkClass.getObjectClass())) {
parents = ei.getElementParents(nsWrite.getUri());
if (parents!=null && parents.contains(ecWrite.getId())) {
refElements.add(checkClass.getId());
break;
}
}
if (ecWrite.getObjectClass()==null) {
continue;
}
Class<?> objectClass = ecWrite.getObjectClass();
Class<?> checkObjectClass = checkClass.getObjectClass();
List<ElementBindingHandler> b = language.findElementBindingHandlers(objectClass,checkObjectClass);
if (b.isEmpty()==false) {
refElements.add(checkClass.getId());
}
}
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");
}
xsdWriter.printTagStartEnd(Tag.element,atts);
}
}
}
public void writeElement(ElementClass ec,ElementNamespace nsWrite) throws IOException {
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
return; // is done in writeElementClass
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ec.getId());
atts.addAttribute ("", "type", "", "", "this:"+ec.getId()+"Type");
xsdWriter.printTagStart(Tag.element,atts);
writeElementMetaBase(ec);
xsdWriter.printTagEnd(Tag.element);
}
private void writeElementAttribute(ElementMetaBase base,AttributesImpl atts) throws IOException {
xsdWriter.printTagStart(Tag.attribute,atts);
writeElementMetaBase(base);
xsdWriter.printTagEnd(Tag.attribute);
}
private void writeElementMetaBase(ElementMetaBase base) throws IOException {
if (base==null) {
return;
}
if (base.getDescription()==null) {
return;
}
if (!propertyConfig.getPropertyBoolean(EldXsdWriter.OUTPUT_DOCUMENTATION)) {
return;
}
xsdWriter.printXsdDocumentation(base.getDescription());
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2014, 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-2014, 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.lang.X4OLanguageSession;
import org.x4o.xml.lang.X4OLanguageClassLoader;
/**
* An AbstractElement.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2005
*/
public abstract class AbstractElement implements Element {
/** The parent Element */
private Element parent = null;
/** The config object */
private Object elementObject = null;
/** The language parsing context */
private X4OLanguageSession languageSession = 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);
setLanguageSession(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#setLanguageSession(X4OLanguageSession)
*/
public void setLanguageSession(X4OLanguageSession languageSession) {
this.languageSession=languageSession;
}
/**
* @see Element#getLanguageSession()
*/
public X4OLanguageSession getLanguageSession() {
return languageSession;
}
/**
* @see org.x4o.xml.element.Element#doCharacters(java.lang.String)
*/
public void doCharacters(String characters) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getLanguageSession().getLanguage().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(getLanguageSession().getLanguage().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(getLanguageSession().getLanguage().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,64 @@
/*
* Copyright (c) 2004-2014, 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
*/
public abstract class AbstractElementBindingHandler<T> extends AbstractElementMetaBase implements ElementBindingHandler {
abstract public void bindChild(Element childElement,T parentObject,Object childObject) throws ElementBindingHandlerException;
abstract public void createChilderen(Element parentElement,T parentObject) throws ElementBindingHandlerException;
@SuppressWarnings("unchecked")
public void bindChild(Element childElement) throws ElementBindingHandlerException {
bindChild(childElement,(T)childElement.getParent().getElementObject(), childElement.getElementObject());
}
@SuppressWarnings("unchecked")
public void createChilderen(Element parentElement) throws ElementBindingHandlerException {
createChilderen(parentElement,(T)parentElement.getElementObject());
}
protected void createChild(Element parentElement,Object childObject) {
if (childObject==null) {
return;
}
if (parentElement==null) {
throw new NullPointerException("Can't create child with null parent.");
}
Element childElement = parentElement.getLanguageSession().getLanguage().createElementInstance(parentElement.getLanguageSession(), childObject.getClass());
if (childElement==null) {
throw new NullPointerException("Could not find Element for child: "+childObject.getClass());
}
childElement.setElementObject(childObject);
childElement.setParent(parentElement);
parentElement.addChild(childElement);
}
}

View file

@ -0,0 +1,152 @@
/*
* Copyright (c) 2004-2014, 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 AbstractElementClass.
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
public abstract class AbstractElementClass extends AbstractElementClassBase implements ElementClass {
private Class<?> objectClass = null;
private Class<?> elementClass = null;
private Boolean autoAttributes = true;
private String schemaContentBase = null;
private Boolean schemaContentComplex = null;
private Boolean schemaContentMixed = null;
private List<String> skipPhases = null;
public AbstractElementClass() {
skipPhases = new ArrayList<String>(3);
}
/**
* @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;
}
/**
* @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,185 @@
/*
* Copyright (c) 2004-2014, 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
*/
public abstract class AbstractElementClassAttribute extends AbstractElementMetaBase implements ElementClassAttribute {
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 runBeanValue = null;
private Integer writeOrder = null;
/**
* Creates a AbstractElementClassAttribute.
*/
public AbstractElementClassAttribute() {
attributeAliases = new ArrayList<String>(3);
}
/**
* Returns the objectConverter.
* @return The objectConverter.
*/
public ObjectConverter getObjectConverter() {
return objectConverter;
}
/**
* Sets the objectConverter.
* @param objectConverter The objectConverter to set.
*/
public void setObjectConverter(ObjectConverter objectConverter) {
this.objectConverter = objectConverter;
}
/**
* Sets the default value.
* @param defaultValue The defaultValue to set.
* @see org.x4o.xml.element.ElementClassAttribute#setDefaultValue(java.lang.Object)
*/
public void setDefaultValue(Object defaultValue) {
this.defaultValue=defaultValue;
}
/**
* Returns the default value.
* @return The default value.
* @see org.x4o.xml.element.ElementClassAttribute#getDefaultValue()
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* Adds an alias of this attribute.
* @param alias The alias to add.
* @see org.x4o.xml.element.ElementClassAttribute#addAttributeAlias(java.lang.String)
*/
public void addAttributeAlias(String alias) {
attributeAliases.add(alias);
}
/**
* Removes an alias of this attribute.
* @param alias The alias to remove.
* @see org.x4o.xml.element.ElementClassAttribute#removeAttributeAlias(java.lang.String)
*/
public void removeAttributeAlias(String alias) {
attributeAliases.remove(alias);
}
/**
* Returns all aliases of this attribute.
* @return An list of aliases.
* @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 runBeanValue.
*/
public Boolean getRunBeanValue() {
return runBeanValue;
}
/**
* @param runBeanValue the runBeanValue to set.
*/
public void setRunBeanValue(Boolean runBeanValue) {
this.runBeanValue = runBeanValue;
}
/**
* @return the writeOrder.
*/
public Integer getWriteOrder() {
return writeOrder;
}
/**
* @param writeOrder the writeOrder to set.
*/
public void setWriteOrder(Integer writeOrder) {
this.writeOrder = writeOrder;
}
}

View file

@ -0,0 +1,136 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* AbstractElementClassBase provides basic element meta class support.
*
* @author Willem Cazander
* @version 1.0 Jan 19, 2012
*/
public abstract class AbstractElementClassBase extends AbstractElementMetaBase implements ElementClassBase {
private Map<String,ElementClassAttribute> elementClassAttributes = null;
private List<ElementConfigurator> elementConfigurators = null;
private Map<String,List<String>> elementParents = null;
/**
* Creates a AbstractElementClassBase.
*/
public AbstractElementClassBase() {
elementConfigurators = new ArrayList<ElementConfigurator>(5);
elementClassAttributes = new HashMap<String,ElementClassAttribute>(15);
elementParents = new HashMap<String,List<String>>(5);
}
/**
* Returns a list of ElementConfigurators.
* @return List of ElementConfigurators.
* @see ElementClass#getElementConfigurators()
*/
public List<ElementConfigurator> getElementConfigurators() {
return elementConfigurators;
}
/**
* @see ElementClass#addElementConfigurators(ElementConfigurator)
* @param elementConfigurator The ElementConfigurator to add.
*/
public void addElementConfigurators(ElementConfigurator elementConfigurator) {
elementConfigurators.add(elementConfigurator);
}
/**
* @param elementClassAttribute The ElementClassAttribute to add.
*/
public void addElementClassAttribute(ElementClassAttribute elementClassAttribute) {
elementClassAttributes.put(elementClassAttribute.getId(),elementClassAttribute);
}
/**
* @return All the element attributes.
*/
public Collection<ElementClassAttribute> getElementClassAttributes() {
return elementClassAttributes.values();
}
/**
* Get the ElementClassAttribute from its name.
* @param attributeName The attribute name.
* @return The element class attribute for the name.
*/
public ElementClassAttribute getElementClassAttributeByName(String attributeName) {
return elementClassAttributes.get(attributeName);
}
/**
* Adds parent tag.
* @see org.x4o.xml.element.ElementClassBase#addElementParent(java.lang.String,java.lang.String)
* @param namespaceUri The namespace uri of the parent tag.
* @param tag The tag of the parent of this tag.
*/
public void addElementParent(String namespaceUri,String tag) {
if (namespaceUri==null) {
throw new NullPointerException("Can't add parent tag with null namespace uri.");
}
if (namespaceUri.length()==0) {
throw new IllegalArgumentException("Can't add parent tag with empty namespace uri.");
}
List<String> tags = elementParents.get(namespaceUri);
if (tags==null) {
tags = new ArrayList<String>(5);
elementParents.put(namespaceUri, tags);
}
tags.add(tag);
}
/**
* Removes parent tag.
* @see org.x4o.xml.element.ElementClassBase#removeElementParent(java.lang.String,java.lang.String)
* @param namespaceUri The namespace uri of the parent tag.
* @param tag The tag of the parent of this tag.
*/
public void removeElementParent(String namespaceUri,String tag) {
List<String> tags = elementParents.get(namespaceUri);
if (tags==null) {
return;
}
tags.remove(tag);
}
/**
* Returns the parent per namespace uri.
* @see org.x4o.xml.element.ElementClassBase#getElementParents(java.lang.String)
* @param namespaceUri The namespace uri to gets the parents of.
* @return List of parent tags of requested parent namespace uri.
*/
public List<String> getElementParents(String namespaceUri) {
return elementParents.get(namespaceUri);
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2014, 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
*/
public abstract 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()
* @return True if set to configAction
*/
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,56 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* AbstractElementInterface extends base support with element interface support.
*
* @author Willem Cazander
* @version 1.0 Apr 15, 2008
*/
public abstract class AbstractElementInterface extends AbstractElementClassBase implements ElementInterface {
private Class<?> interfaceClass = null;
/**
* Creates AbstractElementInterface.
*/
public AbstractElementInterface() {
}
/**
* @see org.x4o.xml.element.ElementInterface#getInterfaceClass()
* @return The interface class
*/
public Class<?> getInterfaceClass() {
return interfaceClass;
}
/**
* @see org.x4o.xml.element.ElementInterface#setInterfaceClass(java.lang.Class)
* @param interfaceClass The interface class to set.
*/
public void setInterfaceClass(Class<?> interfaceClass) {
this.interfaceClass=interfaceClass;
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2004-2014, 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
*/
public abstract class AbstractElementMetaBase implements ElementMetaBase {
/** The id */
private String id = null;
/** The description */
private String description = null;
/**
* Gets the id.
* @see org.x4o.xml.element.ElementMetaBase#getId()
* @return The id.
*/
public String getId() {
return id;
}
/**
* Sets the id.
* @see org.x4o.xml.element.ElementMetaBase#setId(java.lang.String)
* @param id The id to set.
*/
public void setId(String id) {
this.id=id;
}
/**
* Gets the description.
* @see org.x4o.xml.element.ElementConfigurator#getDescription()
* @return The description.
*/
public String getDescription() {
return description;
}
/**
* Sets the description.
* @see org.x4o.xml.element.ElementConfigurator#setDescription(java.lang.String)
* @param description The description to set.
*/
public void setDescription(String description) {
this.description=description;
}
}

View file

@ -0,0 +1,205 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* AbstractElementNamespace is the abstract version of an ElementNamespace.
*
* @author Willem Cazander
* @version 1.0 Oct 28, 2009
*/
public abstract class AbstractElementNamespace extends AbstractElementMetaBase implements ElementNamespace {
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;
private List<ElementNamespaceAttribute> elementNamespaceAttributes = null;
public AbstractElementNamespace() {
elementClasses = new HashMap<String,ElementClass>(60);
elementNamespaceAttributes = new ArrayList<ElementNamespaceAttribute>(5);
}
/**
* @see org.x4o.xml.element.ElementNamespace#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.ElementNamespace#setPrefixMapping(java.lang.String)
*/
public void setPrefixMapping(String prefixMapping) {
this.prefixMapping=prefixMapping;
}
/**
* @see org.x4o.xml.element.ElementNamespace#addElementClass(org.x4o.xml.element.ElementClass)
*/
public void addElementClass(ElementClass elementClass) {
if (elementClass.getId()==null) {
throw new NullPointerException("ElementClass not correctly configured getId is null.");
}
elementClasses.put(elementClass.getId(), elementClass);
}
/**
* @see org.x4o.xml.element.ElementNamespace#getElementClass(java.lang.String)
*/
public ElementClass getElementClass(String tag) {
return elementClasses.get(tag);
}
/**
* @see org.x4o.xml.element.ElementNamespace#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;
}
public void addElementNamespaceAttribute(ElementNamespaceAttribute elementNamespaceAttribute) {
if (elementNamespaceAttribute==null) {
throw new NullPointerException("Can't add null object");
}
if (elementNamespaceAttribute.getId()==null) {
throw new NullPointerException("Can't add with null id property.");
}
//logger.finer("Adding elementNamespaceAttribute: "+elementNamespaceAttribute.getAttributeName());
elementNamespaceAttributes.add(elementNamespaceAttribute);
}
public List<ElementNamespaceAttribute> getElementNamespaceAttributes() {
return elementNamespaceAttributes;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2004-2014, 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 AbstractElementNamespaceAttribute.
*
* @author Willem Cazander
* @version 1.0 Aug 10, 2006
*/
public abstract class AbstractElementNamespaceAttribute extends AbstractElementConfigurator implements ElementNamespaceAttribute {
private String attributeName = null;
private List<String> nextAttributes = new ArrayList<String>(2);
/**
* @see org.x4o.xml.element.ElementNamespaceAttribute#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.ElementNamespaceAttribute#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.ElementNamespaceAttribute#getNextAttributes()
*/
public List<String> getNextAttributes() {
return nextAttributes;
}
/**
* @see org.x4o.xml.element.ElementNamespaceAttribute#getAttributeName()
*/
public String getAttributeName() {
return attributeName;
}
/**
* @see org.x4o.xml.element.ElementNamespaceAttribute#setAttributeName(java.lang.String)
*/
public void setAttributeName(String attributeName) {
this.attributeName=attributeName;
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* The default element to handle the xml events.
*
* @author Willem Cazander
* @version 1.0 Jan 18, 2007
*/
public class DefaultElement extends AbstractElement {
}

View file

@ -0,0 +1,143 @@
/*
* Copyright (c) 2004-2014, 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.Locale;
import java.util.logging.Logger;
import javax.el.ValueExpression;
import org.x4o.xml.conv.ObjectConverterException;
/**
* An DefaultElementAttributeValueParser.
*
* @author Willem Cazander
* @version 1.0 Feb 16, 2007
*/
public class DefaultElementAttributeValueParser implements ElementAttributeValueParser {
private Logger logger = null;
public DefaultElementAttributeValueParser() {
logger = Logger.getLogger(DefaultElementAttributeValueParser.class.getName());
}
/**
* @see org.x4o.xml.element.ElementAttributeValueParser#getParameterValue(java.lang.String, java.lang.String, org.x4o.xml.element.Element)
*/
public Object getParameterValue(String name, String valueString, Element element) throws ElementAttributeValueParserException,ObjectConverterException {
Object value = valueString;
if (isELParameter(name, valueString, element)) {
value = getELParameterValue(valueString, element);
}
return getConvertedParameterValue(name, value, element);
}
/**
* @throws ObjectConverterException
* @see org.x4o.xml.element.ElementAttributeValueParser#getConvertedParameterValue(java.lang.String, java.lang.Object, org.x4o.xml.element.Element)
*/
public Object getConvertedParameterValue(String name,Object value, Element element) throws ElementAttributeValueParserException, ObjectConverterException {
//bit slow here
if (value==null) {
return null; // TODO: make setting for null
}
// do converts for ElementClass
ElementClassAttribute attr = element.getElementClass().getElementClassAttributeByName(name);
if (attr!=null && attr.getObjectConverter()!=null && value.getClass().isAssignableFrom(attr.getObjectConverter().getObjectClassTo())==false) {
logger.finer("attr conv: "+attr.getObjectConverter()+" for name: "+name);
Object result = attr.getObjectConverter().convertTo(value.toString(), Locale.getDefault());
return result;
}
// check interfaces
if (element.getElementObject()==null) {
return value;
}
for (ElementInterface ei:element.getLanguageSession().getLanguage().findElementInterfaces(element.getElementObject())) {
logger.finer("Found interface match executing converter.");
for (ElementClassAttribute attrClass:ei.getElementClassAttributes()) {
if (name.equals(attrClass.getId())==false) {
continue;
}
if (attrClass.getObjectConverter()==null) {
continue;
}
if (value.getClass().isAssignableFrom(attrClass.getObjectConverter().getObjectClassTo())) {
continue; // make flag ?
}
logger.finest("attr conv interface: "+attrClass.getObjectConverter()+" for name: "+name);
Object result = attrClass.getObjectConverter().convertTo(value.toString(), Locale.getDefault());
return result; // ??
}
}
return value;
}
/**
* @see org.x4o.xml.element.ElementAttributeValueParser#getELParameterValue(java.lang.String, org.x4o.xml.element.Element)
*/
public Object getELParameterValue(String value, Element element) throws ElementAttributeValueParserException {
ValueExpression e = element.getLanguageSession().getExpressionLanguageFactory().createValueExpression(element.getLanguageSession().getExpressionLanguageContext(), (String)value,Object.class);
return e.getValue(element.getLanguageSession().getExpressionLanguageContext());
}
/**
* @see org.x4o.xml.element.ElementAttributeValueParser#isELParameter(java.lang.String, java.lang.String, org.x4o.xml.element.Element)
*/
public boolean isELParameter(String name, String value, Element element) {
if (value==null) {
return false;
}
if (value.startsWith("${")==false) {
return false;
}
if (element==null) {
return true; // null element disables checks
}
ElementClassAttribute attr = element.getElementClass().getElementClassAttributeByName(name);
if (attr!=null && attr.getRunResolveEL()!=null && attr.getRunResolveEL()==false) {
logger.finest("Skipping EL parsing for: "+name);
return false;
}
for (ElementInterface ei:element.getLanguageSession().getLanguage().findElementInterfaces(element.getElementObject())) {
logger.finest("Found interface match checking disables el parameters.");
attr = ei.getElementClassAttributeByName(name);
if (attr!=null && attr.getRunResolveEL()!=null && attr.getRunResolveEL()==false) {
logger.finest("Skipping EL parsing for: "+name+" in interface element.");
return false;
}
}
return true;
}
}

View file

@ -0,0 +1,197 @@
/*
* Copyright (c) 2004-2014, 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.lang.X4OLanguageSession;
/**
* DefaultElementBodyCharacters the default characters element.
*
* @author Willem Cazander
* @version 1.0 Jan 9, 2009
*/
public class DefaultElementBodyCharacters implements Element {
/** The parent Element */
private Element parent = null;
/** The config object */
private Object elementObject = null;
/**
* @return The ElementType for characters.
* @see org.x4o.xml.element.Element#getElementType()
*/
public ElementType getElementType() {
return ElementType.characters;
}
// ===== REST Element interface is non-supported
/**
* @see org.x4o.xml.element.Element#addChild(org.x4o.xml.element.Element)
*/
public void addChild(Element element) {
}
/**
* @see org.x4o.xml.element.Element#doCharacters(java.lang.String)
*/
public void doCharacters(String body) throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#doComment(java.lang.String)
*/
public void doComment(String comment) throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#doElementEnd()
*/
public void doElementEnd() throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#doElementRun()
*/
public void doElementRun() throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#doElementStart()
*/
public void doElementStart() throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#doIgnorableWhitespace(java.lang.String)
*/
public void doIgnorableWhitespace(String space) throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#getAllChilderen()
*/
public List<Element> getAllChilderen() {
return new ArrayList<Element>(0);
}
/**
* @see org.x4o.xml.element.Element#getAttributes()
*/
public Map<String, String> getAttributes() {
return new HashMap<String,String>(0);
}
/**
* @see org.x4o.xml.element.Element#getChilderen()
*/
public List<Element> getChilderen() {
return getAllChilderen();
}
/**
* @see org.x4o.xml.element.Element#getElementClass()
*/
public ElementClass getElementClass() {
return null;
}
/**
* @see org.x4o.xml.element.Element#getLanguageSession()
*/
public X4OLanguageSession getLanguageSession() {
return null;
}
/**
* @see org.x4o.xml.element.Element#getElementObject()
*/
public Object getElementObject() {
return elementObject;
}
/**
* @see org.x4o.xml.element.Element#getParent()
*/
public Element getParent() {
return parent;
}
/**
* @see org.x4o.xml.element.Element#isTransformingTree()
*/
public boolean isTransformingTree() {
return false;
}
/**
* @see org.x4o.xml.element.Element#release()
*/
public void release() throws ElementException {
}
/**
* @see org.x4o.xml.element.Element#removeChild(org.x4o.xml.element.Element)
*/
public void removeChild(Element element) {
}
/**
* @see org.x4o.xml.element.Element#setAttribute(java.lang.String, java.lang.String)
*/
public void setAttribute(String name, String value) {
}
/**
* @see org.x4o.xml.element.Element#setElementClass(org.x4o.xml.element.ElementClass)
*/
public void setElementClass(ElementClass elementClass) {
}
/**
* @see org.x4o.xml.element.Element#setLanguageSession(org.x4o.xml.lang.X4OLanguageSession)
*/
public void setLanguageSession(X4OLanguageSession elementLanguage) {
}
/**
* @see org.x4o.xml.element.Element#setElementObject(java.lang.Object)
*/
public void setElementObject(Object elementObject) {
this.elementObject=elementObject;
}
/**
* @see org.x4o.xml.element.Element#setParent(org.x4o.xml.element.Element)
*/
public void setParent(Element parent) {
this.parent=parent;
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* DefaultElementBodyComment the default comment element.
*
* @author Willem Cazander
* @version 1.0 Jan 9, 2009
*/
public class DefaultElementBodyComment extends AbstractElement {
/**
* @return The ElementType for xml comment data.
* @see org.x4o.xml.element.AbstractElement#getElementType()
*/
@Override
public ElementType getElementType() {
return ElementType.comment;
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* DefaultElementBodyWhitespace the default white space element.
*
* @author Willem Cazander
* @version 1.0 Feb 15, 2009
*/
public class DefaultElementBodyWhitespace extends AbstractElement {
/**
* @return Returns the whitespace element type.
* @see org.x4o.xml.element.AbstractElement#getElementType()
*/
@Override
public ElementType getElementType() {
return ElementType.ignorableWhitespace;
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* DefaultElementClass stores the XML Element information.
*
* @author Willem Cazander
* @version 1.0 Feb 19, 2007
*/
public class DefaultElementClass extends AbstractElementClass {
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* The default ElementClassAttribute.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class DefaultElementClassAttribute extends AbstractElementClassAttribute {
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* The default ElementInterface to store config based on class interface.
*
* @author Willem Cazander
* @version 1.0 Apr 15, 2008
*/
public class DefaultElementInterface extends AbstractElementInterface {
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* DefaultElementNamespace is the default element namespace implementation.
*
* @author Willem Cazander
* @version 1.0 Oct 28, 2009
*/
public class DefaultElementNamespace extends AbstractElementNamespace {
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2004-2014, 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.Comparator;
/**
* The DefaultElementNamespaceAttributeComparator.<br>
* This Comparator compares the NextAttribute names with the attributeName of the ElementNamespaceAttribute.<br>
*
* @author Willem Cazander
* @version 1.0 Feb 14, 2007
*/
public class DefaultElementNamespaceAttributeComparator implements Comparator<ElementNamespaceAttribute> {
/**
* @param e1 The first ElementNamespaceAttribute to compare.
* @param e2 The second ElementNamespaceAttribute to compare.
* @return 0 is same.
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(ElementNamespaceAttribute e1, ElementNamespaceAttribute e2) {
for (String param:e1.getNextAttributes()) {
if(param.equals(e2.getAttributeName())) {
return -1;
}
}
for (String param:e2.getNextAttributes()) {
if(param.equals(e1.getAttributeName())) {
return 1;
}
}
return 0;
}
}

View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2004-2014, 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.logging.Logger;
import org.x4o.xml.lang.X4OLanguageSession;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader;
/**
* DefaultElementNamespaceInstanceProvider creates and configures an Element instance.
*
* @author Willem Cazander
* @version 1.0 Aug 17, 2005
*/
public class DefaultElementNamespaceInstanceProvider implements ElementNamespaceInstanceProvider {
private Logger logger = null;
private ElementNamespace elementNamespace = null;
/**
* Creates new DefaultElementNamespaceInstanceProvider.
*/
public DefaultElementNamespaceInstanceProvider() {
logger = Logger.getLogger(DefaultElementNamespaceInstanceProvider.class.getName());
}
/**
* @param language The elementLanguage of this provider.
* @param elementNamespace The elementNamespace for this provider.
* @see org.x4o.xml.element.ElementNamespaceInstanceProvider#start(org.x4o.xml.lang.X4OLanguage, org.x4o.xml.element.ElementNamespace)
*/
public void start(X4OLanguage language,ElementNamespace elementNamespace) {
this.elementNamespace=elementNamespace;
logger.finer("Starting DefaultElementNamespaceInstanceProvider for: "+elementNamespace.getUri());
}
/**
* @param languageSession The language context for which we create the Element instance.
* @param tag The xml tag to create an Element instance for.
* @return The Element to handle the given tag.
* @throws ElementNamespaceInstanceProviderException
* @see org.x4o.xml.element.ElementNamespaceInstanceProvider#createElementInstance(org.x4o.xml.lang.X4OLanguageSession,java.lang.String)
*/
public Element createElementInstance(X4OLanguageSession languageSession,String tag) throws ElementNamespaceInstanceProviderException {
ElementClass elementClass = elementNamespace.getElementClass(tag);
Element element = null;
if (elementClass==null) {
throw new ElementNamespaceInstanceProviderException(this,"Tag: " + tag + " unknown in: " + elementNamespace.getUri());
}
try {
if (elementClass.getElementClass()!=null) {
Object obj = X4OLanguageClassLoader.newInstance(elementClass.getElementClass());
if (obj instanceof Element) {
element = (Element) obj;
} else {
throw new ElementNamespaceInstanceProviderException(this,"Provided elementClassName is not an Element: "+obj.getClass());
}
} else {
element = (Element)X4OLanguageClassLoader.newInstance((languageSession.getLanguage().getLanguageConfiguration().getDefaultElement()));
}
if (elementClass.getObjectClass()!=null) {
element.setElementObject(X4OLanguageClassLoader.newInstance(elementClass.getObjectClass()));
}
} catch (InstantiationException e) {
throw new ElementNamespaceInstanceProviderException(this,"Error while providing Element: "+e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new ElementNamespaceInstanceProviderException(this,"Error while providing Element: "+e.getMessage(),e);
} /*catch (ClassNotFoundException e) {
throw new ElementNamespaceInstanceProviderException(this,"Error while providing Element: "+e.getMessage(),e);
} */
element.setElementClass(elementClass);
element.setLanguageSession(languageSession);
return element;
}
}

View file

@ -0,0 +1,332 @@
/*
* Copyright (c) 2004-2014, 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.io.Serializable;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
import org.x4o.xml.conv.DefaultObjectConverterProvider;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* An DefaultElementObjectPropertyValue which does does get/set operations on pojo beans.
*
* @author Willem Cazander
* @version 1.0 Feb 16, 2007
*/
public class DefaultElementObjectPropertyValue implements ElementObjectPropertyValue,Serializable {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(DefaultElementObjectPropertyValue.class.getName());
private Method findMethod(Object object,String parameterName,Object parameter) {
// Get class but can be null.
Class<?> parameterClass = null;
if(parameter!=null) {
parameterClass=parameter.getClass();
}
logger.finer("Trying value: pn="+parameterName+" o="+object+" p="+parameter+"("+parameterClass+")");
String parameterNameSet = "set"+parameterName;
Method[] methodes = object.getClass().getMethods();
Method lastMethodFall = null;
for (int i=0;i<methodes.length;i++) {
Method method = methodes[i];
Class<?>[] types = method.getParameterTypes();
if (types.length == 0) {
continue;
}
if (types.length > 1) {
continue;
}
if (method.getName().equalsIgnoreCase(parameterNameSet)) {
lastMethodFall = method;
if (parameterClass!=null) {
// Check for class based parameters.
if (types[0].isAssignableFrom(parameterClass)) {
logger.finest("Found method type: "+method.getParameterTypes()[0]+" for parameter: "+parameterName);
return method;
}
// Check the native parameter types.
if (parameterClass.isAssignableFrom(Boolean.class) && types[0].isAssignableFrom(Boolean.TYPE) ) {
return method;
}
if (parameterClass.isAssignableFrom(Integer.class) && types[0].isAssignableFrom(Integer.TYPE) ) {
return method;
}
if (parameterClass.isAssignableFrom(Long.class) && types[0].isAssignableFrom(Long.TYPE) ) {
return method;
}
if (parameterClass.isAssignableFrom(Double.class) && types[0].isAssignableFrom(Double.TYPE) ) {
return method;
}
if (parameterClass.isAssignableFrom(Float.class) && types[0].isAssignableFrom(Float.TYPE) ) {
return method;
}
if (parameterClass.isAssignableFrom(Byte.class) && types[0].isAssignableFrom(Byte.TYPE) ) {
return method;
}
if (parameterClass.isAssignableFrom(Character.class) && types[0].isAssignableFrom(Character.TYPE) ) {
return method;
}
}
}
}
return lastMethodFall;
}
/**
* TODO: this function is not completed !!
*
*
*
* @param object
* @param parameterName
* @param parameter
* @throws ElementObjectPropertyValueException
*/
public void setProperty(Object object,String parameterName,Object parameter) throws ElementObjectPropertyValueException {
// find the method for the parameter
Method lastMethod = findMethod(object,parameterName,parameter);
if (lastMethod==null) {
logger.finest("No method found, aborting parameter: "+parameterName);
return;
}
// Special case for null value.
if (parameter==null) {
logger.finest("Found parameter is null Setting method: "+lastMethod.getParameterTypes()[0]+" for parameter: "+parameterName);
try {
lastMethod.invoke(object,new Object[]{parameter});
return;
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
}
// Invoke for class based parameters
if (lastMethod.getParameterTypes()[0].isAssignableFrom(parameter.getClass())) {
logger.finest("Found parameter type: "+lastMethod.getParameterTypes()[0]+" for parameter: "+parameterName+" setting value: "+parameter);
try {
lastMethod.invoke(object,new Object[]{parameter});
return;
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
}
// Invoke for native based types
// not found 2sec try
logger.finest("No corresoning class is found, trying convert manualy");
// special case for object.
if (lastMethod.getParameterTypes()[0].equals(Object.class) ) {
logger.finest("Set Special object value: "+parameterName+" parm2: "+parameter+" on2="+lastMethod.getName()+" with="+object);
try {
lastMethod.invoke(object,new Object[]{parameter});
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
return;
}
// all below creates from string
if (parameter.toString().length()==0) {
return; // can't set value from string with empty size.
}
//
// JAVA OBJECT TYPES:
//
Object parameter2 = null;
try {
DefaultObjectConverterProvider convProvider = new DefaultObjectConverterProvider();
convProvider.addDefaults();
ObjectConverter conv = convProvider.getObjectConverterForClass(lastMethod.getParameterTypes()[0]);
if (conv!=null) {
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
/*
* JAVA NATIVE TYPES:
*
* TYPE: Size in bits:
* boolean 8, unsigned
* byte 8
* char 16, unsigned
* short 16
* int 32
* long 64
* float 32
* double 64
* void n/a
*/
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Boolean.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Boolean.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Integer.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Integer.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Long.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Long.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Double.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Double.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Float.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Float.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Byte.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Byte.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
if (lastMethod.getParameterTypes()[0].isAssignableFrom(Character.TYPE) ) {
conv = convProvider.getObjectConverterForClass(Character.class);
parameter2 = conv.convertTo(parameter.toString(), Locale.getDefault());
}
} catch (ObjectConverterException oce) {
throw new ElementObjectPropertyValueException(oce.getMessage(),oce);
}
if (parameter2==null) {
throw new ElementObjectPropertyValueException("Could not convert to type for parameter: '"+parameterName+"' value: '"+parameter+"'");
}
logger.finest("Set value: "+parameterName+" parm2: "+parameter2+" on2="+lastMethod.getName()+" with="+object);
try {
lastMethod.invoke(object,new Object[]{parameter2});
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
}
/**
* Gets the property of an bean.
*
* @param object The object to get from.
* @param parameterName The parameter name of the property to get.
* @throws ElementObjectPropertyValueException
*/
public Object getProperty(Object object,String parameterName) throws ElementObjectPropertyValueException {
if (object==null) {
throw new NullPointerException("Can't get property of null object.");
}
if (parameterName==null) {
throw new NullPointerException("Can't get property is the name is null.");
}
Logger logger = Logger.getLogger(DefaultElementObjectPropertyValue.class.getName());
String propRest = null;
int index = parameterName.indexOf(".");
if(index>0) {
propRest = parameterName.substring(index+1);
parameterName = parameterName.substring(0,index);
logger.finest("slit property into: '"+propRest+"' and '"+parameterName+"'");
}
logger.finer("Trying value: pn="+parameterName+" o="+object);
String parameterNameSet = "get"+parameterName;
Method[] methodes = object.getClass().getMethods();
Method lastMethod = null;
// a bit hackie
for(int i=0;i<methodes.length;i++) {
Method method = methodes[i];
Class<?>[] types = method.getParameterTypes();
if (types.length != 0) {
continue;
}
if(method.getName().equalsIgnoreCase(parameterNameSet)) {
logger.finest("Found method: "+method.getName());
lastMethod = method;
break;
}
}
if (lastMethod==null) {
for(int i=0;i<methodes.length;i++) {
Method method = methodes[i];
if(method.getName().equalsIgnoreCase("is"+parameterName)) {
logger.finest("Found is method: "+method.getName());
lastMethod = method;
break;
}
if(method.getName().equalsIgnoreCase("has"+parameterName)) {
logger.finest("Found has method: "+method.getName());
lastMethod = method;
break;
}
}
}
if (lastMethod==null) {
throw new ElementObjectPropertyValueException("Could not find method for parameter: '"+parameterName+"' object: '"+object+"'");
}
Object result = null;
try {
result = lastMethod.invoke(object,new Object[]{});
} catch (Exception e) {
throw new ElementObjectPropertyValueException(e.getMessage(),e);
}
if (propRest!=null) {
if (result==null) {
return null; // no need to go deeper into a null value.
}
// recursif function:
return getProperty(result,propRest);
}
return result;
}
/**
* @see org.x4o.xml.element.ElementObjectPropertyValue#setPropertyMap(java.lang.Object, java.util.Map)
*/
public void setPropertyMap(Object object, Map<String, Object> attributes) throws ElementObjectPropertyValueException {
Iterator<String> keyIterator = attributes.keySet().iterator();
while(keyIterator.hasNext()) {
String key = keyIterator.next();
setProperty(object,key,attributes.get(key));
}
}
}

View file

@ -0,0 +1,231 @@
/*
* Copyright (c) 2004-2014, 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;
import org.x4o.xml.lang.X4OLanguageSession;
/**
* 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 Feb 01, 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;
/**
* Filters the given elments list to elementType.
* @param elements The elements to filter.
* @param elementType The elementType to filter on.
* @return Always returns List of Elements of filter type.
*/
public static 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.
* @throws ElementException Can be thrown when structure is not correct.
*/
void doElementEnd() throws ElementException;
/**
* This method is fired when the start of xml tag is parsed.
* @throws ElementException Can be thrown when structure is not correct.
*/
void doElementStart() throws ElementException;
/**
* This method is fired only once in the run phase.
* @throws ElementException Can be thrown when structure is not correct.
*/
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.
* @throws ElementException Can be thrown when structure is not correct.
*/
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 X4OLanguageSession.
* @param languageSession The X4OLanguageSession to set.
*/
void setLanguageSession(X4OLanguageSession languageSession);
/**
* Gets the X4OLanguageSession.
* @return Returns the X4OLanguageSession.
*/
X4OLanguageSession getLanguageSession();
/**
* Sets the body texts on an event based system.
* @param body The body text.
* @throws ElementException Can be thrown when structure is not correct.
*/
void doCharacters(String body) throws ElementException;
/**
* Sets the comment texts on an event based system.
* @param comment The comment text.
* @throws ElementException Can be thrown when structure is not correct.
*/
void doComment(String comment) throws ElementException;
/**
* Is called when there is whitespace in xml.
* @param space The space.
* @throws ElementException Can be thrown when structure is not correct.
*/
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,76 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* 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 ElementAttributeValueParserException
* @throws ObjectConverterException
*/
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 ElementAttributeValueParserException
* @throws ObjectConverterException
*/
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 ElementAttributeValueParserException
* @throws ObjectConverterException
*/
Object getParameterValue(String name,String value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2004-2014, 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,62 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* 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 childElement The child element to bind to the parent.'
* @throws ElementBindingHandlerException When binding could not happen.
*/
void bindChild(Element childElement) throws ElementBindingHandlerException;
/**
* Creates the childeren of the parent object.
* @param parentElement The parent element to create the childeren from.'
* @throws ElementBindingHandlerException When binding could not happen.
*/
void createChilderen(Element parentElement) throws ElementBindingHandlerException;
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2014, 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,115 @@
/*
* Copyright (c) 2004-2014, 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 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);
/**
* @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,131 @@
/*
* Copyright (c) 2004-2014, 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 ObjectConverter.
* @return The ObjectConverter.
*/
ObjectConverter getObjectConverter();
/**
* Add the ObjectConverter whichs converts.
* @param objectConverter The objectConverter to set for this attribute.
*/
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();
/**
* Gets the required state of this attribute.
* @return If true then attribute is required.
*/
Boolean getRequired();
/**
* Sets the required state of this attribute.
* @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 runBeanValue.
*/
Boolean getRunBeanValue();
/**
* @param runBeanValue the runBeanValue to set.
*/
void setRunBeanValue(Boolean runBeanValue);
/**
* @return the writeOrder
*/
Integer getWriteOrder();
/**
* @param writeOrder the writeOrder to set
*/
void setWriteOrder(Integer writeOrder);
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2004-2014, 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);
/**
* Add an parent element tag.
* Used: for xsd/doc only.
* @param namespaceUri The namespace uri of this tag relation.
* @param tag The parent element tag.
*/
void addElementParent(String namespaceUri,String tag);
/**
* Remove and parent element
* Used: for xsd/doc only.
* @param namespaceUri The namespace uri of this tag relation.
* @param tag The parent element tag.
*/
void removeElementParent(String namespaceUri,String tag);
/**
* Returns list of parent element tags.
* Used: for xsd/doc only.
* @param namespaceUri The namespace uri of this tag relation.
* @return The list of tags.
*/
List<String> getElementParents(String namespaceUri);
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2004-2014, 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).
*
*
* @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,76 @@
/*
* Copyright (c) 2004-2014, 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 {
private ElementConfigurator elementConfigurator = null;
/**
* Creates an configurator exception.
* @param config The ElementConfigurator.
* @param message The error message.
*/
public ElementConfiguratorException(ElementConfigurator config,String message) {
super(message);
this.elementConfigurator=config;
}
/**
* 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);
this.elementConfigurator=config;
}
/**
* 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);
this.elementConfigurator=config;
}
/**
* Gets the ElementConfigurator which has thrown this exception.
* @return The ElementConfigurator.
*/
public ElementConfigurator getElementConfigurator() {
return elementConfigurator;
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2004-2014, 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) global.
*
* @author Willem Cazanders
* @version 1.0 Nov 18, 2012
*/
public interface ElementConfiguratorGlobal extends ElementConfigurator {
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2004-2014, 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,44 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* 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);
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2004-2014, 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;
/**
* ElementMetaBase provides a base interface describe meta information.
*
*
* @author Willem Cazanders
* @version 1.0 Jan 13, 2009
*/
public interface ElementMetaBase {
/**
* Sets the id of the ElementMetaBase.
* @param id The id to set.
*/
void setId(String id);
/**
* Returns the id of the ElementMetaBase.
* @return Returns the id.
*/
String getId();
/**
* Sets the description of the ElementMetaBase.
* @param description The description to set.
*/
void setDescription(String description);
/**
* Returns the description of the ElementMetaBase.
* @return Returns the description.
*/
String getDescription();
}

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