Changed main code artifact from x4o-core to x4o-driver.
This commit is contained in:
parent
9ea83fdd1a
commit
9aa15198c9
250 changed files with 42 additions and 54 deletions
142
x4o-driver/src/main/java/org/x4o/xml/X4ODriver.java
Normal file
142
x4o-driver/src/main/java/org/x4o/xml/X4ODriver.java
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.x4o.xml.io.DefaultX4OReader;
|
||||
import org.x4o.xml.io.DefaultX4OSchemaWriter;
|
||||
import org.x4o.xml.io.DefaultX4OWriter;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.io.X4OSchemaWriter;
|
||||
import org.x4o.xml.io.X4OWriter;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageConfiguration;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseManager;
|
||||
|
||||
/**
|
||||
* This is the starting point of the XML X4O Language Driver.
|
||||
*
|
||||
* @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";
|
||||
|
||||
/**
|
||||
* Force public constructor and register the driver.
|
||||
*/
|
||||
public X4ODriver() {
|
||||
X4ODriverManager.registerX4ODriver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
|
||||
|
||||
protected X4OLanguage buildLanguage(String version) {
|
||||
return X4ODriverManager.getDefaultBuildLanguage(this, version);
|
||||
}
|
||||
|
||||
protected X4OPhaseManager buildPhaseManager() {
|
||||
return X4ODriverManager.getDefaultBuildPhaseManager();
|
||||
}
|
||||
|
||||
protected X4OLanguageConfiguration buildLanguageConfiguration() {
|
||||
return X4ODriverManager.getDefaultBuildLanguageConfiguration();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public X4OSchemaWriter createSchemaWriter() {
|
||||
return createSchemaWriter(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
public X4OSchemaWriter createSchemaWriter(String version) {
|
||||
return new DefaultX4OSchemaWriter(createLanguageContext(version));
|
||||
}
|
||||
|
||||
public X4OReader<T> createReader() {
|
||||
return createReader(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
public X4OReader<T> createReader(String version) {
|
||||
return new DefaultX4OReader<T>(createLanguageContext(version));
|
||||
}
|
||||
|
||||
public X4OWriter<T> createWriter() {
|
||||
return createWriter(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
public X4OWriter<T> createWriter(String version) {
|
||||
return new DefaultX4OWriter<T>(createLanguageContext(version));
|
||||
}
|
||||
|
||||
public String getLanguageVersionDefault() {
|
||||
return X4ODriverManager.getDefaultLanguageVersion(getLanguageVersions());
|
||||
}
|
||||
|
||||
public String[] getGlobalPropertyKeySet() {
|
||||
return X4OLanguagePropertyKeys.DEFAULT_X4O_GLOBAL_KEYS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public X4OLanguage createLanguage(String version) {
|
||||
return buildLanguage(version);
|
||||
}
|
||||
|
||||
final public X4OLanguageContext createLanguageContext() {
|
||||
return createLanguageContext(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
final public X4OLanguageContext createLanguageContext(String version) {
|
||||
return createLanguage(version).createLanguageContext(this);
|
||||
}
|
||||
|
||||
final public Collection<String> getGlobalPropertyKeys() {
|
||||
return X4ODriverManager.getGlobalPropertyKeys(this);
|
||||
}
|
||||
|
||||
final public Object getGlobalProperty(String key) {
|
||||
return X4ODriverManager.getGlobalProperty(this, key);
|
||||
}
|
||||
|
||||
final public void setGlobalProperty(String key,Object value) {
|
||||
X4ODriverManager.setGlobalProperty(this, key, value);
|
||||
}
|
||||
}
|
||||
289
x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java
Normal file
289
x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
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.X4OPhaseLanguageInit;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseManager;
|
||||
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;
|
||||
|
||||
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,Map<String,Object>> globalProperties = 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);
|
||||
globalProperties = new HashMap<String,Map<String,Object>>(20);
|
||||
}
|
||||
|
||||
static {
|
||||
instance = new X4ODriverManager();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return new DefaultX4OLanguage(
|
||||
driver.buildLanguageConfiguration(),
|
||||
driver.buildPhaseManager(),
|
||||
driver.getLanguageName(),
|
||||
version
|
||||
);
|
||||
}
|
||||
|
||||
static protected X4OLanguageConfiguration getDefaultBuildLanguageConfiguration() {
|
||||
return new DefaultX4OLanguageConfiguration();
|
||||
}
|
||||
|
||||
static public Collection<String> getGlobalPropertyKeys(X4ODriver<?> driver) {
|
||||
Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName());
|
||||
if (driverProperties==null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return driverProperties.keySet();
|
||||
}
|
||||
|
||||
static public Object getGlobalProperty(X4ODriver<?> driver,String key) {
|
||||
Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName());
|
||||
if (driverProperties==null) {
|
||||
return null;
|
||||
}
|
||||
return driverProperties.get(key);
|
||||
}
|
||||
|
||||
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) {
|
||||
instance.drivers.put(driver.getLanguageName(), driver);
|
||||
}
|
||||
|
||||
static public void deregisterX4ODriver(X4ODriver<?> driver) {
|
||||
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.isEmpty()) {
|
||||
throw new IllegalArgumentException("Can't provider driver for empty language.");
|
||||
}
|
||||
try {
|
||||
instance.lazyInit();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
X4ODriver<?> result = null;
|
||||
try {
|
||||
result = instance.createX4ODriver(language);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (result==null) {
|
||||
throw new IllegalArgumentException("Can't find driver for language: "+language);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static public List<String> getX4OLanguages() {
|
||||
try {
|
||||
instance.lazyInit();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
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() throws IOException, SAXException {
|
||||
if (reloadDrivers==false) {
|
||||
return;
|
||||
}
|
||||
instance.loadLanguageDrivers();
|
||||
reloadDrivers = false;
|
||||
}
|
||||
|
||||
private X4ODriver<?> createX4ODriver(String language) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
if (classdrivers.containsKey(language)) {
|
||||
String driverClassName = classdrivers.get(language);
|
||||
Class<?> driverClass = X4OLanguageClassLoader.loadClass(driverClassName);
|
||||
X4ODriver<?> driver = (X4ODriver<?>)driverClass.newInstance();
|
||||
return driver;
|
||||
}
|
||||
if (defaultDrivers.containsKey(language)) {
|
||||
String driverClassName = defaultDrivers.get(language);
|
||||
Class<?> driverClass = X4OLanguageClassLoader.loadClass(driverClassName);
|
||||
X4ODriver<?> driver = (X4ODriver<?>)driverClass.newInstance();
|
||||
return driver;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all defined language drivers in classpath.
|
||||
*/
|
||||
private void loadLanguageDrivers() throws IOException, SAXException {
|
||||
|
||||
logger.finer("loading x4o drivers from: "+X4O_DRIVERS_RESOURCE);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("tab")) {
|
||||
String language = attr.getValue("language");
|
||||
logger.finest("DefaultDriver language: "+language);
|
||||
if (defaultDrivers.containsKey(language)==false) {
|
||||
defaultDrivers.put(language,language);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* AbstractObjectConverter to create ObjectConverters.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 30, 2012
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
abstract public class AbstractObjectConverter implements ObjectConverter {
|
||||
|
||||
protected List<ObjectConverter> converters = new ArrayList<ObjectConverter>(5);
|
||||
|
||||
abstract public Object convertAfterTo(Object obj, Locale locale) throws ObjectConverterException;
|
||||
abstract public Object convertAfterBack(Object obj, Locale locale) throws ObjectConverterException;
|
||||
abstract public ObjectConverter clone() throws CloneNotSupportedException;
|
||||
|
||||
protected List<ObjectConverter> cloneConverters() throws CloneNotSupportedException {
|
||||
List<ObjectConverter> result = new ArrayList<ObjectConverter>(converters.size());
|
||||
for (ObjectConverter converter:converters) {
|
||||
result.add(converter.clone());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.conv.ObjectConverter#convertTo(java.lang.Object, java.util.Locale)
|
||||
*/
|
||||
public Object convertTo(Object obj, Locale locale) throws ObjectConverterException {
|
||||
if (converters.isEmpty()) {
|
||||
return convertAfterTo(obj,locale);
|
||||
}
|
||||
Object result = null;
|
||||
for (ObjectConverter conv:converters) {
|
||||
result = conv.convertTo(obj, locale);
|
||||
}
|
||||
result = convertAfterTo(obj,locale);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.conv.ObjectConverter#convertBack(java.lang.Object, java.util.Locale)
|
||||
*/
|
||||
public Object convertBack(Object obj, Locale locale) throws ObjectConverterException {
|
||||
if (converters.isEmpty()) {
|
||||
return convertAfterBack(obj,locale);
|
||||
}
|
||||
Object result = null;
|
||||
for (ObjectConverter conv:converters) {
|
||||
result = conv.convertBack(obj, locale);
|
||||
}
|
||||
result = convertAfterBack(obj,locale);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.conv.ObjectConverter#getObjectConverters()
|
||||
*/
|
||||
public List<ObjectConverter> getObjectConverters() {
|
||||
return converters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.conv.ObjectConverter#addObjectConverter(org.x4o.xml.conv.ObjectConverter)
|
||||
*/
|
||||
public void addObjectConverter(ObjectConverter converter) {
|
||||
converters.add(converter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.conv.ObjectConverter#removeObjectConverter(org.x4o.xml.conv.ObjectConverter)
|
||||
*/
|
||||
public void removeObjectConverter(ObjectConverter converter) {
|
||||
converters.remove(converter);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* AbstractStringObjectConverter to create ObjectConverters which work with strings.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 30, 2012
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
abstract public class AbstractStringObjectConverter extends AbstractObjectConverter {
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassBack()
|
||||
*/
|
||||
public Class<?> getObjectClassBack() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public Object convertAfterTo(Object obj, Locale locale) throws ObjectConverterException {
|
||||
if (obj instanceof String) {
|
||||
return convertStringTo((String)obj,locale);
|
||||
} else {
|
||||
return convertStringTo(obj.toString(),locale);
|
||||
}
|
||||
}
|
||||
|
||||
public Object convertAfterBack(Object obj, Locale locale) throws ObjectConverterException {
|
||||
return convertStringBack(obj,locale);
|
||||
}
|
||||
|
||||
abstract public Object convertStringTo(String str, Locale locale) throws ObjectConverterException;
|
||||
abstract public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException;
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.x4o.xml.conv.text.BooleanConverter;
|
||||
import org.x4o.xml.conv.text.ByteConverter;
|
||||
import org.x4o.xml.conv.text.CharacterConverter;
|
||||
import org.x4o.xml.conv.text.ClassConverter;
|
||||
import org.x4o.xml.conv.text.DoubleConverter;
|
||||
import org.x4o.xml.conv.text.FloatConverter;
|
||||
import org.x4o.xml.conv.text.IntegerConverter;
|
||||
import org.x4o.xml.conv.text.LongConverter;
|
||||
import org.x4o.xml.conv.text.URLConverter;
|
||||
|
||||
/**
|
||||
* DefaultObjectConverterProvider 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The interface to convert objects.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 28, 2008
|
||||
*/
|
||||
public interface ObjectConverter extends Cloneable,Serializable {
|
||||
|
||||
/**
|
||||
* @return Returns the class which we can convert to.
|
||||
*/
|
||||
Class<?> getObjectClassTo();
|
||||
|
||||
/**
|
||||
* @return Returns the class which we can convert from.
|
||||
*/
|
||||
Class<?> getObjectClassBack();
|
||||
|
||||
/**
|
||||
* Convert to the object.
|
||||
* @param obj The object to convert.
|
||||
* @param locale The Object convert locale if needed.
|
||||
* @return Returns the converted object.
|
||||
* @throws ObjectConverterException 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;
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
||||
/**
|
||||
* ObjectConverterException is thrown by an ObjectConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class ObjectConverterException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final ObjectConverter converter;
|
||||
|
||||
/**
|
||||
* Creates an ObjectConverterException.
|
||||
* @param converter The converter which has the exception.
|
||||
* @param message The exception message.
|
||||
*/
|
||||
public ObjectConverterException(ObjectConverter converter,String message) {
|
||||
super(message);
|
||||
this.converter=converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ObjectConverterException.
|
||||
* @param converter The converter which has the exception.
|
||||
* @param message The exception message.
|
||||
* @param exception The parent exception.
|
||||
*/
|
||||
public ObjectConverterException(ObjectConverter converter,String message,Exception exception) {
|
||||
super(message,exception);
|
||||
this.converter=converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ObjectConverter of this exception.
|
||||
*/
|
||||
public ObjectConverter getObjectConverter() {
|
||||
return converter;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
||||
/**
|
||||
* ObjectConverterProvider for class.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public interface ObjectConverterProvider {
|
||||
|
||||
/**
|
||||
* Provides an ObjectConvert based on the converted class result.
|
||||
* @param clazz The result class we want.
|
||||
* @return The ObjectConverter which can convert for us.
|
||||
*/
|
||||
ObjectConverter getObjectConverterForClass(Class<?> clazz);
|
||||
}
|
||||
31
x4o-driver/src/main/java/org/x4o/xml/conv/package-info.java
Normal file
31
x4o-driver/src/main/java/org/x4o/xml/conv/package-info.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides interfaces for two way object converters.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv;
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* BooleanConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class BooleanConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = -6641858854858931768L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* ByteConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class ByteConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = -719929830363810123L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* CharacterConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class CharacterConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = -5864405229292234565L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* DoubleConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class DoubleConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = 3283317726435306051L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
import org.x4o.xml.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* FloatConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class FloatConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = 8038640125557062170L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* IntegerConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class IntegerConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = 6618552093124468324L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* LongConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class LongConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = 25132217809739854L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
import org.x4o.xml.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 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 object,Locale locale) throws ObjectConverterException {
|
||||
List<StringSplitConverterStep> steps = getOrderedSteps(false);
|
||||
if (steps.size()!=splitSize) {
|
||||
throw new ObjectConverterException(this,"Step size is wrong; "+steps.size()+" need: "+splitSize);
|
||||
}
|
||||
try {
|
||||
StringBuffer buf = new StringBuffer(200);
|
||||
for (int i=0;i<steps.size();i++) {
|
||||
StringSplitConverterStep step = steps.get(i);
|
||||
Method m = classTo.getMethod(step.getFromMethod(), new Class[] {});
|
||||
Object stepValue = m.invoke(object, new Object[] {});
|
||||
Object stepString = step.getObjectConverter().convertBack(stepValue, locale);
|
||||
buf.append(stepString.toString());
|
||||
}
|
||||
return buf.toString();
|
||||
} catch (Exception e) {
|
||||
throw new ObjectConverterException(this,e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
|
||||
/**
|
||||
* StringSplitConverterStep.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 23, 2012
|
||||
*/
|
||||
public class StringSplitConverterStep {
|
||||
|
||||
private ObjectConverter objectConverter = null;
|
||||
private String fromMethod = null;
|
||||
private Integer fromOrder = null;
|
||||
private String toMethod = null;
|
||||
private Integer toOrder = null;
|
||||
|
||||
/**
|
||||
* @return the objectConverter
|
||||
*/
|
||||
public ObjectConverter getObjectConverter() {
|
||||
return objectConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param objectConverter the objectConverter to set
|
||||
*/
|
||||
public void setObjectConverter(ObjectConverter objectConverter) {
|
||||
this.objectConverter = objectConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fromMethod
|
||||
*/
|
||||
public String getFromMethod() {
|
||||
return fromMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromMethod the fromMethod to set
|
||||
*/
|
||||
public void setFromMethod(String fromMethod) {
|
||||
this.fromMethod = fromMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fromOrder
|
||||
*/
|
||||
public Integer getFromOrder() {
|
||||
return fromOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromOrder the fromOrder to set
|
||||
*/
|
||||
public void setFromOrder(Integer fromOrder) {
|
||||
this.fromOrder = fromOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toMethod
|
||||
*/
|
||||
public String getToMethod() {
|
||||
return toMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toMethod the toMethod to set
|
||||
*/
|
||||
public void setToMethod(String toMethod) {
|
||||
this.toMethod = toMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toOrder
|
||||
*/
|
||||
public Integer getToOrder() {
|
||||
return toOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toOrder the toOrder to set
|
||||
*/
|
||||
public void setToOrder(Integer toOrder) {
|
||||
this.toOrder = toOrder;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.x4o.xml.conv.AbstractStringObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* URLConverter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class URLConverter extends AbstractStringObjectConverter {
|
||||
|
||||
private static final long serialVersionUID = -611843641266301893L;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides default java text converters.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
* @see org.x4o.xml.conv
|
||||
*/
|
||||
|
||||
package org.x4o.xml.conv.text;
|
||||
87
x4o-driver/src/main/java/org/x4o/xml/el/X4OELContext.java
Normal file
87
x4o-driver/src/main/java/org/x4o/xml/el/X4OELContext.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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;
|
||||
|
||||
public X4OELContext(/* X4OLanguageConfiguration x4oParserConfig */) {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.el.ELContext#getELResolver()
|
||||
*/
|
||||
@Override
|
||||
public ELResolver getELResolver() {
|
||||
return elResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.el.ELContext#getFunctionMapper()
|
||||
*/
|
||||
@Override
|
||||
public FunctionMapper getFunctionMapper() {
|
||||
return functionMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.el.ELContext#getVariableMapper()
|
||||
*/
|
||||
@Override
|
||||
public VariableMapper getVariableMapper() {
|
||||
return variableMapper;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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 {
|
||||
private Map<String,Method> functionMap = null;
|
||||
|
||||
public X4OELFunctionMapper() {
|
||||
functionMap = new HashMap<String,Method>(50);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method resolveFunction(String prefix, String localName) {
|
||||
String key = prefix + ":" + localName;
|
||||
return functionMap.get(key);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
102
x4o-driver/src/main/java/org/x4o/xml/el/X4OELResolver.java
Normal file
102
x4o-driver/src/main/java/org/x4o/xml/el/X4OELResolver.java
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.el;
|
||||
|
||||
import javax.el.ExpressionFactory;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
||||
/**
|
||||
* 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(X4OLanguageContext elementContext) {
|
||||
ExpressionFactory factory = (ExpressionFactory)elementContext.getLanguageProperty(X4OLanguageProperty.EL_FACTORY_INSTANCE);
|
||||
if (factory!=null) {
|
||||
return factory;
|
||||
}
|
||||
try {
|
||||
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_APACHE);
|
||||
ExpressionFactory expressionFactory = (ExpressionFactory) expressionFactoryClass.newInstance();
|
||||
return expressionFactory;
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_ODYSSEUS);
|
||||
ExpressionFactory expressionFactory = (ExpressionFactory) expressionFactoryClass.newInstance();
|
||||
return expressionFactory;
|
||||
} 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
x4o-driver/src/main/java/org/x4o/xml/el/package-info.java
Normal file
31
x4o-driver/src/main/java/org/x4o/xml/el/package-info.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The X4O EL Support classes.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
package org.x4o.xml.el;
|
||||
50
x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java
Normal file
50
x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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";
|
||||
public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return LANGUAGE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
53
x4o-driver/src/main/java/org/x4o/xml/eld/EldDriver.java
Normal file
53
x4o-driver/src/main/java/org/x4o/xml/eld/EldDriver.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
125
x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoader.java
Normal file
125
x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoader.java
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.X4ODriverManager;
|
||||
import org.x4o.xml.io.DefaultX4OReader;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* De default X4OElementConfigurator.
|
||||
*
|
||||
* @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 configuration. */
|
||||
public static final String EL_PARENT_LANGUAGE_CONFIGURATION = "parentLanguageConfiguration";
|
||||
|
||||
/** The EL key to access the parent language module. */
|
||||
public static final String EL_PARENT_ELEMENT_LANGUAGE_MODULE = "parentElementLanguageModule";
|
||||
|
||||
/** 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 elementLanguage The langauge to load for.
|
||||
* @param elementLanguageModule 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.X4OLanguageContext, org.x4o.xml.lang.X4OLanguageModule)
|
||||
*/
|
||||
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModule elementLanguageModule) throws X4OLanguageModuleLoaderException {
|
||||
logger.fine("Loading name eld file from resource: "+eldResource);
|
||||
try {
|
||||
//EldDriver parser = new EldDriver(elementLanguage,elementLanguageModule,isEldCore);
|
||||
|
||||
X4ODriver<?> driver = null;
|
||||
if (isEldCore) {
|
||||
driver = X4ODriverManager.getX4ODriver(CelDriver.LANGUAGE_NAME);
|
||||
} else {
|
||||
driver = X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
}
|
||||
|
||||
X4OLanguageContext eldLang = driver.createLanguageContext(driver.getLanguageVersionDefault());
|
||||
X4OReader<?> reader = new DefaultX4OReader<Object>(eldLang);
|
||||
|
||||
reader.addELBeanInstance(EL_PARENT_LANGUAGE_CONFIGURATION, language.getLanguageConfiguration());
|
||||
reader.addELBeanInstance(EL_PARENT_LANGUAGE, language);
|
||||
reader.addELBeanInstance(EL_PARENT_ELEMENT_LANGUAGE_MODULE, elementLanguageModule);
|
||||
|
||||
//TODO: if (language.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
|
||||
// eldLang.setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter());
|
||||
// }
|
||||
|
||||
reader.readResource(eldResource);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
|
||||
} catch (SecurityException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
|
||||
} catch (NullPointerException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
|
||||
} catch (ParserConfigurationException 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.x4o.xml.conv.text.ClassConverter;
|
||||
import org.x4o.xml.eld.lang.BeanElement;
|
||||
import org.x4o.xml.eld.lang.DescriptionElement;
|
||||
import org.x4o.xml.eld.lang.ElementClassAddParentElement;
|
||||
import org.x4o.xml.eld.lang.ElementClassAttributeBindingHandler;
|
||||
import org.x4o.xml.eld.lang.ElementClassBindingHandler;
|
||||
import org.x4o.xml.eld.lang.ElementInterfaceBindingHandler;
|
||||
import org.x4o.xml.eld.lang.ElementModuleBindingHandler;
|
||||
import org.x4o.xml.eld.lang.ElementNamespaceContextBindingHandler;
|
||||
import org.x4o.xml.eld.lang.ModuleElement;
|
||||
import org.x4o.xml.element.DefaultElementClass;
|
||||
import org.x4o.xml.element.ElementBindingHandler;
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
|
||||
/**
|
||||
* 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 = "cel.x4o.org";
|
||||
private static final String PP_CEL_XMLNS = "http://"+PP_CEL_PROVIDER+"/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_URI = PP_CEL_XMLNS+CEL_CORE;
|
||||
private static final String CEL_ROOT_URI = PP_CEL_XMLNS+CEL_ROOT;
|
||||
private static final String CEL_CORE_XSD_URI = CEL_CORE_URI+PP_CEL_XSD_FILE;
|
||||
private static final String CEL_ROOT_XSD_URI = CEL_ROOT_URI+PP_CEL_XSD_FILE;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Creates the CEL module loader.
|
||||
*/
|
||||
public EldModuleLoaderCore() {
|
||||
logger = Logger.getLogger(EldModuleLoaderCore.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the CEL language into the module.
|
||||
* @param elementLanguage The langauge to load for.
|
||||
* @param elementLanguageModule The module to load it in.
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.element.ElementLanguage, org.x4o.xml.lang.X4OLanguageModule)
|
||||
*/
|
||||
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModule elementLanguageModule) throws X4OLanguageModuleLoaderException {
|
||||
|
||||
elementLanguageModule.setId("cel-module");
|
||||
elementLanguageModule.setName("Core Element Languag Module");
|
||||
elementLanguageModule.setProviderName(PP_CEL_PROVIDER);
|
||||
|
||||
List<ElementClass> elementClassList = new ArrayList<ElementClass>(10);
|
||||
elementClassList.add(new DefaultElementClass("attribute",language.getLanguageConfiguration().getDefaultElementClassAttribute()));
|
||||
elementClassList.add(new DefaultElementClass("classConverter",ClassConverter.class));
|
||||
|
||||
createElementClasses(elementClassList,language); // adds all meta info
|
||||
|
||||
ElementClassAttribute attr;
|
||||
|
||||
DefaultElementClass ns = new DefaultElementClass("namespace",language.getLanguageConfiguration().getDefaultElementNamespaceContext());
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("uri");
|
||||
attr.setRequired(true);
|
||||
ns.addElementClassAttribute(attr);
|
||||
elementClassList.add(ns);
|
||||
|
||||
DefaultElementClass dec = new DefaultElementClass("element",language.getLanguageConfiguration().getDefaultElementClass());
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("objectClass");
|
||||
attr.setObjectConverter(new ClassConverter());
|
||||
dec.addElementClassAttribute(attr);
|
||||
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("elementClass");
|
||||
attr.setObjectConverter(new ClassConverter());
|
||||
dec.addElementClassAttribute(attr);
|
||||
elementClassList.add(dec);
|
||||
|
||||
DefaultElementClass ec = new DefaultElementClass("elementInterface",language.getLanguageConfiguration().getDefaultElementInterface());
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("interfaceClass");
|
||||
attr.setObjectConverter(new ClassConverter());
|
||||
ec.addElementClassAttribute(attr);
|
||||
elementClassList.add(ec);
|
||||
|
||||
logger.finer("Creating eldcore namespace.");
|
||||
ElementNamespaceContext namespace;
|
||||
try {
|
||||
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceContext());
|
||||
} 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(CEL_CORE);
|
||||
namespace.setUri(CEL_CORE_URI);
|
||||
namespace.setSchemaUri(CEL_CORE_XSD_URI);
|
||||
namespace.setSchemaResource(CEL_CORE_XSD_FILE);
|
||||
namespace.setSchemaPrefix(CEL_CORE);
|
||||
|
||||
logger.finer("Loading elementClassList size: "+elementClassList.size());
|
||||
for (ElementClass ecL:elementClassList) {
|
||||
namespace.addElementClass(ecL);
|
||||
}
|
||||
|
||||
addBindingHandler("cel-class-bind",new ElementClassBindingHandler(),elementLanguageModule);
|
||||
addBindingHandler("cel-module-bind",new ElementModuleBindingHandler(),elementLanguageModule);
|
||||
addBindingHandler("cel-class-attr-bind",new ElementClassAttributeBindingHandler(),elementLanguageModule);
|
||||
addBindingHandler("cel-interface-bind",new ElementInterfaceBindingHandler(),elementLanguageModule);
|
||||
addBindingHandler("cel-namespace-bind",new ElementNamespaceContextBindingHandler(),elementLanguageModule);
|
||||
|
||||
try {
|
||||
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
|
||||
} catch (ElementNamespaceInstanceProviderException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
|
||||
}
|
||||
|
||||
elementLanguageModule.addElementNamespaceContext(namespace);
|
||||
|
||||
|
||||
// And define root
|
||||
try {
|
||||
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceContext());
|
||||
} 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(CEL_ROOT);
|
||||
namespace.setUri(CEL_ROOT_URI);
|
||||
namespace.setSchemaUri(CEL_ROOT_XSD_URI);
|
||||
namespace.setSchemaResource(CEL_ROOT_XSD_FILE);
|
||||
namespace.setSchemaPrefix(CEL_ROOT);
|
||||
namespace.addElementClass(new DefaultElementClass("module",language.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class));
|
||||
namespace.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
|
||||
try {
|
||||
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
|
||||
} catch (ElementNamespaceInstanceProviderException e) {
|
||||
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
|
||||
}
|
||||
elementLanguageModule.addElementNamespaceContext(namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds only Element class beans which need extra meta info for schema.
|
||||
*
|
||||
* @param elementClassList The list to fill.
|
||||
* @throws X4OLanguageModuleLoaderException
|
||||
*/
|
||||
private void createElementClasses(List<ElementClass> elementClassList,X4OLanguage language) throws X4OLanguageModuleLoaderException {
|
||||
ElementClass ec = null;
|
||||
ElementClassAttribute attr = null;
|
||||
|
||||
ec = new DefaultElementClass("bindingHandler",null,BeanElement.class);
|
||||
ec.addElementParent(CEL_ROOT_URI, "module");
|
||||
ec.addElementParent(CEL_CORE_URI, "elementInterface");
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("id");
|
||||
attr.setRequired(true);
|
||||
ec.addElementClassAttribute(attr);
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("bean.class");
|
||||
attr.setRequired(true);
|
||||
ec.addElementClassAttribute(attr);
|
||||
elementClassList.add(ec);
|
||||
|
||||
ec = new DefaultElementClass("attributeHandler",null,BeanElement.class);
|
||||
ec.addElementParent(CEL_ROOT_URI, "module");
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("bean.class");
|
||||
attr.setRequired(true);
|
||||
ec.addElementClassAttribute(attr);
|
||||
elementClassList.add(ec);
|
||||
|
||||
ec = new DefaultElementClass("configurator",null,BeanElement.class);
|
||||
ec.addElementParent(CEL_CORE_URI, "elementInterface");
|
||||
ec.addElementParent(CEL_CORE_URI, "element");
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("bean.class");
|
||||
attr.setRequired(true);
|
||||
ec.addElementClassAttribute(attr);
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("configAction");
|
||||
ec.addElementClassAttribute(attr);
|
||||
elementClassList.add(ec);
|
||||
|
||||
ec = new DefaultElementClass("configuratorGlobal",null,BeanElement.class);
|
||||
ec.addElementParent(CEL_ROOT_URI, "module");
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("bean.class");
|
||||
attr.setRequired(true);
|
||||
ec.addElementClassAttribute(attr);
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("configAction");
|
||||
ec.addElementClassAttribute(attr);
|
||||
elementClassList.add(ec);
|
||||
|
||||
ec = new DefaultElementClass("description",null,DescriptionElement.class);
|
||||
ec.setSchemaContentBase("string");
|
||||
ec.addElementParent(CEL_ROOT_URI, "module");
|
||||
ec.addElementParent(CEL_CORE_URI, "namespace");
|
||||
ec.addElementParent(CEL_CORE_URI, "attributeHandler");
|
||||
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");
|
||||
elementClassList.add(ec);
|
||||
|
||||
ec = new DefaultElementClass("elementParent",null,ElementClassAddParentElement.class);
|
||||
ec.addElementParent(CEL_CORE_URI, "element");
|
||||
ec.addElementParent(CEL_CORE_URI, "elementInterface");
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("tag");
|
||||
attr.setRequired(true);
|
||||
ec.addElementClassAttribute(attr);
|
||||
attr = newElementClassAttribute(language);
|
||||
attr.setName("uri");
|
||||
ec.addElementClassAttribute(attr);
|
||||
elementClassList.add(ec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new ElementClassAttribute instance.
|
||||
* @param elementLanguage The ElementLanguage to create from.
|
||||
* @return The new ElementClassAttribute instance.
|
||||
* @throws X4OLanguageModuleLoaderException When class could not be created.
|
||||
*/
|
||||
private ElementClassAttribute newElementClassAttribute(X4OLanguage language) throws X4OLanguageModuleLoaderException {
|
||||
try {
|
||||
return (ElementClassAttribute)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClassAttribute());
|
||||
} 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 id The id to set on the handler.
|
||||
* @param handler The handler to add the the module.
|
||||
* @param elementLanguageModule The module to add the handler to.
|
||||
*/
|
||||
private void addBindingHandler(String id,ElementBindingHandler handler,X4OLanguageModule elementLanguageModule) {
|
||||
handler.setId(id);
|
||||
elementLanguageModule.addElementBindingHandler(handler);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
/**
|
||||
* AttributeAliasElement add the defines alias to the parent element attribute.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 23, 2006
|
||||
*/
|
||||
public class AttributeAliasElement extends AbstractElement {
|
||||
|
||||
/**
|
||||
* 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().getTag());
|
||||
}
|
||||
if (getParent().getElementObject() instanceof ElementClassAttribute) {
|
||||
((ElementClassAttribute)getParent().getElementObject()).addAttributeAlias(alias);
|
||||
} else {
|
||||
throw new ElementException("Wrong parent class is not ElementClassAttribute but: "+getParent().getElementObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.element.AbstractElementConfigurator;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.Element.ElementType;
|
||||
import org.x4o.xml.element.ElementConfiguratorException;
|
||||
|
||||
/**
|
||||
* AttributeFromBodyConfigurator sets the body as attribute.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 23, 2012
|
||||
*/
|
||||
public class AttributeFromBodyConfigurator extends AbstractElementConfigurator {
|
||||
|
||||
private String name = null;
|
||||
private String bodyType = null;
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementConfigurator#doConfigElement(org.x4o.xml.element.Element)
|
||||
*/
|
||||
public void doConfigElement(Element element) throws ElementConfiguratorException {
|
||||
if (name==null) {
|
||||
throw new ElementConfiguratorException(this,"name attribute is not set.");
|
||||
}
|
||||
if (name.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.length()==0) {
|
||||
return;
|
||||
}
|
||||
element.getAttributes().put(name, value);
|
||||
}
|
||||
|
||||
private String fetchBodyType(Element element,ElementType elementType) {
|
||||
StringBuffer buf = new StringBuffer(300);
|
||||
List<Element> childsAll = element.getAllChilderen();
|
||||
List<Element> childs = ElementType.filterElements(childsAll, elementType);
|
||||
for (int i=0;i<childs.size();i++) {
|
||||
Element e = childs.get(i);
|
||||
buf.append(e.getElementObject().toString());
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bodyType
|
||||
*/
|
||||
public String getBodyType() {
|
||||
return bodyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bodyType the bodyType to set
|
||||
*/
|
||||
public void setBodyType(String bodyType) {
|
||||
this.bodyType = bodyType;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementMetaBase;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
/**
|
||||
* Fills all the ElementDescription which the description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 13, 2009
|
||||
*/
|
||||
public class DescriptionElement extends AbstractElement {
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.AbstractElement#doElementStart()
|
||||
*/
|
||||
@Override
|
||||
public void doElementStart() throws ElementException {
|
||||
if (getParent()==null) {
|
||||
throw new ElementException("can't be a root tag");
|
||||
}
|
||||
if (getParent().getElementObject() instanceof ElementMetaBase == false) {
|
||||
throw new ElementException("Wrong parent class is not ElementDescription");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void doCharacters(String characters) throws ElementException {
|
||||
super.doCharacters(characters);
|
||||
setElementObject(characters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
|
||||
*/
|
||||
@Override
|
||||
public void doElementEnd() throws ElementException {
|
||||
if (getElementObject()==null) {
|
||||
throw new ElementException("description is not set.");
|
||||
}
|
||||
if (getParent().getElementObject() instanceof ElementMetaBase) {
|
||||
((ElementMetaBase)getParent().getElementObject()).setDescription(getElementObject().toString());
|
||||
} else {
|
||||
throw new ElementException("Wrong parent class is not ElementClass");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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().getTag());
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.element.AbstractElementBindingHandler;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementBindingHandlerException;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
|
||||
/**
|
||||
* ElementClassAttributeBindingHandler adds the object converter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 21, 2012
|
||||
*/
|
||||
public class ElementClassAttributeBindingHandler extends AbstractElementBindingHandler<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;
|
||||
}
|
||||
|
||||
public void bindChild(Element childElement,ElementClassAttribute parentObject,Object childObject) throws ElementBindingHandlerException {
|
||||
if (childObject instanceof ObjectConverter) {
|
||||
parentObject.setObjectConverter((ObjectConverter)childObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void createChilderen(Element parentElement,ElementClassAttribute parentObject) throws ElementBindingHandlerException {
|
||||
createChild(parentElement, parentObject.getObjectConverter());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElementBindingHandler;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementBindingHandlerException;
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
import org.x4o.xml.element.ElementConfigurator;
|
||||
|
||||
/**
|
||||
* This ElementBindingHandler adds the ElementClassAttributeConverter and the
|
||||
* ElementConfigurator to the ElementClass.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 31, 2007
|
||||
*/
|
||||
public class ElementClassBindingHandler extends AbstractElementBindingHandler<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.ElementBindingHandler#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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElementBindingHandler;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementBindingHandler;
|
||||
import org.x4o.xml.element.ElementBindingHandlerException;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
import org.x4o.xml.element.ElementConfigurator;
|
||||
import org.x4o.xml.element.ElementInterface;
|
||||
|
||||
/**
|
||||
* ElementInterfaceBindingHandler binds all childs into the interface.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 21, 2012
|
||||
*/
|
||||
public class ElementInterfaceBindingHandler extends AbstractElementBindingHandler<ElementInterface> {
|
||||
|
||||
private final static Class<?>[] CLASSES_CHILD = new Class[] {
|
||||
ElementClassAttribute.class,
|
||||
ElementConfigurator.class,
|
||||
ElementBindingHandler.class
|
||||
};
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
|
||||
*/
|
||||
public Class<?> getBindParentClass() {
|
||||
return ElementInterface.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
|
||||
*/
|
||||
public Class<?>[] getBindChildClasses() {
|
||||
return CLASSES_CHILD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#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 ElementBindingHandler) {
|
||||
parent.addElementBindingHandler((ElementBindingHandler)childObject);
|
||||
}
|
||||
if (childObject instanceof ElementClassAttribute) {
|
||||
parent.addElementClassAttribute((ElementClassAttribute)childObject);
|
||||
}
|
||||
if (childObject instanceof ElementConfigurator) {
|
||||
parent.addElementConfigurators((ElementConfigurator)childObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void createChilderen(Element parentElement,ElementInterface parent) throws ElementBindingHandlerException {
|
||||
for (ElementBindingHandler child:parent.getElementBindingHandlers()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
for (ElementClassAttribute child:parent.getElementClassAttributes()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
for (ElementConfigurator child:parent.getElementConfigurators()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.x4o.xml.eld.EldModuleLoader;
|
||||
import org.x4o.xml.element.AbstractElementBindingHandler;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementAttributeHandler;
|
||||
import org.x4o.xml.element.ElementBindingHandler;
|
||||
import org.x4o.xml.element.ElementBindingHandlerException;
|
||||
import org.x4o.xml.element.ElementConfiguratorGlobal;
|
||||
import org.x4o.xml.element.ElementInterface;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
||||
/**
|
||||
* 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<X4OLanguageModule> {
|
||||
|
||||
private final static Class<?>[] CLASSES_CHILD = new Class[] {
|
||||
ElementInterface.class,
|
||||
ElementNamespaceContext.class,
|
||||
ElementBindingHandler.class,
|
||||
ElementAttributeHandler.class,
|
||||
ElementConfiguratorGlobal.class,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
|
||||
*/
|
||||
public Class<?> getBindParentClass() {
|
||||
return X4OLanguageModule.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
|
||||
*/
|
||||
public Class<?>[] getBindChildClasses() {
|
||||
return CLASSES_CHILD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void bindChild(Element childElement,X4OLanguageModule languageModule, Object childObject) throws ElementBindingHandlerException {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map m = (Map)childElement.getLanguageContext().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
|
||||
if (m==null) {
|
||||
return;
|
||||
}
|
||||
X4OLanguage x4oParsingContext = (X4OLanguage)m.get(EldModuleLoader.EL_PARENT_LANGUAGE);
|
||||
//ElementLanguageModule elementLanguageModule = (ElementLanguageModule)m.get(EldParser.PARENT_ELEMENT_LANGUAGE_MODULE);
|
||||
if (x4oParsingContext==null) {
|
||||
return;
|
||||
}
|
||||
if (languageModule==null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (childObject instanceof ElementInterface) {
|
||||
ElementInterface elementInterface = (ElementInterface)childObject;
|
||||
languageModule.addElementInterface(elementInterface);
|
||||
return;
|
||||
}
|
||||
if (childObject instanceof ElementNamespaceContext) {
|
||||
ElementNamespaceContext elementNamespaceContext = (ElementNamespaceContext)childObject;
|
||||
try {
|
||||
elementNamespaceContext.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(childElement.getLanguageContext().getLanguage().getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
|
||||
} catch (Exception e) {
|
||||
throw new ElementBindingHandlerException("Error loading: "+e.getMessage(),e);
|
||||
}
|
||||
try {
|
||||
|
||||
elementNamespaceContext.getElementNamespaceInstanceProvider().start(x4oParsingContext, elementNamespaceContext);
|
||||
} catch (ElementNamespaceInstanceProviderException e) {
|
||||
throw new ElementBindingHandlerException("Error starting: "+e.getMessage(),e);
|
||||
}
|
||||
languageModule.addElementNamespaceContext(elementNamespaceContext);
|
||||
return;
|
||||
}
|
||||
if (childObject instanceof ElementBindingHandler) {
|
||||
ElementBindingHandler elementBindingHandler = (ElementBindingHandler)childObject;
|
||||
languageModule.addElementBindingHandler(elementBindingHandler);
|
||||
return;
|
||||
}
|
||||
if (childObject instanceof ElementAttributeHandler) {
|
||||
ElementAttributeHandler elementAttributeHandler = (ElementAttributeHandler)childObject;
|
||||
languageModule.addElementAttributeHandler(elementAttributeHandler);
|
||||
return;
|
||||
}
|
||||
if (childObject instanceof ElementConfiguratorGlobal) {
|
||||
ElementConfiguratorGlobal elementConfigurator = (ElementConfiguratorGlobal)childObject;
|
||||
languageModule.addElementConfiguratorGlobal(elementConfigurator);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void createChilderen(Element parentElement,X4OLanguageModule parent) throws ElementBindingHandlerException {
|
||||
for (ElementInterface child:parent.getElementInterfaces()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
for (ElementNamespaceContext child:parent.getElementNamespaceContexts()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
for (ElementBindingHandler child:parent.getElementBindingHandlers()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
for (ElementAttributeHandler child:parent.getElementAttributeHandlers()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
for (ElementConfiguratorGlobal child:parent.getElementConfiguratorGlobals()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElementBindingHandler;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementBindingHandlerException;
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
|
||||
/**
|
||||
* ElementNamespaceContextBindingHandler binds ElementClass into namespace.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 21, 2012
|
||||
*/
|
||||
public class ElementNamespaceContextBindingHandler extends AbstractElementBindingHandler<ElementNamespaceContext> {
|
||||
|
||||
private final static Class<?>[] CLASSES_CHILD = new Class[] {
|
||||
ElementClass.class
|
||||
};
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
|
||||
*/
|
||||
public Class<?> getBindParentClass() {
|
||||
return ElementNamespaceContext.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
|
||||
*/
|
||||
public Class<?>[] getBindChildClasses() {
|
||||
return CLASSES_CHILD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void bindChild(Element childElement,ElementNamespaceContext parent, Object childObject) throws ElementBindingHandlerException {
|
||||
if (childObject instanceof ElementClass) {
|
||||
parent.addElementClass((ElementClass)childObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void createChilderen(Element parentElement,ElementNamespaceContext parent) throws ElementBindingHandlerException {
|
||||
for (ElementClass child:parent.getElementClasses()) {
|
||||
createChild(parentElement, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 addMethod = null;
|
||||
private String getMethod = null;
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
|
||||
*/
|
||||
public Class<?> getBindParentClass() {
|
||||
return parentClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
|
||||
*/
|
||||
public Class<?>[] getBindChildClasses() {
|
||||
return new Class[] {childClass};
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementBindingHandler#bindChild(org.x4o.xml.element.Element,java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void bindChild(Element childElement, Object parentObject, Object childObject) throws ElementBindingHandlerException {
|
||||
|
||||
if (parentClass==null | childClass==null | addMethod==null) {
|
||||
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" addMethod="+addMethod+".");
|
||||
}
|
||||
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: "+childClass+" id:"+getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void createChilderen(Element parentElement,Object parentObject) throws ElementBindingHandlerException {
|
||||
if (parentClass==null | childClass==null | getMethod==null) {
|
||||
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" getMethod="+getMethod+".");
|
||||
}
|
||||
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;
|
||||
}
|
||||
try {
|
||||
Object result = m.invoke(parentObject, new Object[]{});
|
||||
if (result==null) {
|
||||
break;
|
||||
}
|
||||
if (result instanceof List) {
|
||||
for (Object o:(List)result) {
|
||||
createChild(parentElement, o);
|
||||
}
|
||||
return;
|
||||
} else if (result instanceof Collection) {
|
||||
for (Object o:(Collection)result) {
|
||||
createChild(parentElement, o);
|
||||
}
|
||||
return;
|
||||
} else if (result instanceof Array) {
|
||||
for (Object o:(Object[])result) {
|
||||
createChild(parentElement, o);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
throw new ElementBindingHandlerException("Unsuported return type: "+result.getClass()+" from: "+getMethod+" on: "+parentObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ElementBindingHandlerException("Error invoke binding method of: "+getId()+" error: "+e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
throw new ElementBindingHandlerException("Could not find method: "+getMethod+" on: "+parentObject+" id:"+getId());
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.x4o.xml.eld.EldModuleLoader;
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map m = (Map)getLanguageContext().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
|
||||
if (m==null) {
|
||||
return;
|
||||
}
|
||||
X4OLanguageModule elementLanguageModule = (X4OLanguageModule)m.get(EldModuleLoader.EL_PARENT_ELEMENT_LANGUAGE_MODULE);
|
||||
setElementObject(elementLanguageModule);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementAttributeHandler;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
/**
|
||||
* NextAttributeElement.<br>
|
||||
* Parses the attributeName and adds it to the ElementClass
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 19, 2007
|
||||
*/
|
||||
public class NextAttributeElement extends AbstractElement {
|
||||
|
||||
@Override
|
||||
public void doElementRun() throws ElementException {
|
||||
String param = getAttributes().get("attributeName");
|
||||
if (param==null) {
|
||||
throw new ElementException("attributeName may not be null");
|
||||
}
|
||||
if (getParent()==null) {
|
||||
throw new ElementException("can't be a root tag");
|
||||
}
|
||||
if (getParent().getElementObject() instanceof ElementAttributeHandler) {
|
||||
((ElementAttributeHandler)getParent().getElementObject()).addNextAttribute(param);
|
||||
} else {
|
||||
throw new ElementException("Wrong parent class");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.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().getTag());
|
||||
}
|
||||
if (getParent().getElementObject() instanceof ElementClass) {
|
||||
((ElementClass)getParent().getElementObject()).addSkipPhase(phase);
|
||||
} else {
|
||||
throw new ElementException("Wrong parent class is not ElementClassAttribute but: "+getParent().getElementObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.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.ElementBindingHandler#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
import org.x4o.xml.conv.text.StringSplitConverterStep;
|
||||
import org.x4o.xml.element.AbstractElementBindingHandler;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementBindingHandlerException;
|
||||
|
||||
/**
|
||||
* StringSplitConverterStepBindingHandler binds the object converter to the step.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 21, 2012
|
||||
*/
|
||||
public class StringSplitConverterStepBindingHandler extends AbstractElementBindingHandler<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.ElementBindingHandler#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());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The X4O ELD Language x4o classes.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.lang;
|
||||
31
x4o-driver/src/main/java/org/x4o/xml/eld/package-info.java
Normal file
31
x4o-driver/src/main/java/org/x4o/xml/eld/package-info.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The X4O Element Language Definition parser.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld;
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.xsd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.sax.XMLWriter;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
|
||||
/**
|
||||
* EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 8, 2012
|
||||
*/
|
||||
public class EldXsdXmlGenerator {
|
||||
|
||||
private X4OLanguage language = null;
|
||||
|
||||
public EldXsdXmlGenerator(X4OLanguage language) {
|
||||
this.language=language;
|
||||
|
||||
}
|
||||
|
||||
private void checkNamespace(ElementNamespaceContext ns) {
|
||||
if (ns.getSchemaResource()==null) {
|
||||
throw new NullPointerException("Can't generate xsd for namespace without schemaResource uri: "+ns.getUri());
|
||||
}
|
||||
if (ns.getSchemaResource().length()==0) {
|
||||
throw new NullPointerException("Can't generate xsd for namespace with empty schemaResource uri: "+ns.getUri());
|
||||
}
|
||||
}
|
||||
|
||||
public void writeSchema(File basePath,String namespace) throws ElementException {
|
||||
try {
|
||||
if (namespace!=null) {
|
||||
ElementNamespaceContext ns = language.findElementNamespaceContext(namespace);
|
||||
if (ns==null) {
|
||||
throw new NullPointerException("Could not find namespace: "+namespace);
|
||||
}
|
||||
checkNamespace(ns);
|
||||
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
|
||||
try {
|
||||
XMLWriter out = new XMLWriter(fio);
|
||||
generateSchema(ns.getUri(), out);
|
||||
} finally {
|
||||
fio.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (X4OLanguageModule mod:language.getLanguageModules()) {
|
||||
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
|
||||
checkNamespace(ns);
|
||||
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
|
||||
try {
|
||||
XMLWriter out = new XMLWriter(fio);
|
||||
generateSchema(ns.getUri(), out);
|
||||
} finally {
|
||||
fio.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ElementException(e); // todo rm
|
||||
}
|
||||
}
|
||||
|
||||
public void generateSchema(String namespaceUri,DefaultHandler2 xmlWriter) throws SAXException {
|
||||
|
||||
ElementNamespaceContext ns = language.findElementNamespaceContext(namespaceUri);
|
||||
if (ns==null) {
|
||||
throw new NullPointerException("Could not find namespace: "+namespaceUri);
|
||||
}
|
||||
|
||||
EldXsdXmlWriter xsdWriter = new EldXsdXmlWriter(xmlWriter,language);
|
||||
xsdWriter.startNamespaces(namespaceUri);
|
||||
xsdWriter.startSchema(ns);
|
||||
for (ElementClass ec:ns.getElementClasses()) {
|
||||
xsdWriter.writeElementClass(ec,ns);
|
||||
}
|
||||
for (ElementClass ec:ns.getElementClasses()) {
|
||||
xsdWriter.writeElement(ec,ns);
|
||||
}
|
||||
xsdWriter.endSchema();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,451 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.xsd;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.x4o.xml.element.ElementAttributeHandler;
|
||||
import org.x4o.xml.element.ElementBindingHandler;
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementClassAttribute;
|
||||
import org.x4o.xml.element.ElementInterface;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* EldXsdXmlWriter Creates the schema from an eld resource.
|
||||
*
|
||||
* Note: this is still writing a bit quick and hacky.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 8, 2012
|
||||
*/
|
||||
public class EldXsdXmlWriter {
|
||||
|
||||
|
||||
static public final String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
protected X4OLanguage language = null;
|
||||
protected DefaultHandler2 xmlWriter = null;
|
||||
protected String writeNamespace = null;
|
||||
protected Map<String, String> namespaces = null;
|
||||
|
||||
public EldXsdXmlWriter(DefaultHandler2 xmlWriter,X4OLanguage language) {
|
||||
this.xmlWriter=xmlWriter;
|
||||
this.language=language;
|
||||
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 (ElementNamespaceContext nsContext:modContext.getElementNamespaceContexts()) {
|
||||
for (ElementClass ec:nsContext.getElementClasses()) {
|
||||
Class<?> objectClass = null;
|
||||
if (ec.getObjectClass()!=null) {
|
||||
objectClass = ec.getObjectClass();
|
||||
for (X4OLanguageModule mod:language.getLanguageModules()) {
|
||||
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
|
||||
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_SEPERATOR = " ==================================================================== ";
|
||||
private static final String COMMENT_TEXT = "=====";
|
||||
|
||||
public void startSchema(ElementNamespaceContext ns) throws SAXException {
|
||||
|
||||
xmlWriter.startDocument();
|
||||
|
||||
// this is a mess;
|
||||
char[] msg;
|
||||
msg = "\n".toCharArray();
|
||||
xmlWriter.ignorableWhitespace(msg,0,msg.length);
|
||||
msg = COMMENT_SEPERATOR.toCharArray();
|
||||
xmlWriter.comment(msg,0,msg.length);
|
||||
String desc = "Automatic generated schema for language: "+language.getLanguageName();
|
||||
int space = COMMENT_SEPERATOR.length()-desc.length()-(2*COMMENT_TEXT.length())-4;
|
||||
StringBuffer b = new StringBuffer(COMMENT_SEPERATOR.length());
|
||||
b.append(" ");
|
||||
b.append(COMMENT_TEXT);
|
||||
b.append(" ");
|
||||
b.append(desc);
|
||||
for (int i=0;i<space;i++) {
|
||||
b.append(' ');
|
||||
}
|
||||
b.append(COMMENT_TEXT);
|
||||
b.append(" ");
|
||||
|
||||
msg = "\n".toCharArray();
|
||||
xmlWriter.ignorableWhitespace(msg,0,msg.length);
|
||||
msg = b.toString().toCharArray();
|
||||
xmlWriter.comment(msg,0,msg.length);
|
||||
msg = "\n".toCharArray();
|
||||
xmlWriter.ignorableWhitespace(msg,0,msg.length);
|
||||
msg = COMMENT_SEPERATOR.toCharArray();
|
||||
xmlWriter.comment(msg,0,msg.length);
|
||||
msg = "\n".toCharArray();
|
||||
xmlWriter.ignorableWhitespace(msg,0,msg.length);
|
||||
|
||||
X4OLanguageModule module = null;
|
||||
for (X4OLanguageModule elm:language.getLanguageModules()) {
|
||||
ElementNamespaceContext s = elm.getElementNamespaceContext(ns.getUri());
|
||||
if (s!=null) {
|
||||
module = elm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b = new StringBuffer(COMMENT_SEPERATOR.length());
|
||||
b.append("\n\tProviderName:\t");
|
||||
b.append(module.getProviderName());
|
||||
b.append("\n\tModuleName:\t\t");
|
||||
b.append(module.getName());
|
||||
b.append("\n\tNamespaces:\t\t");
|
||||
b.append(module.getElementNamespaceContexts().size());
|
||||
b.append("\n\tNamespace:\t\t");
|
||||
b.append(ns.getUri());
|
||||
b.append("\n\tCreated on:\t\t");
|
||||
b.append(new Date());
|
||||
b.append("\n");
|
||||
msg = b.toString().toCharArray();
|
||||
xmlWriter.comment(msg,0,msg.length);
|
||||
|
||||
|
||||
xmlWriter.startPrefixMapping("", SCHEMA_URI);
|
||||
|
||||
for (String uri:namespaces.keySet()) {
|
||||
String prefix = namespaces.get(uri);
|
||||
xmlWriter.startPrefixMapping(prefix, uri);
|
||||
}
|
||||
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "version", "", "", "1.0");
|
||||
atts.addAttribute ("", "elementFormDefault", "", "", "qualified");
|
||||
atts.addAttribute ("", "attributeFormDefault", "", "", "unqualified");
|
||||
atts.addAttribute ("", "targetNamespace", "", "", ns.getUri());
|
||||
xmlWriter.startElement (SCHEMA_URI, "schema", "", atts);
|
||||
|
||||
for (String uri:namespaces.keySet()) {
|
||||
if (ns.getUri().equals(uri)) {
|
||||
continue;
|
||||
}
|
||||
ElementNamespaceContext nsContext = language.findElementNamespaceContext(uri);
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "namespace", "", "", nsContext.getUri());
|
||||
atts.addAttribute ("", "schemaLocation", "", "", nsContext.getSchemaResource());
|
||||
xmlWriter.startElement (SCHEMA_URI, "import", "", atts);
|
||||
xmlWriter.endElement (SCHEMA_URI, "import", "");
|
||||
}
|
||||
}
|
||||
|
||||
public void endSchema() throws SAXException {
|
||||
xmlWriter.endElement (SCHEMA_URI, "schema" , "");
|
||||
xmlWriter.endDocument();
|
||||
}
|
||||
|
||||
public void writeElementClass(ElementClass ec,ElementNamespaceContext nsWrite) throws SAXException {
|
||||
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
|
||||
atts.addAttribute ("", "name", "", "", ec.getTag());
|
||||
xmlWriter.startElement (SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
|
||||
|
||||
atts = new AttributesImpl();
|
||||
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
|
||||
} else {
|
||||
atts.addAttribute ("", "name", "", "", ec.getTag()+"Type");
|
||||
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
|
||||
}
|
||||
|
||||
if (ec.getSchemaContentBase()!=null) {
|
||||
atts = new AttributesImpl();
|
||||
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
|
||||
if (ec.getSchemaContentMixed()!=null && ec.getSchemaContentMixed()) {
|
||||
atts.addAttribute ("", "mixed", "", "", "true");
|
||||
}
|
||||
xmlWriter.startElement (SCHEMA_URI, "complexContent", "", atts);
|
||||
} else {
|
||||
xmlWriter.startElement (SCHEMA_URI, "simpleContent", "", atts);
|
||||
}
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "base", "", "", ec.getSchemaContentBase());
|
||||
xmlWriter.startElement (SCHEMA_URI, "extension", "", atts);
|
||||
}
|
||||
|
||||
if (ec.getSchemaContentBase()==null) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "minOccurs", "", "", "0"); // TODO: make unordered elements
|
||||
atts.addAttribute ("", "maxOccurs", "", "", "unbounded");
|
||||
xmlWriter.startElement (SCHEMA_URI, "choice", "", atts);
|
||||
|
||||
for (X4OLanguageModule mod:language.getLanguageModules()) {
|
||||
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
|
||||
writeElementClassNamespaces(ec,nsWrite,ns);
|
||||
}
|
||||
}
|
||||
xmlWriter.endElement(SCHEMA_URI, "choice", "");
|
||||
}
|
||||
|
||||
List<String> attrNames = new ArrayList<String>(30);
|
||||
for (ElementClassAttribute eca:ec.getElementClassAttributes()) {
|
||||
attrNames.add(eca.getName());
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", eca.getName());
|
||||
atts.addAttribute ("", "type", "", "", "string");
|
||||
if (eca.getRequired()!=null && eca.getRequired()) {
|
||||
atts.addAttribute ("", "use", "", "", "required");
|
||||
}
|
||||
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
|
||||
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
|
||||
}
|
||||
|
||||
for (X4OLanguageModule mod:language.getLanguageModules()) {
|
||||
for (ElementAttributeHandler eah:mod.getElementAttributeHandlers()) {
|
||||
attrNames.add(eah.getAttributeName());
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", eah.getAttributeName());
|
||||
atts.addAttribute ("", "type", "", "", "string");
|
||||
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
|
||||
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
|
||||
}
|
||||
}
|
||||
|
||||
if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) {
|
||||
// oke, reverse this if and rm whitespace.
|
||||
char[] msg;
|
||||
msg = " ".toCharArray();
|
||||
xmlWriter.ignorableWhitespace(msg,0,msg.length);
|
||||
|
||||
} else {
|
||||
|
||||
if (ec.getObjectClass()!=null) {
|
||||
for (Method m:ec.getObjectClass().getMethods()) {
|
||||
if (m.getName().startsWith("set")) {
|
||||
String n = m.getName().substring(3);
|
||||
if (m.getParameterTypes().length==0) {
|
||||
continue; // set without parameters
|
||||
}
|
||||
if (n.length()<2) {
|
||||
continue;
|
||||
}
|
||||
n = n.substring(0,1).toLowerCase()+n.substring(1,n.length());
|
||||
if (attrNames.contains(n)) {
|
||||
continue;
|
||||
}
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", n);
|
||||
|
||||
Class<?> type = m.getParameterTypes()[0]; // TODO make full list for auto attribute type resolving.
|
||||
if (type.equals(Object.class)) {
|
||||
atts.addAttribute ("", "type", "", "", "string");// object is always string because is always assignable
|
||||
} else if (type.isAssignableFrom(Boolean.class) | type.isAssignableFrom(Boolean.TYPE)) {
|
||||
atts.addAttribute ("", "type", "", "", "boolean");
|
||||
} else if (type.isAssignableFrom(Integer.class) | type.isAssignableFrom(Integer.TYPE)) {
|
||||
atts.addAttribute ("", "type", "", "", "integer");
|
||||
} else if (type.isAssignableFrom(Long.class) | type.isAssignableFrom(Long.TYPE)) {
|
||||
atts.addAttribute ("", "type", "", "", "long");
|
||||
} else if (type.isAssignableFrom(Float.class) | type.isAssignableFrom(Float.TYPE)) {
|
||||
atts.addAttribute ("", "type", "", "", "float");
|
||||
} else if (type.isAssignableFrom(Double.class) | type.isAssignableFrom(Double.TYPE)) {
|
||||
atts.addAttribute ("", "type", "", "", "double");
|
||||
} else {
|
||||
atts.addAttribute ("", "type", "", "", "string");
|
||||
}
|
||||
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
|
||||
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
atts = new AttributesImpl();
|
||||
xmlWriter.startElement (SCHEMA_URI, "anyAttribute", "", atts);
|
||||
xmlWriter.endElement(SCHEMA_URI, "anyAttribute", "");
|
||||
}
|
||||
}
|
||||
if (ec.getSchemaContentBase()!=null) {
|
||||
xmlWriter.endElement(SCHEMA_URI, "extension", "");
|
||||
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
|
||||
xmlWriter.endElement(SCHEMA_URI, "complexContent", "");
|
||||
} else {
|
||||
xmlWriter.endElement(SCHEMA_URI, "simpleContent", "");
|
||||
}
|
||||
}
|
||||
xmlWriter.endElement(SCHEMA_URI, "complexType", "");
|
||||
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
|
||||
xmlWriter.endElement(SCHEMA_URI, "element", "");
|
||||
}
|
||||
}
|
||||
|
||||
private void writeElementClassNamespaces(ElementClass ecWrite,ElementNamespaceContext nsWrite,ElementNamespaceContext ns) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
List<String> refElements = new ArrayList<String>(20);
|
||||
for (ElementClass checkClass:ns.getElementClasses()) {
|
||||
List<String> parents = checkClass.getElementParents(nsWrite.getUri());
|
||||
if (parents!=null && parents.contains(ecWrite.getTag())) {
|
||||
refElements.add(checkClass.getTag());
|
||||
continue;
|
||||
}
|
||||
if (checkClass.getObjectClass()==null) {
|
||||
continue;
|
||||
}
|
||||
for (ElementInterface ei:language.findElementInterfaces(checkClass.getObjectClass())) {
|
||||
parents = ei.getElementParents(nsWrite.getUri());
|
||||
if (parents!=null && parents.contains(ecWrite.getTag())) {
|
||||
refElements.add(checkClass.getTag());
|
||||
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.getTag());
|
||||
}
|
||||
}
|
||||
|
||||
if (refElements.isEmpty()==false) {
|
||||
Set<String> s = new HashSet<String>(refElements.size());
|
||||
s.addAll(refElements);
|
||||
List<String> r = new ArrayList<String>(s.size());
|
||||
r.addAll(s);
|
||||
Collections.sort(r);
|
||||
|
||||
String prefix = namespaces.get(ns.getUri());
|
||||
for (String refElement:r) {
|
||||
atts = new AttributesImpl();
|
||||
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
|
||||
atts.addAttribute ("", "ref", "", "", prefix+":"+refElement);
|
||||
} else if (nsWrite.getUri().equals(ns.getUri())==false) {
|
||||
atts.addAttribute ("", "ref", "", "", prefix+":"+refElement);
|
||||
} else {
|
||||
atts.addAttribute ("", "name", "", "", refElement);
|
||||
atts.addAttribute ("", "type", "", "", prefix+":"+refElement+"Type");
|
||||
}
|
||||
xmlWriter.startElement (SCHEMA_URI, "element", "", atts);
|
||||
xmlWriter.endElement (SCHEMA_URI, "element", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeElement(ElementClass ec,ElementNamespaceContext nsWrite) throws SAXException {
|
||||
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
|
||||
return; // is done in writeElementClass
|
||||
}
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", ec.getTag());
|
||||
atts.addAttribute ("", "type", "", "", "this:"+ec.getTag()+"Type");
|
||||
xmlWriter.startElement(SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
|
||||
|
||||
if (ec.getDescription()!=null) {
|
||||
atts = new AttributesImpl();
|
||||
xmlWriter.startElement(SCHEMA_URI, "annotation", "", atts);
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "xml:lang", "", "", "en");
|
||||
xmlWriter.startElement(SCHEMA_URI, "documentation", "", atts);
|
||||
char[] msg = ec.getDescription().toCharArray();
|
||||
xmlWriter.characters(msg,0,msg.length);
|
||||
xmlWriter.endElement(SCHEMA_URI, "documentation", "");
|
||||
xmlWriter.endElement(SCHEMA_URI, "annotation", "");
|
||||
}
|
||||
|
||||
|
||||
xmlWriter.endElement(SCHEMA_URI, "element", "");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.xsd;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.X4ODriverManager;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.io.X4OSchemaWriter;
|
||||
|
||||
/**
|
||||
* X4OLanguageSchemaWriter is support class to write schema files from eld.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 22, 2012
|
||||
*/
|
||||
public class X4OWriteLanguageSchemaExecutor {
|
||||
|
||||
private String language = null;
|
||||
private String languageNamespaceUri = null;
|
||||
private File basePath;
|
||||
|
||||
static public void main(String argu[]) {
|
||||
X4OWriteLanguageSchemaExecutor languageSchema = new X4OWriteLanguageSchemaExecutor();
|
||||
List<String> arguList = Arrays.asList(argu);
|
||||
Iterator<String> arguIterator = arguList.iterator();
|
||||
boolean printStack = false;
|
||||
while (arguIterator.hasNext()) {
|
||||
String arg = arguIterator.next();
|
||||
if ("-path".equals(arg) || "-p".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
System.err.println("No argument for "+arg+" given.");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
File schemaBasePath = new File(arguIterator.next());
|
||||
if (schemaBasePath.exists()==false) {
|
||||
System.err.println("path does not exists; "+schemaBasePath);
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
languageSchema.setBasePath(schemaBasePath);
|
||||
continue;
|
||||
}
|
||||
if ("-language".equals(arg) || "-l".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
System.err.println("No argument for "+arg+" given.");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
languageSchema.setLanguage(arguIterator.next());
|
||||
continue;
|
||||
}
|
||||
if ("-verbose".equals(arg) || "-v".equals(arg)) {
|
||||
printStack = true;
|
||||
}
|
||||
}
|
||||
Exception e = null;
|
||||
try {
|
||||
languageSchema.execute();
|
||||
} catch (ElementException e1) {
|
||||
e = e1;
|
||||
}
|
||||
if (e!=null) {
|
||||
System.err.println("Error while schema writing: "+e.getMessage());
|
||||
if (printStack) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.exit(1);
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void execute() throws ElementException {
|
||||
// Start xsd generator
|
||||
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguage());
|
||||
X4OSchemaWriter xsd = driver.createSchemaWriter(driver.getLanguageVersionDefault());
|
||||
xsd.writeSchema(getBasePath(), getLanguageNamespaceUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the language
|
||||
*/
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language the language to set
|
||||
*/
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the languageNamespaceUri
|
||||
*/
|
||||
public String getLanguageNamespaceUri() {
|
||||
return languageNamespaceUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param languageNamespaceUri the languageNamespaceUri to set
|
||||
*/
|
||||
public void setLanguageNamespaceUri(String languageNamespaceUri) {
|
||||
this.languageNamespaceUri = languageNamespaceUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the basePath
|
||||
*/
|
||||
public File getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param basePath the basePath to set
|
||||
*/
|
||||
public void setBasePath(File basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The X4O ELD to XSD Schema generator classes.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
package org.x4o.xml.eld.xsd;
|
||||
|
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
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 X4OLanguageContext elementLanguage = null;
|
||||
/** The ElementClass */
|
||||
private ElementClass elementClass = null;
|
||||
/** The attributes */
|
||||
private Map<String,String> attributes = new HashMap<String,String>(10);
|
||||
/** The Childeren */
|
||||
private List<Element> childeren = new ArrayList<Element>(10);
|
||||
/** All Childeren */
|
||||
private List<Element> allChilderen = new ArrayList<Element>(10);
|
||||
|
||||
/**
|
||||
* @see Element#doElementStart()
|
||||
*/
|
||||
public void doElementStart() throws ElementException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Element#doElementEnd()
|
||||
*/
|
||||
public void doElementEnd() throws ElementException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Element#doElementRun()
|
||||
*/
|
||||
public void doElementRun() throws ElementException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Element#setParent(Element)
|
||||
*/
|
||||
public void setParent(Element element) {
|
||||
parent = element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Element#getParent()
|
||||
*/
|
||||
public Element getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the attributes and elements(class) and context.
|
||||
* @see Element#release()
|
||||
*/
|
||||
public void release() throws ElementException {
|
||||
getAttributes().clear();
|
||||
setElementClass(null);
|
||||
setParent(null);
|
||||
setLanguageContext(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#setLanguageContext(X4OLanguageContext)
|
||||
*/
|
||||
public void setLanguageContext(X4OLanguageContext elementLanguage) {
|
||||
this.elementLanguage=elementLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Element#getLanguageContext()
|
||||
*/
|
||||
public X4OLanguageContext getLanguageContext() {
|
||||
return elementLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.Element#doCharacters(java.lang.String)
|
||||
*/
|
||||
public void doCharacters(String characters) throws ElementException {
|
||||
try {
|
||||
Element e = (Element)X4OLanguageClassLoader.newInstance(getLanguageContext().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(getLanguageContext().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(getLanguageContext().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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An AbstractElementAttributeHandler.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 10, 2006
|
||||
*/
|
||||
public abstract class AbstractElementAttributeHandler extends AbstractElementConfigurator implements ElementAttributeHandler {
|
||||
|
||||
private String attributeName = null;
|
||||
private List<String> nextAttributes = new ArrayList<String>(2);
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementAttributeHandler#addNextAttribute(java.lang.String)
|
||||
*/
|
||||
public void addNextAttribute(String attribute) {
|
||||
if (attribute==null) {
|
||||
throw new NullPointerException("Can add null attribute for loading.");
|
||||
}
|
||||
nextAttributes.add(attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementAttributeHandler#removeNextAttribute(java.lang.String)
|
||||
*/
|
||||
public void removeNextAttribute(String attribute) {
|
||||
if (attribute==null) {
|
||||
throw new NullPointerException("Can remove null attribute for loading.");
|
||||
}
|
||||
nextAttributes.remove(attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementAttributeHandler#getNextAttributes()
|
||||
*/
|
||||
public List<String> getNextAttributes() {
|
||||
return nextAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementAttributeHandler#getAttributeName()
|
||||
*/
|
||||
public String getAttributeName() {
|
||||
return attributeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementAttributeHandler#setAttributeName(java.lang.String)
|
||||
*/
|
||||
public void setAttributeName(String attributeName) {
|
||||
this.attributeName=attributeName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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.getLanguageContext().getLanguage().createElementInstance(parentElement.getLanguageContext(), 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An AbstractElementClass.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 11, 2005
|
||||
*/
|
||||
public abstract class AbstractElementClass extends AbstractElementClassBase implements ElementClass {
|
||||
|
||||
private String tag = null;
|
||||
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#getTag()
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ElementClass#setTag(String)
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ElementClass#getElementClass()
|
||||
*/
|
||||
public Class<?> getElementClass() {
|
||||
return elementClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ElementClass#setElementClass(Class)
|
||||
*/
|
||||
public void setElementClass(Class<?> elementClass) {
|
||||
this.elementClass = elementClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ElementClass#getObjectClass()
|
||||
*/
|
||||
public Class<?> getObjectClass() {
|
||||
return objectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ElementClass#setObjectClass(Class)
|
||||
*/
|
||||
public void setObjectClass(Class<?> objectClass) {
|
||||
this.objectClass = objectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the autoAttributes
|
||||
*/
|
||||
public Boolean getAutoAttributes() {
|
||||
return autoAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param autoAttributes the autoAttributes to set
|
||||
*/
|
||||
public void setAutoAttributes(Boolean autoAttributes) {
|
||||
this.autoAttributes = autoAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
|
||||
/**
|
||||
* An AbstractElementClassAttribute.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 19, 2012
|
||||
*/
|
||||
public abstract class AbstractElementClassAttribute extends AbstractElementMetaBase implements ElementClassAttribute {
|
||||
|
||||
private String name = null;
|
||||
private ObjectConverter objectConverter = null;
|
||||
private Object defaultValue = null;
|
||||
private List<String> attributeAliases = null;
|
||||
private Boolean required = null;
|
||||
private Boolean runResolveEL = null;
|
||||
//private Boolean runInterfaces = null;
|
||||
private Boolean runConverters = null;
|
||||
private Boolean runBeanFill = null;
|
||||
|
||||
public AbstractElementClassAttribute() {
|
||||
attributeAliases = new ArrayList<String>(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#setName(java.lang.String)
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the objectConverter
|
||||
*/
|
||||
public ObjectConverter getObjectConverter() {
|
||||
return objectConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param objectConverter the objectConverter to set
|
||||
*/
|
||||
public void setObjectConverter(ObjectConverter objectConverter) {
|
||||
this.objectConverter = objectConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#setDefaultValue(java.lang.Object)
|
||||
*/
|
||||
public void setDefaultValue(Object defaultValue) {
|
||||
this.defaultValue=defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#getDefaultValue()
|
||||
*/
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#addAttributeAlias(java.lang.String)
|
||||
*/
|
||||
public void addAttributeAlias(String alias) {
|
||||
attributeAliases.add(alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#removeAttributeAlias(java.lang.String)
|
||||
*/
|
||||
public void removeAttributeAlias(String alias) {
|
||||
attributeAliases.remove(alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementClassAttribute#getAttributeAliases()
|
||||
*/
|
||||
public List<String> getAttributeAliases() {
|
||||
return attributeAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the required
|
||||
*/
|
||||
public Boolean getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param required the required to set
|
||||
*/
|
||||
public void setRequired(Boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the runResolveEL
|
||||
*/
|
||||
public Boolean getRunResolveEL() {
|
||||
return runResolveEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param runResolveEL the runResolveEL to set
|
||||
*/
|
||||
public void setRunResolveEL(Boolean runResolveEL) {
|
||||
this.runResolveEL = runResolveEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the runConverters
|
||||
*/
|
||||
public Boolean getRunConverters() {
|
||||
return runConverters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param runConverters the runConverters to set
|
||||
*/
|
||||
public void setRunConverters(Boolean runConverters) {
|
||||
this.runConverters = runConverters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the runBeanFill
|
||||
*/
|
||||
public Boolean getRunBeanFill() {
|
||||
return runBeanFill;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param runBeanFill the runBeanFill to set
|
||||
*/
|
||||
public void setRunBeanFill(Boolean runBeanFill) {
|
||||
this.runBeanFill = runBeanFill;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
public AbstractElementClassBase() {
|
||||
elementConfigurators = new ArrayList<ElementConfigurator>(5);
|
||||
elementClassAttributes = new HashMap<String,ElementClassAttribute>(15);
|
||||
elementParents = new HashMap<String,List<String>>(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.getName(),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.isEmpty()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private List<ElementBindingHandler> elementBindingHandlers = null;
|
||||
|
||||
/**
|
||||
* Creates AbstractElementInterface.
|
||||
*/
|
||||
public AbstractElementInterface() {
|
||||
elementBindingHandlers = new ArrayList<ElementBindingHandler>(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementInterface#addElementBindingHandler(org.x4o.xml.element.ElementBindingHandler)
|
||||
* @param elementBindingHandler The binding handler to add.
|
||||
*/
|
||||
public void addElementBindingHandler(ElementBindingHandler elementBindingHandler) {
|
||||
elementBindingHandlers.add(elementBindingHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementInterface#getElementBindingHandlers()
|
||||
* @return All binding handlers.
|
||||
*/
|
||||
public List<ElementBindingHandler> getElementBindingHandlers() {
|
||||
return elementBindingHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The abstract verion of ElementNamespaceContext
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 28, 2009
|
||||
*/
|
||||
public abstract class AbstractElementNamespaceContext extends AbstractElementMetaBase implements ElementNamespaceContext {
|
||||
|
||||
private ElementNamespaceInstanceProvider elementNamespaceInstanceProvider = null;
|
||||
private String prefixMapping = null;
|
||||
private Map<String,ElementClass> elementClasses = null;
|
||||
private String uri = null;
|
||||
private String name = null;
|
||||
private String schemaUri = null;
|
||||
private String schemaResource = null;
|
||||
private String schemaPrefix = null;
|
||||
private Boolean languageRoot = null;
|
||||
|
||||
public AbstractElementNamespaceContext() {
|
||||
elementClasses = new HashMap<String,ElementClass>(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementNamespaceContext#getPrefixMapping()
|
||||
*/
|
||||
public String getPrefixMapping() {
|
||||
return prefixMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the elementNamespaceInstanceProvider
|
||||
*/
|
||||
public ElementNamespaceInstanceProvider getElementNamespaceInstanceProvider() {
|
||||
return elementNamespaceInstanceProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param elementNamespaceInstanceProvider the elementNamespaceInstanceProvider to set
|
||||
*/
|
||||
public void setElementNamespaceInstanceProvider(ElementNamespaceInstanceProvider elementNamespaceInstanceProvider) {
|
||||
this.elementNamespaceInstanceProvider = elementNamespaceInstanceProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementNamespaceContext#setPrefixMapping(java.lang.String)
|
||||
*/
|
||||
public void setPrefixMapping(String prefixMapping) {
|
||||
this.prefixMapping=prefixMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementNamespaceContext#addElementClass(org.x4o.xml.element.ElementClass)
|
||||
*/
|
||||
public void addElementClass(ElementClass elementClass) {
|
||||
if (elementClass.getTag()==null) {
|
||||
throw new NullPointerException("ElementClass not correctly configured getTag is null.");
|
||||
}
|
||||
elementClasses.put(elementClass.getTag(), elementClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementNamespaceContext#getElementClass(java.lang.String)
|
||||
*/
|
||||
public ElementClass getElementClass(String tag) {
|
||||
return elementClasses.get(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.ElementNamespaceContext#getElementClasses()
|
||||
*/
|
||||
public List<ElementClass> getElementClasses() {
|
||||
return new ArrayList<ElementClass>(elementClasses.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uri
|
||||
*/
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri the namespace uri to set
|
||||
*/
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the schemaUri
|
||||
*/
|
||||
public String getSchemaUri() {
|
||||
return schemaUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schemaUri the schemaUri to set
|
||||
*/
|
||||
public void setSchemaUri(String schemaUri) {
|
||||
this.schemaUri = schemaUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the schemaResource
|
||||
*/
|
||||
public String getSchemaResource() {
|
||||
return schemaResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schemaResource the schemaResource to set
|
||||
*/
|
||||
public void setSchemaResource(String schemaResource) {
|
||||
this.schemaResource = schemaResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the languageRoot
|
||||
*/
|
||||
public Boolean getLanguageRoot() {
|
||||
return languageRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param languageRoot the languageRoot to set
|
||||
*/
|
||||
public void setLanguageRoot(Boolean languageRoot) {
|
||||
this.languageRoot = languageRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the schemaPrefix
|
||||
*/
|
||||
public String getSchemaPrefix() {
|
||||
return schemaPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schemaPrefix the schemaPrefix to set
|
||||
*/
|
||||
public void setSchemaPrefix(String schemaPrefix) {
|
||||
this.schemaPrefix = schemaPrefix;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* The default element to handle the xml events.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 18, 2007
|
||||
*/
|
||||
public class DefaultElement extends AbstractElement {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.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.getLanguageContext().getLanguage().findElementInterfaces(element.getElementObject())) {
|
||||
logger.finer("Found interface match executing converter.");
|
||||
for (ElementClassAttribute attrClass:ei.getElementClassAttributes()) {
|
||||
if (name.equals(attrClass.getName())==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.getLanguageContext().getExpressionLanguageFactory().createValueExpression(element.getLanguageContext().getExpressionLanguageContext(), (String)value,Object.class);
|
||||
return e.getValue(element.getLanguageContext().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.getLanguageContext().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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
|
||||
|
||||
/**
|
||||
* 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#getLanguageContext()
|
||||
*/
|
||||
public X4OLanguageContext getLanguageContext() {
|
||||
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#setLanguageContext(org.x4o.xml.lang.X4OLanguageContext)
|
||||
*/
|
||||
public void setLanguageContext(X4OLanguageContext 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* The default ElementClass to store the Element information.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 19, 2007
|
||||
*/
|
||||
public class DefaultElementClass extends AbstractElementClass {
|
||||
|
||||
/**
|
||||
* Creates an default DefaultElementClass.
|
||||
*/
|
||||
public DefaultElementClass() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates config-ed ElementClass.
|
||||
* @param tag The tag of this ElementClass.
|
||||
* @param objectClass The objectClass of the ElementClass.
|
||||
*/
|
||||
public DefaultElementClass(String tag,Class<?> objectClass) {
|
||||
this(tag,objectClass,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates config-ed ElementClass.
|
||||
* @param tag The tag of this ElementClass.
|
||||
* @param objectClass The objectClass of the ElementClass.
|
||||
* @param elementClass The elementClass of this ElementClass.
|
||||
*/
|
||||
public DefaultElementClass(String tag,Class<?> objectClass,Class<?> elementClass) {
|
||||
setTag(tag);
|
||||
setObjectClass(objectClass);
|
||||
setElementClass(elementClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* The default ElementClassAttribute.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class DefaultElementClassAttribute extends AbstractElementClassAttribute {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* The default ElementInterface to store config based on class interface.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 15, 2008
|
||||
*/
|
||||
public class DefaultElementInterface extends AbstractElementInterface {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* The default namespace context.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 28, 2009
|
||||
*/
|
||||
public class DefaultElementNamespaceContext extends AbstractElementNamespaceContext {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
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 ElementNamespaceContext elementNamespaceContext = null;
|
||||
|
||||
/**
|
||||
* Creates new DefaultElementNamespaceInstanceProvider.
|
||||
*/
|
||||
public DefaultElementNamespaceInstanceProvider() {
|
||||
logger = Logger.getLogger(DefaultElementNamespaceInstanceProvider.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language The elementLanguage of this provider.
|
||||
* @param elementNamespaceContext The elementNamespaceContext for this provider.
|
||||
* @see org.x4o.xml.element.ElementNamespaceInstanceProvider#start(org.x4o.xml.lang.X4OLanguageContext, org.x4o.xml.element.ElementNamespaceContext)
|
||||
*/
|
||||
public void start(X4OLanguage language,ElementNamespaceContext elementNamespaceContext) {
|
||||
this.elementNamespaceContext=elementNamespaceContext;
|
||||
logger.finer("Starting DefaultElementNamespaceInstanceProvider for: "+elementNamespaceContext.getUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(java.lang.String)
|
||||
*/
|
||||
public Element createElementInstance(X4OLanguageContext elementLanguage,String tag) throws ElementNamespaceInstanceProviderException {
|
||||
ElementClass elementClass = elementNamespaceContext.getElementClass(tag);
|
||||
Element element = null;
|
||||
|
||||
if (elementClass==null) {
|
||||
throw new ElementNamespaceInstanceProviderException(this,"Tag: " + tag + " unknown in: " + elementNamespaceContext.getUri());
|
||||
}
|
||||
|
||||
try {
|
||||
if (elementClass.getElementClass()!=null) {
|
||||
Object obj = X4OLanguageClassLoader.newInstance(elementClass.getElementClass());
|
||||
if ((obj instanceof Element) == false) {
|
||||
throw new ElementNamespaceInstanceProviderException(this,"Provided elementClassName is not an Element: "+obj.getClass());
|
||||
}
|
||||
element = (Element) obj;
|
||||
} else {
|
||||
element = (Element)X4OLanguageClassLoader.newInstance((elementLanguage.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.setLanguageContext(elementLanguage);
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,331 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.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 ElementParameterException
|
||||
* @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 ElementParameterException
|
||||
* @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];
|
||||
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);
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The DefaultGlobalAttributeHandlerComparator.<br>
|
||||
* This Comparator compares the NextAttribute names with the attributeName of the ElementAttributeHandlers.<br>
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 14, 2007
|
||||
*/
|
||||
public class DefaultGlobalAttributeHandlerComparator implements Comparator<ElementAttributeHandler> {
|
||||
|
||||
/**
|
||||
* @param e1 The first ElementAttributeHandler to compare.
|
||||
* @param e2 The second ElementAttributeHandler to compare.
|
||||
* @return 0 is same.
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public int compare(ElementAttributeHandler e1, ElementAttributeHandler 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;
|
||||
}
|
||||
}
|
||||
232
x4o-driver/src/main/java/org/x4o/xml/element/Element.java
Normal file
232
x4o-driver/src/main/java/org/x4o/xml/element/Element.java
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
|
||||
/**
|
||||
* Defines an XML element with an object.<br>
|
||||
* <br>
|
||||
* The main function is to store the ElementObject.<br>
|
||||
* Also we can configure the ElementObject from differted events hooks.
|
||||
* from the attibutes or parent (object)element.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 01/02/2005
|
||||
*/
|
||||
public interface Element {
|
||||
|
||||
/**
|
||||
* The ElementTypes which are possible.
|
||||
*/
|
||||
public enum ElementType {
|
||||
|
||||
/** The normale ElementType, which is mostly bound to an object. */
|
||||
element,
|
||||
|
||||
/** Extra meta characters in xml. */
|
||||
characters,
|
||||
|
||||
/** The xml comments in xml. */
|
||||
comment,
|
||||
|
||||
/** ignorableWhitespace in xml. */
|
||||
ignorableWhitespace,
|
||||
|
||||
/** Receive raw sax event on elementObject. */
|
||||
overrideSax;
|
||||
|
||||
/**
|
||||
* 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 ElementLanguage.
|
||||
* @param elementLanguage The ElementLanguage to set.
|
||||
*/
|
||||
void setLanguageContext(X4OLanguageContext elementLanguage);
|
||||
|
||||
/**
|
||||
* Gets the ElementLanguage.
|
||||
* @return Returns the ElementLanguage.
|
||||
*/
|
||||
X4OLanguageContext getLanguageContext();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Handlers attributes for xml attributes of all elements processed.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 20, 2005
|
||||
*/
|
||||
public interface ElementAttributeHandler extends ElementConfigurator {
|
||||
|
||||
/**
|
||||
* Gets the attribute name this attribute handler handles.
|
||||
* @return Returns the attributes name of this attribute handler.
|
||||
*/
|
||||
String getAttributeName();
|
||||
|
||||
/**
|
||||
* Sets the attribute name this attribute handler handles.
|
||||
* @param attributeName The attribute to handle.
|
||||
*/
|
||||
void setAttributeName(String attributeName);
|
||||
|
||||
/**
|
||||
* Adds an NextAttribute.
|
||||
* There next attributes will defines the order in which the ElementAttributeHandlers are executed.
|
||||
* @param attribute Add attribute which be will processed after this one.
|
||||
*/
|
||||
void addNextAttribute(String attribute);
|
||||
|
||||
/**
|
||||
* Removes an next attribute.
|
||||
* @param attribute Removes this next attribute.
|
||||
*/
|
||||
void removeNextAttribute(String attribute);
|
||||
|
||||
/**
|
||||
* Get all next attributes.
|
||||
* @return Returns the list of all next attributes.
|
||||
*/
|
||||
List<String> getNextAttributes();
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import org.x4o.xml.conv.ObjectConverterException;
|
||||
|
||||
/**
|
||||
* Helper interface for setting properties.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 20, 2005
|
||||
*/
|
||||
public interface ElementAttributeValueParser {
|
||||
|
||||
/**
|
||||
* Checks if the value is an EL parameter.
|
||||
* @param name The name of the attribute.
|
||||
* @param value The value of the attribute.
|
||||
* @param element The element of the attribute.
|
||||
* @return Returns true if value is EL parameter.
|
||||
*/
|
||||
boolean isELParameter(String name,String value,Element element);
|
||||
|
||||
/**
|
||||
* Returns the object which is stored in the ELContext
|
||||
* @param value The attribute value.
|
||||
* @param element The element of the attribute.
|
||||
* @return Returns the resolved el parameter value.
|
||||
* @throws ElementParameterException
|
||||
* @throws ElementObjectPropertyValueException
|
||||
*/
|
||||
Object getELParameterValue(String value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
|
||||
|
||||
/**
|
||||
* Convert the value into a new value genereted by parameterConverters.
|
||||
* @param name The name of the attribute.
|
||||
* @param value The value of the attribute.
|
||||
* @param element The element of the attribute.
|
||||
* @return Returns the converted attribute value.
|
||||
* @throws ElementParameterException
|
||||
*/
|
||||
Object getConvertedParameterValue(String name,Object value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
|
||||
|
||||
/**
|
||||
* Does is all, Checks if value is EL parameter and lookups the object.
|
||||
* and converts to new object via parameter converter and return value.
|
||||
* @param name The name of the attribute.
|
||||
* @param value The value of the attribute.
|
||||
* @param element The element of the attribute.
|
||||
* @return Returns the attribute value.
|
||||
* @throws ElementParameterException
|
||||
*/
|
||||
Object getParameterValue(String name,String value,Element element) throws ElementAttributeValueParserException,ObjectConverterException;
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* ElementAttributeValueParserException.<br>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 2, 2008
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ElementAttributeValueParserException extends ElementException {
|
||||
|
||||
/*
|
||||
public ElementAttributeValueParserException(ElementAttributeConverter converter,String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ElementAttributeValueParserException(ElementAttributeConverter converter,String message,Exception exception) {
|
||||
super(message,exception);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* Bind ElementObjects together.
|
||||
*
|
||||
* This interface is used to bind a parent and child ElementObject together.
|
||||
* For example; when both objects are an JComponent then we can add the child to the parent
|
||||
* with the method: ((JComponent)parent).add((JComponent)child);
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 17, 2005
|
||||
*/
|
||||
public interface ElementBindingHandler extends ElementMetaBase {
|
||||
|
||||
/**
|
||||
* @return Returns the parent classes which this binding handler can do.
|
||||
*/
|
||||
Class<?> getBindParentClass();
|
||||
|
||||
/**
|
||||
* @return Returns array of child classes which this binding handler can do.
|
||||
*/
|
||||
Class<?>[] getBindChildClasses();
|
||||
|
||||
/**
|
||||
* Do the binding of this child to the parent object.
|
||||
* @param parentObject The parentObject of this childElement.
|
||||
* @param childObject The childObject of this childElement.
|
||||
* @param childElement The child element to bind to the parent.'
|
||||
* @throws ElementBindingHandlerException When binding could not happen.
|
||||
*/
|
||||
void bindChild(Element childElement) throws ElementBindingHandlerException;
|
||||
|
||||
void createChilderen(Element parentElement) throws ElementBindingHandlerException;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* ElementBindingException.<br>
|
||||
* Is throw with there is a exception in binding the objects
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 15, 2008
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ElementBindingHandlerException extends ElementException {
|
||||
|
||||
/**
|
||||
* Creates binding exception.
|
||||
* @param message The error message.
|
||||
*/
|
||||
public ElementBindingHandlerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates binding exception.
|
||||
* @param message The error message.
|
||||
* @param exception The error exception.
|
||||
*/
|
||||
public ElementBindingHandlerException(String message,Exception exception) {
|
||||
super(message,exception);
|
||||
}
|
||||
}
|
||||
128
x4o-driver/src/main/java/org/x4o/xml/element/ElementClass.java
Normal file
128
x4o-driver/src/main/java/org/x4o/xml/element/ElementClass.java
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The ElementClass stores all parse information to config the Element.
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 11, 2005
|
||||
*/
|
||||
public interface ElementClass extends ElementClassBase {
|
||||
|
||||
/**
|
||||
* Gets the xml tag the Element should handle.
|
||||
* @return the tag
|
||||
*/
|
||||
String getTag();
|
||||
|
||||
/**
|
||||
* Sets the XML tag the Element should handle.
|
||||
* @param tag the tag to set
|
||||
*/
|
||||
void setTag(String tag);
|
||||
|
||||
/**
|
||||
* Gets the ElementClass.
|
||||
* @return the elementClass
|
||||
*/
|
||||
Class<?> getElementClass();
|
||||
|
||||
/**
|
||||
* Sets the ElementClass.
|
||||
* @param elementClass the elementClass to set.
|
||||
*/
|
||||
void setElementClass(Class<?> elementClass);
|
||||
|
||||
/**
|
||||
* @return the objectClass.
|
||||
*/
|
||||
Class<?> getObjectClass();
|
||||
|
||||
/**
|
||||
* @param objectClass the objectClass to set.
|
||||
*/
|
||||
void setObjectClass(Class<?> objectClass);
|
||||
|
||||
/**
|
||||
* @return the autoAttributes.
|
||||
*/
|
||||
Boolean getAutoAttributes();
|
||||
|
||||
/**
|
||||
* @param autoAttributes the autoAttributes to set.
|
||||
*/
|
||||
void setAutoAttributes(Boolean autoAttributes);
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.conv.ObjectConverter;
|
||||
|
||||
/**
|
||||
* The ElementClass stores all parse information to config the Element.
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 11, 2005
|
||||
*/
|
||||
public interface ElementClassAttribute extends ElementMetaBase {
|
||||
|
||||
/**
|
||||
* Gets the attribute name of the ElementClass.
|
||||
* @return The name.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Sets the attribute name of the ElementClass.
|
||||
* @param name The name of the attribute.
|
||||
*/
|
||||
void setName(String name);
|
||||
|
||||
/**
|
||||
* 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 runBeanFill.
|
||||
*/
|
||||
Boolean getRunBeanFill();
|
||||
|
||||
/**
|
||||
* @param runBeanFill the runBeanFill to set.
|
||||
*/
|
||||
void setRunBeanFill(Boolean runBeanFill);
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* Provides an Interface to configure Element(Object).
|
||||
*
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* Provides an Interface to configure Element(Object) global.
|
||||
*
|
||||
* @author Willem Cazanders
|
||||
* @version 1.0 Nov 18, 2012
|
||||
*/
|
||||
public interface ElementConfiguratorGlobal extends ElementConfigurator {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
/**
|
||||
* Is throw when there is en Exception within an Element.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 8, 2005
|
||||
*/
|
||||
public class ElementException extends Exception {
|
||||
|
||||
/** The serial version uid */
|
||||
static final long serialVersionUID = 10L;
|
||||
|
||||
/**
|
||||
* Constructs an ElementException without a detail message.
|
||||
*/
|
||||
public ElementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an ElementException with a detail message.
|
||||
* @param message The message of this Exception
|
||||
*/
|
||||
public ElementException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ElementException from a parent exception.
|
||||
* @param e The error exception.
|
||||
*/
|
||||
public ElementException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an ElementException with a detail message.
|
||||
* @param message The message of this Exception
|
||||
* @param e The error exception.
|
||||
*/
|
||||
public ElementException(String message,Exception e) {
|
||||
super(message,e);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines an ElementInterface.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 15, 2008
|
||||
*/
|
||||
public interface ElementInterface extends ElementClassBase {
|
||||
|
||||
/**
|
||||
* Gets this class of the interface to match this converters/etc/ to.
|
||||
* @return the tag.
|
||||
*/
|
||||
Class<?> getInterfaceClass();
|
||||
|
||||
/**
|
||||
* Sets the interface class.
|
||||
* @param interfaceClass the interfaceClass to set.
|
||||
*/
|
||||
void setInterfaceClass(Class<?> interfaceClass);
|
||||
|
||||
/**
|
||||
* Adds an ElementBindingHanlder.
|
||||
* @param elementBindingHandler The ElementBindingHandler to add.
|
||||
*/
|
||||
void addElementBindingHandler(ElementBindingHandler elementBindingHandler);
|
||||
|
||||
/**
|
||||
* Gets all ElementBindingHandlers.
|
||||
* @return Returns all the ElementBindingHandlers.
|
||||
*/
|
||||
List<ElementBindingHandler> getElementBindingHandlers();
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ElementNamespaceContext stores all element tag classes for the namespace.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 28, 2009
|
||||
*/
|
||||
public interface ElementNamespaceContext extends ElementMetaBase {
|
||||
|
||||
//void init(ElementLanguageModuleLoader elementProvider,String language);
|
||||
|
||||
//String getNamespace();
|
||||
//String getNamespaceResourceFile();
|
||||
//String getNamespaceLanguage();
|
||||
|
||||
/**
|
||||
* Sets the prefix mapping.
|
||||
* @param prefixMapping The prefix mapping to set.
|
||||
*/
|
||||
void setPrefixMapping(String prefixMapping);
|
||||
|
||||
/**
|
||||
* Gets the set prefix mapping of this namespace.
|
||||
* @return Returns the prefix mapping.
|
||||
*/
|
||||
String getPrefixMapping();
|
||||
|
||||
/**
|
||||
* Sets the elememen instance provider which creates the elements objects.
|
||||
* @param elementNamespaceInstanceProvider The ElementNamespaceInstanceProvider to set.
|
||||
*/
|
||||
void setElementNamespaceInstanceProvider(ElementNamespaceInstanceProvider elementNamespaceInstanceProvider);
|
||||
|
||||
/**
|
||||
* Returns the ElementProvider.
|
||||
* @return Returns the ElementNamespaceInstanceProvider for this namespace.
|
||||
*/
|
||||
ElementNamespaceInstanceProvider getElementNamespaceInstanceProvider();
|
||||
|
||||
/**
|
||||
* Adds an ElementClass.
|
||||
* @param elementClass The elementClass to add to this context.
|
||||
*/
|
||||
void addElementClass(ElementClass elementClass);
|
||||
|
||||
/**
|
||||
* Gets the ElementClass for an namespace and tag.
|
||||
* @param tag The tag to get the ElementClass for.
|
||||
* @return Returns the ElementClass for a tag in an namespace.
|
||||
*/
|
||||
ElementClass getElementClass(String tag);
|
||||
|
||||
/**
|
||||
* Returns the loaded ElementClass'es in an namespace in this context.
|
||||
* @return Returns all ElementClasses handled by this namespace.
|
||||
*/
|
||||
List<ElementClass> getElementClasses();
|
||||
|
||||
/**
|
||||
* @return the uri of this namespace.
|
||||
*/
|
||||
String getUri();
|
||||
|
||||
/**
|
||||
* @param uri the namespace uri to set.
|
||||
*/
|
||||
void setUri(String uri);
|
||||
|
||||
/**
|
||||
* @return the name.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @param name the name to set.
|
||||
*/
|
||||
void setName(String name);
|
||||
|
||||
/**
|
||||
* @return the schemaUri.
|
||||
*/
|
||||
String getSchemaUri();
|
||||
|
||||
/**
|
||||
* @param schemaUri the schemaUri to set.
|
||||
*/
|
||||
void setSchemaUri(String schemaUri);
|
||||
|
||||
/**
|
||||
* @return the schemaResource.
|
||||
*/
|
||||
String getSchemaResource();
|
||||
|
||||
/**
|
||||
* @param schemaResource the schemaResource to set.
|
||||
*/
|
||||
void setSchemaResource(String schemaResource);
|
||||
|
||||
/**
|
||||
* @return the description.
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* @param description the description to set.
|
||||
*/
|
||||
void setDescription(String description);
|
||||
|
||||
/**
|
||||
* @return the languageRoot
|
||||
*/
|
||||
Boolean getLanguageRoot();
|
||||
|
||||
/**
|
||||
* @param languageRoot the languageRoot to set
|
||||
*/
|
||||
void setLanguageRoot(Boolean languageRoot);
|
||||
|
||||
/**
|
||||
* @return the schemaPrefix
|
||||
*/
|
||||
String getSchemaPrefix();
|
||||
|
||||
/**
|
||||
* @param schemaPrefix the schemaPrefix to set
|
||||
*/
|
||||
void setSchemaPrefix(String schemaPrefix);
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
|
||||
/**
|
||||
* ElementNamespaceInstanceProvider is provider for creating new Element instances for an xml tag.<br>
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jul 8, 2006
|
||||
*/
|
||||
public interface ElementNamespaceInstanceProvider {
|
||||
|
||||
/**
|
||||
* Starts the ElementProvider.
|
||||
* @param elementLanguage The ElementLanguage to start in.
|
||||
* @param elementNamespaceContext The ElementNamespaceContext to start for.
|
||||
* @throws ElementNamespaceInstanceProviderException Thrown when error happened in language.
|
||||
*/
|
||||
void start(X4OLanguage elementLanguage,ElementNamespaceContext elementNamespaceContext) throws ElementNamespaceInstanceProviderException;
|
||||
|
||||
/**
|
||||
* Provide an Element for an xml tag.
|
||||
* @param tag The xml tag to create instance for.
|
||||
* @return An new Element instance.
|
||||
* @throws ElementNamespaceInstanceProviderException Thrown when error happened in language.
|
||||
*/
|
||||
Element createElementInstance(X4OLanguageContext elementLanguage,String tag) throws ElementNamespaceInstanceProviderException;
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* ElementNamespaceInstanceProviderException holds the ElementNamespaceInstanceProvider which created this Exception.<br>
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 2, 2012
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ElementNamespaceInstanceProviderException extends ElementException {
|
||||
|
||||
private ElementNamespaceInstanceProvider elementNamespaceInstanceProvider = null;
|
||||
|
||||
/**
|
||||
* Creates provider instance exception.
|
||||
* @param elementNamespaceInstanceProvider The provider which creates this exception.
|
||||
* @param message The message of this exception.
|
||||
*/
|
||||
public ElementNamespaceInstanceProviderException(ElementNamespaceInstanceProvider elementNamespaceInstanceProvider,String message) {
|
||||
super(message);
|
||||
this.elementNamespaceInstanceProvider=elementNamespaceInstanceProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates provider instance exception.
|
||||
* @param elementNamespaceInstanceProvider The provider which creates this exception.
|
||||
* @param message The message of this exception.
|
||||
* @param exception The root cause of this exception.
|
||||
*/
|
||||
public ElementNamespaceInstanceProviderException(ElementNamespaceInstanceProvider elementNamespaceInstanceProvider,String message,Exception exception) {
|
||||
super(message,exception);
|
||||
this.elementNamespaceInstanceProvider=elementNamespaceInstanceProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ElementNamespaceInstanceProvider which created this exception.
|
||||
* @return The provider which created the exception.
|
||||
*/
|
||||
public ElementNamespaceInstanceProvider getElementNamespaceInstanceProvider() {
|
||||
return elementNamespaceInstanceProvider;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Interface for doing refection for get/set the property values of any java object.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 20, 2005
|
||||
*/
|
||||
public interface ElementObjectPropertyValue {
|
||||
|
||||
/**
|
||||
* Sets an bean property of the object.
|
||||
* @param object
|
||||
* @param propertyName
|
||||
* @param value
|
||||
* @throws ElementObjectPropertyValueException
|
||||
*/
|
||||
void setProperty(Object object,String propertyName,Object value) throws ElementObjectPropertyValueException;
|
||||
|
||||
/**
|
||||
* Get the value of a properterie of a bean,
|
||||
* @param object The object to get the properties from
|
||||
* @param propertyName The name of the property to get.
|
||||
* @return Returns the value of the property.
|
||||
* @throws ElementObjectPropertyValueException
|
||||
*/
|
||||
Object getProperty(Object object,String propertyName) throws ElementObjectPropertyValueException;
|
||||
|
||||
/**
|
||||
* Sets all bean properties.
|
||||
* @param object To object to set all the properties to.
|
||||
* @param propertyMap A Map with the keys as properties names and the valua as value to set.
|
||||
* @throws ElementObjectPropertyValueException
|
||||
*/
|
||||
void setPropertyMap(Object object,Map<String,Object> propertyMap) throws ElementObjectPropertyValueException;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
||||
|
||||
/**
|
||||
* ElementObjectPropertyValueException.<br>
|
||||
* Is throw when the attribute value could not be found.
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 2, 2008
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ElementObjectPropertyValueException extends ElementException {
|
||||
|
||||
/**
|
||||
* Creates ElementObjectPropertyValueException with message.
|
||||
* @param message The error message.
|
||||
*/
|
||||
public ElementObjectPropertyValueException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates ElementObjectPropertyValueException with message and exception.
|
||||
* @param message The error message.
|
||||
* @param exception The error exception.
|
||||
*/
|
||||
public ElementObjectPropertyValueException(String message,Exception exception) {
|
||||
super(message,exception);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The X4O XML Element interfaces.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
package org.x4o.xml.element;
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.io;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
||||
public abstract class AbstractX4OConnection implements X4OConnection {
|
||||
|
||||
private X4OLanguageContext languageContext = null;
|
||||
|
||||
public AbstractX4OConnection(X4OLanguageContext languageContext) {
|
||||
this.languageContext=languageContext;
|
||||
}
|
||||
|
||||
protected X4OLanguageContext getLanguageContext() {
|
||||
return languageContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an X4O Language property.
|
||||
* @param key The key of the property to set.
|
||||
* @param value The vlue of the property to set.
|
||||
*/
|
||||
public void setProperty(String key,Object value) {
|
||||
String keyLimits[] = getPropertyKeySet();
|
||||
for (int i=0;i<keyLimits.length;i++) {
|
||||
String keyLimit = keyLimits[i];
|
||||
if (keyLimit.equals(key)) {
|
||||
//if (phaseManager!=null) {
|
||||
// TODO: throw new IllegalStateException("Can't set property after phaseManager is created.");
|
||||
//}
|
||||
languageContext.setLanguageProperty(X4OLanguageProperty.valueByUri(key), value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Property with key: "+key+" is protected by key limit.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value an X4O Language property.
|
||||
* @param key The key of the property to get the value for.
|
||||
* @return Returns null or the value of the property.
|
||||
*/
|
||||
public Object getProperty(String key) {
|
||||
return languageContext.getLanguageProperty(X4OLanguageProperty.valueByUri(key));
|
||||
}
|
||||
}
|
||||
185
x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OReader.java
Normal file
185
x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OReader.java
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.io;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
|
||||
import org.xml.sax.SAXException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
/**
|
||||
* This is a base class for building an SAX XML parser.
|
||||
* It adds methode's for parsing different input types of
|
||||
* xml data which gets wrapped into an InputStream for parsing.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 11, 2005
|
||||
*/
|
||||
abstract public class AbstractX4OReader<T> extends AbstractX4OReaderContext<T> implements X4OReader<T> {
|
||||
|
||||
public AbstractX4OReader(X4OLanguageContext elementLanguage) {
|
||||
super(elementLanguage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.X4OConnection#getPropertyKeySet()
|
||||
*/
|
||||
public String[] getPropertyKeySet() {
|
||||
return X4OLanguagePropertyKeys.DEFAULT_X4O_READER_KEYS;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T read(InputStream input, String systemId, URL basePath) throws ParserConfigurationException, SAXException, IOException {
|
||||
X4OLanguageContext context = readContext(input, systemId, basePath);
|
||||
return (T)context.getRootElement().getElementObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file fileName and reads it as an InputStream.
|
||||
* @param fileName The file name to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws FileNotFoundException
|
||||
* @throws SecurityException
|
||||
* @throws NullPointerException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public T readFile(String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException {
|
||||
if (fileName==null) {
|
||||
throw new NullPointerException("Can't convert null fileName to file object.");
|
||||
}
|
||||
return readFile(new File(fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file and reads it as an InputStream.
|
||||
* @param file The file to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws FileNotFoundException
|
||||
* @throws SecurityException
|
||||
* @throws NullPointerException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public T readFile(File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException {
|
||||
if (file==null) {
|
||||
throw new NullPointerException("Can't read null file.");
|
||||
}
|
||||
if (file.exists()==false) {
|
||||
throw new FileNotFoundException("File does not exists; "+file);
|
||||
}
|
||||
if (file.canRead()==false) {
|
||||
throw new IOException("File exists but can't read file: "+file);
|
||||
}
|
||||
URL basePath = new File(file.getAbsolutePath()).toURI().toURL();
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
try {
|
||||
return read(inputStream,file.getAbsolutePath(),basePath);
|
||||
} finally {
|
||||
if(inputStream!=null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reads an resource locaction.
|
||||
* @param resourceName The resource to readr.
|
||||
* @throws readrConfigurationException
|
||||
* @throws FileNotFoundException
|
||||
* @throws SecurityException
|
||||
* @throws NullPointerException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
*/
|
||||
public T readResource(String resourceName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException {
|
||||
if (resourceName==null) {
|
||||
throw new NullPointerException("Can't read null resourceName from classpath.");
|
||||
}
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) cl = getClass().getClassLoader(); // fallback
|
||||
URL url = cl.getResource(resourceName);
|
||||
if (url==null) {
|
||||
throw new NullPointerException("Could not find resource on classpath: "+resourceName);
|
||||
}
|
||||
String baseUrl = url.toExternalForm();
|
||||
int lastSlash = baseUrl.lastIndexOf('/');
|
||||
if (lastSlash > 0 && (lastSlash+1) < baseUrl.length()) {
|
||||
baseUrl = baseUrl.substring(0,lastSlash+1);
|
||||
}
|
||||
URL basePath = new URL(baseUrl);
|
||||
InputStream inputStream = cl.getResourceAsStream(resourceName);
|
||||
try {
|
||||
return read(inputStream,url.toExternalForm(),basePath);
|
||||
} finally {
|
||||
if(inputStream!=null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a InputStream to is can me readd by SAX.
|
||||
* @param xmlString The xml as String to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws NullPointerException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public T readString(String xmlString) throws ParserConfigurationException,SAXException,IOException,NullPointerException {
|
||||
if (xmlString==null) {
|
||||
throw new NullPointerException("Can't read null xml string.");
|
||||
}
|
||||
URL basePath = new File(System.getProperty("user.dir")).toURI().toURL();
|
||||
return read(new ByteArrayInputStream(xmlString.getBytes()),"inline-xml",basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetched the data direct from remote url to a InputStream to is can me readd by SAX.
|
||||
* @param url The url to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws NullPointerException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public T readUrl(URL url) throws ParserConfigurationException,SAXException,IOException,NullPointerException {
|
||||
if (url==null) {
|
||||
throw new NullPointerException("Can't read null url.");
|
||||
}
|
||||
URL basePath = new URL(url.toExternalForm().substring(0,url.toExternalForm().length()-url.getFile().length()));
|
||||
return read(url.openStream(),url.toExternalForm(),basePath);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2012, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.x4o.xml.io;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.xml.sax.SAXException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
/**
|
||||
* AbstractX4OContextReader
|
||||
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 6, 2013
|
||||
*/
|
||||
abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection implements X4OReaderContext<T> {
|
||||
|
||||
public AbstractX4OReaderContext(X4OLanguageContext languageContext) {
|
||||
super(languageContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file fileName and reads it as an InputStream.
|
||||
* @param fileName The file name to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws FileNotFoundException
|
||||
* @throws SecurityException
|
||||
* @throws NullPointerException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public X4OLanguageContext readFileContext(String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException {
|
||||
if (fileName==null) {
|
||||
throw new NullPointerException("Can't convert null fileName to file object.");
|
||||
}
|
||||
return readFileContext(new File(fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file and reads it as an InputStream.
|
||||
* @param file The file to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws FileNotFoundException
|
||||
* @throws SecurityException
|
||||
* @throws NullPointerException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public X4OLanguageContext readFileContext(File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException {
|
||||
if (file==null) {
|
||||
throw new NullPointerException("Can't read null file.");
|
||||
}
|
||||
if (file.exists()==false) {
|
||||
throw new FileNotFoundException("File does not exists; "+file);
|
||||
}
|
||||
if (file.canRead()==false) {
|
||||
throw new IOException("File exists but can't read file: "+file);
|
||||
}
|
||||
URL basePath = new File(file.getAbsolutePath()).toURI().toURL();
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
try {
|
||||
return readContext(inputStream,file.getAbsolutePath(),basePath);
|
||||
} finally {
|
||||
if(inputStream!=null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reads an resource locaction.
|
||||
* @param resourceName The resource to readr.
|
||||
* @throws readrConfigurationException
|
||||
* @throws FileNotFoundException
|
||||
* @throws SecurityException
|
||||
* @throws NullPointerException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
*/
|
||||
public X4OLanguageContext readResourceContext(String resourceName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException {
|
||||
if (resourceName==null) {
|
||||
throw new NullPointerException("Can't read null resourceName from classpath.");
|
||||
}
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) cl = getClass().getClassLoader(); // fallback
|
||||
URL url = cl.getResource(resourceName);
|
||||
if (url==null) {
|
||||
throw new NullPointerException("Could not find resource on classpath: "+resourceName);
|
||||
}
|
||||
String baseUrl = url.toExternalForm();
|
||||
int lastSlash = baseUrl.lastIndexOf('/');
|
||||
if (lastSlash > 0 && (lastSlash+1) < baseUrl.length()) {
|
||||
baseUrl = baseUrl.substring(0,lastSlash+1);
|
||||
}
|
||||
URL basePath = new URL(baseUrl);
|
||||
InputStream inputStream = cl.getResourceAsStream(resourceName);
|
||||
try {
|
||||
return readContext(inputStream,url.toExternalForm(),basePath);
|
||||
} finally {
|
||||
if(inputStream!=null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a InputStream to is can me readd by SAX.
|
||||
* @param xmlString The xml as String to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws NullPointerException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public X4OLanguageContext readStringContext(String xmlString) throws ParserConfigurationException,SAXException,IOException,NullPointerException {
|
||||
if (xmlString==null) {
|
||||
throw new NullPointerException("Can't read null xml string.");
|
||||
}
|
||||
URL basePath = new File(System.getProperty("user.dir")).toURI().toURL();
|
||||
return readContext(new ByteArrayInputStream(xmlString.getBytes()),"inline-xml",basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetched the data direct from remote url to a InputStream to is can me readd by SAX.
|
||||
* @param url The url to read.
|
||||
* @throws readrConfigurationException
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
* @throws NullPointerException
|
||||
* @see org.x4o.xml.sax.AbstractXMLreadr#read(java.io.InputStream,java.lang.String,java.net.URL)
|
||||
*/
|
||||
public X4OLanguageContext readUrlContext(URL url) throws ParserConfigurationException,SAXException,IOException,NullPointerException {
|
||||
if (url==null) {
|
||||
throw new NullPointerException("Can't read null url.");
|
||||
}
|
||||
URL basePath = new URL(url.toExternalForm().substring(0,url.toExternalForm().length()-url.getFile().length()));
|
||||
return readContext(url.openStream(),url.toExternalForm(),basePath);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue