Fixed some checkstyle and javadoc warnings and added a few new IO unit

tests.
This commit is contained in:
Willem Cazander 2013-04-29 01:04:24 +02:00
parent ed1732a625
commit edbe6bb737
39 changed files with 581 additions and 111 deletions

View file

@ -39,7 +39,7 @@ Usage
* x4o-plugin-ant = X4O Ant plugins for schema and documentation task. * x4o-plugin-ant = X4O Ant plugins for schema and documentation task.
* x4o-plugin-ant-schema = Ant x4o schema task. * x4o-plugin-maven = X4O Maven plugin task.
* Setup as library * Setup as library
@ -58,17 +58,12 @@ Usage
* Setup build task * Setup build task
Append one or both of the x4o eld ant tasks; Append the x4o ant tasks;
+-- +--
<dependency> <dependency>
<groupId>org.x4o.plugin</groupId> <groupId>org.x4o.plugin</groupId>
<artifactId>x4o-plugin-ant-elddoc</artifactId> <artifactId>x4o-plugin-ant</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.x4o.plugin</groupId>
<artifactId>x4o-plugin-ant-schema</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
+-- +--
@ -76,21 +71,21 @@ Usage
Use in ant and set the supportclass from the language you want to run the task for. Use in ant and set the supportclass from the language you want to run the task for.
+-- +--
<taskdef name="eldDocWriter" classname="org.x4o.plugin.ant.eld.doc.EldDocWriterTask"/> <taskdef name="writeLanguageDoc" classname="org.x4o.plugin.ant.X4OWriteLanguageDocTask"/>
<taskdef name="eldXsdWriter" classname="org.x4o.plugin.ant.eld.xsd.EldXsdWriterTask"/> <taskdef name="writeLanguageSchema" classname="org.x4o.plugin.ant.X4OWriteLanguageSchemaTask"/>
<target name="build-cel-schema" depends="init"> <target name="build-cel-schema" depends="init">
<mkdir dir="${test.dir}/cel-schema"/> <mkdir dir="${test.dir}/cel-schema"/>
<eldXsdWriter <writeLanguageSchema
destdir="${test.dir}/cel-schema" destdir="${test.dir}/cel-schema"
supportclass="org.x4o.xml.eld.EldParserSupportCore" languageName="cel"
/> />
</target> </target>
<target name="build-cel-elddoc" depends="init"> <target name="build-cel-elddoc" depends="init">
<mkdir dir="${test.dir}/cel-elddoc"/> <mkdir dir="${test.dir}/cel-elddoc"/>
<eldDocWriter <writeLanguageDoc
destdir="${test.dir}/cel-elddoc" destdir="${test.dir}/cel-elddoc"
supportclass="org.x4o.xml.eld.EldParserSupportCore" languageName="cel"
/> />
</target> </target>
+-- +--

View file

@ -272,7 +272,7 @@ public final class X4ODriverManager {
if (classdrivers.containsKey(className)==false) { if (classdrivers.containsKey(className)==false) {
classdrivers.put(language,className); classdrivers.put(language,className);
} }
} else if ("defaultDriver".equals("tab")) { } else if ("defaultDriver".equals(tag)) {
String language = attr.getValue("language"); String language = attr.getValue("language");
logger.finest("DefaultDriver language: "+language); logger.finest("DefaultDriver language: "+language);
if (defaultDrivers.containsKey(language)==false) { if (defaultDrivers.containsKey(language)==false) {

View file

@ -47,6 +47,9 @@ public class X4OELContext extends ELContext {
private FunctionMapper functionMapper = null; private FunctionMapper functionMapper = null;
private VariableMapper variableMapper = null; private VariableMapper variableMapper = null;
/**
* Creates a X4OELContext.
*/
public X4OELContext(/* X4OLanguageConfiguration x4oParserConfig */) { public X4OELContext(/* X4OLanguageConfiguration x4oParserConfig */) {
CompositeELResolver compositeELResolver = new CompositeELResolver(); CompositeELResolver compositeELResolver = new CompositeELResolver();
@ -62,6 +65,8 @@ public class X4OELContext extends ELContext {
} }
/** /**
* Returns the ELResolver.
* @return The ELResolver.
* @see javax.el.ELContext#getELResolver() * @see javax.el.ELContext#getELResolver()
*/ */
@Override @Override
@ -70,6 +75,8 @@ public class X4OELContext extends ELContext {
} }
/** /**
* Returns the FunctionMapper.
* @return The FunctionMapper.
* @see javax.el.ELContext#getFunctionMapper() * @see javax.el.ELContext#getFunctionMapper()
*/ */
@Override @Override
@ -78,6 +85,8 @@ public class X4OELContext extends ELContext {
} }
/** /**
* Returns the VariableMapper.
* @return The VariableMapper.
* @see javax.el.ELContext#getVariableMapper() * @see javax.el.ELContext#getVariableMapper()
*/ */
@Override @Override

View file

@ -39,6 +39,9 @@ import javax.el.FunctionMapper;
public class X4OELFunctionMapper extends FunctionMapper { public class X4OELFunctionMapper extends FunctionMapper {
private Map<String,Method> functionMap = null; private Map<String,Method> functionMap = null;
/**
* Creates a X4OELFunctionMapper.
*/
public X4OELFunctionMapper() { public X4OELFunctionMapper() {
functionMap = new HashMap<String,Method>(50); functionMap = new HashMap<String,Method>(50);
} }
@ -49,6 +52,12 @@ public class X4OELFunctionMapper extends FunctionMapper {
return functionMap.get(key); return functionMap.get(key);
} }
/**
* Add an static method to the function mapper.
* @param prefix The function prefix.
* @param localName The local name of function.
* @param method The method to execute on.
*/
public void addFunction(String prefix, String localName, Method method) { public void addFunction(String prefix, String localName, Method method) {
if(prefix==null || localName==null || method==null) { if(prefix==null || localName==null || method==null) {
throw new NullPointerException(); throw new NullPointerException();

View file

@ -36,6 +36,8 @@ public class CelDriver extends X4ODriver<X4OLanguageModule> {
/** Defines the identifier of the 'Core Element Language' language. */ /** Defines the identifier of the 'Core Element Language' language. */
public static final String LANGUAGE_NAME = "cel"; public static final String LANGUAGE_NAME = "cel";
/** Defines the versions this langauge knowns. */
public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION}; public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
@Override @Override

View file

@ -42,6 +42,9 @@ public class AttributeFromBodyConfigurator extends AbstractElementConfigurator {
private String bodyType = null; private String bodyType = null;
/** /**
* Config an element body as attribute of parent elememt.
* @param element The element to config.
* @throws ElementConfiguratorException Is thrown when object tree is non valid.
* @see org.x4o.xml.element.ElementConfigurator#doConfigElement(org.x4o.xml.element.Element) * @see org.x4o.xml.element.ElementConfigurator#doConfigElement(org.x4o.xml.element.Element)
*/ */
public void doConfigElement(Element element) throws ElementConfiguratorException { public void doConfigElement(Element element) throws ElementConfiguratorException {
@ -64,7 +67,7 @@ public class AttributeFromBodyConfigurator extends AbstractElementConfigurator {
} else { } else {
throw new ElementConfiguratorException(this,"bodyType attribute value is unknown; "+bodyType); throw new ElementConfiguratorException(this,"bodyType attribute value is unknown; "+bodyType);
} }
if (value.length()==0) { if (value.trim().length()==0) {
return; return;
} }
element.getAttributes().put(name, value); element.getAttributes().put(name, value);

View file

@ -28,9 +28,7 @@ import org.x4o.xml.element.ElementMetaBase;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
/** /**
* Fills all the ElementDescription which the description * Fills all the ElementDescription which the description.
*
*
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 13, 2009 * @version 1.0 Jan 13, 2009
@ -38,6 +36,8 @@ import org.x4o.xml.element.ElementException;
public class DescriptionElement extends AbstractElement { public class DescriptionElement extends AbstractElement {
/** /**
* Starts the description element and validates that it is not root and parent is meta base.
* @throws ElementException When parent element object is not meta base object.
* @see org.x4o.xml.element.AbstractElement#doElementStart() * @see org.x4o.xml.element.AbstractElement#doElementStart()
*/ */
@Override @Override
@ -51,6 +51,9 @@ public class DescriptionElement extends AbstractElement {
} }
/** /**
* The description elememt body characters are stored as element object.
* @param characters The text of the description.
* @throws ElementException When super has error.
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String) * @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
*/ */
@Override @Override
@ -60,6 +63,8 @@ public class DescriptionElement extends AbstractElement {
} }
/** /**
* Ends the description element and sets the description on the parent.
* @throws ElementException When parent element object is not meta base object.
* @see org.x4o.xml.element.AbstractElement#doElementEnd() * @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/ */
@Override @Override

View file

@ -46,7 +46,11 @@ public class X4OWriteLanguageSchemaExecutor {
private String languageNamespaceUri = null; private String languageNamespaceUri = null;
private File basePath; private File basePath;
static public void main(String argu[]) { /**
* Config and executes this language task.
* @param argu The command line arguments.
*/
public static void main(String[] argu) {
X4OWriteLanguageSchemaExecutor languageSchema = new X4OWriteLanguageSchemaExecutor(); X4OWriteLanguageSchemaExecutor languageSchema = new X4OWriteLanguageSchemaExecutor();
List<String> arguList = Arrays.asList(argu); List<String> arguList = Arrays.asList(argu);
Iterator<String> arguIterator = arguList.iterator(); Iterator<String> arguIterator = arguList.iterator();
@ -108,6 +112,9 @@ public class X4OWriteLanguageSchemaExecutor {
} }
} }
/**
* Executes this language task.
*/
public void execute() throws ElementException { public void execute() throws ElementException {
// Start xsd generator // Start xsd generator
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName()); X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName());

View file

@ -36,7 +36,6 @@ import org.x4o.xml.conv.ObjectConverter;
*/ */
public abstract class AbstractElementClassAttribute extends AbstractElementMetaBase implements ElementClassAttribute { public abstract class AbstractElementClassAttribute extends AbstractElementMetaBase implements ElementClassAttribute {
private String name = null;
private ObjectConverter objectConverter = null; private ObjectConverter objectConverter = null;
private Object defaultValue = null; private Object defaultValue = null;
private List<String> attributeAliases = null; private List<String> attributeAliases = null;
@ -47,39 +46,32 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB
private Boolean runBeanValue = null; private Boolean runBeanValue = null;
private Integer writeOrder = null; private Integer writeOrder = null;
/**
* Creates a AbstractElementClassAttribute.
*/
public AbstractElementClassAttribute() { public AbstractElementClassAttribute() {
attributeAliases = new ArrayList<String>(3); attributeAliases = new ArrayList<String>(3);
} }
/** /**
* @see org.x4o.xml.element.ElementClassAttribute#getName() * Returns the objectConverter.
*/ * @return The objectConverter.
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() { public ObjectConverter getObjectConverter() {
return objectConverter; return objectConverter;
} }
/** /**
* @param objectConverter the objectConverter to set * Sets the objectConverter.
* @param objectConverter The objectConverter to set.
*/ */
public void setObjectConverter(ObjectConverter objectConverter) { public void setObjectConverter(ObjectConverter objectConverter) {
this.objectConverter = objectConverter; this.objectConverter = objectConverter;
} }
/** /**
* Sets the default value.
* @param defaultValue The defaultValue to set.
* @see org.x4o.xml.element.ElementClassAttribute#setDefaultValue(java.lang.Object) * @see org.x4o.xml.element.ElementClassAttribute#setDefaultValue(java.lang.Object)
*/ */
public void setDefaultValue(Object defaultValue) { public void setDefaultValue(Object defaultValue) {
@ -87,6 +79,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB
} }
/** /**
* Returns the default value.
* @return The default value.
* @see org.x4o.xml.element.ElementClassAttribute#getDefaultValue() * @see org.x4o.xml.element.ElementClassAttribute#getDefaultValue()
*/ */
public Object getDefaultValue() { public Object getDefaultValue() {
@ -94,6 +88,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB
} }
/** /**
* Adds an alias of this attribute.
* @param alias The alias to add.
* @see org.x4o.xml.element.ElementClassAttribute#addAttributeAlias(java.lang.String) * @see org.x4o.xml.element.ElementClassAttribute#addAttributeAlias(java.lang.String)
*/ */
public void addAttributeAlias(String alias) { public void addAttributeAlias(String alias) {
@ -101,6 +97,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB
} }
/** /**
* Removes an alias of this attribute.
* @param alias The alias to remove.
* @see org.x4o.xml.element.ElementClassAttribute#removeAttributeAlias(java.lang.String) * @see org.x4o.xml.element.ElementClassAttribute#removeAttributeAlias(java.lang.String)
*/ */
public void removeAttributeAlias(String alias) { public void removeAttributeAlias(String alias) {
@ -108,6 +106,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB
} }
/** /**
* Returns all aliases of this attribute.
* @return An list of aliases.
* @see org.x4o.xml.element.ElementClassAttribute#getAttributeAliases() * @see org.x4o.xml.element.ElementClassAttribute#getAttributeAliases()
*/ */
public List<String> getAttributeAliases() { public List<String> getAttributeAliases() {
@ -115,70 +115,70 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB
} }
/** /**
* @return the required * @return the required.
*/ */
public Boolean getRequired() { public Boolean getRequired() {
return required; return required;
} }
/** /**
* @param required the required to set * @param required the required to set.
*/ */
public void setRequired(Boolean required) { public void setRequired(Boolean required) {
this.required = required; this.required = required;
} }
/** /**
* @return the runResolveEL * @return the runResolveEL.
*/ */
public Boolean getRunResolveEL() { public Boolean getRunResolveEL() {
return runResolveEL; return runResolveEL;
} }
/** /**
* @param runResolveEL the runResolveEL to set * @param runResolveEL the runResolveEL to set.
*/ */
public void setRunResolveEL(Boolean runResolveEL) { public void setRunResolveEL(Boolean runResolveEL) {
this.runResolveEL = runResolveEL; this.runResolveEL = runResolveEL;
} }
/** /**
* @return the runConverters * @return the runConverters.
*/ */
public Boolean getRunConverters() { public Boolean getRunConverters() {
return runConverters; return runConverters;
} }
/** /**
* @param runConverters the runConverters to set * @param runConverters the runConverters to set.
*/ */
public void setRunConverters(Boolean runConverters) { public void setRunConverters(Boolean runConverters) {
this.runConverters = runConverters; this.runConverters = runConverters;
} }
/** /**
* @return the runBeanValue * @return the runBeanValue.
*/ */
public Boolean getRunBeanValue() { public Boolean getRunBeanValue() {
return runBeanValue; return runBeanValue;
} }
/** /**
* @param runBeanValue the runBeanValue to set * @param runBeanValue the runBeanValue to set.
*/ */
public void setRunBeanValue(Boolean runBeanValue) { public void setRunBeanValue(Boolean runBeanValue) {
this.runBeanValue = runBeanValue; this.runBeanValue = runBeanValue;
} }
/** /**
* @return the writeOrder * @return the writeOrder.
*/ */
public Integer getWriteOrder() { public Integer getWriteOrder() {
return writeOrder; return writeOrder;
} }
/** /**
* @param writeOrder the writeOrder to set * @param writeOrder the writeOrder to set.
*/ */
public void setWriteOrder(Integer writeOrder) { public void setWriteOrder(Integer writeOrder) {
this.writeOrder = writeOrder; this.writeOrder = writeOrder;

View file

@ -41,6 +41,9 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i
private List<ElementConfigurator> elementConfigurators = null; private List<ElementConfigurator> elementConfigurators = null;
private Map<String,List<String>> elementParents = null; private Map<String,List<String>> elementParents = null;
/**
* Creates a AbstractElementClassBase.
*/
public AbstractElementClassBase() { public AbstractElementClassBase() {
elementConfigurators = new ArrayList<ElementConfigurator>(5); elementConfigurators = new ArrayList<ElementConfigurator>(5);
elementClassAttributes = new HashMap<String,ElementClassAttribute>(15); elementClassAttributes = new HashMap<String,ElementClassAttribute>(15);
@ -48,6 +51,8 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i
} }
/** /**
* Returns a list of ElementConfigurators.
* @return List of ElementConfigurators.
* @see ElementClass#getElementConfigurators() * @see ElementClass#getElementConfigurators()
*/ */
public List<ElementConfigurator> getElementConfigurators() { public List<ElementConfigurator> getElementConfigurators() {

View file

@ -75,10 +75,11 @@ public class DefaultElementNamespaceInstanceProvider implements ElementNamespace
try { try {
if (elementClass.getElementClass()!=null) { if (elementClass.getElementClass()!=null) {
Object obj = X4OLanguageClassLoader.newInstance(elementClass.getElementClass()); Object obj = X4OLanguageClassLoader.newInstance(elementClass.getElementClass());
if ((obj instanceof Element) == false) { if (obj instanceof Element) {
element = (Element) obj;
} else {
throw new ElementNamespaceInstanceProviderException(this,"Provided elementClassName is not an Element: "+obj.getClass()); throw new ElementNamespaceInstanceProviderException(this,"Provided elementClassName is not an Element: "+obj.getClass());
} }
element = (Element) obj;
} else { } else {
element = (Element)X4OLanguageClassLoader.newInstance((languageContext.getLanguage().getLanguageConfiguration().getDefaultElement())); element = (Element)X4OLanguageClassLoader.newInstance((languageContext.getLanguage().getLanguageConfiguration().getDefaultElement()));
} }

View file

@ -36,17 +36,18 @@ public interface ElementNamespaceInstanceProvider {
/** /**
* Starts the ElementProvider. * Starts the ElementProvider.
* @param elementLanguage The ElementLanguage to start in. * @param language The X4OLanguage to start in.
* @param elementNamespaceContext The ElementNamespaceContext to start for. * @param elementNamespaceContext The ElementNamespaceContext to start for.
* @throws ElementNamespaceInstanceProviderException Thrown when error happened in language. * @throws ElementNamespaceInstanceProviderException Thrown when error happened in language.
*/ */
void start(X4OLanguage elementLanguage,ElementNamespaceContext elementNamespaceContext) throws ElementNamespaceInstanceProviderException; void start(X4OLanguage language,ElementNamespaceContext elementNamespaceContext) throws ElementNamespaceInstanceProviderException;
/** /**
* Provide an Element for an xml tag. * Provide an Element for an xml tag.
* @param languageContext The languageContext to create element for.
* @param tag The xml tag to create instance for. * @param tag The xml tag to create instance for.
* @return An new Element instance. * @return An new Element instance.
* @throws ElementNamespaceInstanceProviderException Thrown when error happened in language. * @throws ElementNamespaceInstanceProviderException Thrown when error happened in language.
*/ */
Element createElementInstance(X4OLanguageContext elementLanguage,String tag) throws ElementNamespaceInstanceProviderException; Element createElementInstance(X4OLanguageContext languageContext,String tag) throws ElementNamespaceInstanceProviderException;
} }

View file

@ -36,10 +36,17 @@ public abstract class AbstractX4OConnection implements X4OConnection {
private X4OLanguageContext languageContext = null; private X4OLanguageContext languageContext = null;
/**
* Creates a AbstractX4OConnection.
* @param languageContext The language context of this connection.
*/
public AbstractX4OConnection(X4OLanguageContext languageContext) { public AbstractX4OConnection(X4OLanguageContext languageContext) {
this.languageContext=languageContext; this.languageContext=languageContext;
} }
/**
* @return Returns the language context.
*/
protected X4OLanguageContext getLanguageContext() { protected X4OLanguageContext getLanguageContext() {
return languageContext; return languageContext;
} }
@ -50,7 +57,7 @@ public abstract class AbstractX4OConnection implements X4OConnection {
* @param value The vlue of the property to set. * @param value The vlue of the property to set.
*/ */
public void setProperty(String key,Object value) { public void setProperty(String key,Object value) {
String keyLimits[] = getPropertyKeySet(); String[] keyLimits = getPropertyKeySet();
for (int i=0;i<keyLimits.length;i++) { for (int i=0;i<keyLimits.length;i++) {
String keyLimit = keyLimits[i]; String keyLimit = keyLimits[i];
if (keyLimit.equals(key)) { if (keyLimit.equals(key)) {

View file

@ -87,9 +87,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
try { try {
return readContext(inputStream,file.getAbsolutePath(),basePath); return readContext(inputStream,file.getAbsolutePath(),basePath);
} finally { } finally {
if(inputStream!=null) { inputStream.close();
inputStream.close();
}
} }
} }
@ -121,9 +119,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
try { try {
return readContext(inputStream,url.toExternalForm(),basePath); return readContext(inputStream,url.toExternalForm(),basePath);
} finally { } finally {
if(inputStream!=null) { inputStream.close();
inputStream.close();
}
} }
} }

View file

@ -58,9 +58,7 @@ public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection
try { try {
writeContext(context,outputStream); writeContext(context,outputStream);
} finally { } finally {
if(outputStream!=null) { outputStream.close();
outputStream.close();
}
} }
} }
} }

View file

@ -156,6 +156,7 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
languageContext.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length); languageContext.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length);
languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", ""); languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
} catch (Exception ee) { } catch (Exception ee) {
logger.warning(ee.getMessage());
} }
} }

View file

@ -52,7 +52,7 @@ public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
* @see org.x4o.xml.io.X4OWriterContext#writeContext(org.x4o.xml.lang.X4OLanguageContext, java.io.OutputStream) * @see org.x4o.xml.io.X4OWriterContext#writeContext(org.x4o.xml.lang.X4OLanguageContext, java.io.OutputStream)
*/ */
public void writeContext(X4OLanguageContext languageContext,OutputStream output) throws X4OConnectionException,SAXException,IOException { public void writeContext(X4OLanguageContext languageContext,OutputStream output) throws X4OConnectionException,SAXException,IOException {
setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_STREAM, output); languageContext.setLanguageProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_STREAM, output);
try { try {
languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE); languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE);
} catch (X4OPhaseException e) { } catch (X4OPhaseException e) {

View file

@ -39,7 +39,12 @@ import org.xml.sax.SAXException;
*/ */
public interface X4OReader<T> extends X4OConnection { public interface X4OReader<T> extends X4OConnection {
public void addELBeanInstance(String name,Object bean); /**
* Adds an bean instance to the el context.
* @param name The el name for the bean.
* @param bean The bean to add to the el context.
*/
void addELBeanInstance(String name,Object bean);
/** /**
* Method to parse the xml data. * Method to parse the xml data.

View file

@ -103,6 +103,8 @@ public class X4OEntityResolver implements EntityResolver {
* *
* @param publicId The public id to search for. * @param publicId The public id to search for.
* @param systemId The system id to search for. * @param systemId The system id to search for.
* @throws IOException When resource could not be read.
* @throws SAXException When exception is thrown.
* @return Returns null or the InputSource of the requested ids. * @return Returns null or the InputSource of the requested ids.
*/ */
public InputSource resolveEntity(String publicId, String systemId) throws IOException,SAXException { public InputSource resolveEntity(String publicId, String systemId) throws IOException,SAXException {

View file

@ -57,7 +57,7 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
private Map<String,Object> languageProperties; private Map<String,Object> languageProperties;
/** /**
* Creates a new empty ElementLanguage. * Creates a new empty language context.
*/ */
public AbstractX4OLanguageContext(X4OLanguage language) { public AbstractX4OLanguageContext(X4OLanguage language) {
if (language==null) { if (language==null) {

View file

@ -32,6 +32,9 @@ package org.x4o.xml.lang;
*/ */
public class DefaultX4OLanguageContext extends AbstractX4OLanguageContext { public class DefaultX4OLanguageContext extends AbstractX4OLanguageContext {
/**
* Creates a new empty language context.
*/
public DefaultX4OLanguageContext(X4OLanguage language) { public DefaultX4OLanguageContext(X4OLanguage language) {
super(language); super(language);
} }

View file

@ -63,6 +63,7 @@ public interface X4OLanguage {
/** /**
* Creates and fills the initial element language used to store the language. * Creates and fills the initial element language used to store the language.
* @param driver The driver to create language context for.
* @return The newly created ElementLanguage. * @return The newly created ElementLanguage.
*/ */
X4OLanguageContext createLanguageContext(X4ODriver<?> driver); X4OLanguageContext createLanguageContext(X4ODriver<?> driver);

View file

@ -29,7 +29,7 @@ package org.x4o.xml.lang;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 6 Aug 2012 * @version 1.0 6 Aug 2012
*/ */
public class X4OLanguageClassLoader { public final class X4OLanguageClassLoader {
/** /**
* Made X4OLanguageClassLoader have private constructor. * Made X4OLanguageClassLoader have private constructor.

View file

@ -54,12 +54,12 @@ public interface X4OLanguageModule extends ElementMetaBase {
/** /**
* @return the providerHost * @return the providerHost
*/ */
public String getProviderHost(); String getProviderHost();
/** /**
* @param providerHost the providerHost to set * @param providerHost the providerHost to set
*/ */
public void setProviderHost(String providerHost); void setProviderHost(String providerHost);
/** /**
* Adds an ElementAttributeHandler. * Adds an ElementAttributeHandler.

View file

@ -237,6 +237,7 @@ public class X4OPhaseLanguageWrite {
try { try {
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
logger.warning(e.getMessage());
} }
} }
} }

View file

@ -24,16 +24,25 @@
package org.x4o.xml.lang.phase; package org.x4o.xml.lang.phase;
/** /**
* X4OPhaseType * X4OPhaseType defines which phase type there are to put phases in to execute.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Apr 30, 2013 * @version 1.0 Apr 30, 2013
*/ */
public enum X4OPhaseType { public enum X4OPhaseType {
/** Language init. */
INIT, INIT,
/** Read/Write xml.(not used) */
XML_RW, XML_RW,
/** XML Reading. */
XML_READ, XML_READ,
/** XML Writing. */
XML_WRITE, XML_WRITE,
/** XML Schema writing. */
XML_WRITE_SCHEMA XML_WRITE_SCHEMA
} }

View file

@ -23,10 +23,13 @@
package org.x4o.xml.core; package org.x4o.xml.core;
import java.util.List;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestBean; import org.x4o.xml.test.models.TestBean;
import org.x4o.xml.test.models.TestObjectChild;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -39,6 +42,20 @@ import junit.framework.TestCase;
*/ */
public class AttributeBeanTest extends TestCase { public class AttributeBeanTest extends TestCase {
public void testBeanBody() throws Exception {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
TestObjectRoot root = reader.readResource("tests/attributes/test-body.xml");
assertNotNull(root);
List<TestObjectChild> childs = root.getTestObjectChilds();
assertEquals(2,childs.size());
TestObjectChild child0 = childs.get(0);
TestObjectChild child1 = childs.get(1);
assertEquals("attr-name",child0.getName());
assertEquals("body-name",child1.getName());
}
public void testBeanProperties() throws Exception { public void testBeanProperties() throws Exception {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();

View file

@ -25,9 +25,12 @@ package org.x4o.xml.eld.xsd;
import java.io.File; import java.io.File;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
import org.x4o.xml.eld.CelDriver; import org.x4o.xml.eld.CelDriver;
import org.x4o.xml.eld.EldDriver; import org.x4o.xml.eld.EldDriver;
import org.x4o.xml.eld.xsd.X4OWriteLanguageSchemaExecutor; import org.x4o.xml.eld.xsd.X4OWriteLanguageSchemaExecutor;
import org.x4o.xml.io.X4OSchemaWriter;
import org.x4o.xml.test.swixml.SwiXmlDriver; import org.x4o.xml.test.swixml.SwiXmlDriver;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -52,6 +55,12 @@ public class X4OWriteLanguageSchemaExecutorTest extends TestCase {
return result; return result;
} }
public void testSchemaWriterDirect() throws Exception {
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(CelDriver.LANGUAGE_NAME);
X4OSchemaWriter xsd = driver.createSchemaWriter();
xsd.writeSchema(getTempPath("junit-xsd-cel-direct"));
}
public void testEldSchema() throws Exception { public void testEldSchema() throws Exception {
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor(); X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(getTempPath("junit-xsd-eld")); writer.setBasePath(getTempPath("junit-xsd-eld"));

View file

@ -0,0 +1,86 @@
/*
* 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.X4ODriver;
import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot;
import junit.framework.TestCase;
/**
* X4OConnectionTest.
*
* @author Willem Cazander
* @version 1.0 Apr 28, 2013
*/
public class X4OConnectionTest extends TestCase {
public void testReaderPropertyFail() throws Exception {
Exception e = null;
try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
reader.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_ENCODING, "test");
} catch (Exception catchE) {
e = catchE;
}
assertNotNull("No exception",e);
assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("key"));
assertTrue("Wrong exception message",e.getMessage().contains("protected"));
}
public void testWriterPropertyFail() throws Exception {
Exception e = null;
try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OWriter<TestObjectRoot> writer = driver.createWriter();
writer.setProperty(X4OLanguagePropertyKeys.READER_INPUT_ENCODING, "test");
} catch (Exception catchE) {
e = catchE;
}
assertNotNull("No exception",e);
assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("key"));
assertTrue("Wrong exception message",e.getMessage().contains("protected"));
}
public void testSchemaWriterPropertyFail() throws Exception {
Exception e = null;
try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OSchemaWriter schemaWriter = driver.createSchemaWriter();
schemaWriter.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_ENCODING, "test");
} catch (Exception catchE) {
e = catchE;
}
assertNotNull("No exception",e);
assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("key"));
assertTrue("Wrong exception message",e.getMessage().contains("protected"));
}
}

View file

@ -38,12 +38,12 @@ import org.x4o.xml.test.models.TestObjectRoot;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* X4OAbstractReaderContextTest. * X4OReaderContextTest.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Apr 15, 2013 * @version 1.0 Apr 15, 2013
*/ */
public class X4OAbstractReaderContextTest extends TestCase { public class X4OReaderContextTest extends TestCase {
private File copyResourceToTempFile() throws IOException { private File copyResourceToTempFile() throws IOException {
File tempFile = File.createTempFile("test-resource", ".xml"); File tempFile = File.createTempFile("test-resource", ".xml");
@ -132,6 +132,24 @@ public class X4OAbstractReaderContextTest extends TestCase {
assertTrue("Wrong exception message",e.getMessage().contains("File")); assertTrue("Wrong exception message",e.getMessage().contains("File"));
} }
public void testReadFileNotReadable() throws Exception {
if (File.separatorChar != '/') {
return; // only test on real os.
}
TestDriver driver = TestDriver.getInstance();
X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext();
Exception e = null;
try {
reader.readFileContext(new File("/etc/shadow"));
} catch (Exception catchE) {
e = catchE;
}
assertNotNull("No exception",e);
assertEquals("Wrong exception class",IOException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("exists"));
assertTrue("Wrong exception message",e.getMessage().contains("read"));
}
public void testReadResource() throws Exception { public void testReadResource() throws Exception {
TestDriver driver = TestDriver.getInstance(); TestDriver driver = TestDriver.getInstance();

View file

@ -24,7 +24,9 @@
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URL; import java.net.URL;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
@ -36,12 +38,12 @@ import org.x4o.xml.test.models.TestObjectRoot;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* X4OAbstractReaderTest. * X4OReaderTest.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Apr 15, 2013 * @version 1.0 Apr 15, 2013
*/ */
public class X4OAbstractReaderTest extends TestCase { public class X4OReaderTest extends TestCase {
private File copyResourceToTempFile() throws IOException { private File copyResourceToTempFile() throws IOException {
File tempFile = File.createTempFile("test-resource", ".xml"); File tempFile = File.createTempFile("test-resource", ".xml");
@ -57,6 +59,23 @@ public class X4OAbstractReaderTest extends TestCase {
return tempFile; return tempFile;
} }
public void testReadInputStream() throws Exception {
TestDriver driver = TestDriver.getInstance();
X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext();
File xmlFile = copyResourceToTempFile();
URL basePath = new File(xmlFile.getAbsolutePath()).toURI().toURL();
InputStream inputStream = new FileInputStream(xmlFile);
TestObjectRoot root = null;
try {
root = reader.read(inputStream, xmlFile.getAbsolutePath(), basePath);
} finally {
inputStream.close();
}
assertNotNull(root);
assertTrue(root.getTestBeans().size()>0);
TestBean bean = root.getTestBeans().get(0);
assertNotNull(bean);
}
public void testReadResource() throws Exception { public void testReadResource() throws Exception {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();

View file

@ -0,0 +1,155 @@
/*
* 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.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.element.Element;
import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot;
import org.xml.sax.SAXException;
import junit.framework.TestCase;
/**
* X4OWriterContextTest.
*
* @author Willem Cazander
* @version 1.0 Apr 28, 2013
*/
public class X4OWriterContextTest extends TestCase {
private File createOutputFile() throws IOException {
File outputFile = File.createTempFile("test-writer-context", ".xml");
outputFile.deleteOnExit();
return outputFile;
}
private X4OLanguageContext createContext() throws SAXException, X4OConnectionException, IOException {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
X4OLanguageContext context = driver.createLanguageContext();
Element rootElement = null;
try {
rootElement = (Element)context.getLanguage().getLanguageConfiguration().getDefaultElement().newInstance();
} catch (InstantiationException e) {
throw new SAXException(e);
} catch (IllegalAccessException e) {
throw new SAXException(e);
}
rootElement.setElementObject(root);
context.setRootElement(rootElement);
return context;
}
public void testWriteFile() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OWriterContext<TestObjectRoot> writer = driver.createWriterContext();
writer.writeFileContext(createContext(), outputFile);
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
}
public void testWriteFileNull() throws Exception {
TestDriver driver = TestDriver.getInstance();
X4OWriterContext<TestObjectRoot> writer = driver.createWriterContext();
Exception e = null;
File nullFile = null;
try {
writer.writeFileContext(createContext(), nullFile);
} catch (Exception catchE) {
e = catchE;
}
assertNotNull("No exception",e);
assertEquals("Wrong exception class",NullPointerException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("null"));
assertTrue("Wrong exception message",e.getMessage().contains("file"));
}
public void testWriteFileName() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OWriterContext<TestObjectRoot> writer = driver.createWriterContext();
writer.writeFileContext(createContext(), outputFile.getAbsolutePath());
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
}
public void testWriteFileNameNull() throws Exception {
TestDriver driver = TestDriver.getInstance();
X4OWriterContext<TestObjectRoot> writer = driver.createWriterContext();
Exception e = null;
String nullFileName = null;
try {
writer.writeFileContext(createContext(), nullFileName);
} catch (Exception catchE) {
e = catchE;
}
assertNotNull("No exception",e);
assertEquals("Wrong exception class",NullPointerException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("null"));
assertTrue("Wrong exception message",e.getMessage().contains("fileName"));
}
public void testWriteStream() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OWriterContext<TestObjectRoot> writer = driver.createWriterContext();
OutputStream outputStream = new FileOutputStream(outputFile);
try {
writer.writeContext(createContext(),outputStream);
} finally {
outputStream.close();
}
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
}
}

View file

@ -25,12 +25,13 @@ package org.x4o.xml.io;
import java.awt.Component; import java.awt.Component;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner; import java.util.Scanner;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
import org.x4o.xml.test.swixml.Accelerator3; import org.x4o.xml.test.swixml.Accelerator3;
@ -40,7 +41,7 @@ import org.x4o.xml.test.swixml.SwingEngine;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* X4ODebugWriterTest runs parser with debug output. * X4OWriterTest runs parser with debug output.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Aug 26, 2012 * @version 1.0 Aug 26, 2012
@ -54,31 +55,6 @@ public class X4OWriterTest extends TestCase {
return outputFile; return outputFile;
} }
public void testWriterOutput() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
X4OWriter<TestObjectRoot> writer = driver.createWriter();
writer.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_CHAR_TAB, " ");
writer.setProperty(X4OLanguagePropertyKeys.WRITER_SCHEMA_URI_PRINT, false);
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
writer.writeFile(root, outputFile);
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath());
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
assertTrue(text.contains("privateIntegerTypeField=\"123\""));
assertTrue(text.contains("privateDoubleObjectField=\"123.45\""));
assertTrue(text.contains("privateStringObjectField=\"x4o\""));
}
public void testWriterSwiXmlOutput() throws Exception { public void testWriterSwiXmlOutput() throws Exception {
Accelerator3 ac3 = new Accelerator3(false); Accelerator3 ac3 = new Accelerator3(false);
SwingEngine engine = new SwingEngine(ac3); SwingEngine engine = new SwingEngine(ac3);
@ -86,7 +62,7 @@ public class X4OWriterTest extends TestCase {
File outputFile = createOutputFile(); File outputFile = createOutputFile();
X4ODriver<Component> driver = SwiXmlDriver.getInstance(); X4ODriver<Component> driver = SwiXmlDriver.getInstance();
X4OReader<Component> reader = driver.createReader(); X4OReader<Component> reader = driver.createReader();
X4OWriter<Component> writer = driver.createWriter(); X4OWriter<Component> writer = driver.createWriter(SwiXmlDriver.LANGUAGE_VERSION_3);
//reader.setProperty(key, value); //reader.setProperty(key, value);
//writer.setProperty(key, value); //writer.setProperty(key, value);
@ -102,4 +78,62 @@ public class X4OWriterTest extends TestCase {
outputFile.delete(); outputFile.delete();
} }
public void testWriteFile() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
X4OWriter<TestObjectRoot> writer = driver.createWriter();
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
writer.writeFile(root, outputFile);
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
}
public void testWriteFileName() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
X4OWriter<TestObjectRoot> writer = driver.createWriter();
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
writer.writeFile(root, outputFile.getAbsolutePath());
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
}
public void testWriteStream() throws Exception {
File outputFile = createOutputFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
X4OWriter<TestObjectRoot> writer = driver.createWriter();
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
OutputStream outputStream = new FileOutputStream(outputFile);
try {
writer.write(root,outputStream);
} finally {
outputStream.close();
}
writer.writeFile(root, outputFile.getAbsolutePath());
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete();
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
assertTrue(text.contains("<test-lang:parent name=\"test-bean.xml\"/>"));
assertTrue(text.contains("<test-lang:testBean"));
}
} }

View file

@ -125,7 +125,19 @@
</eld:element> </eld:element>
<eld:element tag="parent" objectClass="org.x4o.xml.test.models.TestObjectParent"/> <eld:element tag="parent" objectClass="org.x4o.xml.test.models.TestObjectParent"/>
<eld:element tag="child" objectClass="org.x4o.xml.test.models.TestObjectChild"/> <eld:element tag="child" objectClass="org.x4o.xml.test.models.TestObjectChild">
<eld:attributeFromBody name="name" id="child-name"/>
</eld:element>
<!--
<eld:element tag="childName">
<eld:attributeFromBody name="name" id="child-name" useParent="true"/>
<eld:elementParent tag="child"/>
</eld:element>
<eld:element tag="childSize">
<eld:attributeFromBody name="size" id="child-size" useParent="true"/>
<eld:elementParent tag="child"/>
</eld:element>
-->
<eld:element tag="testObjectParent" objectClass="org.x4o.xml.test.models.TestObjectParent"/> <eld:element tag="testObjectParent" objectClass="org.x4o.xml.test.models.TestObjectParent"/>
<eld:element tag="testObjectChild" objectClass="org.x4o.xml.test.models.TestObjectChild"/> <eld:element tag="testObjectChild" objectClass="org.x4o.xml.test.models.TestObjectChild"/>

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<root:root
xmlns:root="http://test.x4o.org/xml/ns/test-root"
xmlns="http://test.x4o.org/xml/ns/test-lang"
>
<child name="attr-name"/>
<child>body-name</child>
</root:root>

View file

@ -24,6 +24,7 @@
package org.x4o.xml.eld.doc; package org.x4o.xml.eld.doc;
import java.io.File; import java.io.File;
import java.io.IOException;
import org.x4o.xml.element.ElementAttributeHandler; import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementBindingHandler;
@ -45,10 +46,19 @@ public class EldDocGenerator {
private X4OLanguageContext context = null; private X4OLanguageContext context = null;
/**
* Creates an EldDocGenerator for this langauge context.
* @param context The language context to generate doc for.
*/
public EldDocGenerator(X4OLanguageContext context) { public EldDocGenerator(X4OLanguageContext context) {
this.context=context; this.context=context;
} }
/**
* Writes the language documentation to the base path.
* @param basePath The path to write to documentation to.
* @throws ElementException Is thrown when error is done.
*/
public void writeDoc(File basePath) throws ElementException { public void writeDoc(File basePath) throws ElementException {
EldDocHtmlWriter writer = new EldDocHtmlWriter(); EldDocHtmlWriter writer = new EldDocHtmlWriter();
try { try {
@ -97,8 +107,8 @@ public class EldDocGenerator {
} }
} }
} catch (Exception e) { } catch (IOException e) {
throw new ElementException(e); // todo rm throw new ElementException(e);
} }
} }
} }

View file

@ -45,7 +45,11 @@ public class X4OWriteLanguageDocExecutor {
private String languageVersion = null; private String languageVersion = null;
private File basePath; private File basePath;
static public void main(String argu[]) { /**
* Config and executes this language task.
* @param argu The command line arguments.
*/
public static void main(String[] argu) {
X4OWriteLanguageDocExecutor languageSchema = new X4OWriteLanguageDocExecutor(); X4OWriteLanguageDocExecutor languageSchema = new X4OWriteLanguageDocExecutor();
List<String> arguList = Arrays.asList(argu); List<String> arguList = Arrays.asList(argu);
Iterator<String> arguIterator = arguList.iterator(); Iterator<String> arguIterator = arguList.iterator();
@ -87,6 +91,9 @@ public class X4OWriteLanguageDocExecutor {
} }
} }
/**
* Executes this language task.
*/
public void execute() throws ElementException { public void execute() throws ElementException {
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName()); X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName());
X4OLanguageContext context = driver.createLanguageContext(getLanguageVersion()); X4OLanguageContext context = driver.createLanguageContext(getLanguageVersion());

View file

@ -25,6 +25,7 @@ package org.x4o.plugin.maven;
import java.io.File; import java.io.File;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.AbstractMojoTestCase;
/** /**
@ -54,6 +55,16 @@ public class X4OWriteLanguageDocMojoTest extends AbstractMojoTestCase {
mojo.execute(); mojo.execute();
} }
public void testHelp() throws Exception {
File pom = getTestFile("src/test/resources/junit/test-plugin-defaults.pom");
assertNotNull(pom);
assertTrue(pom.exists());
Mojo mojo = lookupMojo("help",pom);
assertNotNull(mojo);
mojo.execute();
}
public void testConfAllWriteDoc() throws Exception { public void testConfAllWriteDoc() throws Exception {
executeGoal(X4OWriteLanguageDocMojo.GOAL,"src/test/resources/junit/test-plugin-conf-all.pom"); executeGoal(X4OWriteLanguageDocMojo.GOAL,"src/test/resources/junit/test-plugin-conf-all.pom");
File outputDir = new File("target/jtest/test-plugin-conf-all/doc-eld-1.0"); File outputDir = new File("target/jtest/test-plugin-conf-all/doc-eld-1.0");