X4O Formatted x4o driver tests cases
This commit is contained in:
parent
bd4a04a813
commit
ed096a1427
74 changed files with 1640 additions and 1453 deletions
|
|
@ -29,16 +29,16 @@ package org.x4o.xml.lang;
|
|||
* @version 1.0 Apr 28, 2013
|
||||
*/
|
||||
public abstract class AbstractX4OLanguageConfiguration implements X4OLanguageConfigurationLocal {
|
||||
|
||||
|
||||
private String languageResourcePathPrefix = null;
|
||||
private String languageResourceModulesFileName = null;
|
||||
|
||||
|
||||
private Class<?> defaultElementNamespace = null;
|
||||
private Class<?> defaultElementInterface = null;
|
||||
private Class<?> defaultElement = null;
|
||||
private Class<?> defaultElementClass = null;
|
||||
private Class<?> defaultElementClassAttribute = null;
|
||||
|
||||
|
||||
private Class<?> defaultElementLanguageModule = null;
|
||||
private Class<?> defaultElementBodyComment = null;
|
||||
private Class<?> defaultElementBodyCharacters = null;
|
||||
|
|
@ -47,262 +47,262 @@ public abstract class AbstractX4OLanguageConfiguration implements X4OLanguageCon
|
|||
private Class<?> defaultElementAttributeValueParser = null;
|
||||
private Class<?> defaultElementObjectPropertyValue = null;
|
||||
private Class<?> defaultElementNamespaceAttributeComparator = null;
|
||||
|
||||
|
||||
private Class<?> defaultLanguageVersionFilter = null;
|
||||
private Class<?> defaultLanguageLoader = null;
|
||||
private Class<?> defaultExpressionLanguageContext = null;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public AbstractX4OLanguageConfiguration() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the languageResourcePathPrefix
|
||||
*/
|
||||
public String getLanguageResourcePathPrefix() {
|
||||
return languageResourcePathPrefix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param languageResourcePathPrefix the languageResourcePathPrefix to set
|
||||
*/
|
||||
public void setLanguageResourcePathPrefix(String languageResourcePathPrefix) {
|
||||
this.languageResourcePathPrefix = languageResourcePathPrefix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the languageResourceModulesFileName
|
||||
*/
|
||||
public String getLanguageResourceModulesFileName() {
|
||||
return languageResourceModulesFileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param languageResourceModulesFileName the languageResourceModulesFileName to set
|
||||
*/
|
||||
public void setLanguageResourceModulesFileName(String languageResourceModulesFileName) {
|
||||
this.languageResourceModulesFileName = languageResourceModulesFileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementNamespace
|
||||
*/
|
||||
public Class<?> getDefaultElementNamespace() {
|
||||
return defaultElementNamespace;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementNamespace the defaultElementNamespace to set
|
||||
*/
|
||||
public void setDefaultElementNamespace(Class<?> defaultElementNamespace) {
|
||||
this.defaultElementNamespace = defaultElementNamespace;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementInterface
|
||||
*/
|
||||
public Class<?> getDefaultElementInterface() {
|
||||
return defaultElementInterface;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementInterface the defaultElementInterface to set
|
||||
*/
|
||||
public void setDefaultElementInterface(Class<?> defaultElementInterface) {
|
||||
this.defaultElementInterface = defaultElementInterface;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElement
|
||||
*/
|
||||
public Class<?> getDefaultElement() {
|
||||
return defaultElement;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElement the defaultElement to set
|
||||
*/
|
||||
public void setDefaultElement(Class<?> defaultElement) {
|
||||
this.defaultElement = defaultElement;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementClass
|
||||
*/
|
||||
public Class<?> getDefaultElementClass() {
|
||||
return defaultElementClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementClass the defaultElementClass to set
|
||||
*/
|
||||
public void setDefaultElementClass(Class<?> defaultElementClass) {
|
||||
this.defaultElementClass = defaultElementClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementClassAttribute
|
||||
*/
|
||||
public Class<?> getDefaultElementClassAttribute() {
|
||||
return defaultElementClassAttribute;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementClassAttribute the defaultElementClassAttribute to set
|
||||
*/
|
||||
public void setDefaultElementClassAttribute(Class<?> defaultElementClassAttribute) {
|
||||
this.defaultElementClassAttribute = defaultElementClassAttribute;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementLanguageModule
|
||||
*/
|
||||
public Class<?> getDefaultElementLanguageModule() {
|
||||
return defaultElementLanguageModule;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementLanguageModule the defaultElementLanguageModule to set
|
||||
*/
|
||||
public void setDefaultElementLanguageModule(Class<?> defaultElementLanguageModule) {
|
||||
this.defaultElementLanguageModule = defaultElementLanguageModule;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementBodyComment
|
||||
*/
|
||||
public Class<?> getDefaultElementBodyComment() {
|
||||
return defaultElementBodyComment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementBodyComment the defaultElementBodyComment to set
|
||||
*/
|
||||
public void setDefaultElementBodyComment(Class<?> defaultElementBodyComment) {
|
||||
this.defaultElementBodyComment = defaultElementBodyComment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementBodyCharacters
|
||||
*/
|
||||
public Class<?> getDefaultElementBodyCharacters() {
|
||||
return defaultElementBodyCharacters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementBodyCharacters the defaultElementBodyCharacters to set
|
||||
*/
|
||||
public void setDefaultElementBodyCharacters(Class<?> defaultElementBodyCharacters) {
|
||||
this.defaultElementBodyCharacters = defaultElementBodyCharacters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementBodyWhitespace
|
||||
*/
|
||||
public Class<?> getDefaultElementBodyWhitespace() {
|
||||
return defaultElementBodyWhitespace;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementBodyWhitespace the defaultElementBodyWhitespace to set
|
||||
*/
|
||||
public void setDefaultElementBodyWhitespace(Class<?> defaultElementBodyWhitespace) {
|
||||
this.defaultElementBodyWhitespace = defaultElementBodyWhitespace;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementNamespaceInstanceProvider
|
||||
*/
|
||||
public Class<?> getDefaultElementNamespaceInstanceProvider() {
|
||||
return defaultElementNamespaceInstanceProvider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementNamespaceInstanceProvider the defaultElementNamespaceInstanceProvider to set
|
||||
*/
|
||||
public void setDefaultElementNamespaceInstanceProvider(Class<?> defaultElementNamespaceInstanceProvider) {
|
||||
this.defaultElementNamespaceInstanceProvider = defaultElementNamespaceInstanceProvider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementAttributeValueParser
|
||||
*/
|
||||
public Class<?> getDefaultElementAttributeValueParser() {
|
||||
return defaultElementAttributeValueParser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementAttributeValueParser the defaultElementAttributeValueParser to set
|
||||
*/
|
||||
public void setDefaultElementAttributeValueParser(Class<?> defaultElementAttributeValueParser) {
|
||||
this.defaultElementAttributeValueParser = defaultElementAttributeValueParser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementObjectPropertyValue
|
||||
*/
|
||||
public Class<?> getDefaultElementObjectPropertyValue() {
|
||||
return defaultElementObjectPropertyValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementObjectPropertyValue the defaultElementObjectPropertyValue to set
|
||||
*/
|
||||
public void setDefaultElementObjectPropertyValue(Class<?> defaultElementObjectPropertyValue) {
|
||||
this.defaultElementObjectPropertyValue = defaultElementObjectPropertyValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultElementNamespaceAttributeComparator
|
||||
*/
|
||||
public Class<?> getDefaultElementNamespaceAttributeComparator() {
|
||||
return defaultElementNamespaceAttributeComparator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultElementNamespaceAttributeComparator the defaultElementNamespaceAttributeComparator to set
|
||||
*/
|
||||
public void setDefaultElementNamespaceAttributeComparator(Class<?> defaultElementNamespaceAttributeComparator) {
|
||||
this.defaultElementNamespaceAttributeComparator = defaultElementNamespaceAttributeComparator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultLanguageVersionFilter
|
||||
*/
|
||||
public Class<?> getDefaultLanguageVersionFilter() {
|
||||
return defaultLanguageVersionFilter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultLanguageVersionFilter the defaultLanguageVersionFilter to set
|
||||
*/
|
||||
public void setDefaultLanguageVersionFilter(Class<?> defaultLanguageVersionFilter) {
|
||||
this.defaultLanguageVersionFilter = defaultLanguageVersionFilter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultLanguageLoader
|
||||
*/
|
||||
public Class<?> getDefaultLanguageLoader() {
|
||||
return defaultLanguageLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultLanguageLoader the defaultLanguageLoader to set
|
||||
*/
|
||||
public void setDefaultLanguageLoader(Class<?> defaultLanguageLoader) {
|
||||
this.defaultLanguageLoader = defaultLanguageLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the defaultExpressionLanguageContext
|
||||
*/
|
||||
public Class<?> getDefaultExpressionLanguageContext() {
|
||||
return defaultExpressionLanguageContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param defaultExpressionLanguageContext the defaultExpressionLanguageContext to set
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -43,14 +43,14 @@ import org.x4o.xml.element.ElementNamespace;
|
|||
public abstract class AbstractX4OLanguageModule extends AbstractElementMetaBase implements X4OLanguageModuleLocal {
|
||||
|
||||
private Logger logger = null;
|
||||
private String providerName=null;
|
||||
private String providerHost=null;
|
||||
|
||||
private String providerName = null;
|
||||
private String providerHost = null;
|
||||
|
||||
private List<ElementBindingHandler> elementBindingHandlers = null;
|
||||
private List<ElementConfiguratorGlobal> elementConfiguratorGlobals = null;
|
||||
private List<ElementInterface> elementInterfaces = null;
|
||||
private Map<String,ElementNamespace> elementNamespaces = null;
|
||||
private Map<X4OLanguageModuleLoaderResult,String> loaderResults = null;
|
||||
private Map<String, ElementNamespace> elementNamespaces = null;
|
||||
private Map<X4OLanguageModuleLoaderResult, String> loaderResults = null;
|
||||
|
||||
/**
|
||||
* Creates a new empty ElementLanguage.
|
||||
|
|
@ -61,31 +61,31 @@ public abstract class AbstractX4OLanguageModule extends AbstractElementMetaBase
|
|||
elementBindingHandlers = new ArrayList<ElementBindingHandler>(4);
|
||||
elementConfiguratorGlobals = new ArrayList<ElementConfiguratorGlobal>(4);
|
||||
elementInterfaces = new ArrayList<ElementInterface>(20);
|
||||
elementNamespaces = new HashMap<String,ElementNamespace>(10);
|
||||
loaderResults = new HashMap<X4OLanguageModuleLoaderResult,String>(10);
|
||||
elementNamespaces = new HashMap<String, ElementNamespace>(10);
|
||||
loaderResults = new HashMap<X4OLanguageModuleLoaderResult, String>(10);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the providerName
|
||||
*/
|
||||
public String getProviderName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param providerName the providerName to set
|
||||
*/
|
||||
public void setProviderName(String providerName) {
|
||||
this.providerName = providerName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the providerHost
|
||||
*/
|
||||
public String getProviderHost() {
|
||||
return providerHost;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param providerHost the providerHost to set
|
||||
*/
|
||||
|
|
@ -97,109 +97,107 @@ public abstract class AbstractX4OLanguageModule extends AbstractElementMetaBase
|
|||
* @see org.x4o.xml.lang.X4OLanguageModuleLocal#addElementBindingHandler(ElementBindingHandler)
|
||||
*/
|
||||
public void addElementBindingHandler(ElementBindingHandler elementBindingHandler) {
|
||||
if (elementBindingHandler==null) {
|
||||
if (elementBindingHandler == null) {
|
||||
throw new NullPointerException("Can't add null binding handler.");
|
||||
}
|
||||
if (elementBindingHandler.getId()==null) {
|
||||
if (elementBindingHandler.getId() == null) {
|
||||
throw new NullPointerException("Can't add with null id property.");
|
||||
}
|
||||
// Check so doc tree does not loop; see EldDocHtmlWriter.findChilderen()
|
||||
/*
|
||||
for (Class<?> cl:elementBindingHandler.getBindChildClasses()) {
|
||||
if (elementBindingHandler.getBindParentClass().equals(cl)) {
|
||||
throw new IllegalStateException("Can't add binding handler: "+elementBindingHandler.getId()+" with same parent as child class.");
|
||||
}
|
||||
}*/
|
||||
logger.finer("Adding ElementBindingHandler: "+elementBindingHandler);
|
||||
* for (Class<?> cl:elementBindingHandler.getBindChildClasses()) { if (elementBindingHandler.getBindParentClass().equals(cl)) { throw new
|
||||
* IllegalStateException("Can't add binding handler: "+elementBindingHandler.getId()+" with same parent as child class."); } }
|
||||
*/
|
||||
logger.finer("Adding ElementBindingHandler: " + elementBindingHandler);
|
||||
elementBindingHandlers.add(elementBindingHandler);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModule#getElementBindingHandlers()
|
||||
*/
|
||||
public List<ElementBindingHandler> getElementBindingHandlers() {
|
||||
return elementBindingHandlers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLocal#addElementConfiguratorGlobal(ElementConfiguratorGlobal)
|
||||
*/
|
||||
public void addElementConfiguratorGlobal(ElementConfiguratorGlobal elementConfigurator) {
|
||||
if (elementConfigurator==null) {
|
||||
if (elementConfigurator == null) {
|
||||
throw new NullPointerException("Can't add null");
|
||||
}
|
||||
if (elementConfigurator.getId()==null) {
|
||||
if (elementConfigurator.getId() == null) {
|
||||
throw new NullPointerException("Can't add with null id property.");
|
||||
}
|
||||
logger.finer("Adding ElementConfiguratorGlobal: "+elementConfigurator);
|
||||
logger.finer("Adding ElementConfiguratorGlobal: " + elementConfigurator);
|
||||
elementConfiguratorGlobals.add(elementConfigurator);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModule#getElementConfiguratorGlobals()
|
||||
*/
|
||||
public List<ElementConfiguratorGlobal> getElementConfiguratorGlobals() {
|
||||
return elementConfiguratorGlobals;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLocal#addElementInterface(org.x4o.xml.element.ElementInterface)
|
||||
*/
|
||||
public void addElementInterface(ElementInterface elementInterface) {
|
||||
if (elementInterface==null) {
|
||||
if (elementInterface == null) {
|
||||
throw new NullPointerException("Can't add null.");
|
||||
}
|
||||
if (elementInterface.getId()==null) {
|
||||
if (elementInterface.getId() == null) {
|
||||
throw new NullPointerException("Can't add with null id property.");
|
||||
}
|
||||
if (elementInterface.getInterfaceClass()==null) {
|
||||
if (elementInterface.getInterfaceClass() == null) {
|
||||
throw new NullPointerException("ElementInterface not correctly configured getInterfaceClass returns null.");
|
||||
}
|
||||
elementInterfaces.add(elementInterface);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModule#getElementInterfaces()
|
||||
*/
|
||||
public List<ElementInterface> getElementInterfaces() {
|
||||
return elementInterfaces;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLocal#addElementNamespace(org.x4o.xml.element.ElementNamespace)
|
||||
*/
|
||||
public void addElementNamespace(ElementNamespace elementNamespace) {
|
||||
if (elementNamespace==null) {
|
||||
if (elementNamespace == null) {
|
||||
throw new NullPointerException("Can't add null.");
|
||||
}
|
||||
if (elementNamespace.getUri()==null) {
|
||||
if (elementNamespace.getUri() == null) {
|
||||
throw new NullPointerException("Can add ElementNamespace without uri.");
|
||||
}
|
||||
logger.fine("Adding namespaceUri: "+elementNamespace.getUri());
|
||||
logger.fine("Adding namespaceUri: " + elementNamespace.getUri());
|
||||
elementNamespaces.put(elementNamespace.getUri(), elementNamespace);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModule#getElementNamespace(java.lang.String)
|
||||
*/
|
||||
public ElementNamespace getElementNamespace(String namespaceUri) {
|
||||
return elementNamespaces.get(namespaceUri);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModule#getElementNamespaces()
|
||||
*/
|
||||
public List<ElementNamespace> getElementNamespaces() {
|
||||
return new ArrayList<ElementNamespace>(elementNamespaces.values());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModule#getLoaderResult(org.x4o.xml.lang.X4OLanguageModuleLoaderResult)
|
||||
*/
|
||||
public String getLoaderResult(X4OLanguageModuleLoaderResult key) {
|
||||
return loaderResults.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageModuleLocal#putLoaderResult(org.x4o.xml.lang.X4OLanguageModuleLoaderResult, java.lang.String)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public abstract class AbstractX4OLanguageSession implements X4OLanguageSessionLo
|
|||
private String phaseStop = null;
|
||||
private List<String> phaseSkip = null;
|
||||
private Map<String, List<X4OPhaseListener>> phaseListeners = null;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new empty language context.
|
||||
*/
|
||||
|
|
@ -69,84 +69,84 @@ public abstract class AbstractX4OLanguageSession implements X4OLanguageSessionLo
|
|||
}
|
||||
logger = Logger.getLogger(AbstractX4OLanguageSession.class.getName());
|
||||
logger.finest("Creating new ParsingContext");
|
||||
this.language=language;
|
||||
this.language = language;
|
||||
dirtyElements = new ArrayList<>(20);
|
||||
phaseSkip = new ArrayList<>(5);
|
||||
phaseListeners = new HashMap<>(3);
|
||||
}
|
||||
|
||||
|
||||
public X4OLanguage getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getExpressionLanguageContext()
|
||||
*/
|
||||
public ELContext getExpressionLanguageContext() {
|
||||
return eLContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSessionLocal#setExpressionLanguageContext(javax.el.ELContext)
|
||||
*/
|
||||
public void setExpressionLanguageContext(ELContext context) {
|
||||
if (eLContext!=null) {
|
||||
if (eLContext != null) {
|
||||
throw new IllegalStateException("Can only set elContext once.");
|
||||
}
|
||||
eLContext = context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getExpressionLanguageFactory()
|
||||
*/
|
||||
public ExpressionFactory getExpressionLanguageFactory() {
|
||||
return expressionFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSessionLocal#setExpressionLanguageFactory(javax.el.ExpressionFactory)
|
||||
*/
|
||||
public void setExpressionLanguageFactory(ExpressionFactory expressionFactory) {
|
||||
if (this.expressionFactory!=null) {
|
||||
if (this.expressionFactory != null) {
|
||||
throw new IllegalStateException("Can only set expressionFactory once.");
|
||||
}
|
||||
this.expressionFactory = expressionFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the elementAttributeValueParser
|
||||
*/
|
||||
public ElementAttributeValueParser getElementAttributeValueParser() {
|
||||
return elementAttributeValueParser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param elementAttributeValueParser the elementAttributeValueParser to set
|
||||
*/
|
||||
public void setElementAttributeValueParser(ElementAttributeValueParser elementAttributeValueParser) {
|
||||
if (this.elementAttributeValueParser!=null) {
|
||||
if (this.elementAttributeValueParser != null) {
|
||||
throw new IllegalStateException("Can only set elementAttributeValueParser once.");
|
||||
}
|
||||
this.elementAttributeValueParser = elementAttributeValueParser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the elementObjectPropertyValue
|
||||
*/
|
||||
public ElementObjectPropertyValue getElementObjectPropertyValue() {
|
||||
return elementObjectPropertyValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param elementObjectPropertyValue the elementObjectPropertyValue to set
|
||||
*/
|
||||
public void setElementObjectPropertyValue(ElementObjectPropertyValue elementObjectPropertyValue) {
|
||||
if (this.elementObjectPropertyValue!=null) {
|
||||
if (this.elementObjectPropertyValue != null) {
|
||||
throw new IllegalStateException("Can only set elementObjectPropertyValue once.");
|
||||
}
|
||||
this.elementObjectPropertyValue = elementObjectPropertyValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#addDirtyElement(org.x4o.xml.element.Element)
|
||||
*/
|
||||
|
|
@ -156,98 +156,99 @@ public abstract class AbstractX4OLanguageSession implements X4OLanguageSessionLo
|
|||
}
|
||||
dirtyElements.add(element);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getDirtyElements()
|
||||
*/
|
||||
public List<Element> getDirtyElements() {
|
||||
return dirtyElements;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getRootElement()
|
||||
*/
|
||||
public Element getRootElement() {
|
||||
return rootElement;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#setRootElement(org.x4o.xml.element.Element)
|
||||
*/
|
||||
public void setRootElement(Element element) {
|
||||
if (element==null) {
|
||||
if (element == null) {
|
||||
throw new NullPointerException("May not set rootElement to null");
|
||||
}
|
||||
rootElement=element;
|
||||
rootElement = element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getX4ODebugWriter()
|
||||
*/
|
||||
public X4ODebugWriter getX4ODebugWriter() {
|
||||
return debugWriter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#hasX4ODebugWriter()
|
||||
*/
|
||||
public boolean hasX4ODebugWriter() {
|
||||
return debugWriter!=null;
|
||||
return debugWriter != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSessionLocal#setX4ODebugWriter(org.x4o.xml.io.X4ODebugWriter)
|
||||
*/
|
||||
public void setX4ODebugWriter(X4ODebugWriter debugWriter) {
|
||||
this.debugWriter=debugWriter;
|
||||
this.debugWriter = debugWriter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getPhaseCurrent()
|
||||
*/
|
||||
public X4OPhase getPhaseCurrent() {
|
||||
return phaseCurrent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSessionLocal#setPhaseCurrent(org.x4o.xml.lang.phase.X4OPhase)
|
||||
*/
|
||||
public void setPhaseCurrent(X4OPhase phaseCurrent) {
|
||||
this.phaseCurrent = phaseCurrent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getPhaseStop()
|
||||
*/
|
||||
public String getPhaseStop() {
|
||||
return phaseStop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSession#getPhaseSkip()
|
||||
*/
|
||||
public List<String> getPhaseSkip() {
|
||||
return phaseSkip;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSessionLocal#setPhaseStop(java.lang.String)
|
||||
*/
|
||||
public void setPhaseStop(String phaseId) {
|
||||
this.phaseStop=phaseId;
|
||||
this.phaseStop = phaseId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageSessionLocal#addPhaseSkip(java.lang.String)
|
||||
*/
|
||||
public void addPhaseSkip(String phaseId) {
|
||||
phaseSkip.add(phaseId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the phase listeners for a phase.
|
||||
*
|
||||
* @param phaseId The phaseId of for the listeners.
|
||||
* @return The x4o phase listeners.
|
||||
* @return The x4o phase listeners.
|
||||
*/
|
||||
public List<X4OPhaseListener> storePhaseListeners(String phaseId) {
|
||||
List<X4OPhaseListener> result = phaseListeners.get(phaseId);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
|
|||
inited = true;
|
||||
getPhaseManager().runPhases(session, X4OPhaseType.INIT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguage#getLanguageName()
|
||||
*/
|
||||
|
|
@ -151,13 +151,16 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
|
|||
languageSession.setExpressionLanguageFactory(X4OExpressionFactory.createExpressionFactory());
|
||||
}
|
||||
if (languageSession.getExpressionLanguageContext() == null) {
|
||||
languageSession.setExpressionLanguageContext(X4OExpressionFactory.createELContext(languageSession.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext()));
|
||||
languageSession.setExpressionLanguageContext(
|
||||
X4OExpressionFactory.createELContext(languageSession.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext()));
|
||||
}
|
||||
if (languageSession.getElementAttributeValueParser() == null) {
|
||||
languageSession.setElementAttributeValueParser(X4OLanguageClassLoader.newInstance(ElementAttributeValueParser.class, getLanguageConfiguration().getDefaultElementAttributeValueParser()));
|
||||
languageSession.setElementAttributeValueParser(X4OLanguageClassLoader.newInstance(ElementAttributeValueParser.class,
|
||||
getLanguageConfiguration().getDefaultElementAttributeValueParser()));
|
||||
}
|
||||
if (languageSession.getElementObjectPropertyValue() == null) {
|
||||
languageSession.setElementObjectPropertyValue(X4OLanguageClassLoader.newInstance(ElementObjectPropertyValue.class, getLanguageConfiguration().getDefaultElementObjectPropertyValue()));
|
||||
languageSession.setElementObjectPropertyValue(X4OLanguageClassLoader.newInstance(ElementObjectPropertyValue.class,
|
||||
getLanguageConfiguration().getDefaultElementObjectPropertyValue()));
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
|
|
|
|||
|
|
@ -47,13 +47,14 @@ import org.x4o.xml.element.DefaultElementNamespaceAttributeComparator;
|
|||
* @version 1.0 27 Oct 2009
|
||||
*/
|
||||
public class DefaultX4OLanguageConfiguration extends AbstractX4OLanguageConfiguration {
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public DefaultX4OLanguageConfiguration() {
|
||||
}
|
||||
|
||||
|
||||
//@formatter:off
|
||||
public void fillDefaults() {
|
||||
if (getLanguageResourcePathPrefix()==null) { setLanguageResourcePathPrefix( X4OLanguageConfiguration.DEFAULT_LANG_PATH_PREFIX); }
|
||||
if (getLanguageResourceModulesFileName()==null) { setLanguageResourceModulesFileName( X4OLanguageConfiguration.DEFAULT_LANG_MODULES_FILE);}
|
||||
|
|
@ -74,28 +75,29 @@ public class DefaultX4OLanguageConfiguration extends AbstractX4OLanguageConfigur
|
|||
if (getDefaultLanguageLoader()==null) { setDefaultLanguageLoader( DefaultX4OLanguageLoader.class); }
|
||||
if (getDefaultExpressionLanguageContext()==null) { setDefaultExpressionLanguageContext( X4OELContext.class); }
|
||||
}
|
||||
|
||||
//@formatter:on
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.X4OLanguageConfigurationLocal#createProxy()
|
||||
*/
|
||||
public X4OLanguageConfiguration createProxy() {
|
||||
Object proxy = Proxy.newProxyInstance(X4OLanguageClassLoader.getClassLoader(), new Class[]{X4OLanguageConfiguration.class}, new InvocationHandler() {
|
||||
Object proxy = Proxy.newProxyInstance(X4OLanguageClassLoader.getClassLoader(), new Class[] { X4OLanguageConfiguration.class }, new InvocationHandler() {
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
X4OLanguageConfigurationLocal local = DefaultX4OLanguageConfiguration.this;
|
||||
int argsLength = 0;
|
||||
if (args!=null) {
|
||||
if (args != null) {
|
||||
argsLength = args.length;
|
||||
}
|
||||
Class<?>[] invokeArgs = new Class[argsLength];
|
||||
for (int i=0;i<argsLength;i++) {
|
||||
//Object o = args[i];
|
||||
invokeArgs[i] = X4OLanguageSession.class; //o.getClass(); todo fix
|
||||
for (int i = 0; i < argsLength; i++) {
|
||||
// Object o = args[i];
|
||||
invokeArgs[i] = X4OLanguageSession.class; // o.getClass(); todo fix
|
||||
}
|
||||
Method localMethod = local.getClass().getMethod(method.getName(), invokeArgs);
|
||||
Object result = localMethod.invoke(local, args);
|
||||
return result; // result is reflection safe interface hiding.
|
||||
}
|
||||
});
|
||||
return (X4OLanguageConfiguration)proxy;
|
||||
return (X4OLanguageConfiguration) proxy;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,18 +55,19 @@ import org.xml.sax.ext.DefaultHandler2;
|
|||
public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
||||
|
||||
private Logger logger = null;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the DefaultX4OLanguageLoader.
|
||||
*/
|
||||
public DefaultX4OLanguageLoader() {
|
||||
logger = Logger.getLogger(DefaultX4OLanguageLoader.class.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write log message to debug writer.
|
||||
* @param language The X4O language we are loading.
|
||||
* @param message The message to log to the debug output.
|
||||
*
|
||||
* @param language The X4O language we are loading.
|
||||
* @param message The message to log to the debug output.
|
||||
*/
|
||||
private void logMessage(X4OLanguageSession session, String message) {
|
||||
logger.finest(message + " from: " + session.getLanguage().getLanguageName());
|
||||
|
|
@ -78,14 +79,15 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadLanguage(X4OLanguageSession session, X4OLanguageLocal languageLocal, String language, String languageVersion) throws X4OLanguageLoaderException {
|
||||
public void loadLanguage(X4OLanguageSession session, X4OLanguageLocal languageLocal, String language, String languageVersion)
|
||||
throws X4OLanguageLoaderException {
|
||||
logger.finer("Loading all modules for language: " + language);
|
||||
List<VersionedResources> modulesAll = loadLanguageModules(session, languageLocal, language);
|
||||
modulesAll = filterVersionModules(modulesAll, languageLocal, languageVersion);
|
||||
validateModules(modulesAll);
|
||||
|
||||
|
||||
int loaded = 0;
|
||||
for (VersionedResources versionedResources : modulesAll) {
|
||||
X4OLanguageModuleLoader loader;
|
||||
|
|
@ -93,31 +95,32 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
String languagePrefix = languageLocal.getLanguageConfiguration().getLanguageResourcePathPrefix();
|
||||
String resource = languagePrefix + "/" + language + "/" + value;
|
||||
if (language.equals(EldDriver.LANGUAGE_NAME)) {
|
||||
loader = new EldModuleLoader(resource,true); // load cel
|
||||
loader = new EldModuleLoader(resource, true); // load cel
|
||||
} else {
|
||||
loader = new EldModuleLoader(resource,false); // load eld
|
||||
loader = new EldModuleLoader(resource, false); // load eld
|
||||
}
|
||||
loadModule(session, languageLocal, loader, value, versionedResources);
|
||||
}
|
||||
for (String value : versionedResources.moduleLoaders) {
|
||||
try {
|
||||
loader = (X4OLanguageModuleLoader)X4OLanguageClassLoader.newInstance(value);
|
||||
loader = (X4OLanguageModuleLoader) X4OLanguageClassLoader.newInstance(value);
|
||||
} catch (Exception ee) {
|
||||
throw new X4OLanguageLoaderException("Could not load class: " + value + " error: " + ee.getMessage(),ee);
|
||||
throw new X4OLanguageLoaderException("Could not load class: " + value + " error: " + ee.getMessage(), ee);
|
||||
}
|
||||
loadModule(session, languageLocal, loader, value, versionedResources);
|
||||
}
|
||||
for (String value : versionedResources.siblingLoaders) {
|
||||
try {
|
||||
loader = (X4OLanguageModuleLoader)X4OLanguageClassLoader.newInstance(value);
|
||||
loader = (X4OLanguageModuleLoader) X4OLanguageClassLoader.newInstance(value);
|
||||
} catch (Exception ee) {
|
||||
throw new X4OLanguageLoaderException("Could not load class: " + value + " error: " + ee.getMessage(),ee);
|
||||
throw new X4OLanguageLoaderException("Could not load class: " + value + " error: " + ee.getMessage(), ee);
|
||||
}
|
||||
loadModule(session, languageLocal, loader, value, versionedResources);
|
||||
if (loader instanceof X4OLanguageModuleLoaderSibling) {
|
||||
// mmm
|
||||
X4OPhaseInitLanguageSiblings sibPhase = (X4OPhaseInitLanguageSiblings)languageLocal.getPhaseManager().getPhase(X4OPhaseLanguageInit.INIT_LANG_SIB);
|
||||
sibPhase.addLanguageModuleLoaderSibling((X4OLanguageModuleLoaderSibling)loader);
|
||||
X4OPhaseInitLanguageSiblings sibPhase = (X4OPhaseInitLanguageSiblings) languageLocal.getPhaseManager()
|
||||
.getPhase(X4OPhaseLanguageInit.INIT_LANG_SIB);
|
||||
sibPhase.addLanguageModuleLoaderSibling((X4OLanguageModuleLoaderSibling) loader);
|
||||
}
|
||||
}
|
||||
for (String value : versionedResources.elbResources) {
|
||||
|
|
@ -130,12 +133,14 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
throw new X4OLanguageLoaderException("No modules defined for version: " + languageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
private List<VersionedResources> filterVersionModules(List<VersionedResources> resources, X4OLanguageLocal languageLocal, String languageVersion) throws X4OLanguageLoaderException {
|
||||
|
||||
private List<VersionedResources> filterVersionModules(List<VersionedResources> resources, X4OLanguageLocal languageLocal, String languageVersion)
|
||||
throws X4OLanguageLoaderException {
|
||||
List<VersionedResources> result = new ArrayList<VersionedResources>(resources.size());
|
||||
X4OLanguageVersionFilter lvf;
|
||||
try {
|
||||
lvf = X4OLanguageClassLoader.newInstance(X4OLanguageVersionFilter.class, languageLocal.getLanguageConfiguration().getDefaultLanguageVersionFilter());
|
||||
lvf = X4OLanguageClassLoader.newInstance(X4OLanguageVersionFilter.class,
|
||||
languageLocal.getLanguageConfiguration().getDefaultLanguageVersionFilter());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new X4OLanguageLoaderException(e);
|
||||
}
|
||||
|
|
@ -150,7 +155,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected void validateModules(List<VersionedResources> resources) throws X4OLanguageLoaderException {
|
||||
List<String> eldResources = new ArrayList<String>(5);
|
||||
List<String> moduleLoaders = new ArrayList<String>(5);
|
||||
|
|
@ -163,7 +168,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
validateModuleList(siblingLoaders, vr.siblingLoaders, "sibling-loader");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void validateModuleList(List<String> data, List<String> values, String xmlTag) throws X4OLanguageLoaderException {
|
||||
for (String value : values) {
|
||||
if (data.contains(value)) {
|
||||
|
|
@ -172,21 +177,23 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
data.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadModule(X4OLanguageSession session, X4OLanguageLocal languageLocal, X4OLanguageModuleLoader loader, String resource, VersionedResources versionedResources) throws X4OLanguageLoaderException {
|
||||
|
||||
private void loadModule(X4OLanguageSession session, X4OLanguageLocal languageLocal, X4OLanguageModuleLoader loader, String resource,
|
||||
VersionedResources versionedResources) throws X4OLanguageLoaderException {
|
||||
X4OLanguageModuleLocal module;
|
||||
try {
|
||||
module = X4OLanguageClassLoader.newInstance(X4OLanguageModuleLocal.class, languageLocal.getLanguageConfiguration().getDefaultElementLanguageModule());
|
||||
module = X4OLanguageClassLoader.newInstance(X4OLanguageModuleLocal.class,
|
||||
languageLocal.getLanguageConfiguration().getDefaultElementLanguageModule());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new X4OLanguageLoaderException(e);
|
||||
}
|
||||
logMessage(session,"Created module: " + module);
|
||||
logMessage(session, "Created module: " + module);
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
logMessage(session,"Starting modules: " + module + " for language: " + languageLocal.getLanguageName());
|
||||
logMessage(session, "Starting modules: " + module + " for language: " + languageLocal.getLanguageName());
|
||||
loader.loadLanguageModule(session, languageLocal, module);
|
||||
} catch (X4OLanguageModuleLoaderException e) {
|
||||
throw new X4OLanguageLoaderException(e); // FIXME info
|
||||
throw new X4OLanguageLoaderException(e); // FIXME info
|
||||
}
|
||||
long totalTime = System.currentTimeMillis() - startTime;
|
||||
module.putLoaderResult(X4OLanguageModuleLoaderResult.LOAD_TIME, "" + totalTime);
|
||||
|
|
@ -197,16 +204,18 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
module.putLoaderResult(X4OLanguageModuleLoaderResult.LOAD_MODULE_RESOURCE, resource);
|
||||
}
|
||||
module.putLoaderResult(X4OLanguageModuleLoaderResult.LOAD_FROM_RESOURCE, versionedResources.loadedFrom);
|
||||
|
||||
|
||||
languageLocal.addLanguageModule(module);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads all modules of an language.
|
||||
* @param languageLocal The ElementLanguage to load for.
|
||||
* @param language The language to load.
|
||||
*
|
||||
* @param languageLocal The ElementLanguage to load for.
|
||||
* @param language The language to load.
|
||||
*/
|
||||
protected List<VersionedResources> loadLanguageModules(X4OLanguageSession session, X4OLanguageLocal languageLocal, String language) throws X4OLanguageLoaderException {
|
||||
protected List<VersionedResources> loadLanguageModules(X4OLanguageSession session, X4OLanguageLocal languageLocal, String language)
|
||||
throws X4OLanguageLoaderException {
|
||||
List<VersionedResources> result = new ArrayList<VersionedResources>(15);
|
||||
StringBuilder buf = new StringBuilder(150);
|
||||
buf.append(languageLocal.getLanguageConfiguration().getLanguageResourcePathPrefix());
|
||||
|
|
@ -215,7 +224,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
buf.append('/');
|
||||
buf.append(language);
|
||||
buf.append(languageLocal.getLanguageConfiguration().getLanguageResourceModulesFileName());
|
||||
|
||||
|
||||
logger.finer("loading X4O language: " + language);
|
||||
try {
|
||||
Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources(buf.toString());
|
||||
|
|
@ -224,27 +233,29 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
logMessage(session, "Loading relative modules: " + u + " for: " + language);
|
||||
result.addAll(loadLanguageModulesXml(u.openStream(), u.toString()));
|
||||
}
|
||||
|
||||
e = Thread.currentThread().getContextClassLoader().getResources("/"+buf.toString());
|
||||
|
||||
e = Thread.currentThread().getContextClassLoader().getResources("/" + buf.toString());
|
||||
while (e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logMessage(session, "Loading root modules: " + u + " for: " + language);
|
||||
result.addAll(loadLanguageModulesXml(u.openStream(), u.toString()));
|
||||
}
|
||||
return result;
|
||||
} catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
} catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
throw new X4OLanguageLoaderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parser xml inputstream to languge modules.
|
||||
* @param in The inputstream to parser.
|
||||
*
|
||||
* @param in The inputstream to parser.
|
||||
* @throws IOException
|
||||
* @throws SAXException
|
||||
* @throws ParserConfigurationException
|
||||
* @throws ParserConfigurationException
|
||||
*/
|
||||
protected List<VersionedResources> loadLanguageModulesXml(InputStream in, String loadedFrom) throws IOException, SAXException, ParserConfigurationException {
|
||||
protected List<VersionedResources> loadLanguageModulesXml(InputStream in, String loadedFrom)
|
||||
throws IOException, SAXException, ParserConfigurationException {
|
||||
if (in == null) {
|
||||
throw new NullPointerException("Can't parse null input stream");
|
||||
}
|
||||
|
|
@ -255,7 +266,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
XMLReader reader = parser.getXMLReader();
|
||||
reader.setContentHandler(xth);
|
||||
reader.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
|
||||
reader.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
|
||||
reader.setProperty("http://xml.org/sax/properties/declaration-handler", xth);
|
||||
try {
|
||||
reader.parse(new InputSource(in));
|
||||
return xth.getResult();
|
||||
|
|
@ -263,26 +274,26 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ModulesTagHandler extends DefaultHandler2 {
|
||||
private StringBuilder buf = new StringBuilder();
|
||||
private String loadedFrom = null;
|
||||
private VersionedResources versionedResources = null;
|
||||
private List<VersionedResources> result = null;
|
||||
|
||||
|
||||
public ModulesTagHandler(String loadedFrom) {
|
||||
this.loadedFrom = loadedFrom;
|
||||
this.result = new ArrayList<VersionedResources>(5);
|
||||
}
|
||||
|
||||
|
||||
public List<VersionedResources> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void startElement(String namespaceUri, String tag, String qName, Attributes attr) throws SAXException {
|
||||
if ("language".equals(tag)) {
|
||||
|
|
@ -293,14 +304,14 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
logger.finest("Version attribute: " + version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endElement(String namespaceUri, String tag,String qName) throws SAXException {
|
||||
|
||||
public void endElement(String namespaceUri, String tag, String qName) throws SAXException {
|
||||
|
||||
// Get and clear text
|
||||
String value = buf.toString();
|
||||
buf = new StringBuilder();
|
||||
|
||||
|
||||
// Skip root and language and non versions
|
||||
if ("modules".equals(tag)) {
|
||||
return;
|
||||
|
|
@ -313,7 +324,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
if (versionedResources == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ("eld-resource".equals(tag)) {
|
||||
versionedResources.eldResources.add(value);
|
||||
} else if ("module-loader".equals(tag)) {
|
||||
|
|
@ -325,7 +336,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
}
|
||||
logger.finest("Stored tag: " + tag + " value: " + value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
String text = new String(ch, start, length).trim();
|
||||
|
|
@ -335,7 +346,7 @@ public class DefaultX4OLanguageLoader implements X4OLanguageLoader {
|
|||
buf.append(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class VersionedResources {
|
||||
public String version;
|
||||
public String loadedFrom;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
/**
|
||||
* An DefaultElementLanguageModule.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import org.x4o.xml.io.X4OConnectionException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ package org.x4o.xml.lang;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* DefaultX4OLanguageVersionFilter makes best filter match attempt.
|
||||
*
|
||||
|
|
@ -35,26 +34,27 @@ public class DefaultX4OLanguageVersionFilter implements X4OLanguageVersionFilter
|
|||
|
||||
/**
|
||||
* Filters to the best version.
|
||||
*
|
||||
* @see org.x4o.xml.lang.X4OLanguageVersionFilter#filterVersion(java.lang.String, java.util.List)
|
||||
* @return The perfect or best match or null if no match for requested language.
|
||||
* @param requestVersion The language version to search for.
|
||||
* @param versions The list of version to search in.
|
||||
* @param requestVersion The language version to search for.
|
||||
* @param versions The list of version to search in.
|
||||
*/
|
||||
public String filterVersion(String requestVersion, List<String> versions) {
|
||||
for (int i=0;i<versions.size();i++) {
|
||||
for (int i = 0; i < versions.size(); i++) {
|
||||
String version = versions.get(i);
|
||||
if (version.equals(requestVersion)) {
|
||||
return version; // full match
|
||||
}
|
||||
}
|
||||
String requestVersionDot = requestVersion;
|
||||
if (requestVersion.length()>2) {
|
||||
requestVersionDot = requestVersion.substring(0,requestVersion.length()-2);
|
||||
if (requestVersion.length() > 2) {
|
||||
requestVersionDot = requestVersion.substring(0, requestVersion.length() - 2);
|
||||
}
|
||||
for (int i=0;i<versions.size();i++) {
|
||||
for (int i = 0; i < versions.size(); i++) {
|
||||
String version = versions.get(i);
|
||||
if (version.endsWith(".*")) {
|
||||
String versionDot = version.substring(0,version.length()-2);
|
||||
String versionDot = version.substring(0, version.length() - 2);
|
||||
if (versionDot.equals(requestVersionDot)) {
|
||||
return version; // star match
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,24 +38,26 @@ import org.x4o.xml.lang.phase.X4OPhaseManager;
|
|||
* @version 1.0 30 apr 2013
|
||||
*/
|
||||
public interface X4OLanguage {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the language name of this x4o xml language.
|
||||
* @return Returns the language name.
|
||||
*
|
||||
* @return Returns the language name.
|
||||
*/
|
||||
String getLanguageName();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the language version of this language instance.
|
||||
* @return Returns the language version of this language instance.
|
||||
*/
|
||||
String getLanguageVersion();
|
||||
|
||||
/**
|
||||
* Returns the phase manager which runs the phases
|
||||
* Returns the phase manager which runs the phases
|
||||
*
|
||||
* @return Returns the phase manager.
|
||||
*/
|
||||
X4OPhaseManager getPhaseManager();
|
||||
|
||||
|
||||
/**
|
||||
* @return the language configuration.
|
||||
*/
|
||||
|
|
@ -63,47 +65,53 @@ public interface X4OLanguage {
|
|||
|
||||
/**
|
||||
* Creates and fills the initial element language used to store the language.
|
||||
* @return The newly created X4OLanguageSession.
|
||||
*
|
||||
* @return The newly created X4OLanguageSession.
|
||||
*/
|
||||
X4OLanguageSession createLanguageSession();
|
||||
|
||||
/**
|
||||
* Search language for object and create element for it.
|
||||
* @param context The X4O language context to create for.
|
||||
*
|
||||
* @param context The X4O language context to create for.
|
||||
* @param objectClass The object to search for.
|
||||
* @return Returns an new Element instance for the object.
|
||||
* @return Returns an new Element instance for the object.
|
||||
*/
|
||||
Element createElementInstance(X4OLanguageSession context,Class<?> objectClass);
|
||||
|
||||
Element createElementInstance(X4OLanguageSession context, Class<?> objectClass);
|
||||
|
||||
/**
|
||||
* Gets all ElementBindingHandlers which are possible for parent.
|
||||
*
|
||||
* @param parent The parent element object or class to search for.
|
||||
* @return Returns an List with all ElementBindingHandler for the search.
|
||||
* @return Returns an List with all ElementBindingHandler for the search.
|
||||
*/
|
||||
List<ElementBindingHandler> findElementBindingHandlers(Object parent);
|
||||
|
||||
|
||||
/**
|
||||
* Gets all ElementBindingHandlers for parent and child combination.
|
||||
*
|
||||
* @param parent The parent element object or class to search for.
|
||||
* @param child The parent element object or class to search for.
|
||||
* @return Returns an List with all ElementBindingHandler for the search pair.
|
||||
* @param child The parent element object or class to search for.
|
||||
* @return Returns an List with all ElementBindingHandler for the search pair.
|
||||
*/
|
||||
List<ElementBindingHandler> findElementBindingHandlers(Object parent,Object child);
|
||||
|
||||
List<ElementBindingHandler> findElementBindingHandlers(Object parent, Object child);
|
||||
|
||||
/**
|
||||
* Returns list of ElementInterfaces for an element.
|
||||
*
|
||||
* @param object The element object or class to search for.
|
||||
* @return The list of elementInterfaces.
|
||||
* @return The list of elementInterfaces.
|
||||
*/
|
||||
List<ElementInterface> findElementInterfaces(Object object);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the namespace context for an namespace uri.
|
||||
*
|
||||
* @param namespaceUri the namespace uri.
|
||||
* @return The ElementNamespace.
|
||||
* @return The ElementNamespace.
|
||||
*/
|
||||
ElementNamespace findElementNamespace(String namespaceUri);
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns a collection of element language modules in this defined and loaded language.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -33,16 +33,17 @@ import java.net.URL;
|
|||
* @version 1.0 6 Aug 2012
|
||||
*/
|
||||
public final class X4OLanguageClassLoader {
|
||||
|
||||
|
||||
/**
|
||||
* Made X4OLanguageClassLoader have private constructor.
|
||||
*/
|
||||
private X4OLanguageClassLoader() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the thread classloader or the normal classloader.
|
||||
* @return Returns the ClassLoader.
|
||||
*
|
||||
* @return Returns the ClassLoader.
|
||||
*/
|
||||
public static ClassLoader getClassLoader() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
|
|
@ -51,69 +52,74 @@ public final class X4OLanguageClassLoader {
|
|||
}
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads a Class from the ContextClassLoader and if that is not set, then
|
||||
* uses the class of the String className instance.
|
||||
* Loads a Class from the ContextClassLoader and if that is not set, then uses the class of the String className instance.
|
||||
*
|
||||
* @param className The class name to load
|
||||
* @return The loaded class
|
||||
* @throws ClassNotFoundException if class not loaded.
|
||||
* @param className The class name to load
|
||||
* @return The loaded class
|
||||
* @throws ClassNotFoundException if class not loaded.
|
||||
*/
|
||||
public static Class<?> loadClass(String className) throws ClassNotFoundException {
|
||||
return getClassLoader().loadClass(className);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates new instance of clazz.
|
||||
*
|
||||
* @param resultType The result type to cast to..
|
||||
* @param clazz The class to make object from.
|
||||
* @return The object of the clazz.
|
||||
* @throws ClassNotFoundException On any construct access or invoke error.
|
||||
* @param clazz The class to make object from.
|
||||
* @return The object of the clazz.
|
||||
* @throws ClassNotFoundException On any construct access or invoke error.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T newInstance(Class<T> resultType, Class<?> clazz) throws ClassNotFoundException {
|
||||
return (T) newInstance(clazz);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates new instance of clazz.
|
||||
* @param clazz The class to make object from.
|
||||
* @return The object of the clazz.
|
||||
* @throws ClassNotFoundException On any construct access or invoke error.
|
||||
*
|
||||
* @param clazz The class to make object from.
|
||||
* @return The object of the clazz.
|
||||
* @throws ClassNotFoundException On any construct access or invoke error.
|
||||
*/
|
||||
public static Object newInstance(Class<?> clazz) throws ClassNotFoundException {
|
||||
try {
|
||||
return clazz.getConstructor().newInstance();
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException e) {
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new ClassNotFoundException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates new instance of className.
|
||||
* @param className The className to create object from.
|
||||
* @return The object of the className.
|
||||
* @throws ClassNotFoundException When className is not found or can't be created.
|
||||
*
|
||||
* @param className The className to create object from.
|
||||
* @return The object of the className.
|
||||
* @throws ClassNotFoundException When className is not found or can't be created.
|
||||
*/
|
||||
public static Object newInstance(String className) throws ClassNotFoundException {
|
||||
return newInstance(loadClass(className));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a resource from the classloader to an url.
|
||||
* @param resourceName The resource to get from the classloader.
|
||||
* @return The url to the resource or null if not found.
|
||||
*
|
||||
* @param resourceName The resource to get from the classloader.
|
||||
* @return The url to the resource or null if not found.
|
||||
* @see java.lang.ClassLoader#getResource(String)
|
||||
*/
|
||||
public static URL getResource(String resourceName) {
|
||||
return getClassLoader().getResource(resourceName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a resource from the classloader to an inputstream.
|
||||
* @param resourceName The resource to get from the classloader.
|
||||
* @return The inputstream to the resource or null if not found.
|
||||
*
|
||||
* @param resourceName The resource to get from the classloader.
|
||||
* @return The inputstream to the resource or null if not found.
|
||||
* @see java.lang.ClassLoader#getResourceAsStream(String)
|
||||
*/
|
||||
public static InputStream getResourceAsStream(String resourceName) {
|
||||
|
|
|
|||
|
|
@ -29,52 +29,63 @@ package org.x4o.xml.lang;
|
|||
* @version 1.0 27 Oct 2009
|
||||
*/
|
||||
public interface X4OLanguageConfiguration {
|
||||
|
||||
|
||||
/** Prefix where we load all language definitions from. */
|
||||
public static final String DEFAULT_LANG_PATH_PREFIX = "META-INF";
|
||||
|
||||
|
||||
/** The modules file to startup the language definition process. */
|
||||
public static final String DEFAULT_LANG_MODULES_FILE = "-modules.xml";
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the path prefix for loading language resources.
|
||||
* @return Returns the path prefix for loading language resources.
|
||||
*/
|
||||
String getLanguageResourcePathPrefix();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the filename (postfix) of the modules definition file.
|
||||
* @return Returns the filename (postfix) of the modules definition file.
|
||||
*/
|
||||
String getLanguageResourceModulesFileName();
|
||||
|
||||
|
||||
// Core interfaces are also in class for text reference without instance
|
||||
Class<?> getDefaultElementNamespace();
|
||||
|
||||
Class<?> getDefaultElementInterface();
|
||||
|
||||
Class<?> getDefaultElement();
|
||||
|
||||
Class<?> getDefaultElementClass();
|
||||
|
||||
Class<?> getDefaultElementClassAttribute();
|
||||
|
||||
|
||||
// Other needed interfaces in class form also
|
||||
Class<?> getDefaultElementLanguageModule();
|
||||
|
||||
Class<?> getDefaultElementBodyComment();
|
||||
|
||||
Class<?> getDefaultElementBodyCharacters();
|
||||
|
||||
Class<?> getDefaultElementBodyWhitespace();
|
||||
|
||||
Class<?> getDefaultElementNamespaceInstanceProvider();
|
||||
|
||||
Class<?> getDefaultElementAttributeValueParser();
|
||||
|
||||
Class<?> getDefaultElementObjectPropertyValue();
|
||||
|
||||
Class<?> getDefaultElementNamespaceAttributeComparator();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the X4OLanguageVersionFilter which filters the best version to use.
|
||||
* @return Returns the X4OLanguageVersionFilter which filters the best version to use.
|
||||
*/
|
||||
Class<?> getDefaultLanguageVersionFilter();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the X4OLanguageLoader which loads languages into the element context.
|
||||
* @return Returns the X4OLanguageLoader which loads languages into the element context.
|
||||
*/
|
||||
Class<?> getDefaultLanguageLoader();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the Expression Language Context which holds the el objects.
|
||||
* @return Returns the Expression Language Context which holds the el objects.
|
||||
*/
|
||||
Class<?> getDefaultExpressionLanguageContext();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,26 +31,40 @@ package org.x4o.xml.lang;
|
|||
public interface X4OLanguageConfigurationLocal extends X4OLanguageConfiguration {
|
||||
|
||||
X4OLanguageConfiguration createProxy();
|
||||
|
||||
|
||||
void setLanguageResourcePathPrefix(String value);
|
||||
|
||||
void setLanguageResourceModulesFileName(String value);
|
||||
|
||||
|
||||
void setDefaultElementNamespace(Class<?> value);
|
||||
|
||||
void setDefaultElementInterface(Class<?> value);
|
||||
|
||||
void setDefaultElement(Class<?> value);
|
||||
|
||||
void setDefaultElementClass(Class<?> value);
|
||||
|
||||
void setDefaultElementClassAttribute(Class<?> value);
|
||||
|
||||
|
||||
void setDefaultElementLanguageModule(Class<?> value);
|
||||
|
||||
void setDefaultElementBodyComment(Class<?> value);
|
||||
|
||||
void setDefaultElementBodyCharacters(Class<?> value);
|
||||
|
||||
void setDefaultElementBodyWhitespace(Class<?> value);
|
||||
|
||||
void setDefaultElementNamespaceInstanceProvider(Class<?> value);
|
||||
|
||||
void setDefaultElementAttributeValueParser(Class<?> value);
|
||||
|
||||
void setDefaultElementObjectPropertyValue(Class<?> value);
|
||||
|
||||
void setDefaultElementNamespaceAttributeComparator(Class<?> value);
|
||||
|
||||
|
||||
void setDefaultLanguageVersionFilter(Class<?> value);
|
||||
|
||||
void setDefaultLanguageLoader(Class<?> value);
|
||||
|
||||
void setDefaultExpressionLanguageContext(Class<?> value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,14 +29,15 @@ package org.x4o.xml.lang;
|
|||
* @version 1.0 28 Oct 2009
|
||||
*/
|
||||
public interface X4OLanguageLoader {
|
||||
|
||||
|
||||
/**
|
||||
* Loads the language modules.
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param languageName The language name to load.
|
||||
* @param languageVersion The language version to load.
|
||||
* @throws X4OLanguageLoaderException When there is an error.
|
||||
*
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param languageName The language name to load.
|
||||
* @param languageVersion The language version to load.
|
||||
* @throws X4OLanguageLoaderException When there is an error.
|
||||
*/
|
||||
void loadLanguage(X4OLanguageSession session, X4OLanguageLocal language, String languageName, String languageVersion) throws X4OLanguageLoaderException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
/**
|
||||
* Is throw when there is en Exception within an Element.
|
||||
|
|
@ -29,10 +29,10 @@ package org.x4o.xml.lang;
|
|||
* @version 1.0 Oct 28, 2009
|
||||
*/
|
||||
public class X4OLanguageLoaderException extends Exception {
|
||||
|
||||
|
||||
/** The serial version uid */
|
||||
static final long serialVersionUID = 10L;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an X4OLanguageLoaderException without a detail message.
|
||||
*/
|
||||
|
|
@ -42,26 +42,29 @@ public class X4OLanguageLoaderException extends Exception {
|
|||
|
||||
/**
|
||||
* Constructs an X4OLanguageLoaderException with a detail message.
|
||||
* @param message The message of this Exception
|
||||
*
|
||||
* @param message The message of this Exception
|
||||
*/
|
||||
public X4OLanguageLoaderException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an X4OLanguageLoaderException from a parent exception.
|
||||
* @param e The exception.
|
||||
*
|
||||
* @param e The exception.
|
||||
*/
|
||||
public X4OLanguageLoaderException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an X4OLanguageLoaderException with a detail message.
|
||||
* @param message The message of this Exception
|
||||
* @param e The exception.
|
||||
*
|
||||
* @param message The message of this Exception
|
||||
* @param e The exception.
|
||||
*/
|
||||
public X4OLanguageLoaderException(String message,Exception e) {
|
||||
super(message,e);
|
||||
public X4OLanguageLoaderException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,13 @@ import org.x4o.xml.lang.phase.X4OPhaseException;
|
|||
* @version 1.0 30 apr 2013
|
||||
*/
|
||||
public interface X4OLanguageLocal extends X4OLanguage {
|
||||
|
||||
|
||||
// TODO: refactor a bit more a this is now called manually on magic places
|
||||
void init(X4OLanguageSession session) throws X4OPhaseException;
|
||||
|
||||
|
||||
/**
|
||||
* Adds an X4OLanguageModule to this language.
|
||||
*
|
||||
* @param languageModule The element language module to add.
|
||||
*/
|
||||
void addLanguageModule(X4OLanguageModule languageModule);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -40,52 +40,58 @@ public interface X4OLanguageModule /* extends ElementMetaBase TODO add local lay
|
|||
|
||||
// temp here see local
|
||||
String getId();
|
||||
|
||||
String getDescription();
|
||||
|
||||
|
||||
/**
|
||||
* @return the providerName.
|
||||
*/
|
||||
String getProviderName();
|
||||
|
||||
|
||||
/**
|
||||
* @return the providerHost
|
||||
*/
|
||||
String getProviderHost();
|
||||
|
||||
|
||||
/**
|
||||
* Gets all ElementBindingHandlers.
|
||||
* @return Returns an List with all ElementBindingHandlers.
|
||||
*
|
||||
* @return Returns an List with all ElementBindingHandlers.
|
||||
*/
|
||||
List<ElementBindingHandler> getElementBindingHandlers();
|
||||
|
||||
|
||||
/**
|
||||
* Gets all ElementConfiguratorGlobals.
|
||||
* @return All gloval ElementConfigurators.
|
||||
*
|
||||
* @return All gloval ElementConfigurators.
|
||||
*/
|
||||
List<ElementConfiguratorGlobal> getElementConfiguratorGlobals();
|
||||
|
||||
|
||||
/**
|
||||
* Returns list of ElementInterfaces in this context.
|
||||
* @return The list of elementInterfaces.
|
||||
*
|
||||
* @return The list of elementInterfaces.
|
||||
*/
|
||||
List<ElementInterface> getElementInterfaces();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the namespace context for an namespace uri.
|
||||
*
|
||||
* @param namespaceUri the namespace uri.
|
||||
* @return The ElementNamespace.
|
||||
* @return The ElementNamespace.
|
||||
*/
|
||||
ElementNamespace getElementNamespace(String namespaceUri);
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns a list of all namespaces defined in this language.
|
||||
*/
|
||||
List<ElementNamespace> getElementNamespaces();
|
||||
|
||||
|
||||
/**
|
||||
* Gets module loader meta result info.
|
||||
* @param key The key to get info of.
|
||||
* @return The value of the info.
|
||||
* Gets module loader meta result info.
|
||||
*
|
||||
* @param key The key to get info of.
|
||||
* @return The value of the info.
|
||||
*/
|
||||
String getLoaderResult(X4OLanguageModuleLoaderResult key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@
|
|||
package org.x4o.xml.lang;
|
||||
|
||||
/**
|
||||
* X4OLanguageModuleLoader Loads all elements and other options
|
||||
* into the X4OLanguageModule for the X4OLanguageLocal language.
|
||||
* X4OLanguageModuleLoader Loads all elements and other options into the X4OLanguageModule for the X4OLanguageLocal language.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jul 8, 2006
|
||||
*/
|
||||
public interface X4OLanguageModuleLoader {
|
||||
|
||||
|
||||
/**
|
||||
* Starts the ElementProvider.
|
||||
* @param session The session we run in.
|
||||
*
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param module The language module to load it into.
|
||||
* @throws X4OLanguageModuleLoaderException Gets thrown when modules could not be correctly loaded.
|
||||
* @param module The language module to load it into.
|
||||
* @throws X4OLanguageModuleLoaderException Gets thrown when modules could not be correctly loaded.
|
||||
*/
|
||||
void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal module) throws X4OLanguageModuleLoaderException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
|
|
@ -32,32 +32,35 @@ import org.x4o.xml.element.ElementException;
|
|||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class X4OLanguageModuleLoaderException extends ElementException {
|
||||
|
||||
|
||||
private X4OLanguageModuleLoader elementLanguageModuleLoader = null;
|
||||
|
||||
|
||||
/**
|
||||
* Creates module loader exception.
|
||||
* @param elementLanguageModuleLoader The loader module which creates this exception.
|
||||
* @param message The message of the exception.
|
||||
* Creates module loader exception.
|
||||
*
|
||||
* @param elementLanguageModuleLoader The loader module which creates this exception.
|
||||
* @param message The message of the exception.
|
||||
*/
|
||||
public X4OLanguageModuleLoaderException(X4OLanguageModuleLoader elementLanguageModuleLoader,String message) {
|
||||
public X4OLanguageModuleLoaderException(X4OLanguageModuleLoader elementLanguageModuleLoader, String message) {
|
||||
super(message);
|
||||
this.elementLanguageModuleLoader=elementLanguageModuleLoader;
|
||||
this.elementLanguageModuleLoader = elementLanguageModuleLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates module loader exception.
|
||||
* @param elementLanguageModuleLoader The loader module which creates this exception.
|
||||
* @param message The message of the exception.
|
||||
* @param exception The root cause of the exception.
|
||||
* Creates module loader exception.
|
||||
*
|
||||
* @param elementLanguageModuleLoader The loader module which creates this exception.
|
||||
* @param message The message of the exception.
|
||||
* @param exception The root cause of the exception.
|
||||
*/
|
||||
public X4OLanguageModuleLoaderException(X4OLanguageModuleLoader elementLanguageModuleLoader,String message,Exception exception) {
|
||||
super(message,exception);
|
||||
this.elementLanguageModuleLoader=elementLanguageModuleLoader;
|
||||
public X4OLanguageModuleLoaderException(X4OLanguageModuleLoader elementLanguageModuleLoader, String message, Exception exception) {
|
||||
super(message, exception);
|
||||
this.elementLanguageModuleLoader = elementLanguageModuleLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the module loader which created the exception.
|
||||
*
|
||||
* @return Returns the module loader.
|
||||
*/
|
||||
public X4OLanguageModuleLoader getElementProvider() {
|
||||
|
|
|
|||
|
|
@ -29,11 +29,13 @@ package org.x4o.xml.lang;
|
|||
* @version 1.0 Mar 7, 2014
|
||||
*/
|
||||
public enum X4OLanguageModuleLoaderResult {
|
||||
|
||||
|
||||
//@formatter:off
|
||||
LOAD_MODULE_RESOURCE,
|
||||
LOAD_FROM_RESOURCE,
|
||||
LOAD_VERSION,
|
||||
LOAD_CLASS,
|
||||
LOAD_TIME,
|
||||
LOAD_DATE;
|
||||
//@formatter:on
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@
|
|||
*/
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ElementLanguageModuleLoaderSibling provides sibling language loading support.
|
||||
*
|
||||
|
|
@ -32,12 +30,13 @@ package org.x4o.xml.lang;
|
|||
* @version 1.0 Aug 7, 2012
|
||||
*/
|
||||
public interface X4OLanguageModuleLoaderSibling extends X4OLanguageModuleLoader {
|
||||
|
||||
|
||||
/**
|
||||
* Loads in the sibling language.
|
||||
* @param session The session we run in.
|
||||
*
|
||||
* @param session The session we run in.
|
||||
* @param language The local Language to load for.
|
||||
* @param loader The loader to use to load the x4o languages.
|
||||
* @param loader The loader to use to load the x4o languages.
|
||||
* @throws X4OLanguageLoaderException Gets thrown when there is an error loading the sibling language.
|
||||
*/
|
||||
void loadLanguageSibling(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageLoader loader) throws X4OLanguageLoaderException;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import org.x4o.xml.element.ElementBindingHandler;
|
||||
import org.x4o.xml.element.ElementConfiguratorGlobal;
|
||||
|
|
@ -34,46 +34,51 @@ import org.x4o.xml.element.ElementNamespace;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 7, 2014
|
||||
*/
|
||||
public interface X4OLanguageModuleLocal extends X4OLanguageModule,ElementMetaBase {
|
||||
|
||||
public interface X4OLanguageModuleLocal extends X4OLanguageModule, ElementMetaBase {
|
||||
|
||||
/**
|
||||
* @param providerName the providerName to set.
|
||||
*/
|
||||
void setProviderName(String providerName);
|
||||
|
||||
|
||||
/**
|
||||
* @param providerHost the providerHost to set
|
||||
*/
|
||||
void setProviderHost(String providerHost);
|
||||
|
||||
|
||||
/**
|
||||
* Adds an ElementBindingHanlder.
|
||||
* @param elementBindingHandler The ElementBindingHandler to add.
|
||||
*
|
||||
* @param elementBindingHandler The ElementBindingHandler to add.
|
||||
*/
|
||||
void addElementBindingHandler(ElementBindingHandler elementBindingHandler);
|
||||
|
||||
|
||||
/**
|
||||
* Adds an ElementConfiguratorGlobal.
|
||||
* @param elementConfigurator The ElementConfigurtor to add.
|
||||
*
|
||||
* @param elementConfigurator The ElementConfigurtor to add.
|
||||
*/
|
||||
void addElementConfiguratorGlobal(ElementConfiguratorGlobal elementConfigurator);
|
||||
|
||||
|
||||
/**
|
||||
* Adds an ElementInterface.
|
||||
* @param elementInterface The elementInterface to add.
|
||||
*
|
||||
* @param elementInterface The elementInterface to add.
|
||||
*/
|
||||
void addElementInterface(ElementInterface elementInterface);
|
||||
|
||||
|
||||
/**
|
||||
* Adds an namespace to this langauge module.
|
||||
*
|
||||
* @param elementNamespace Adds an ElementNamespace to this langauge module.
|
||||
*/
|
||||
void addElementNamespace(ElementNamespace elementNamespace);
|
||||
|
||||
|
||||
/**
|
||||
* Sets module loader meta result info.
|
||||
* @param key The key of the info.
|
||||
* @param value The value of the info.
|
||||
*
|
||||
* @param key The key of the info.
|
||||
* @param value The value of the info.
|
||||
*/
|
||||
void putLoaderResult(X4OLanguageModuleLoaderResult key,String value);
|
||||
void putLoaderResult(X4OLanguageModuleLoaderResult key, String value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -41,85 +41,91 @@ import org.x4o.xml.lang.phase.X4OPhase;
|
|||
* @version 1.0 Feb 14, 2007
|
||||
*/
|
||||
public interface X4OLanguageSession extends AutoCloseable {
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the language from which this session in created.
|
||||
* @return Returns the language from which this session in created.
|
||||
*/
|
||||
X4OLanguage getLanguage();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the EL Context.
|
||||
* @return Returns the ELContext.
|
||||
*
|
||||
* @return Returns the ELContext.
|
||||
*/
|
||||
ELContext getExpressionLanguageContext();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the ExpressionFactory.
|
||||
* @return Returns the ExpressionFactory.
|
||||
*
|
||||
* @return Returns the ExpressionFactory.
|
||||
*/
|
||||
ExpressionFactory getExpressionLanguageFactory();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the ElementAttributeValueParser.
|
||||
* @return Returns the ElementAttributeValueParser.
|
||||
*/
|
||||
ElementAttributeValueParser getElementAttributeValueParser();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the ElementObjectPropertyValue.
|
||||
* @return Returns the ElementObjectPropertyValue.
|
||||
*/
|
||||
ElementObjectPropertyValue getElementObjectPropertyValue();
|
||||
|
||||
|
||||
/**
|
||||
* Marks an (new) Element as dirty and run the phases from this start phase.
|
||||
*
|
||||
* @param element The Element which needs the magic.
|
||||
* @param element The Element which needs the magic.
|
||||
*/
|
||||
void addDirtyElement(Element element);
|
||||
|
||||
/**
|
||||
* Get all Dirty Elements.
|
||||
* @return Returns List with dirty elements.
|
||||
*
|
||||
* @return Returns List with dirty elements.
|
||||
*/
|
||||
List<Element> getDirtyElements();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the root Element which starts the xml tree.
|
||||
* @return Returns the root element of the document instance we parse.
|
||||
*
|
||||
* @return Returns the root element of the document instance we parse.
|
||||
*/
|
||||
Element getRootElement();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the root element.
|
||||
* @param element The root element to set.
|
||||
*
|
||||
* @param element The root element to set.
|
||||
*/
|
||||
void setRootElement(Element element);
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns null or an X4ODebugWriter to write parsing steps and debug data to.
|
||||
* @return Returns null or an X4ODebugWriter to write parsing steps and debug data to.
|
||||
*/
|
||||
X4ODebugWriter getX4ODebugWriter();
|
||||
|
||||
/**
|
||||
* @return Returns true if this config has a debug writer.
|
||||
|
||||
/**
|
||||
* @return Returns true if this config has a debug writer.
|
||||
*/
|
||||
boolean hasX4ODebugWriter();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current X4OPhase of the parser.
|
||||
* @return Returns the current phase.
|
||||
*
|
||||
* @return Returns the current phase.
|
||||
*/
|
||||
X4OPhase getPhaseCurrent();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the phase this session will stop processing.
|
||||
* @return Returns the phase this session will stop processing.
|
||||
*/
|
||||
String getPhaseStop();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns a list of phases we skip while processing.
|
||||
* @return Returns a list of phases we skip while processing.
|
||||
*/
|
||||
List<String> getPhaseSkip();
|
||||
|
||||
|
||||
/**
|
||||
* Closes this language session
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang;
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -40,49 +40,52 @@ import org.x4o.xml.lang.phase.X4OPhaseListener;
|
|||
* @version 1.0 Oct 28, 2009
|
||||
*/
|
||||
public interface X4OLanguageSessionLocal extends X4OLanguageSession {
|
||||
|
||||
|
||||
/**
|
||||
* Returns list of phase listeners which where added to it.
|
||||
* TODO: bad api here
|
||||
* Returns list of phase listeners which where added to it. TODO: bad api here
|
||||
*
|
||||
* @param phaseId The phaseId of for the listeners.
|
||||
* @return All X4OPhaseListeners.
|
||||
*/
|
||||
List<X4OPhaseListener> storePhaseListeners(String phaseId);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the EL Context.
|
||||
* @param context The ELContext to set.
|
||||
*
|
||||
* @param context The ELContext to set.
|
||||
*/
|
||||
void setExpressionLanguageContext(ELContext context);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the ExpressionFactory.
|
||||
* @param expressionFactory The ExpressionFactory to set.
|
||||
*
|
||||
* @param expressionFactory The ExpressionFactory to set.
|
||||
*/
|
||||
void setExpressionLanguageFactory(ExpressionFactory expressionFactory);
|
||||
|
||||
|
||||
/**
|
||||
* @param elementAttributeValueParser The elementAttributeValueParser to set.
|
||||
*/
|
||||
void setElementAttributeValueParser(ElementAttributeValueParser elementAttributeValueParser);
|
||||
|
||||
|
||||
/**
|
||||
* @param elementObjectPropertyValue The elementObjectPropertyValue to set.
|
||||
* @param elementObjectPropertyValue The elementObjectPropertyValue to set.
|
||||
*/
|
||||
void setElementObjectPropertyValue(ElementObjectPropertyValue elementObjectPropertyValue);
|
||||
|
||||
|
||||
/**
|
||||
* @param debugWriter The debug writer to set
|
||||
* @param debugWriter The debug writer to set
|
||||
*/
|
||||
void setX4ODebugWriter(X4ODebugWriter debugWriter);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the phase of the context.
|
||||
* @param phase The current phase to set.
|
||||
*
|
||||
* @param phase The current phase to set.
|
||||
*/
|
||||
void setPhaseCurrent(X4OPhase phase);
|
||||
|
||||
|
||||
void setPhaseStop(String phaseId);
|
||||
|
||||
|
||||
void addPhaseSkip(String phaseId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ import java.util.List;
|
|||
* @version 1.0 6 Aug 2012
|
||||
*/
|
||||
public interface X4OLanguageVersionFilter {
|
||||
|
||||
|
||||
/**
|
||||
* Finds the version to load or returns null if no match is found.
|
||||
*
|
||||
* @param languageVersion The languageVersion to requested.
|
||||
* @param versions The versions provided by the module.
|
||||
* @return The version to load.
|
||||
* @param languageVersion The languageVersion to requested.
|
||||
* @param versions The versions provided by the module.
|
||||
* @return The version to load.
|
||||
*/
|
||||
String filterVersion(String languageVersion,List<String> versions);
|
||||
String filterVersion(String languageVersion, List<String> versions);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import org.x4o.xml.element.AbstractElementNamespaceAttribute;
|
|||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementConfiguratorException;
|
||||
|
||||
|
||||
/**
|
||||
* Stores an ElementObject into the EL context.
|
||||
*
|
||||
|
|
@ -44,17 +43,23 @@ public class ELIDAttributeHandler extends AbstractElementNamespaceAttribute {
|
|||
*/
|
||||
public void doConfigElement(Element element) throws ElementConfiguratorException {
|
||||
String attributeValue = element.getAttributes().get(getAttributeName());
|
||||
if(attributeValue==null) { return; }
|
||||
if(element.getElementObject()==null) {
|
||||
if (attributeValue == null) {
|
||||
return;
|
||||
}
|
||||
if (element.getElementObject() == null) {
|
||||
if (this.isConfigAction()) {
|
||||
throw new NullPointerException("Can't bind null object to el context");
|
||||
}
|
||||
this.setConfigAction(true);
|
||||
return;
|
||||
}
|
||||
if(element.getElementObject()==null) { throw new NullPointerException("Can't bind null object to el context"); }
|
||||
ValueExpression ee = element.getLanguageSession().getExpressionLanguageFactory().createValueExpression(element.getLanguageSession().getExpressionLanguageContext(),"${"+attributeValue+"}", element.getElementObject().getClass());
|
||||
Logger.getLogger(ELIDAttributeHandler.class.getName()).finer("Set Variable in ELContext: "+"${"+attributeValue+"}"+" object SET: "+element.getElementObject());
|
||||
if (element.getElementObject() == null) {
|
||||
throw new NullPointerException("Can't bind null object to el context");
|
||||
}
|
||||
ValueExpression ee = element.getLanguageSession().getExpressionLanguageFactory().createValueExpression(
|
||||
element.getLanguageSession().getExpressionLanguageContext(), "${" + attributeValue + "}", element.getElementObject().getClass());
|
||||
Logger.getLogger(ELIDAttributeHandler.class.getName())
|
||||
.finer("Set Variable in ELContext: " + "${" + attributeValue + "}" + " object SET: " + element.getElementObject());
|
||||
ee.setValue(element.getLanguageSession().getExpressionLanguageContext(), element.getElementObject());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import javax.el.ValueExpression;
|
|||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
|
||||
/**
|
||||
* An ELReferenceElement.<br>
|
||||
* Fills the ElementObject with an object from el.
|
||||
|
|
@ -38,13 +37,16 @@ import org.x4o.xml.element.ElementException;
|
|||
* @version 1.0 Jan 23, 2007
|
||||
*/
|
||||
public class ELReferenceElement extends AbstractElement {
|
||||
|
||||
|
||||
@Override
|
||||
public void doElementRun() throws ElementException {
|
||||
String attributeValue = getAttributes().get("el.ref");
|
||||
if("".equals(attributeValue) | attributeValue==null) { throw new ElementException("Set the el.ref attribute"); }
|
||||
ValueExpression ee = getLanguageSession().getExpressionLanguageFactory().createValueExpression(getLanguageSession().getExpressionLanguageContext(),"${"+attributeValue+"}",Object.class);
|
||||
Logger.getLogger(ELReferenceElement.class.getName()).finer("Get Variable in ELContext: ${"+attributeValue+"}");
|
||||
if ("".equals(attributeValue) | attributeValue == null) {
|
||||
throw new ElementException("Set the el.ref attribute");
|
||||
}
|
||||
ValueExpression ee = getLanguageSession().getExpressionLanguageFactory().createValueExpression(getLanguageSession().getExpressionLanguageContext(),
|
||||
"${" + attributeValue + "}", Object.class);
|
||||
Logger.getLogger(ELReferenceElement.class.getName()).finer("Get Variable in ELContext: ${" + attributeValue + "}");
|
||||
setElementObject(ee.getValue(getLanguageSession().getExpressionLanguageContext()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import org.x4o.xml.lang.X4OLanguageModuleLocal;
|
|||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
/**
|
||||
* MetaLanguageSiblingLoader loads the generic x4o meta language into defined language.
|
||||
* MetaLanguageSiblingLoader loads the generic x4o meta language into defined language.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 7, 2012
|
||||
|
|
@ -40,18 +40,19 @@ public class MetaLanguageSiblingLoader implements X4OLanguageModuleLoaderSibling
|
|||
|
||||
/** Defines the identifier of the meta x4o language. */
|
||||
public static final String META_LANGUAGE = "meta";
|
||||
|
||||
|
||||
/** Defines the version of the meta x4o language. */
|
||||
public static final String META_LANGUAGE_VERSION = "1.0";
|
||||
|
||||
|
||||
/** Defines the identifier of the meta x4o language host. */
|
||||
public static final String META_LANGUAGE_HOST = "meta.x4o.org";
|
||||
|
||||
/** Defines the identifier of the meta x4o language host. */
|
||||
public static final String META_LANGUAGE_DESCRIPTION = "X4O Meta XML Language Module.";
|
||||
|
||||
|
||||
@Override
|
||||
public void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal module) throws X4OLanguageModuleLoaderException {
|
||||
public void loadLanguageModule(X4OLanguageSession session, X4OLanguageLocal language, X4OLanguageModuleLocal module)
|
||||
throws X4OLanguageModuleLoaderException {
|
||||
module.setId(META_LANGUAGE);
|
||||
module.setProviderHost(META_LANGUAGE_HOST);
|
||||
module.setProviderName(MetaLanguageSiblingLoader.class.getSimpleName());
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.lang.reflect.Method;
|
|||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
|
||||
/**
|
||||
* MethodElement invokes an method on a element object.
|
||||
*
|
||||
|
|
@ -44,17 +43,17 @@ public class MethodElement extends AbstractElement {
|
|||
*/
|
||||
@Override
|
||||
public void doElementRun() throws ElementException {
|
||||
if (getParent()==null) {
|
||||
if (getParent() == null) {
|
||||
throw new IllegalStateException("need to have parent.");
|
||||
}
|
||||
Object parent = getParent().getElementObject();
|
||||
if (parent==null) {
|
||||
if (parent == null) {
|
||||
throw new IllegalStateException("need to have parent ElementObject.");
|
||||
}
|
||||
String methodString = getAttributes().get("method");
|
||||
Method[] ms = parent.getClass().getMethods();
|
||||
try {
|
||||
for (Method m:ms) {
|
||||
for (Method m : ms) {
|
||||
if (methodString.equalsIgnoreCase(m.getName())) {
|
||||
m.invoke(parent);
|
||||
return;
|
||||
|
|
@ -67,6 +66,6 @@ public class MethodElement extends AbstractElement {
|
|||
} catch (InvocationTargetException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
throw new ElementException("could not find method on parent element object: "+methodString+" on; "+parent);
|
||||
throw new ElementException("could not find method on parent element object: " + methodString + " on; " + parent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class ParentObjectElement extends AbstractElement {
|
|||
|
||||
@Override
|
||||
public Object getElementObject() {
|
||||
if (getParent()==null) {
|
||||
if (getParent() == null) {
|
||||
return null;
|
||||
}
|
||||
return getParent().getElementObject();
|
||||
|
|
@ -43,7 +43,7 @@ public class ParentObjectElement extends AbstractElement {
|
|||
|
||||
@Override
|
||||
public void setElementObject(Object object) {
|
||||
if (getParent()==null) {
|
||||
if (getParent() == null) {
|
||||
return;
|
||||
}
|
||||
getParent().setElementObject(object);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import org.x4o.xml.eld.lang.BeanElement;
|
|||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
|
||||
|
||||
/**
|
||||
* An PropertyElement.<br>
|
||||
*
|
||||
|
|
@ -46,65 +45,65 @@ public class PropertyElement extends AbstractElement {
|
|||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void doElementRun() throws ElementException {
|
||||
|
||||
if (getParent().getElementObject()==null) {
|
||||
|
||||
if (getParent().getElementObject() == null) {
|
||||
throw new IllegalStateException("need to have parent ElementObject");
|
||||
}
|
||||
|
||||
|
||||
String name = getAttributes().get("key");
|
||||
String valueString = getAttributes().get("value");
|
||||
Object value = valueString;
|
||||
|
||||
if (name==null) {
|
||||
|
||||
if (name == null) {
|
||||
name = getAttributes().get("name");
|
||||
}
|
||||
if (name==null) {
|
||||
if (name == null) {
|
||||
name = getAttributes().get("field");
|
||||
}
|
||||
|
||||
// convert value object
|
||||
try {
|
||||
value = getLanguageSession().getElementAttributeValueParser().getParameterValue(name,valueString,this);
|
||||
value = getLanguageSession().getElementAttributeValueParser().getParameterValue(name, valueString, this);
|
||||
} catch (ObjectConverterException ece) {
|
||||
throw new ElementException(ece);
|
||||
}
|
||||
|
||||
|
||||
if (getParent() instanceof BeanElement) {
|
||||
BeanElement bean = (BeanElement)getParent();
|
||||
BeanElement bean = (BeanElement) getParent();
|
||||
bean.addConstuctorArgument(value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name==null) {
|
||||
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("Can't set properties without key.");
|
||||
}
|
||||
|
||||
|
||||
// check map interface
|
||||
if (getParent().getElementObject() instanceof Map) {
|
||||
((Map)getParent().getElementObject()).put(name,value);
|
||||
((Map) getParent().getElementObject()).put(name, value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check for setProperty(String,Object) method
|
||||
Method[] methodes = getParent().getElementObject().getClass().getMethods();
|
||||
for (int i=0;i<methodes.length;i++) {
|
||||
Method method = methodes[i];
|
||||
for (int i = 0; i < methodes.length; i++) {
|
||||
Method method = methodes[i];
|
||||
if (method.getName().toLowerCase().equals("setproperty")) {
|
||||
try {
|
||||
method.invoke(getParent().getElementObject(),new Object[]{name,value});
|
||||
method.invoke(getParent().getElementObject(), new Object[] { name, value });
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
throw new ElementException("Could not invoke setproperty of "+method.getName()+" on: "+getParent().getElementObject(),e);
|
||||
throw new ElementException("Could not invoke setproperty of " + method.getName() + " on: " + getParent().getElementObject(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// try to set as property on bean.
|
||||
try {
|
||||
getLanguageSession().getElementObjectPropertyValue().setProperty(getParent().getElementObject(), name, value);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
throw new ElementException("Could not set property on parent element object: "+name,e);
|
||||
throw new ElementException("Could not set property on parent element object: " + name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,12 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
|
||||
/**
|
||||
* AbstractX4OPhaseHandler a base class for creating a phase handler.
|
||||
*
|
||||
|
|
@ -34,13 +33,13 @@ import org.x4o.xml.lang.X4OLanguageSession;
|
|||
* @version 1.0 Dec 31, 2008
|
||||
*/
|
||||
public abstract class AbstractX4OPhase implements X4OPhase {
|
||||
|
||||
|
||||
/**
|
||||
* Creates the AbstractX4OPhaseHandler.
|
||||
*/
|
||||
public AbstractX4OPhase() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* defaults to false
|
||||
*/
|
||||
|
|
@ -49,7 +48,8 @@ public abstract class AbstractX4OPhase implements X4OPhase {
|
|||
}
|
||||
|
||||
/**
|
||||
* If returns true then this handler will run on all elements.
|
||||
* If returns true then this handler will run on all elements.
|
||||
*
|
||||
* @return defaults to true.
|
||||
*/
|
||||
public boolean isElementPhase() {
|
||||
|
|
@ -58,6 +58,7 @@ public abstract class AbstractX4OPhase implements X4OPhase {
|
|||
|
||||
/**
|
||||
* Abstract method.
|
||||
*
|
||||
* @param element The element to run phase for.
|
||||
* @throws X4OPhaseException when phase has error.
|
||||
*/
|
||||
|
|
@ -65,18 +66,19 @@ public abstract class AbstractX4OPhase implements X4OPhase {
|
|||
|
||||
/**
|
||||
* Empty method.
|
||||
*
|
||||
* @param elementLanguage The language to run phase for.
|
||||
* @throws X4OPhaseException when phase has error.
|
||||
*/
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
|
||||
public void debugPhaseMessage(X4OLanguageSession languageSession, String message) throws X4OPhaseException {
|
||||
if (!languageSession.hasX4ODebugWriter()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
languageSession.getX4ODebugWriter().debugPhaseMessage(message,this.getClass());
|
||||
languageSession.getX4ODebugWriter().debugPhaseMessage(message, this.getClass());
|
||||
} catch (ElementException ee) {
|
||||
throw new X4OPhaseException(this, ee);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -32,25 +32,24 @@ import org.x4o.xml.lang.X4OLanguageSession;
|
|||
import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
||||
|
||||
/**
|
||||
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order.
|
||||
* And will execute the phases when runPhases is called.
|
||||
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order. And will execute the phases when runPhases is called.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 6, 2008
|
||||
*/
|
||||
public class DefaultX4OPhaseManager implements X4OPhaseManagerLocal {
|
||||
|
||||
|
||||
/** The X4OPhaseHandler */
|
||||
private final List<X4OPhase> x4oPhases;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DefaultX4OPhaseManager() {
|
||||
x4oPhases = new ArrayList<X4OPhase>(25);
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
//@formatter:off
|
||||
PHASE_ORDER = { *startupX4OPhase,
|
||||
*createLanguagePhase,
|
||||
*createLanguageSiblingsPhase,
|
||||
|
|
@ -64,9 +63,9 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
*releasePhase
|
||||
};
|
||||
* = runOnce
|
||||
|
||||
//@formatter:on
|
||||
*/
|
||||
|
||||
|
||||
public X4OPhase getPhase(String phaseName) {
|
||||
for (X4OPhase phase : x4oPhases) {
|
||||
if (phase.getId().equals(phaseName)) {
|
||||
|
|
@ -75,7 +74,7 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getPhaseKeys() {
|
||||
List<String> result = new ArrayList<String>(x4oPhases.size());
|
||||
for (X4OPhase phase : x4oPhases) {
|
||||
|
|
@ -83,25 +82,27 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an X4OPhaseHandler.
|
||||
* @param phase The X4OPhaseHandler to add.
|
||||
*
|
||||
* @param phase The X4OPhaseHandler to add.
|
||||
*/
|
||||
public void addX4OPhase(X4OPhase phase) {
|
||||
if (phase==null) {
|
||||
if (phase == null) {
|
||||
throw new NullPointerException("Can't add null phase handler.");
|
||||
}
|
||||
// context is created in first phase.
|
||||
//if (X4OPhase.FIRST_PHASE.equals(elementLanguage.getCurrentX4OPhase())==false) {
|
||||
// context is created in first phase.
|
||||
// if (X4OPhase.FIRST_PHASE.equals(elementLanguage.getCurrentX4OPhase())==false) {
|
||||
// throw new IllegalStateException("Can't add new phases after first phase is completed.");
|
||||
//}
|
||||
// }
|
||||
x4oPhases.add(phase);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the X4OPhaseHandlers.
|
||||
* @return Returns all X4OPhaseHandlers.
|
||||
*
|
||||
* @return Returns all X4OPhaseHandlers.
|
||||
*/
|
||||
public List<X4OPhase> getAllPhases() {
|
||||
return new ArrayList<X4OPhase>(x4oPhases);
|
||||
|
|
@ -109,7 +110,8 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
|
||||
/**
|
||||
* Returns all the X4OPhaseHandlers in ordered list.
|
||||
* @return Returns all X4OPhaseHandler is order.
|
||||
*
|
||||
* @return Returns all X4OPhaseHandler is order.
|
||||
*/
|
||||
public List<X4OPhase> getOrderedPhases(X4OPhaseType type) {
|
||||
List<X4OPhase> result = new ArrayList<X4OPhase>(x4oPhases.size());
|
||||
|
|
@ -124,44 +126,45 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
|
||||
/**
|
||||
* Runs all the phases in the right order.
|
||||
*
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
public void runPhases(X4OLanguageSession languageSession, X4OPhaseType type) throws X4OPhaseException {
|
||||
// convert to local for state changes
|
||||
X4OLanguageSessionLocal languageSessionLocal = X4OLanguageSessionLocal.class.cast(languageSession);
|
||||
|
||||
|
||||
// sort for the order
|
||||
List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type);
|
||||
|
||||
|
||||
// debug output
|
||||
if (languageSession.getX4ODebugWriter() != null) {
|
||||
languageSession.getX4ODebugWriter().debugPhaseOrder(x4oPhasesOrder);
|
||||
}
|
||||
|
||||
|
||||
List<String> phaseSkip = languageSession.getPhaseSkip();
|
||||
String phaseStop = languageSession.getPhaseStop();
|
||||
|
||||
|
||||
// run the phases in ordered order
|
||||
for (X4OPhase phase : x4oPhasesOrder) {
|
||||
|
||||
|
||||
if (phaseSkip.contains(phase.getId())) {
|
||||
continue; // skip phase when requested by context
|
||||
}
|
||||
|
||||
|
||||
// debug output
|
||||
languageSessionLocal.setPhaseCurrent(phase);
|
||||
|
||||
|
||||
// run listeners
|
||||
for (X4OPhaseListener l : languageSessionLocal.storePhaseListeners(phase.getId())) {
|
||||
l.preRunPhase(phase, languageSession);
|
||||
}
|
||||
|
||||
|
||||
// always run endRunPhase for valid debug xml
|
||||
try {
|
||||
// do the run interface
|
||||
phase.runPhase(languageSession);
|
||||
|
||||
// run the element phase if possible
|
||||
|
||||
// run the element phase if possible
|
||||
executePhaseRoot(languageSession, phase);
|
||||
} finally {
|
||||
// run the listeners again
|
||||
|
|
@ -169,24 +172,25 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
l.endRunPhase(phase, languageSession);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (phaseStop != null && phaseStop.equals(phase.getId())) {
|
||||
return; // we are done
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs phase on single element.
|
||||
* @param e The Element to process.
|
||||
* @param p The phase to run.
|
||||
*
|
||||
* @param e The Element to process.
|
||||
* @param p The phase to run.
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
public void runPhasesForElement(Element e,X4OPhaseType type,X4OPhase p) throws X4OPhaseException {
|
||||
public void runPhasesForElement(Element e, X4OPhaseType type, X4OPhase p) throws X4OPhaseException {
|
||||
X4OLanguageSession languageSession = e.getLanguageSession();
|
||||
List<String> phaseSkip = languageSession.getPhaseSkip();
|
||||
String phaseStop = languageSession.getPhaseStop();
|
||||
|
||||
|
||||
// sort for the order
|
||||
List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type);
|
||||
for (X4OPhase phase : x4oPhasesOrder) {
|
||||
|
|
@ -196,24 +200,25 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
if (phaseSkip.contains(phase.getId())) {
|
||||
continue; // skip phase when requested by context
|
||||
}
|
||||
|
||||
|
||||
// set phase
|
||||
((X4OLanguageSessionLocal)languageSession).setPhaseCurrent(phase);
|
||||
|
||||
((X4OLanguageSessionLocal) languageSession).setPhaseCurrent(phase);
|
||||
|
||||
// do the run interface
|
||||
phase.runPhase(languageSession);
|
||||
|
||||
// run the element phase if possible
|
||||
|
||||
// run the element phase if possible
|
||||
executePhaseRoot(languageSession, phase);
|
||||
|
||||
|
||||
if (phaseStop != null && phaseStop.equals(phase.getId())) {
|
||||
return; // we are done
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run release phase manual if auto release is disabled by config.
|
||||
*
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
public void doReleasePhaseManual(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
|
|
@ -227,15 +232,15 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
}
|
||||
if (releaseRequested == null) {
|
||||
return; // No manual release requested
|
||||
//throw new IllegalStateException("No manual release requested.");
|
||||
// throw new IllegalStateException("No manual release requested.");
|
||||
}
|
||||
if (languageSession.getRootElement() == null) {
|
||||
return; // no root element , empty xml document ?
|
||||
return; // no root element , empty xml document ?
|
||||
}
|
||||
if (languageSession.getRootElement().getElementClass() == null) {
|
||||
throw new IllegalStateException("Release phase has already been runned.");
|
||||
}
|
||||
|
||||
|
||||
X4OPhase h = null;
|
||||
for (X4OPhase phase : x4oPhases) {
|
||||
if (phase.getId().equals(releaseRequested)) {
|
||||
|
|
@ -246,26 +251,26 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
if (h == null) {
|
||||
throw new IllegalStateException("No release phase found in manager to run.");
|
||||
}
|
||||
|
||||
|
||||
// set phase
|
||||
((X4OLanguageSessionLocal)languageSession).setPhaseCurrent(h);
|
||||
|
||||
((X4OLanguageSessionLocal) languageSession).setPhaseCurrent(h);
|
||||
|
||||
// do the run interface
|
||||
h.runPhase(languageSession);
|
||||
|
||||
// run the element phase if possible
|
||||
|
||||
// run the element phase if possible
|
||||
executePhaseRoot(languageSession, h);
|
||||
}
|
||||
|
||||
|
||||
class X4OPhaseComparator implements Comparator<X4OPhase> {
|
||||
/**
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public int compare(X4OPhase e1, X4OPhase e2) {
|
||||
|
||||
|
||||
String pid = e1.getId();
|
||||
String[] dpids = e2.getPhaseDependencies();
|
||||
|
||||
|
||||
for (int i = 0; i < dpids.length; i++) {
|
||||
String dpid = dpids[i];
|
||||
if (pid.equals(dpid)) {
|
||||
|
|
@ -273,69 +278,35 @@ PHASE_ORDER = { *startupX4OPhase,
|
|||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
/*
|
||||
if (p1==p2) {
|
||||
return 0;
|
||||
}
|
||||
if (p1==X4OPhase.debugPhase) {
|
||||
return 0;
|
||||
}
|
||||
if (p2==X4OPhase.debugPhase) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i1 = phaseOrder(p1);
|
||||
int i2 = phaseOrder(p2);
|
||||
|
||||
if (i1>i2) {
|
||||
return 1;
|
||||
}
|
||||
if (i1<i2) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
/*
|
||||
private int phaseOrder(X4OPhase check) {
|
||||
int result=0;
|
||||
for (X4OPhase p:X4OPhase.PHASE_ORDER) {
|
||||
if (p==check) {
|
||||
return result;
|
||||
}
|
||||
result++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute element phase handler on full tree.
|
||||
* @param phase The phase to run.
|
||||
* Execute element phase handler on full tree.
|
||||
*
|
||||
* @param phase The phase to run.
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
private void executePhaseRoot(X4OLanguageSession elementLanguage, X4OPhase phase) throws X4OPhaseException {
|
||||
if (elementLanguage.getRootElement() == null) {
|
||||
return;
|
||||
}
|
||||
executePhaseTree(elementLanguage.getRootElement(),phase);
|
||||
executePhaseTree(elementLanguage.getRootElement(), phase);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* todo: rewrite to itterator for big deep trees.
|
||||
*
|
||||
* @param element The element in the tree.
|
||||
* @param phase The phase to run.
|
||||
* @param element The element in the tree.
|
||||
* @param phase The phase to run.
|
||||
* @throws X4OPhaseException
|
||||
*/
|
||||
private void executePhaseTree(Element element, X4OPhase phase) throws X4OPhaseException {
|
||||
if (element.getElementClass() != null && element.getElementClass().getSkipPhases().contains(phase.getId()) == false) {
|
||||
phase.runElementPhase(element);
|
||||
phase.runElementPhase(element);
|
||||
}
|
||||
for (Element e:element.getChilderen()) {
|
||||
executePhaseTree(e,phase);
|
||||
for (Element e : element.getChilderen()) {
|
||||
executePhaseTree(e, phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
|
@ -32,42 +32,46 @@ import org.x4o.xml.lang.X4OLanguageSession;
|
|||
* @version 1.0 Dec 31, 2008
|
||||
*/
|
||||
public interface X4OPhase {
|
||||
|
||||
|
||||
X4OPhaseType getType();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the X4OPhase for which this handler was written.
|
||||
* @return Returns the phase for which this handler works.
|
||||
*
|
||||
* @return Returns the phase for which this handler works.
|
||||
*/
|
||||
String getId();
|
||||
|
||||
|
||||
String[] getPhaseDependencies();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a flag indicating that this phase is runnable multiple times.
|
||||
* @return True if phase is restricted to run once.
|
||||
*
|
||||
* @return True if phase is restricted to run once.
|
||||
*/
|
||||
boolean isRunOnce();
|
||||
|
||||
|
||||
/**
|
||||
* Runs this phase.
|
||||
* @param elementLanguage The elementLanguage running this phase.
|
||||
* @throws X4OPhaseException When error has happend.
|
||||
*
|
||||
* @param elementLanguage The elementLanguage running this phase.
|
||||
* @throws X4OPhaseException When error has happend.
|
||||
*/
|
||||
void runPhase(X4OLanguageSession elementLanguage) throws X4OPhaseException;
|
||||
|
||||
|
||||
/**
|
||||
* runPhase is called but should do nothig.
|
||||
* When elementPhase is enables x4o tries to merge all element phases so
|
||||
* we don't need to loop element tree to often.
|
||||
* @return True if to run in config.
|
||||
* runPhase is called but should do nothig. When elementPhase is enables x4o tries to merge all element phases so we don't need to loop element tree to
|
||||
* often.
|
||||
*
|
||||
* @return True if to run in config.
|
||||
*/
|
||||
boolean isElementPhase();
|
||||
|
||||
|
||||
/**
|
||||
* Run this phase for this Element.
|
||||
* @param element The element to run this phase for.
|
||||
* @throws X4OPhaseException Is thrown when error has happen.
|
||||
*
|
||||
* @param element The element to run this phase for.
|
||||
* @throws X4OPhaseException Is thrown when error has happen.
|
||||
*/
|
||||
void runElementPhase(Element element) throws X4OPhaseException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
/**
|
||||
* Is throw when there is en Exception within an Element.
|
||||
|
|
@ -33,42 +33,46 @@ public class X4OPhaseException extends Exception {
|
|||
/** The serial version uid */
|
||||
static final long serialVersionUID = 10L;
|
||||
|
||||
private X4OPhase exceptionPhase = null;
|
||||
|
||||
private X4OPhase exceptionPhase = null;
|
||||
|
||||
/**
|
||||
* Creates an ElementException from a parent exception.
|
||||
* @param exceptionPhase The handler which throwed.
|
||||
* @param e The Exception.
|
||||
*
|
||||
* @param exceptionPhase The handler which throwed.
|
||||
* @param e The Exception.
|
||||
*/
|
||||
public X4OPhaseException(X4OPhase exceptionPhase,Exception e) {
|
||||
public X4OPhaseException(X4OPhase exceptionPhase, Exception e) {
|
||||
super(e);
|
||||
this.exceptionPhase=exceptionPhase;
|
||||
this.exceptionPhase = exceptionPhase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an ElementException from a parent exception.
|
||||
* @param exceptionPhase The handler which throwed.
|
||||
* @param message The message of the error.
|
||||
*
|
||||
* @param exceptionPhase The handler which throwed.
|
||||
* @param message The message of the error.
|
||||
*/
|
||||
public X4OPhaseException(X4OPhase exceptionPhase,String message) {
|
||||
public X4OPhaseException(X4OPhase exceptionPhase, String message) {
|
||||
super(message);
|
||||
this.exceptionPhase=exceptionPhase;
|
||||
this.exceptionPhase = exceptionPhase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an ElementException from a parent exception.
|
||||
* @param exceptionPhase The handler which throwed.
|
||||
* @param message The message of the error.
|
||||
* @param e The Exception.
|
||||
*
|
||||
* @param exceptionPhase The handler which throwed.
|
||||
* @param message The message of the error.
|
||||
* @param e The Exception.
|
||||
*/
|
||||
public X4OPhaseException(X4OPhase exceptionPhase,String message,Exception e) {
|
||||
super(message,e);
|
||||
this.exceptionPhase=exceptionPhase;
|
||||
public X4OPhaseException(X4OPhase exceptionPhase, String message, Exception e) {
|
||||
super(message, e);
|
||||
this.exceptionPhase = exceptionPhase;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the X4OPhaseHandler which created this Exception.
|
||||
* @return An X4OPhaseHandler
|
||||
*
|
||||
* @return An X4OPhaseHandler
|
||||
*/
|
||||
public X4OPhase getX4OPhaseHandler() {
|
||||
return exceptionPhase;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -46,18 +46,18 @@ public class X4OPhaseLanguageInit {
|
|||
public static final String INIT_LANG = "INIT_LANG";
|
||||
public static final String INIT_LANG_SIB = "INIT_LANG_SIB";
|
||||
public static final String INIT_END = "INIT_END";
|
||||
|
||||
|
||||
public X4OPhaseLanguageInit() {
|
||||
logger = Logger.getLogger(X4OPhaseLanguageInit.class.getName());
|
||||
}
|
||||
|
||||
|
||||
public void createPhases(X4OPhaseManagerLocal manager) {
|
||||
manager.addX4OPhase(new X4OPhaseInitStart());
|
||||
manager.addX4OPhase(new X4OPhaseInitLanguage());
|
||||
manager.addX4OPhase(new X4OPhaseInitLanguageSiblings());
|
||||
manager.addX4OPhase(new X4OPhaseInitEnd());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the X4OPhaseInitStart which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -65,86 +65,104 @@ public class X4OPhaseLanguageInit {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.INIT;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return INIT_START;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{};
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
logger.finest("Run init start phase");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Loads all the modules a language.
|
||||
* Then creates the ElementProviders
|
||||
* Loads all the modules a language. Then creates the ElementProviders
|
||||
*/
|
||||
class X4OPhaseInitLanguage extends AbstractX4OPhase {
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.INIT;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return INIT_LANG;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{INIT_START};
|
||||
return new String[] { INIT_START };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
try {
|
||||
debugPhaseMessage(languageSession, "Load main language: " + languageSession.getLanguage().getLanguageName());
|
||||
X4OLanguageLoader loader = X4OLanguageClassLoader.newInstance(X4OLanguageLoader.class, languageSession.getLanguage().getLanguageConfiguration().getDefaultLanguageLoader());
|
||||
X4OLanguageLocal language = (X4OLanguageLocal)languageSession.getLanguage();
|
||||
loader.loadLanguage(languageSession, language, language.getLanguageName(), language.getLanguageVersion());
|
||||
|
||||
X4OLanguageLoader loader = X4OLanguageClassLoader.newInstance(X4OLanguageLoader.class,
|
||||
languageSession.getLanguage().getLanguageConfiguration().getDefaultLanguageLoader());
|
||||
X4OLanguageLocal language = (X4OLanguageLocal) languageSession.getLanguage();
|
||||
loader.loadLanguage(languageSession, language, language.getLanguageName(), language.getLanguageVersion());
|
||||
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
languageSession.getX4ODebugWriter().debugElementLanguageModules(languageSession);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Loads all sibling languages.
|
||||
*/
|
||||
public class X4OPhaseInitLanguageSiblings extends AbstractX4OPhase {
|
||||
private List<X4OLanguageModuleLoaderSibling> siblingLoaders = new ArrayList<X4OLanguageModuleLoaderSibling>(2);
|
||||
|
||||
// mmmm think of better then cast
|
||||
public void addLanguageModuleLoaderSibling(X4OLanguageModuleLoaderSibling loader) {
|
||||
siblingLoaders.add(loader);
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.INIT;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return INIT_LANG_SIB;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {INIT_LANG};
|
||||
return new String[] { INIT_LANG };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
try {
|
||||
if (siblingLoaders.isEmpty()==false) {
|
||||
X4OLanguageLoader loader = X4OLanguageClassLoader.newInstance(X4OLanguageLoader.class, languageSession.getLanguage().getLanguageConfiguration().getDefaultLanguageLoader());
|
||||
X4OLanguageLocal language = (X4OLanguageLocal)languageSession.getLanguage();
|
||||
for (X4OLanguageModuleLoaderSibling siblingLoader:siblingLoaders) {
|
||||
if (siblingLoaders.isEmpty() == false) {
|
||||
X4OLanguageLoader loader = X4OLanguageClassLoader.newInstance(X4OLanguageLoader.class,
|
||||
languageSession.getLanguage().getLanguageConfiguration().getDefaultLanguageLoader());
|
||||
X4OLanguageLocal language = (X4OLanguageLocal) languageSession.getLanguage();
|
||||
for (X4OLanguageModuleLoaderSibling siblingLoader : siblingLoaders) {
|
||||
debugPhaseMessage(languageSession, "Loading sibling langauge loader: " + siblingLoader);
|
||||
siblingLoader.loadLanguageSibling(languageSession, language, loader);
|
||||
}
|
||||
|
|
@ -154,11 +172,11 @@ public class X4OPhaseLanguageInit {
|
|||
siblingLoaders.clear();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates the X4OPhaseInitEnd which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -166,17 +184,22 @@ public class X4OPhaseLanguageInit {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.INIT;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return INIT_END;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{INIT_LANG_SIB};
|
||||
return new String[] { INIT_LANG_SIB };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
logger.finest("Run init end phase");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -68,48 +68,48 @@ public class X4OPhaseLanguageRead {
|
|||
public static final String READ_RUN_DIRTY_LAST = "READ_RUN_DIRTY_LAST";
|
||||
public static final String READ_END = "READ_END";
|
||||
public static final String READ_RELEASE = "READ_RELEASE";
|
||||
|
||||
|
||||
public X4OPhaseLanguageRead() {
|
||||
logger = Logger.getLogger(X4OPhaseLanguageRead.class.getName());
|
||||
}
|
||||
|
||||
|
||||
public void createPhases(X4OPhaseManagerLocal manager) {
|
||||
|
||||
|
||||
// meta start point
|
||||
manager.addX4OPhase(new X4OPhaseReadBegin());
|
||||
|
||||
|
||||
// config
|
||||
X4OPhaseReadRunConfigurator runConf = new X4OPhaseReadRunConfigurator();
|
||||
manager.addX4OPhase(new X4OPhaseReadConfigElement(runConf));
|
||||
manager.addX4OPhase(new X4OPhaseReadConfigElementInterface(runConf));
|
||||
manager.addX4OPhase(new X4OPhaseReadConfigGlobalElement(runConf));
|
||||
manager.addX4OPhase(new X4OPhaseReadConfigGlobalAttribute(runConf));
|
||||
|
||||
|
||||
// run all attribute events
|
||||
manager.addX4OPhase(new X4OPhaseReadRunAttribute());
|
||||
|
||||
|
||||
// templating
|
||||
manager.addX4OPhase(new X4OPhaseReadFillTemplate());
|
||||
|
||||
|
||||
// transforming
|
||||
manager.addX4OPhase(new X4OPhaseReadTransform());
|
||||
manager.addX4OPhase(new X4OPhaseReadRunDirty(manager));
|
||||
|
||||
|
||||
// binding elements
|
||||
manager.addX4OPhase(new X4OPhaseReadBindElement());
|
||||
|
||||
|
||||
// runing and releasing
|
||||
manager.addX4OPhase(new X4OPhaseReadRun());
|
||||
manager.addX4OPhase(runConf);
|
||||
manager.addX4OPhase(new X4OPhaseReadRunDirtyLast(manager));
|
||||
manager.addX4OPhase(new X4OPhaseReadEnd());
|
||||
|
||||
|
||||
// after release phase Element Tree is not avible anymore
|
||||
manager.addX4OPhase(releasePhase());
|
||||
|
||||
|
||||
// We are done
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the startX4OPhase which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -117,57 +117,67 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_BEGIN;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{};
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
// not used.
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
// print the properties and classes for this language/config
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
try {
|
||||
//languageSession.getX4ODebugWriter().debugLanguageProperties(languageSession);
|
||||
// languageSession.getX4ODebugWriter().debugLanguageProperties(languageSession);
|
||||
languageSession.getX4ODebugWriter().debugLanguageDefaultClasses(languageSession);
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadConfigElement
|
||||
*/
|
||||
class X4OPhaseReadConfigElement extends AbstractX4OPhase {
|
||||
private X4OPhaseReadRunConfigurator runConf = null;
|
||||
|
||||
public X4OPhaseReadConfigElement(X4OPhaseReadRunConfigurator runConf) {
|
||||
this.runConf=runConf;
|
||||
this.runConf = runConf;
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_CONFIG_ELEMENT;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_BEGIN};
|
||||
return new String[] { READ_BEGIN };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
|
||||
|
||||
// First phase is to rename attributes, maybe move so sax phase
|
||||
for (ElementClassAttribute eca:element.getElementClass().getElementClassAttributes()) {
|
||||
for (ElementClassAttribute eca : element.getElementClass().getElementClassAttributes()) {
|
||||
List<String> aliases = eca.getAttributeAliases();
|
||||
if (aliases.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (String alias:aliases) {
|
||||
for (String alias : aliases) {
|
||||
if (element.getAttributes().containsKey(alias)) {
|
||||
String attributeValue = element.getAttributes().get(alias);
|
||||
element.getAttributes().put(eca.getId(), attributeValue);
|
||||
|
|
@ -175,122 +185,138 @@ public class X4OPhaseLanguageRead {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.finest("Do ElementClass Config Configurators: "+element.getElementClass().getElementConfigurators().size());
|
||||
for (ElementConfigurator ec:element.getElementClass().getElementConfigurators()) {
|
||||
runConf.runElementConfigurator(ec,element,this);
|
||||
|
||||
logger.finest("Do ElementClass Config Configurators: " + element.getElementClass().getElementConfigurators().size());
|
||||
for (ElementConfigurator ec : element.getElementClass().getElementConfigurators()) {
|
||||
runConf.runElementConfigurator(ec, element, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadConfigElementInterface
|
||||
*/
|
||||
class X4OPhaseReadConfigElementInterface extends AbstractX4OPhase {
|
||||
private X4OPhaseReadRunConfigurator runConf = null;
|
||||
|
||||
public X4OPhaseReadConfigElementInterface(X4OPhaseReadRunConfigurator runConf) {
|
||||
this.runConf=runConf;
|
||||
this.runConf = runConf;
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_CONFIG_ELEMENT_INTERFACE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_CONFIG_ELEMENT};
|
||||
return new String[] { READ_CONFIG_ELEMENT };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
if (element.getElementObject()==null) {
|
||||
if (element.getElementObject() == null) {
|
||||
logger.finest("Null elementObject skipping, interfaces");
|
||||
return;
|
||||
}
|
||||
for (ElementInterface ei:element.getLanguageSession().getLanguage().findElementInterfaces(element.getElementObject())) {
|
||||
logger.finest("Do ElementInterface Config Configurators: "+ei.getElementConfigurators().size());
|
||||
for (ElementConfigurator ec:ei.getElementConfigurators()) {
|
||||
runConf.runElementConfigurator(ec,element,this);
|
||||
for (ElementInterface ei : element.getLanguageSession().getLanguage().findElementInterfaces(element.getElementObject())) {
|
||||
logger.finest("Do ElementInterface Config Configurators: " + ei.getElementConfigurators().size());
|
||||
for (ElementConfigurator ec : ei.getElementConfigurators()) {
|
||||
runConf.runElementConfigurator(ec, element, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadConfigGlobalElement
|
||||
*/
|
||||
class X4OPhaseReadConfigGlobalElement extends AbstractX4OPhase {
|
||||
private X4OPhaseReadRunConfigurator runConf = null;
|
||||
|
||||
public X4OPhaseReadConfigGlobalElement(X4OPhaseReadRunConfigurator runConf) {
|
||||
this.runConf=runConf;
|
||||
this.runConf = runConf;
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_CONFIG_GLOBAL_ELEMENT;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_CONFIG_ELEMENT,READ_CONFIG_ELEMENT_INTERFACE};
|
||||
return new String[] { READ_CONFIG_ELEMENT, READ_CONFIG_ELEMENT_INTERFACE };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
for (X4OLanguageModule mod:element.getLanguageSession().getLanguage().getLanguageModules()) {
|
||||
logger.finest("Do Element Config Global Configurators: "+mod.getElementConfiguratorGlobals().size());
|
||||
for (ElementConfiguratorGlobal ec:mod.getElementConfiguratorGlobals()) {
|
||||
runConf.runElementConfigurator(ec,element,this);
|
||||
for (X4OLanguageModule mod : element.getLanguageSession().getLanguage().getLanguageModules()) {
|
||||
logger.finest("Do Element Config Global Configurators: " + mod.getElementConfiguratorGlobals().size());
|
||||
for (ElementConfiguratorGlobal ec : mod.getElementConfiguratorGlobals()) {
|
||||
runConf.runElementConfigurator(ec, element, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadConfigGlobalAttribute
|
||||
*/
|
||||
class X4OPhaseReadConfigGlobalAttribute extends AbstractX4OPhase {
|
||||
Comparator<ElementNamespaceAttribute> elementNamespaceAttributeComparator = null;
|
||||
private X4OPhaseReadRunConfigurator runConf = null;
|
||||
|
||||
public X4OPhaseReadConfigGlobalAttribute(X4OPhaseReadRunConfigurator runConf) {
|
||||
this.runConf=runConf;
|
||||
this.runConf = runConf;
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_CONFIG_GLOBAL_ATTRIBUTE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_CONFIG_GLOBAL_ELEMENT};
|
||||
return new String[] { READ_CONFIG_GLOBAL_ELEMENT };
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
if (elementNamespaceAttributeComparator==null) {
|
||||
if (elementNamespaceAttributeComparator == null) {
|
||||
try {
|
||||
elementNamespaceAttributeComparator = (Comparator<ElementNamespaceAttribute>)X4OLanguageClassLoader.newInstance(element.getLanguageSession().getLanguage().getLanguageConfiguration().getDefaultElementNamespaceAttributeComparator());
|
||||
elementNamespaceAttributeComparator = (Comparator<ElementNamespaceAttribute>) X4OLanguageClassLoader
|
||||
.newInstance(element.getLanguageSession().getLanguage().getLanguageConfiguration().getDefaultElementNamespaceAttributeComparator());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// do global parameters
|
||||
logger.finest("Do Element Global AttributeHandlers.");
|
||||
List<ElementNamespaceAttribute> handlers = new ArrayList<ElementNamespaceAttribute>();
|
||||
for (X4OLanguageModule mod:element.getLanguageSession().getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespace ns:mod.getElementNamespaces()) {
|
||||
for (ElementNamespaceAttribute global:ns.getElementNamespaceAttributes()) {
|
||||
for (X4OLanguageModule mod : element.getLanguageSession().getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespace ns : mod.getElementNamespaces()) {
|
||||
for (ElementNamespaceAttribute global : ns.getElementNamespaceAttributes()) {
|
||||
String attribute = element.getAttributes().get(global.getAttributeName());
|
||||
if (attribute!=null) {
|
||||
if (attribute != null) {
|
||||
handlers.add(global);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(handlers,elementNamespaceAttributeComparator);
|
||||
Collections.sort(handlers, elementNamespaceAttributeComparator);
|
||||
List<ElementConfigurator> handlers2 = new ArrayList<ElementConfigurator>(handlers.size());
|
||||
handlers2.addAll(handlers);
|
||||
for (ElementConfigurator ec:handlers) {
|
||||
runConf.runElementConfigurator(ec,element,this);
|
||||
for (ElementConfigurator ec : handlers) {
|
||||
runConf.runElementConfigurator(ec, element, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadRunAttribute
|
||||
*/
|
||||
|
|
@ -298,75 +324,78 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_RUN_ATTRIBUTE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_CONFIG_GLOBAL_ATTRIBUTE};
|
||||
return new String[] { READ_CONFIG_GLOBAL_ATTRIBUTE };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
// we only can config ElementObjects
|
||||
if (element.getElementObject()==null) {
|
||||
if (element.getElementObject() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// do config
|
||||
Map<String,String> attr = element.getAttributes();
|
||||
Map<String, String> attr = element.getAttributes();
|
||||
ElementAttributeValueParser attrParser = element.getLanguageSession().getElementAttributeValueParser();
|
||||
Boolean autoAttributes = element.getElementClass().getAutoAttributes();
|
||||
if (autoAttributes==null) {
|
||||
if (autoAttributes == null) {
|
||||
autoAttributes = true;
|
||||
}
|
||||
try {
|
||||
for (String name:attr.keySet()) {
|
||||
String valueString = (String)attr.get(name);
|
||||
if (valueString==null) {
|
||||
for (String name : attr.keySet()) {
|
||||
String valueString = (String) attr.get(name);
|
||||
if (valueString == null) {
|
||||
continue;
|
||||
}
|
||||
Object value = valueString;
|
||||
ElementClassAttribute attrClass = element.getElementClass().getElementClassAttributeByName(name);
|
||||
if (attrClass!=null) {
|
||||
if (attrClass.getRunResolveEL()==null || attrClass.getRunResolveEL() && attrParser.isELParameter(name, valueString, element)) {
|
||||
if (attrClass != null) {
|
||||
if (attrClass.getRunResolveEL() == null || attrClass.getRunResolveEL() && attrParser.isELParameter(name, valueString, element)) {
|
||||
value = attrParser.getELParameterValue(valueString, element);
|
||||
}
|
||||
if (attrClass.getRunConverters()==null || attrClass.getRunConverters()) {
|
||||
if (attrClass.getRunConverters() == null || attrClass.getRunConverters()) {
|
||||
value = attrParser.getConvertedParameterValue(name, value, element);
|
||||
}
|
||||
if (attrClass.getRunBeanValue()==null || attrClass.getRunBeanValue()) {
|
||||
if (attrClass.getRunBeanValue() == null || attrClass.getRunBeanValue()) {
|
||||
element.getLanguageSession().getElementObjectPropertyValue().setProperty(element.getElementObject(), name, value);
|
||||
}
|
||||
} else if (autoAttributes) {
|
||||
|
||||
value = attrParser.getParameterValue(name,valueString,element);
|
||||
|
||||
value = attrParser.getParameterValue(name, valueString, element);
|
||||
element.getLanguageSession().getElementObjectPropertyValue().setProperty(element.getElementObject(), name, value);
|
||||
|
||||
|
||||
} else {
|
||||
continue; // skip all non auto attribute non attribute defined xml attributes, or throw exception ?
|
||||
}
|
||||
}
|
||||
// check for defaults
|
||||
for (ElementClassAttribute attrClass:element.getElementClass().getElementClassAttributes()) {
|
||||
if (attrClass.getDefaultValue()!=null && attr.containsKey(attrClass.getId())==false) {
|
||||
for (ElementClassAttribute attrClass : element.getElementClass().getElementClassAttributes()) {
|
||||
if (attrClass.getDefaultValue() != null && attr.containsKey(attrClass.getId()) == false) {
|
||||
Object value = null;
|
||||
if (attrClass.getDefaultValue() instanceof String) {
|
||||
value = attrParser.getParameterValue(attrClass.getId(),(String)attrClass.getDefaultValue(),element);
|
||||
value = attrParser.getParameterValue(attrClass.getId(), (String) attrClass.getDefaultValue(), element);
|
||||
} else {
|
||||
value = attrClass.getDefaultValue();
|
||||
}
|
||||
if (attrClass.getRunBeanValue()==null || attrClass.getRunBeanValue()) {
|
||||
if (attrClass.getRunBeanValue() == null || attrClass.getRunBeanValue()) {
|
||||
element.getLanguageSession().getElementObjectPropertyValue().setProperty(element.getElementObject(), attrClass.getId(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ObjectConverterException oce) {
|
||||
throw new X4OPhaseException(this,"Error while converting parameters: "+oce.getMessage(),oce);
|
||||
throw new X4OPhaseException(this, "Error while converting parameters: " + oce.getMessage(), oce);
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,"Error while setting parameters: "+e.getMessage(),e);
|
||||
throw new X4OPhaseException(this, "Error while setting parameters: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadFillTemplate
|
||||
*/
|
||||
|
|
@ -374,16 +403,19 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_FILL_TEMPLATE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_RUN_ATTRIBUTE};
|
||||
return new String[] { READ_RUN_ATTRIBUTE };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadTransform
|
||||
*/
|
||||
|
|
@ -391,14 +423,17 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_TRANSFORM;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_FILL_TEMPLATE};
|
||||
return new String[] { READ_FILL_TEMPLATE };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
if (element.isTransformingTree()==false) {
|
||||
if (element.isTransformingTree() == false) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
@ -407,28 +442,33 @@ public class X4OPhaseLanguageRead {
|
|||
}
|
||||
element.doElementRun();
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadRunDirty
|
||||
*/
|
||||
class X4OPhaseReadRunDirty extends AbstractX4OPhase {
|
||||
private X4OPhaseManager phaseManager = null;
|
||||
|
||||
public X4OPhaseReadRunDirty(X4OPhaseManager phaseManager) {
|
||||
this.phaseManager = phaseManager;
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_RUN_DIRTY;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_TRANSFORM};
|
||||
return new String[] { READ_TRANSFORM };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
List<Element> dirtyElements = element.getLanguageSession().getDirtyElements();
|
||||
if (dirtyElements.isEmpty()) {
|
||||
|
|
@ -437,7 +477,7 @@ public class X4OPhaseLanguageRead {
|
|||
debugPhaseMessage(element.getLanguageSession(), "Dirty elements: " + dirtyElements.size());
|
||||
X4OPhase p = phaseManager.getPhase(READ_BEGIN);
|
||||
for (Element e : dirtyElements) {
|
||||
phaseManager.runPhasesForElement(e,getType(), p);
|
||||
phaseManager.runPhasesForElement(e, getType(), p);
|
||||
}
|
||||
element.getLanguageSession().getDirtyElements().clear();
|
||||
}
|
||||
|
|
@ -448,18 +488,23 @@ public class X4OPhaseLanguageRead {
|
|||
*/
|
||||
class X4OPhaseReadRunDirtyLast extends AbstractX4OPhase {
|
||||
private X4OPhaseManager phaseManager = null;
|
||||
|
||||
public X4OPhaseReadRunDirtyLast(X4OPhaseManager phaseManager) {
|
||||
this.phaseManager = phaseManager;
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_RUN_DIRTY_LAST;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_RUN};
|
||||
return new String[] { READ_RUN };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
List<Element> dirtyElements = element.getLanguageSession().getDirtyElements();
|
||||
if (dirtyElements.isEmpty()) {
|
||||
|
|
@ -468,12 +513,12 @@ public class X4OPhaseLanguageRead {
|
|||
debugPhaseMessage(element.getLanguageSession(), "Dirty elements last: " + dirtyElements.size());
|
||||
X4OPhase p = phaseManager.getPhase(READ_BEGIN);
|
||||
for (Element e : dirtyElements) {
|
||||
phaseManager.runPhasesForElement(e,getType(), p);
|
||||
phaseManager.runPhasesForElement(e, getType(), p);
|
||||
}
|
||||
element.getLanguageSession().getDirtyElements().clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadBindElement
|
||||
*/
|
||||
|
|
@ -481,44 +526,47 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_BIND_ELEMENT;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_RUN_DIRTY};
|
||||
return new String[] { READ_RUN_DIRTY };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
Element parentElement = element.getParent();
|
||||
if(parentElement==null) {
|
||||
if (parentElement == null) {
|
||||
logger.finest("No parent element, so no binding needed.");
|
||||
return;
|
||||
}
|
||||
Object parentObject = parentElement.getElementObject();
|
||||
if(parentObject==null) {
|
||||
if (parentObject == null) {
|
||||
logger.finest("No parent object, so no binding needed.");
|
||||
return;
|
||||
}
|
||||
Object childObject = element.getElementObject();
|
||||
if (childObject==null) {
|
||||
if (childObject == null) {
|
||||
logger.finest("No child object, so no binding needed.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
List<ElementBindingHandler> binds = element.getLanguageSession().getLanguage().findElementBindingHandlers(parentObject, childObject);
|
||||
logger.finest("Calling bindings handlers; "+binds.size());
|
||||
logger.finest("Calling bindings handlers; " + binds.size());
|
||||
try {
|
||||
for (ElementBindingHandler binding:binds) {
|
||||
for (ElementBindingHandler binding : binds) {
|
||||
if (element.getLanguageSession().hasX4ODebugWriter()) {
|
||||
element.getLanguageSession().getX4ODebugWriter().debugElementBindingHandler(binding,element);
|
||||
element.getLanguageSession().getX4ODebugWriter().debugElementBindingHandler(binding, element);
|
||||
}
|
||||
binding.bindChild(element);
|
||||
}
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,"Error while binding",e);
|
||||
throw new X4OPhaseException(this, "Error while binding", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadRun
|
||||
*/
|
||||
|
|
@ -526,88 +574,101 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_RUN;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_BIND_ELEMENT};
|
||||
return new String[] { READ_BIND_ELEMENT };
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
if (element.isTransformingTree()) {
|
||||
return; // has already runned.
|
||||
}
|
||||
try {
|
||||
//if (element.getlanguageSession().hasX4ODebugWriter()) {
|
||||
// element.getlanguageSession().getX4ODebugWriter().debugElement(element);
|
||||
//}
|
||||
// if (element.getlanguageSession().hasX4ODebugWriter()) {
|
||||
// element.getlanguageSession().getX4ODebugWriter().debugElement(element);
|
||||
// }
|
||||
element.doElementRun();
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class X4OPhaseReadRunConfigurator extends AbstractX4OPhase {
|
||||
private List<RunConfigurator> runConf = null;
|
||||
|
||||
protected X4OPhaseReadRunConfigurator() {
|
||||
runConf = new ArrayList<RunConfigurator>(10);
|
||||
}
|
||||
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_RUN_CONFIGURATOR;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_RUN};
|
||||
return new String[] { READ_RUN };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
for (RunConfigurator conf:runConf) {
|
||||
for (RunConfigurator conf : runConf) {
|
||||
try {
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
languageSession.getX4ODebugWriter().debugElementConfigurator(conf.elementConfigurator,conf.element);
|
||||
languageSession.getX4ODebugWriter().debugElementConfigurator(conf.elementConfigurator, conf.element);
|
||||
}
|
||||
conf.elementConfigurator.doConfigElement(conf.element);
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
|
||||
class RunConfigurator {
|
||||
Element element;
|
||||
ElementConfigurator elementConfigurator;
|
||||
RunConfigurator(Element element,ElementConfigurator elementConfigurator) {
|
||||
this.element=element;
|
||||
this.elementConfigurator=elementConfigurator;
|
||||
|
||||
RunConfigurator(Element element, ElementConfigurator elementConfigurator) {
|
||||
this.element = element;
|
||||
this.elementConfigurator = elementConfigurator;
|
||||
}
|
||||
}
|
||||
public void runElementConfigurator(ElementConfigurator ec,Element e,X4OPhase phase) throws X4OPhaseException {
|
||||
|
||||
public void runElementConfigurator(ElementConfigurator ec, Element e, X4OPhase phase) throws X4OPhaseException {
|
||||
if (ec.isConfigAction()) {
|
||||
runConf.add(new RunConfigurator(e,ec));
|
||||
runConf.add(new RunConfigurator(e, ec));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (e.getLanguageSession().hasX4ODebugWriter()) {
|
||||
e.getLanguageSession().getX4ODebugWriter().debugElementConfigurator(ec,e);
|
||||
e.getLanguageSession().getX4ODebugWriter().debugElementConfigurator(ec, e);
|
||||
}
|
||||
ec.doConfigElement(e);
|
||||
|
||||
// may request rerun of config
|
||||
|
||||
// may request rerun of config
|
||||
if (ec.isConfigAction()) {
|
||||
runConf.add(new RunConfigurator(e,ec));
|
||||
runConf.add(new RunConfigurator(e, ec));
|
||||
}
|
||||
} catch (ElementException ee) {
|
||||
throw new X4OPhaseException(phase,ee);
|
||||
throw new X4OPhaseException(phase, ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* X4OPhaseReadEnd Is the read end phase.
|
||||
*/
|
||||
|
|
@ -615,87 +676,81 @@ public class X4OPhaseLanguageRead {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_END;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{READ_RUN_CONFIGURATOR};
|
||||
return new String[] { READ_RUN_CONFIGURATOR };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
// not used.
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
// print the properties and classes for this language/config
|
||||
if (languageSession.hasX4ODebugWriter()) {
|
||||
try {
|
||||
languageSession.getX4ODebugWriter().debugLanguageDefaultClasses(languageSession);
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The X4OPhaseHandler for this phase.
|
||||
* @return The X4OPhaseHandler for this phase.
|
||||
*/
|
||||
public X4OPhase releasePhase() {
|
||||
|
||||
|
||||
// for debug output TODO: redo release counters
|
||||
/*
|
||||
class ReleasePhaseListener implements X4OPhaseListener {
|
||||
private int elementsReleased = 0;
|
||||
public void preRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
elementsReleased=0;
|
||||
}
|
||||
public void endRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
if (languageSession.hasX4ODebugWriter()==false) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "elements", "", "", elementsReleased+"");
|
||||
languageSession.getX4ODebugWriter().getContentWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts);
|
||||
languageSession.getX4ODebugWriter().getContentWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , "");
|
||||
} catch (SAXException e) {
|
||||
throw new X4OPhaseException(phase,e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addReleasedElement() {
|
||||
elementsReleased++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
|
||||
* class ReleasePhaseListener implements X4OPhaseListener { private int elementsReleased = 0; public void preRunPhase(X4OPhase phase,X4OLanguageSession
|
||||
* languageSession) throws X4OPhaseException { elementsReleased=0; } public void endRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws
|
||||
* X4OPhaseException { if (languageSession.hasX4ODebugWriter()==false) { return; } try { AttributesImpl atts = new AttributesImpl(); atts.addAttribute
|
||||
* ("", "elements", "", "", elementsReleased+""); languageSession.getX4ODebugWriter().getContentWriter().startElement (X4ODebugWriter.DEBUG_URI,
|
||||
* "executeReleases", "", atts); languageSession.getX4ODebugWriter().getContentWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , ""); }
|
||||
* catch (SAXException e) { throw new X4OPhaseException(phase,e); } }
|
||||
*
|
||||
* public void addReleasedElement() { elementsReleased++; } }
|
||||
*/
|
||||
|
||||
// final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
|
||||
X4OPhase result = new AbstractX4OPhase() {
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_READ;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return READ_RELEASE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {READ_END};
|
||||
return new String[] { READ_END };
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
}
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
try {
|
||||
element.release();
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
}// finally {
|
||||
// releaseCounter.addReleasedElement();
|
||||
//}
|
||||
throw new X4OPhaseException(this, e);
|
||||
} // finally {
|
||||
// releaseCounter.addReleasedElement();
|
||||
// }
|
||||
}
|
||||
};
|
||||
//result.addPhaseListener(releaseCounter);
|
||||
// result.addPhaseListener(releaseCounter);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
|
@ -47,18 +47,18 @@ public class X4OPhaseLanguageWrite {
|
|||
public static final String WRITE_FILL_TREE = "WRITE_FILL_TREE";
|
||||
public static final String WRITE_END = "WRITE_END";
|
||||
public static final String WRITE_RELEASE = "WRITE_RELEASE";
|
||||
|
||||
|
||||
public X4OPhaseLanguageWrite() {
|
||||
logger = Logger.getLogger(X4OPhaseLanguageWrite.class.getName());
|
||||
}
|
||||
|
||||
|
||||
public void createPhases(X4OPhaseManagerLocal manager) {
|
||||
manager.addX4OPhase(new X4OPhaseWriteBegin());
|
||||
manager.addX4OPhase(new X4OPhaseWriteFillTree());
|
||||
manager.addX4OPhase(new X4OPhaseWriteEnd());
|
||||
//manager.addX4OPhase(new X4OPhaseWriteRelease());
|
||||
// manager.addX4OPhase(new X4OPhaseWriteRelease());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the X4OPhaseWriteBegin which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -66,22 +66,27 @@ public class X4OPhaseLanguageWrite {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_WRITE;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return WRITE_BEGIN;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{};
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
logger.finest("Run init begin phase");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Fills the element tree
|
||||
*/
|
||||
|
|
@ -89,77 +94,84 @@ public class X4OPhaseLanguageWrite {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_WRITE;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return WRITE_FILL_TREE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{WRITE_BEGIN};
|
||||
return new String[] { WRITE_BEGIN };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
try {
|
||||
Element root = languageSession.getRootElement();
|
||||
// TODO: check for read tree then write support as ec is not null then ..
|
||||
if (root.getElementClass()==null) {
|
||||
root = fillElementTree(languageSession,root.getElementObject());
|
||||
if (root.getElementClass() == null) {
|
||||
root = fillElementTree(languageSession, root.getElementObject());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
throw new X4OPhaseException(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Element fillElementTree(X4OLanguageSession languageSession,Object object) throws ElementNamespaceInstanceProviderException, ElementBindingHandlerException {
|
||||
Element element = findRootElement(languageSession,object.getClass());
|
||||
|
||||
private Element fillElementTree(X4OLanguageSession languageSession, Object object)
|
||||
throws ElementNamespaceInstanceProviderException, ElementBindingHandlerException {
|
||||
Element element = findRootElement(languageSession, object.getClass());
|
||||
element.setElementObject(object);
|
||||
languageSession.setRootElement(element);
|
||||
|
||||
for (ElementBindingHandler bind:languageSession.getLanguage().findElementBindingHandlers(object)) {
|
||||
|
||||
for (ElementBindingHandler bind : languageSession.getLanguage().findElementBindingHandlers(object)) {
|
||||
bind.createChilderen(element);
|
||||
fillTree(languageSession,element);
|
||||
fillTree(languageSession, element);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
private void fillTree(X4OLanguageSession languageSession,Element element) throws ElementNamespaceInstanceProviderException, ElementBindingHandlerException {
|
||||
for (Element e:element.getChilderen()) {
|
||||
|
||||
private void fillTree(X4OLanguageSession languageSession, Element element)
|
||||
throws ElementNamespaceInstanceProviderException, ElementBindingHandlerException {
|
||||
for (Element e : element.getChilderen()) {
|
||||
Object object = e.getElementObject();
|
||||
for (ElementBindingHandler bind:languageSession.getLanguage().findElementBindingHandlers(object)) {
|
||||
for (ElementBindingHandler bind : languageSession.getLanguage().findElementBindingHandlers(object)) {
|
||||
bind.createChilderen(e);
|
||||
fillTree(languageSession,e);
|
||||
fillTree(languageSession, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Element findRootElement(X4OLanguageSession languageSession,Class<?> objectClass) throws ElementNamespaceInstanceProviderException {
|
||||
|
||||
private Element findRootElement(X4OLanguageSession languageSession, Class<?> objectClass) throws ElementNamespaceInstanceProviderException {
|
||||
// redo this mess, add nice find for root
|
||||
for (X4OLanguageModule modContext:languageSession.getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespace nsContext:modContext.getElementNamespaces()) {
|
||||
if (nsContext.getLanguageRoot()!=null && nsContext.getLanguageRoot()) {
|
||||
for (ElementClass ec:nsContext.getElementClasses()) {
|
||||
if (ec.getObjectClass()!=null && ec.getObjectClass().equals(objectClass)) {
|
||||
for (X4OLanguageModule modContext : languageSession.getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespace nsContext : modContext.getElementNamespaces()) {
|
||||
if (nsContext.getLanguageRoot() != null && nsContext.getLanguageRoot()) {
|
||||
for (ElementClass ec : nsContext.getElementClasses()) {
|
||||
if (ec.getObjectClass() != null && ec.getObjectClass().equals(objectClass)) {
|
||||
return nsContext.getElementNamespaceInstanceProvider().createElementInstance(languageSession, ec.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (X4OLanguageModule modContext:languageSession.getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespace nsContext:modContext.getElementNamespaces()) {
|
||||
for (ElementClass ec:nsContext.getElementClasses()) {
|
||||
if (ec.getObjectClass()!=null && ec.getObjectClass().equals(objectClass)) {
|
||||
for (X4OLanguageModule modContext : languageSession.getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespace nsContext : modContext.getElementNamespaces()) {
|
||||
for (ElementClass ec : nsContext.getElementClasses()) {
|
||||
if (ec.getObjectClass() != null && ec.getObjectClass().equals(objectClass)) {
|
||||
return nsContext.getElementNamespaceInstanceProvider().createElementInstance(languageSession, ec.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Could not find ElementClass for: "+objectClass.getName());
|
||||
throw new IllegalArgumentException("Could not find ElementClass for: " + objectClass.getName());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates the X4OPhaseWriteEnd which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -167,42 +179,51 @@ public class X4OPhaseLanguageWrite {
|
|||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_WRITE;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return WRITE_END;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[]{WRITE_FILL_TREE};
|
||||
return new String[] { WRITE_FILL_TREE };
|
||||
}
|
||||
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
logger.finest("Run init end phase");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class X4OPhaseWriteRelease extends AbstractX4OPhase {
|
||||
public X4OPhaseType getType() {
|
||||
return X4OPhaseType.XML_WRITE;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return WRITE_RELEASE;
|
||||
}
|
||||
|
||||
public String[] getPhaseDependencies() {
|
||||
return new String[] {WRITE_END};
|
||||
return new String[] { WRITE_END };
|
||||
}
|
||||
|
||||
public void runPhase(X4OLanguageSession languageSession) throws X4OPhaseException {
|
||||
}
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
try {
|
||||
element.release();
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
}/* finally {
|
||||
releaseCounter.addReleasedElement();
|
||||
}*/
|
||||
throw new X4OPhaseException(this, e);
|
||||
} /*
|
||||
* finally { releaseCounter.addReleasedElement(); }
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,33 +20,33 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
|
||||
/**
|
||||
* An X4OPhaseListener can be placed on an X4OPhaseHandler and is called
|
||||
* before and after the phase has runned.
|
||||
* An X4OPhaseListener can be placed on an X4OPhaseHandler and is called before and after the phase has runned.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Dec 31, 2008
|
||||
*/
|
||||
public interface X4OPhaseListener {
|
||||
|
||||
|
||||
/**
|
||||
* Gets called before the X4OPhaseHandler is run.
|
||||
* @param phase The phase to be run.
|
||||
* @param languageSession The X4O language session of the driver.
|
||||
* @throws X4OPhaseException Is throws when listeners has error.
|
||||
*
|
||||
* @param phase The phase to be run.
|
||||
* @param languageSession The X4O language session of the driver.
|
||||
* @throws X4OPhaseException Is throws when listeners has error.
|
||||
*/
|
||||
void preRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws X4OPhaseException;
|
||||
|
||||
void preRunPhase(X4OPhase phase, X4OLanguageSession languageSession) throws X4OPhaseException;
|
||||
|
||||
/**
|
||||
* Gets called after the X4OPhaseHandler is runned.
|
||||
* @param phase The phase just run.
|
||||
* @param languageSession The X4O language session of the driver.
|
||||
* @throws X4OPhaseException Is throws when listeners has error.
|
||||
*
|
||||
* @param phase The phase just run.
|
||||
* @param languageSession The X4O language session of the driver.
|
||||
* @throws X4OPhaseException Is throws when listeners has error.
|
||||
*/
|
||||
void endRunPhase(X4OPhase phase,X4OLanguageSession languageSession) throws X4OPhaseException;
|
||||
void endRunPhase(X4OPhase phase, X4OLanguageSession languageSession) throws X4OPhaseException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -28,45 +28,49 @@ import org.x4o.xml.element.Element;
|
|||
import org.x4o.xml.lang.X4OLanguageSession;
|
||||
|
||||
/**
|
||||
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order.
|
||||
* And will execute the phases when runPhases is called.
|
||||
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order. And will execute the phases when runPhases is called.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 6, 2008
|
||||
*/
|
||||
public interface X4OPhaseManager {
|
||||
|
||||
|
||||
/**
|
||||
* Gets an X4OPhase object by the phaseName.
|
||||
* @param phaseName The phaseName to lookup.
|
||||
* @return The X4OPhase requested or null.
|
||||
*
|
||||
* @param phaseName The phaseName to lookup.
|
||||
* @return The X4OPhase requested or null.
|
||||
*/
|
||||
X4OPhase getPhase(String phaseName);
|
||||
|
||||
|
||||
/**
|
||||
* Gets all the keys of the phases registrated whith this phase manager.
|
||||
* @return The phase keys.
|
||||
*
|
||||
* @return The phase keys.
|
||||
*/
|
||||
List<String> getPhaseKeys();
|
||||
|
||||
|
||||
/**
|
||||
* Runs release phase if it was requested not to run it automaticly.
|
||||
* @param languageSession The session to release.
|
||||
* Runs release phase if it was requested not to run it automaticly.
|
||||
*
|
||||
* @param languageSession The session to release.
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
void doReleasePhaseManual(X4OLanguageSession languageSession) throws X4OPhaseException;
|
||||
|
||||
|
||||
/**
|
||||
* Runs all the phases in the right order.
|
||||
*
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
void runPhases(X4OLanguageSession elementContext,X4OPhaseType type) throws X4OPhaseException;
|
||||
|
||||
void runPhases(X4OLanguageSession elementContext, X4OPhaseType type) throws X4OPhaseException;
|
||||
|
||||
/**
|
||||
* Runs phase on single element.
|
||||
* @param e The Element to process.
|
||||
* @param p The phase to run.
|
||||
*
|
||||
* @param e The Element to process.
|
||||
* @param p The phase to run.
|
||||
* @throws X4OPhaseException When a running handlers throws one.
|
||||
*/
|
||||
void runPhasesForElement(Element e,X4OPhaseType type,X4OPhase p) throws X4OPhaseException;
|
||||
void runPhasesForElement(Element e, X4OPhaseType type, X4OPhase p) throws X4OPhaseException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,15 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
/**
|
||||
* X4OPhaseManagerLocal has the local config methods.
|
||||
* X4OPhaseManagerLocal has the local config methods.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mrt 8, 2014
|
||||
*/
|
||||
public interface X4OPhaseManagerLocal extends X4OPhaseManager {
|
||||
|
||||
|
||||
void addX4OPhase(X4OPhase phase);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
/**
|
||||
* X4OPhaseType defines which phase type there are to put phases in to execute.
|
||||
|
|
@ -29,13 +29,13 @@ package org.x4o.xml.lang.phase;
|
|||
* @version 1.0 Apr 30, 2013
|
||||
*/
|
||||
public enum X4OPhaseType {
|
||||
|
||||
|
||||
/** Language init. */
|
||||
INIT,
|
||||
|
||||
|
||||
/** XML Reading. */
|
||||
XML_READ,
|
||||
|
||||
|
||||
/** XML Writing. */
|
||||
XML_WRITE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.task;
|
||||
package org.x4o.xml.lang.task;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -38,27 +38,27 @@ public abstract class AbstractX4OLanguageTask implements X4OLanguageTask {
|
|||
private final String name;
|
||||
private final String description;
|
||||
private final SAX3PropertyConfig propertyConfig;
|
||||
|
||||
public AbstractX4OLanguageTask(String id,SAX3PropertyConfig propertyConfig) {
|
||||
this(id,id,id,propertyConfig);
|
||||
|
||||
public AbstractX4OLanguageTask(String id, SAX3PropertyConfig propertyConfig) {
|
||||
this(id, id, id, propertyConfig);
|
||||
}
|
||||
|
||||
public AbstractX4OLanguageTask(String id,String name,String description,SAX3PropertyConfig propertyConfig) {
|
||||
this.id=id;
|
||||
this.name=name;
|
||||
this.description=description;
|
||||
this.propertyConfig=propertyConfig;
|
||||
|
||||
public AbstractX4OLanguageTask(String id, String name, String description, SAX3PropertyConfig propertyConfig) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.propertyConfig = propertyConfig;
|
||||
}
|
||||
|
||||
|
||||
protected abstract X4OLanguageTaskExecutor createTaskExecutorChecked(SAX3PropertyConfig config);
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.task.X4OLanguageTask#createTaskExecutor(org.x4o.sax3.io.SAX3PropertyConfig)
|
||||
*/
|
||||
public X4OLanguageTaskExecutor createTaskExecutor(SAX3PropertyConfig config) {
|
||||
return createTaskExecutorChecked(checkConfig(config));
|
||||
}
|
||||
|
||||
|
||||
private SAX3PropertyConfig checkConfig(SAX3PropertyConfig config) {
|
||||
List<String> keys = config.getPropertyKeysRequiredValues();
|
||||
if (keys.isEmpty()) {
|
||||
|
|
@ -66,39 +66,39 @@ public abstract class AbstractX4OLanguageTask implements X4OLanguageTask {
|
|||
}
|
||||
StringBuilder buf = new StringBuilder(100);
|
||||
buf.append("Error missing value(s) for key(s) {");
|
||||
for (int i=0;i<keys.size();i++) {
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
buf.append('"');
|
||||
buf.append(keys.get(i));
|
||||
buf.append('"');
|
||||
if (i<keys.size()-1) {
|
||||
if (i < keys.size() - 1) {
|
||||
buf.append(',');
|
||||
}
|
||||
buf.append('}');
|
||||
}
|
||||
throw new IllegalArgumentException(buf.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.task.X4OLanguageTask#createTaskConfig()
|
||||
*/
|
||||
public SAX3PropertyConfig createTaskConfig() {
|
||||
return propertyConfig.clone();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.task.X4OLanguageTask#getId()
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.task.X4OLanguageTask#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.lang.task.X4OLanguageTask#getDescription()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.task;
|
||||
package org.x4o.xml.lang.task;
|
||||
|
||||
import org.x4o.sax3.io.SAX3PropertyConfig;
|
||||
|
||||
|
|
@ -33,28 +33,28 @@ import org.x4o.sax3.io.SAX3PropertyConfig;
|
|||
public interface X4OLanguageTask {
|
||||
|
||||
/**
|
||||
* @return Returns the task id.
|
||||
* @return Returns the task id.
|
||||
*/
|
||||
String getId();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the task name.
|
||||
* @return Returns the task name.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the task description.
|
||||
* @return Returns the task description.
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns newly created PropertyConfig for configuring this task.
|
||||
* @return Returns newly created PropertyConfig for configuring this task.
|
||||
*/
|
||||
SAX3PropertyConfig createTaskConfig();
|
||||
|
||||
|
||||
/**
|
||||
* @param config The config with which the task will be runned.
|
||||
* @return The task executor for running the task.
|
||||
* @param config The config with which the task will be runned.
|
||||
* @return The task executor for running the task.
|
||||
*/
|
||||
X4OLanguageTaskExecutor createTaskExecutor(SAX3PropertyConfig config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.task;
|
||||
package org.x4o.xml.lang.task;
|
||||
|
||||
import org.x4o.sax3.io.SAX3PropertyConfig;
|
||||
|
||||
|
|
@ -31,18 +31,18 @@ import org.x4o.sax3.io.SAX3PropertyConfig;
|
|||
* @version 1.0 Aug 26, 2013
|
||||
*/
|
||||
public class X4OLanguageTaskException extends Exception {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 8490969221732950292L;
|
||||
private SAX3PropertyConfig propertyConfig = null;
|
||||
|
||||
public X4OLanguageTaskException(SAX3PropertyConfig propertyConfig,String message) {
|
||||
|
||||
public X4OLanguageTaskException(SAX3PropertyConfig propertyConfig, String message) {
|
||||
super(message);
|
||||
this.propertyConfig=propertyConfig;
|
||||
this.propertyConfig = propertyConfig;
|
||||
}
|
||||
|
||||
public X4OLanguageTaskException(SAX3PropertyConfig propertyConfig,String message,Exception exception) {
|
||||
super(message,exception);
|
||||
this.propertyConfig=propertyConfig;
|
||||
|
||||
public X4OLanguageTaskException(SAX3PropertyConfig propertyConfig, String message, Exception exception) {
|
||||
super(message, exception);
|
||||
this.propertyConfig = propertyConfig;
|
||||
}
|
||||
|
||||
public SAX3PropertyConfig getPropertyConfig() {
|
||||
|
|
|
|||
|
|
@ -20,11 +20,10 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.task;
|
||||
package org.x4o.xml.lang.task;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
|
||||
|
||||
/**
|
||||
* X4OLanguageTaskExecutor runs the language task.
|
||||
*
|
||||
|
|
@ -34,9 +33,10 @@ import org.x4o.xml.lang.X4OLanguage;
|
|||
public interface X4OLanguageTaskExecutor {
|
||||
|
||||
/**
|
||||
* Executes a task for which this executor is created.
|
||||
* @param language The language for which we run the task.
|
||||
* @throws X4OLanguageTaskException Can be thrown in case of error.
|
||||
* Executes a task for which this executor is created.
|
||||
*
|
||||
* @param language The language for which we run the task.
|
||||
* @throws X4OLanguageTaskException Can be thrown in case of error.
|
||||
*/
|
||||
void execute(X4OLanguage language) throws X4OLanguageTaskException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@ import org.xml.sax.SAXException;
|
|||
* @version 1.0 May 6, 2024
|
||||
*/
|
||||
public class X4OStaticLanguageTask extends AbstractX4OLanguageTask {
|
||||
|
||||
public static final String TASK_ID = "x4o-static";
|
||||
|
||||
public static final String TASK_ID = "x4o-static";
|
||||
private static final String TASK_NAME = "X4O Static Task";
|
||||
private static final String TASK_DESC = "Writes static support resources of X4O.";
|
||||
|
||||
|
||||
public X4OStaticLanguageTask() {
|
||||
super(TASK_ID,TASK_NAME,TASK_DESC,X4OStaticWriter.DEFAULT_PROPERTY_CONFIG);
|
||||
super(TASK_ID, TASK_NAME, TASK_DESC, X4OStaticWriter.DEFAULT_PROPERTY_CONFIG);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes this language task.
|
||||
*/
|
||||
|
|
@ -53,9 +53,9 @@ public class X4OStaticLanguageTask extends AbstractX4OLanguageTask {
|
|||
try {
|
||||
new X4OStaticWriter(config).writeStatic();
|
||||
} catch (SAXException e) {
|
||||
throw new X4OLanguageTaskException(config,e.getMessage(),e);
|
||||
throw new X4OLanguageTaskException(config, e.getMessage(), e);
|
||||
} catch (IOException e) {
|
||||
throw new X4OLanguageTaskException(config,e.getMessage(),e);
|
||||
throw new X4OLanguageTaskException(config, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@ import org.x4o.xml.lang.X4OLanguageClassLoader;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* X4OStaticWriter writes the static support resources of X4O.
|
||||
* X4OStaticWriter writes the static support resources of X4O.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 6, 2024
|
||||
*/
|
||||
public class X4OStaticWriter {
|
||||
|
||||
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"x4o-static/";
|
||||
|
||||
//@formatter:off
|
||||
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
|
||||
|
||||
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"x4o-static/";
|
||||
public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path";
|
||||
public final static String OUTPUT_OASIS_XMLNS_CATALOG = PROPERTY_CONTEXT_PREFIX+"output/oasis-xml-catalog";
|
||||
|
||||
|
|
@ -53,18 +53,19 @@ public class X4OStaticWriter {
|
|||
new PropertyConfigItem(OUTPUT_OASIS_XMLNS_CATALOG, Boolean.class, false)
|
||||
);
|
||||
}
|
||||
|
||||
//@formatter:on
|
||||
|
||||
private final SAX3PropertyConfig propertyConfig;
|
||||
|
||||
|
||||
public X4OStaticWriter(SAX3PropertyConfig parentConfig) {
|
||||
this.propertyConfig=new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
|
||||
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
||||
this.propertyConfig.copyParentProperties(parentConfig);
|
||||
}
|
||||
|
||||
|
||||
public void writeStatic() throws SAXException, IOException {
|
||||
File basePath = propertyConfig.getPropertyFile(OUTPUT_PATH);
|
||||
Boolean outputOasis = propertyConfig.getPropertyBoolean(OUTPUT_OASIS_XMLNS_CATALOG);
|
||||
if (basePath==null) {
|
||||
if (basePath == null) {
|
||||
throw new NullPointerException("Can't write resources to null output path.");
|
||||
}
|
||||
if (!basePath.exists()) {
|
||||
|
|
@ -76,18 +77,18 @@ public class X4OStaticWriter {
|
|||
copyResourceToFile("META-INF/language/oasis-xmlns-catalog.dtd", new File(basePath, "oasis-xmlns-catalog.dtd"));
|
||||
}
|
||||
}
|
||||
|
||||
private void copyResourceToFile(String resource,File output) throws IOException {
|
||||
|
||||
private void copyResourceToFile(String resource, File output) throws IOException {
|
||||
ClassLoader cl = X4OLanguageClassLoader.getClassLoader();
|
||||
InputStream inputStream = cl.getResourceAsStream(resource);
|
||||
try {
|
||||
copyStreamToFile(inputStream,output);
|
||||
copyStreamToFile(inputStream, output);
|
||||
} catch (SecurityException | IOException | InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyStreamToFile(InputStream inputStream,File output) throws SecurityException, IOException, InterruptedException {
|
||||
|
||||
private void copyStreamToFile(InputStream inputStream, File output) throws SecurityException, IOException, InterruptedException {
|
||||
OutputStream outputStream = new FileOutputStream(output);
|
||||
try {
|
||||
byte[] buffer = new byte[4096];
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.lang.task.run;
|
||||
package org.x4o.xml.lang.task.run;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -46,20 +46,20 @@ import org.x4o.xml.lang.task.X4OLanguageTaskException;
|
|||
* @version 1.0 Aug 24, 2013
|
||||
*/
|
||||
public class X4OTaskCommandLine {
|
||||
|
||||
|
||||
private X4ODriver<?> driver = null;
|
||||
private X4OLanguageTask task = null;
|
||||
private SAX3PropertyConfig config = null;
|
||||
|
||||
|
||||
public static void main(String[] argu) {
|
||||
X4OTaskCommandLine cmd = new X4OTaskCommandLine();
|
||||
cmd.parseCommandLine(argu);
|
||||
cmd.executeCommandLine();
|
||||
}
|
||||
|
||||
|
||||
private X4OTaskCommandLine() {
|
||||
}
|
||||
|
||||
|
||||
private void parseCommandLine(String[] argu) {
|
||||
List<String> arguList = Arrays.asList(argu);
|
||||
viewHelp(arguList);
|
||||
|
|
@ -71,45 +71,45 @@ public class X4OTaskCommandLine {
|
|||
findProperties(arguList.iterator());
|
||||
checkConfig();
|
||||
}
|
||||
|
||||
|
||||
private void executeCommandLine() {
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
executeLanguageTask();
|
||||
long totalTime = System.currentTimeMillis()-startTime;
|
||||
System.out.println("Succesfully executed task: "+task.getId()+" in "+totalTime+" ms.");
|
||||
long totalTime = System.currentTimeMillis() - startTime;
|
||||
System.out.println("Succesfully executed task: " + task.getId() + " in " + totalTime + " ms.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while executing task: "+e.getMessage());
|
||||
System.err.println("Error while executing task: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void executeLanguageTask() throws X4OLanguageTaskException {
|
||||
X4OLanguage language = driver.createLanguage(); // TODO: also add support for version select
|
||||
X4OTaskRunner.runTaskLanguage(task, language, config);
|
||||
}
|
||||
|
||||
|
||||
private void systemErrExit(String message) {
|
||||
System.err.println(message);
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
private void checkConfig() {
|
||||
Collection<String> keys = config.getPropertyKeysRequiredValues();
|
||||
if (keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
System.err.println("Missing properties;");
|
||||
for (String key:keys) {
|
||||
System.err.println(" - "+key);
|
||||
for (String key : keys) {
|
||||
System.err.println(" - " + key);
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
private void viewHelp(List<String> argu) {
|
||||
for (String arg:argu) {
|
||||
for (String arg : argu) {
|
||||
if ("-help".equals(arg) || "-h".equals(arg)) {
|
||||
System.out.println("X4O Language Task Command Line Usage;");
|
||||
System.out.println("-languages <lang> (-l) = Selects langauge.");
|
||||
|
|
@ -131,13 +131,13 @@ public class X4OTaskCommandLine {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void viewListings(List<String> argu) {
|
||||
for (String arg:argu) {
|
||||
for (String arg : argu) {
|
||||
if ("-list-languages".equals(arg) || "-ll".equals(arg)) {
|
||||
System.out.println("X4O Languages;");
|
||||
for (String language:X4ODriverManager.getX4OLanguages()) {
|
||||
System.out.println("- "+language);
|
||||
for (String language : X4ODriverManager.getX4OLanguages()) {
|
||||
System.out.println("- " + language);
|
||||
}
|
||||
System.out.println();
|
||||
System.exit(0);
|
||||
|
|
@ -146,14 +146,14 @@ public class X4OTaskCommandLine {
|
|||
if ("-list-language-tasks".equals(arg) || "-llt".equals(arg)) {
|
||||
System.out.println("X4O Language Tasks;");
|
||||
int prefix = 12;
|
||||
for (X4OLanguageTask task:X4ODriverManager.getX4OLanguageTasks()) {
|
||||
for (X4OLanguageTask task : X4ODriverManager.getX4OLanguageTasks()) {
|
||||
int lId = task.getId().length();
|
||||
System.out.print(task.getId());
|
||||
for (int i=0;i<prefix-lId;i++) {
|
||||
for (int i = 0; i < prefix - lId; i++) {
|
||||
System.out.print(" "); // classic, todo use formatter
|
||||
}
|
||||
System.out.println(" - "+task.getName());
|
||||
for (int i=0;i<prefix+3;i++) {
|
||||
System.out.println(" - " + task.getName());
|
||||
for (int i = 0; i < prefix + 3; i++) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println(task.getDescription());
|
||||
|
|
@ -164,27 +164,27 @@ public class X4OTaskCommandLine {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void viewKeyListing(Iterator<String> arguIterator) {
|
||||
if (task==null) {
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
while (arguIterator.hasNext()) {
|
||||
String arg = arguIterator.next();
|
||||
if ("-list-keys".equals(arg) || "-lk".equals(arg)) {
|
||||
System.out.println(task.getName()+" config keys;");
|
||||
System.out.println(task.getName() + " config keys;");
|
||||
SAX3PropertyConfig config = task.createTaskConfig();
|
||||
for (String key:config.getPropertyKeys()) {
|
||||
for (String key : config.getPropertyKeys()) {
|
||||
Class<?> keyType = config.getPropertyType(key);
|
||||
Object valueDefault = config.getPropertyDefault(key);
|
||||
String def = "";
|
||||
if (valueDefault!=null) {
|
||||
def = "(default=\""+unescapeDefault(valueDefault.toString())+"\")";
|
||||
if (valueDefault != null) {
|
||||
def = "(default=\"" + unescapeDefault(valueDefault.toString()) + "\")";
|
||||
}
|
||||
if (config.isPropertyRequired(key)) {
|
||||
def = "(required=\"true\")";
|
||||
}
|
||||
System.out.println(String.format("%1$-65s - %2$-8s %3$s", key,keyType.getSimpleName(),def));
|
||||
System.out.println(String.format("%1$-65s - %2$-8s %3$s", key, keyType.getSimpleName(), def));
|
||||
}
|
||||
System.out.println();
|
||||
System.exit(0);
|
||||
|
|
@ -192,98 +192,101 @@ public class X4OTaskCommandLine {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String unescapeDefault(String defaultValue) {
|
||||
StringBuilder buf = new StringBuilder(defaultValue.length()+10);
|
||||
for (char c:defaultValue.toCharArray()) {
|
||||
if (c=='\n') {
|
||||
buf.append("\\n");continue;
|
||||
StringBuilder buf = new StringBuilder(defaultValue.length() + 10);
|
||||
for (char c : defaultValue.toCharArray()) {
|
||||
if (c == '\n') {
|
||||
buf.append("\\n");
|
||||
continue;
|
||||
}
|
||||
if (c=='\t') {
|
||||
buf.append("\\t");continue;
|
||||
if (c == '\t') {
|
||||
buf.append("\\t");
|
||||
continue;
|
||||
}
|
||||
if (c=='\r') {
|
||||
buf.append("\\r");continue;
|
||||
if (c == '\r') {
|
||||
buf.append("\\r");
|
||||
continue;
|
||||
}
|
||||
buf.append(c);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
private void findDriver(Iterator<String> arguIterator) {
|
||||
while (arguIterator.hasNext()) {
|
||||
String arg = arguIterator.next();
|
||||
if ("-language".equals(arg) || "-l".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
systemErrExit("No argument for "+arg+" given.");
|
||||
if (arguIterator.hasNext() == false) {
|
||||
systemErrExit("No argument for " + arg + " given.");
|
||||
}
|
||||
String languageName = arguIterator.next();
|
||||
driver = X4ODriverManager.getX4ODriver(languageName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (driver==null) {
|
||||
if (driver == null) {
|
||||
systemErrExit("No -language or -l argument with language given.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void findTask(Iterator<String> arguIterator) {
|
||||
while (arguIterator.hasNext()) {
|
||||
String arg = arguIterator.next();
|
||||
if ("-task".equals(arg) || "-t".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
systemErrExit("No argument for "+arg+" given.");
|
||||
if (arguIterator.hasNext() == false) {
|
||||
systemErrExit("No argument for " + arg + " given.");
|
||||
}
|
||||
String taskId = arguIterator.next();
|
||||
task = driver.getLanguageTask(taskId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (task==null) {
|
||||
if (task == null) {
|
||||
systemErrExit("No -task or -t argument with task given.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void findProperties(Iterator<String> arguIterator) {
|
||||
config = task.createTaskConfig();
|
||||
while (arguIterator.hasNext()) {
|
||||
String arg = arguIterator.next();
|
||||
if ("-property".equals(arg) || "-p".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
systemErrExit("No argument for "+arg+" given.");
|
||||
if (arguIterator.hasNext() == false) {
|
||||
systemErrExit("No argument for " + arg + " given.");
|
||||
}
|
||||
String valuePair = arguIterator.next();
|
||||
String[] values = valuePair.split("=");
|
||||
if (values.length==1) {
|
||||
systemErrExit("No property value given for key "+valuePair);
|
||||
if (values.length == 1) {
|
||||
systemErrExit("No property value given for key " + valuePair);
|
||||
}
|
||||
config.setPropertyParsedValue(values[0],values[1]);
|
||||
config.setPropertyParsedValue(values[0], values[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void loadFileProperties(Iterator<String> arguIterator) {
|
||||
while (arguIterator.hasNext()) {
|
||||
String arg = arguIterator.next();
|
||||
if ("-load-props".equals(arg) || "-lp".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
systemErrExit("No argument for "+arg+" given.");
|
||||
if (arguIterator.hasNext() == false) {
|
||||
systemErrExit("No argument for " + arg + " given.");
|
||||
}
|
||||
loadProperties(arguIterator.next(),false);
|
||||
loadProperties(arguIterator.next(), false);
|
||||
}
|
||||
if ("-load-props-xml".equals(arg) || "-lpx".equals(arg)) {
|
||||
if (arguIterator.hasNext()==false) {
|
||||
systemErrExit("No argument for "+arg+" given.");
|
||||
if (arguIterator.hasNext() == false) {
|
||||
systemErrExit("No argument for " + arg + " given.");
|
||||
}
|
||||
loadProperties(arguIterator.next(),true);
|
||||
loadProperties(arguIterator.next(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadProperties(String file,boolean isXml) {
|
||||
|
||||
private void loadProperties(String file, boolean isXml) {
|
||||
File propFile = new File(file);
|
||||
if (!propFile.exists()) {
|
||||
systemErrExit("File does not exsits; "+propFile);
|
||||
systemErrExit("File does not exsits; " + propFile);
|
||||
}
|
||||
Properties p = new Properties();
|
||||
InputStream in = null;
|
||||
|
|
@ -294,13 +297,13 @@ public class X4OTaskCommandLine {
|
|||
} else {
|
||||
p.load(in);
|
||||
}
|
||||
for (Object keyObj:p.keySet()) {
|
||||
for (Object keyObj : p.keySet()) {
|
||||
String key = keyObj.toString();
|
||||
String value = p.getProperty(key);
|
||||
config.setPropertyParsedValue(key, value);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
systemErrExit("Fatal-Error: "+e.getMessage());
|
||||
systemErrExit("Fatal-Error: " + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
|
|
|
|||
|
|
@ -29,59 +29,60 @@ package org.x4o.xml.lang.task.run;
|
|||
* @version 1.0 Aug 30, 2013
|
||||
*/
|
||||
public class X4OTaskProperty {
|
||||
|
||||
|
||||
/** The key of the property. */
|
||||
private String key = null;
|
||||
|
||||
|
||||
/** The value of the property. */
|
||||
private String value = null;
|
||||
|
||||
|
||||
/**
|
||||
* @return the key.
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key the key to set.
|
||||
*/
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param value the value to set.
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parsed line like 'key=value' into a X4OTaskProperty object.
|
||||
* @param line The text line to parse.
|
||||
* @return The filled X4OTaskProperty.
|
||||
*
|
||||
* @param line The text line to parse.
|
||||
* @return The filled X4OTaskProperty.
|
||||
*/
|
||||
static public X4OTaskProperty parseLine(String line) {
|
||||
if (line==null) {
|
||||
if (line == null) {
|
||||
throw new NullPointerException("Can't parse null line.");
|
||||
}
|
||||
int idx = line.indexOf('=');
|
||||
if (idx<0) {
|
||||
if (idx < 0) {
|
||||
throw new IllegalArgumentException("Can't parse line with '=' sign.");
|
||||
}
|
||||
if (idx==line.length()) {
|
||||
if (idx == line.length()) {
|
||||
throw new IllegalArgumentException("Can't parse line empty value.");
|
||||
}
|
||||
String key = line.substring(0,idx);
|
||||
String value = line.substring(idx+1);
|
||||
String key = line.substring(0, idx);
|
||||
String value = line.substring(idx + 1);
|
||||
X4OTaskProperty result = new X4OTaskProperty();
|
||||
result.setKey(key);
|
||||
result.setValue(value);
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ import org.x4o.xml.lang.task.X4OLanguageTaskException;
|
|||
import org.x4o.xml.lang.task.X4OLanguageTaskExecutor;
|
||||
|
||||
/**
|
||||
* X4OTaskRunner finds all x4o objects and configs and then run the x4o langauge
|
||||
* task.
|
||||
* X4OTaskRunner finds all x4o objects and configs and then run the x4o langauge task.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 30, 2013
|
||||
|
|
|
|||
|
|
@ -38,28 +38,28 @@ import org.x4o.xml.lang.X4OLanguageSessionLocal;
|
|||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class X4ODriverManagerTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultLanguageVersionSelect() throws Exception {
|
||||
String version = X4ODriverManager.getDefaultLanguageVersion(new String[]{"1.0","2.0","3.0"});
|
||||
String version = X4ODriverManager.getDefaultLanguageVersion(new String[] { "1.0", "2.0", "3.0" });
|
||||
Assertions.assertNotNull(version);
|
||||
Assertions.assertEquals("3.0",version);
|
||||
Assertions.assertEquals("3.0", version);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultLanguageVersionEmpty() throws Exception {
|
||||
String version = X4ODriverManager.getDefaultLanguageVersion(new String[]{});
|
||||
String version = X4ODriverManager.getDefaultLanguageVersion(new String[] {});
|
||||
Assertions.assertNotNull(version);
|
||||
Assertions.assertEquals(X4ODriver.DEFAULT_LANGUAGE_VERSION,version);
|
||||
Assertions.assertEquals(X4ODriver.DEFAULT_LANGUAGE_VERSION, version);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultLanguageVersionNull() throws Exception {
|
||||
String version = X4ODriverManager.getDefaultLanguageVersion(null);
|
||||
Assertions.assertNotNull(version);
|
||||
Assertions.assertEquals(X4ODriver.DEFAULT_LANGUAGE_VERSION,version);
|
||||
Assertions.assertEquals(X4ODriver.DEFAULT_LANGUAGE_VERSION, version);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguageNull() throws Exception {
|
||||
String language = null;
|
||||
|
|
@ -73,7 +73,7 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("language"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguageEmpty() throws Exception {
|
||||
String language = "";
|
||||
|
|
@ -87,7 +87,7 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(IllegalArgumentException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("language"), "Error message string is missing language");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguageVersionNonExcisting() throws Exception {
|
||||
String languageTest = "test";
|
||||
|
|
@ -101,26 +101,23 @@ public class X4ODriverManagerTest {
|
|||
e = catchE;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
/* TODO
|
||||
assertNotNull(e);
|
||||
assertNotNull(e.getCause());
|
||||
assertNotNull(e.getCause().getCause());
|
||||
assertEquals(X4OPhaseException.class, e.getCause().getClass());
|
||||
assertEquals(X4OLanguageLoaderException.class, e.getCause().getCause().getClass());
|
||||
assertTrue("Error message string is missing language",e.getMessage().contains("language"));
|
||||
assertTrue("Error message string is missing test",e.getMessage().contains("test"));
|
||||
assertTrue("Error message string is missing modules",e.getMessage().contains("modules"));
|
||||
assertTrue("Error message string is missing 2.0",e.getMessage().contains("2.0"));
|
||||
*/
|
||||
/*
|
||||
* TODO assertNotNull(e); assertNotNull(e.getCause()); assertNotNull(e.getCause().getCause()); assertEquals(X4OPhaseException.class,
|
||||
* e.getCause().getClass()); assertEquals(X4OLanguageLoaderException.class, e.getCause().getCause().getClass());
|
||||
* assertTrue("Error message string is missing language",e.getMessage().contains("language"));
|
||||
* assertTrue("Error message string is missing test",e.getMessage().contains("test"));
|
||||
* assertTrue("Error message string is missing modules",e.getMessage().contains("modules"));
|
||||
* assertTrue("Error message string is missing 2.0",e.getMessage().contains("2.0"));
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguageCount() throws Exception {
|
||||
List<String> languages = X4ODriverManager.getX4OLanguages();
|
||||
Assertions.assertNotNull(languages);
|
||||
Assertions.assertFalse(languages.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguageNames() throws Exception {
|
||||
List<String> languages = X4ODriverManager.getX4OLanguages();
|
||||
|
|
@ -129,17 +126,17 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertTrue(languages.contains("eld"), "eld language is missing");
|
||||
Assertions.assertTrue(languages.contains("test"), "test language is missing");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLanguagesLoopSpeed() throws Exception {
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i=0;i<100;i++) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
testLanguageCount();
|
||||
}
|
||||
long loopTime = System.currentTimeMillis() - startTime;
|
||||
Assertions.assertEquals(true, loopTime<500, "Language list loop is slow;"+loopTime);
|
||||
Assertions.assertEquals(true, loopTime < 500, "Language list loop is slow;" + loopTime);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegisterDriverNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -152,15 +149,22 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegisterDriverNameNull() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
X4ODriverManager.registerX4ODriver(new X4ODriver<Object>() {
|
||||
@Override public String[] getLanguageVersions() { return new String[]{"1.0"}; }
|
||||
@Override public String getLanguageName() { return null; }
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return new String[] { "1.0" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
|
|
@ -169,15 +173,22 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegisterDriverNameEmpty() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
X4ODriverManager.registerX4ODriver(new X4ODriver<Object>() {
|
||||
@Override public String[] getLanguageVersions() { return new String[]{"1.0"}; }
|
||||
@Override public String getLanguageName() { return ""; }
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return new String[] { "1.0" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
});
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
|
|
@ -186,15 +197,22 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(IllegalArgumentException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("empty"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegisterDriverVersionNull() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
X4ODriverManager.registerX4ODriver(new X4ODriver<Object>() {
|
||||
@Override public String[] getLanguageVersions() { return null; }
|
||||
@Override public String getLanguageName() { return "junit-driver-test"; }
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return "junit-driver-test";
|
||||
}
|
||||
|
||||
});
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
|
|
@ -203,15 +221,22 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegisterDriverVersionEmpty() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
X4ODriverManager.registerX4ODriver(new X4ODriver<Object>() {
|
||||
@Override public String[] getLanguageVersions() { return new String[]{}; }
|
||||
@Override public String getLanguageName() { return "junit-driver-test"; }
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return "junit-driver-test";
|
||||
}
|
||||
|
||||
});
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
|
|
@ -220,7 +245,7 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(IllegalArgumentException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("empty"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeregisterDriverNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -233,15 +258,22 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeregisterDriverNameNull() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
X4ODriverManager.deregisterX4ODriver(new X4ODriver<Object>() {
|
||||
@Override public String[] getLanguageVersions() { return new String[]{"1.0"}; }
|
||||
@Override public String getLanguageName() { return null; }
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return new String[] { "1.0" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
|
|
@ -250,14 +282,21 @@ public class X4ODriverManagerTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass(), "Wrong exception class");
|
||||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeregisterDriverInstance() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
X4ODriver<?> driver = new X4ODriver<Object>() {
|
||||
@Override public String[] getLanguageVersions() { return new String[]{"1.0"}; }
|
||||
@Override public String getLanguageName() { return "junit-driver-test"; }
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return new String[] { "1.0" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageName() {
|
||||
return "junit-driver-test";
|
||||
}
|
||||
};
|
||||
X4ODriverManager.registerX4ODriver(driver);
|
||||
Assertions.assertEquals(driver.hashCode(), X4ODriverManager.getX4ODriver("junit-driver-test").hashCode());
|
||||
|
|
|
|||
|
|
@ -40,19 +40,19 @@ import org.x4o.xml.lang.phase.X4OPhaseType;
|
|||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class DefaultObjectConverterProviderTest {
|
||||
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterClone() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
for (ObjectConverter conv:p.getObjectConverters()) {
|
||||
for (ObjectConverter conv : p.getObjectConverters()) {
|
||||
Assertions.assertNotNull(conv);
|
||||
ObjectConverter clone = conv.clone();
|
||||
Assertions.assertNotNull(clone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterBoolean() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
|
|
@ -60,14 +60,14 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertNotNull(conv);
|
||||
Object result = conv.convertTo("true", locale);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(Boolean.class,result.getClass(), "Result is not Boolean.class");
|
||||
Assertions.assertEquals(true,result, "Result is not true");
|
||||
Assertions.assertEquals(Boolean.class, result.getClass(), "Result is not Boolean.class");
|
||||
Assertions.assertEquals(true, result, "Result is not true");
|
||||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertNotNull(resultBack);
|
||||
Assertions.assertEquals(String.class,resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("true",resultBack, "resultBack is not true");
|
||||
Assertions.assertEquals(String.class, resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("true", resultBack, "resultBack is not true");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterInteger() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
|
|
@ -75,14 +75,14 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertNotNull(conv);
|
||||
Object result = conv.convertTo("123", locale);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(Integer.class,result.getClass(), "Result is not Integer.class");
|
||||
Assertions.assertEquals(123,result, "Result is not 123");
|
||||
Assertions.assertEquals(Integer.class, result.getClass(), "Result is not Integer.class");
|
||||
Assertions.assertEquals(123, result, "Result is not 123");
|
||||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertNotNull(resultBack);
|
||||
Assertions.assertEquals(String.class,resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("123",resultBack, "resultBack is not 123");
|
||||
Assertions.assertEquals(String.class, resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("123", resultBack, "resultBack is not 123");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterFloat() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
|
|
@ -90,14 +90,14 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertNotNull(conv);
|
||||
Object result = conv.convertTo("123.23", locale);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(Float.class,result.getClass(), "Result is not Float.class");
|
||||
Assertions.assertEquals(123.23F,result, "Result is not 123.23");
|
||||
Assertions.assertEquals(Float.class, result.getClass(), "Result is not Float.class");
|
||||
Assertions.assertEquals(123.23F, result, "Result is not 123.23");
|
||||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertNotNull(resultBack);
|
||||
Assertions.assertEquals(String.class,resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("123.23",resultBack, "resultBack is not 123.23");
|
||||
Assertions.assertEquals(String.class, resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("123.23", resultBack, "resultBack is not 123.23");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterLong() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
|
|
@ -105,14 +105,14 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertNotNull(conv);
|
||||
Object result = conv.convertTo("12323", locale);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(Long.class,result.getClass(), "Result is not Long.class");
|
||||
Assertions.assertEquals(12323L,result, "Result is not 12323");
|
||||
Assertions.assertEquals(Long.class, result.getClass(), "Result is not Long.class");
|
||||
Assertions.assertEquals(12323L, result, "Result is not 12323");
|
||||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertNotNull(resultBack);
|
||||
Assertions.assertEquals(String.class,resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("12323",resultBack, "resultBack is not 12323");
|
||||
Assertions.assertEquals(String.class, resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("12323", resultBack, "resultBack is not 12323");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterDouble() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
|
|
@ -120,14 +120,14 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertNotNull(conv);
|
||||
Object result = conv.convertTo("1232.3", locale);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(Double.class,result.getClass(), "Result is not Double.class");
|
||||
Assertions.assertEquals(1232.3D,result, "Result is not 1232.3");
|
||||
Assertions.assertEquals(Double.class, result.getClass(), "Result is not Double.class");
|
||||
Assertions.assertEquals(1232.3D, result, "Result is not 1232.3");
|
||||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertNotNull(resultBack);
|
||||
Assertions.assertEquals(String.class,resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("1232.3",resultBack, "resultBack is not 1232.3");
|
||||
Assertions.assertEquals(String.class, resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("1232.3", resultBack, "resultBack is not 1232.3");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterUrl() throws Exception {
|
||||
DefaultObjectConverterProvider p = new DefaultObjectConverterProvider(true);
|
||||
|
|
@ -135,14 +135,14 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertNotNull(conv);
|
||||
Object result = conv.convertTo("http://www.x4o.org", locale);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(URL.class,result.getClass(), "Result is not Url.class");
|
||||
Assertions.assertEquals(new URL("http://www.x4o.org"),result, "Result is not http://www.x4o.org");
|
||||
Assertions.assertEquals(URL.class, result.getClass(), "Result is not Url.class");
|
||||
Assertions.assertEquals(new URL("http://www.x4o.org"), result, "Result is not http://www.x4o.org");
|
||||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertNotNull(resultBack);
|
||||
Assertions.assertEquals(String.class,resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("http://www.x4o.org",resultBack, "resultBack is not http://www.x4o.org");
|
||||
Assertions.assertEquals(String.class, resultBack.getClass(), "resultBack is not String.class");
|
||||
Assertions.assertEquals("http://www.x4o.org", resultBack, "resultBack is not http://www.x4o.org");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterUrlException() throws Exception {
|
||||
URLConverter conv = new URLConverter();
|
||||
|
|
@ -158,7 +158,7 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertEquals(MalformedURLException.class, e.getCause().getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("error"), "Error message string is missing error");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterEnum() throws Exception {
|
||||
EnumConverter convOrg = new EnumConverter();
|
||||
|
|
@ -170,16 +170,16 @@ public class DefaultObjectConverterProviderTest {
|
|||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertEquals("XML_READ", resultBack.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterEnumError() throws Exception {
|
||||
EnumConverter convOrg = new EnumConverter();
|
||||
convOrg.setEnumClass(X4OPhaseType.class.getName());
|
||||
ObjectConverter conv = convOrg.clone();
|
||||
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
conv.convertTo("nonEnumError", locale);
|
||||
conv.convertTo("nonEnumError", locale);
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
|
|
@ -187,13 +187,13 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertEquals(ObjectConverterException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("EnumError"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterEnumNullError() throws Exception {
|
||||
EnumConverter conv = new EnumConverter();
|
||||
Exception e = null;
|
||||
try {
|
||||
conv.convertTo("nonEnumError", locale);
|
||||
conv.convertTo("nonEnumError", locale);
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ public class DefaultObjectConverterProviderTest {
|
|||
Assertions.assertEquals(ObjectConverterException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("enumClass"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterClass() throws Exception {
|
||||
ClassConverter classOrg = new ClassConverter();
|
||||
|
|
@ -212,12 +212,12 @@ public class DefaultObjectConverterProviderTest {
|
|||
Object resultBack = conv.convertBack(result, locale);
|
||||
Assertions.assertEquals("java.lang.Object", resultBack.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterClassError() throws Exception {
|
||||
ClassConverter classOrg = new ClassConverter();
|
||||
ObjectConverter conv = classOrg.clone();
|
||||
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
conv.convertTo("java.lang.ObjectError", locale);
|
||||
|
|
|
|||
|
|
@ -40,63 +40,63 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class AttributeBeanTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testBeanBody() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
|
||||
|
||||
TestObjectRoot root = reader.readResource("tests/attributes/test-body.xml");
|
||||
Assertions.assertNotNull(root);
|
||||
List<TestObjectChild> childs = root.getTestObjectChilds();
|
||||
Assertions.assertEquals(2,childs.size());
|
||||
Assertions.assertEquals(2, childs.size());
|
||||
TestObjectChild child0 = childs.get(0);
|
||||
TestObjectChild child1 = childs.get(1);
|
||||
Assertions.assertEquals("attr-name-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕",child0.getName());
|
||||
Assertions.assertEquals("body-name-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕",child1.getName());
|
||||
Assertions.assertEquals("attr-name-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", child0.getName());
|
||||
Assertions.assertEquals("body-name-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", child1.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBeanProperties() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
|
||||
|
||||
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertNotNull(root.getTestBeans());
|
||||
Assertions.assertEquals(2, root.getTestBeans().size());
|
||||
TestBean b = root.getTestBeans().get(0);
|
||||
TestBean beanPublic = root.getTestBeans().get(1);
|
||||
|
||||
Assertions.assertEquals(123 ,0+ b.getPrivateIntegerTypeField());
|
||||
Assertions.assertEquals(123 ,0+ b.getPrivateIntegerObjectField());
|
||||
|
||||
Assertions.assertEquals(123l ,0+ b.getPrivateLongTypeField());
|
||||
Assertions.assertEquals(123l ,0+ b.getPrivateLongObjectField());
|
||||
|
||||
Assertions.assertEquals(123.45d ,0+ b.getPrivateDoubleTypeField());
|
||||
Assertions.assertEquals(123.45d ,0+ b.getPrivateDoubleObjectField());
|
||||
|
||||
Assertions.assertEquals(123.45f ,0+ b.getPrivateFloatTypeField());
|
||||
Assertions.assertEquals(123.45f ,0+ b.getPrivateFloatObjectField());
|
||||
|
||||
Assertions.assertEquals(67 ,0+ b.getPrivateByteTypeField());
|
||||
Assertions.assertEquals(67 ,0+ b.getPrivateByteObjectField());
|
||||
|
||||
Assertions.assertEquals(true, b.isPrivateBooleanTypeField());
|
||||
Assertions.assertEquals(new Boolean(true), b.getPrivateBooleanObjectField());
|
||||
|
||||
Assertions.assertEquals('W' ,0+ b.getPrivateCharTypeField());
|
||||
Assertions.assertEquals('C' ,0+ b.getPrivateCharObjectField());
|
||||
|
||||
Assertions.assertEquals("x4o-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕" ,b.getPrivateStringObjectField());
|
||||
//Assertions.assertEquals("x4o-ᒡᒢᑊᒻᒻᓫᔿ" ,b.getPrivateStringObjectFieldUnicodeᒡᒢᑊᒻᒻᓫᔿ()); // SAX fails
|
||||
Assertions.assertEquals("x4o-仙上主天" ,b.getPrivateStringObjectFieldUnicode仙上主天());
|
||||
|
||||
//TODO: add again: assertEquals(true ,null!=b.getPrivateDateObjectField());
|
||||
|
||||
Assertions.assertEquals("x4o-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕" ,beanPublic.publicStringObjectField);
|
||||
//Assertions.assertEquals("x4o-ᒡᒢᑊᒻᒻᓫᔿ" ,beanPublic.publicStringObjectFieldUnicodeᒡᒢᑊᒻᒻᓫᔿ); // SAX fails
|
||||
Assertions.assertEquals("x4o-仙上主天" ,beanPublic.publicStringObjectFieldUnicode仙上主天);
|
||||
|
||||
Assertions.assertEquals(123, 0 + b.getPrivateIntegerTypeField());
|
||||
Assertions.assertEquals(123, 0 + b.getPrivateIntegerObjectField());
|
||||
|
||||
Assertions.assertEquals(123l, 0 + b.getPrivateLongTypeField());
|
||||
Assertions.assertEquals(123l, 0 + b.getPrivateLongObjectField());
|
||||
|
||||
Assertions.assertEquals(123.45d, 0 + b.getPrivateDoubleTypeField());
|
||||
Assertions.assertEquals(123.45d, 0 + b.getPrivateDoubleObjectField());
|
||||
|
||||
Assertions.assertEquals(123.45f, 0 + b.getPrivateFloatTypeField());
|
||||
Assertions.assertEquals(123.45f, 0 + b.getPrivateFloatObjectField());
|
||||
|
||||
Assertions.assertEquals(67, 0 + b.getPrivateByteTypeField());
|
||||
Assertions.assertEquals(67, 0 + b.getPrivateByteObjectField());
|
||||
|
||||
Assertions.assertEquals(true, b.isPrivateBooleanTypeField());
|
||||
Assertions.assertEquals(new Boolean(true), b.getPrivateBooleanObjectField());
|
||||
|
||||
Assertions.assertEquals('W', 0 + b.getPrivateCharTypeField());
|
||||
Assertions.assertEquals('C', 0 + b.getPrivateCharObjectField());
|
||||
|
||||
Assertions.assertEquals("x4o-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", b.getPrivateStringObjectField());
|
||||
// Assertions.assertEquals("x4o-ᒡᒢᑊᒻᒻᓫᔿ" ,b.getPrivateStringObjectFieldUnicodeᒡᒢᑊᒻᒻᓫᔿ()); // SAX fails
|
||||
Assertions.assertEquals("x4o-仙上主天", b.getPrivateStringObjectFieldUnicode仙上主天());
|
||||
|
||||
// TODO: add again: assertEquals(true ,null!=b.getPrivateDateObjectField());
|
||||
|
||||
Assertions.assertEquals("x4o-𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", beanPublic.publicStringObjectField);
|
||||
// Assertions.assertEquals("x4o-ᒡᒢᑊᒻᒻᓫᔿ" ,beanPublic.publicStringObjectFieldUnicodeᒡᒢᑊᒻᒻᓫᔿ); // SAX fails
|
||||
Assertions.assertEquals("x4o-仙上主天", beanPublic.publicStringObjectFieldUnicode仙上主天);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import org.xml.sax.SAXException;
|
|||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class EmptyXmlTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testFileNotFound() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -50,9 +50,9 @@ public class EmptyXmlTest {
|
|||
Assertions.assertEquals(true, e.getMessage().contains("non-excisting-file.xml"));
|
||||
return;
|
||||
}
|
||||
Assertions.assertEquals(true,false);
|
||||
Assertions.assertEquals(true, false);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResourceNotFound() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -60,25 +60,25 @@ public class EmptyXmlTest {
|
|||
try {
|
||||
reader.readResource("tests/empty-xml/non-excisting-resource.xml");
|
||||
} catch (NullPointerException e) {
|
||||
Assertions.assertEquals(true,e.getMessage().contains("Could not find resource"));
|
||||
Assertions.assertEquals(true, e.getMessage().contains("Could not find resource"));
|
||||
return;
|
||||
}
|
||||
Assertions.assertEquals(true,false);
|
||||
Assertions.assertEquals(true, false);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResourceParsing() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
try {
|
||||
reader.readResource("tests/empty-xml/empty-test.xml");
|
||||
reader.readResource("tests/empty-xml/empty-test.xml");
|
||||
} catch (SAXException e) {
|
||||
// Assertions.assertEquals("No ElementNamespace found for empty namespace.", e.getMessage());
|
||||
return;
|
||||
}
|
||||
Assertions.assertEquals(true,false);
|
||||
Assertions.assertEquals(true, false);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResourceEmptyReal() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -86,12 +86,12 @@ public class EmptyXmlTest {
|
|||
try {
|
||||
reader.readResource("tests/empty-xml/empty-real.xml");
|
||||
} catch (SAXException e) {
|
||||
Assertions.assertEquals(true,e.getMessage().contains("Premature end of file."));
|
||||
Assertions.assertEquals(true, e.getMessage().contains("Premature end of file."));
|
||||
return;
|
||||
}
|
||||
Assertions.assertEquals(true,false);
|
||||
Assertions.assertEquals(true, false);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResourceEmptyXml() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -100,29 +100,29 @@ public class EmptyXmlTest {
|
|||
reader.readResource("tests/empty-xml/empty-xml.xml");
|
||||
} catch (SAXException e) {
|
||||
boolean hasError = e.getMessage().contains("Premature end of file."); // java6+ sax message
|
||||
if (hasError==false) {
|
||||
if (hasError == false) {
|
||||
hasError = e.getMessage().contains("A well-formed document requires a root element."); // xercesImpl sax message
|
||||
}
|
||||
Assertions.assertEquals(true,hasError);
|
||||
Assertions.assertEquals(true, hasError);
|
||||
return;
|
||||
}
|
||||
Assertions.assertEquals(true,false);
|
||||
Assertions.assertEquals(true, false);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmptyX40() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
Assertions.assertNotNull(driver);
|
||||
|
||||
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
Assertions.assertNotNull(reader);
|
||||
|
||||
|
||||
TestObjectRoot root = reader.readResource("tests/empty-xml/empty-x4o.xml");
|
||||
Assertions.assertNotNull(root);
|
||||
|
||||
Assertions.assertEquals(true,root.getTestBeans().isEmpty());
|
||||
Assertions.assertEquals(true,root.getTestObjectChilds().isEmpty());
|
||||
Assertions.assertEquals(true,root.getTestObjectParents().isEmpty());
|
||||
Assertions.assertEquals(true,root.getTestObjects().isEmpty());
|
||||
|
||||
Assertions.assertEquals(true, root.getTestBeans().isEmpty());
|
||||
Assertions.assertEquals(true, root.getTestObjectChilds().isEmpty());
|
||||
Assertions.assertEquals(true, root.getTestObjectParents().isEmpty());
|
||||
Assertions.assertEquals(true, root.getTestObjects().isEmpty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 May 1, 2011
|
||||
*/
|
||||
public class NamespaceUriTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleUri() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -46,10 +46,10 @@ public class NamespaceUriTest {
|
|||
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "tests/namespace/uri-simple.xml");
|
||||
Assertions.assertEquals(true,session.getRootElement().getChilderen().size()==1);
|
||||
Assertions.assertEquals(true, session.getRootElement().getChilderen().size() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEmptyUri() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -58,10 +58,10 @@ public class NamespaceUriTest {
|
|||
reader.setProperty(DefaultX4OReader.DOC_EMPTY_NAMESPACE_URI, "http://test.junit.x4o.org/xml/ns/junit-test-lang");
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "tests/namespace/uri-empty.xml");
|
||||
Assertions.assertEquals(true,session.getRootElement().getChilderen().size()==1);
|
||||
Assertions.assertEquals(true, session.getRootElement().getChilderen().size() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSchemaUri() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -69,7 +69,7 @@ public class NamespaceUriTest {
|
|||
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "tests/namespace/uri-schema.xml");
|
||||
Assertions.assertEquals(true,session.getRootElement().getChilderen().size()==1);
|
||||
Assertions.assertEquals(true, session.getRootElement().getChilderen().size() == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,15 +52,15 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 Aug 26, 2012
|
||||
*/
|
||||
public class X4ODebugWriterTest {
|
||||
|
||||
|
||||
private File createDebugFile() throws IOException {
|
||||
File debugFile = File.createTempFile("test-debug", ".xml");
|
||||
debugFile.deleteOnExit();
|
||||
return debugFile;
|
||||
}
|
||||
|
||||
|
||||
static public String readFile(File file) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),Charset.forName("UTF-8")));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")));
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
|
|
@ -70,13 +70,13 @@ public class X4ODebugWriterTest {
|
|||
line = br.readLine();
|
||||
}
|
||||
String out = sb.toString();
|
||||
//System.out.println(out);
|
||||
// System.out.println(out);
|
||||
return out;
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDebugOutputReader() throws Exception {
|
||||
File debugFile = createDebugFile();
|
||||
|
|
@ -89,18 +89,18 @@ public class X4ODebugWriterTest {
|
|||
reader.readResource("tests/attributes/test-bean.xml");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Assertions.assertTrue(debugFile.exists(), "Debug file does not exists.");
|
||||
String debug = readFile(debugFile);
|
||||
Assertions.assertNotNull(debug);
|
||||
Assertions.assertFalse(debug.length()==0, "no debug content");
|
||||
Assertions.assertTrue(debug.length()>20, "debug content to small");
|
||||
|
||||
//System.out.println("=================== Reader Output ======================");
|
||||
//System.out.println(debug);
|
||||
Assertions.assertFalse(debug.length() == 0, "no debug content");
|
||||
Assertions.assertTrue(debug.length() > 20, "debug content to small");
|
||||
|
||||
// System.out.println("=================== Reader Output ======================");
|
||||
// System.out.println(debug);
|
||||
debugFile.delete();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDebugOutputWriter() throws Exception {
|
||||
File debugFile = createDebugFile();
|
||||
|
|
@ -109,20 +109,20 @@ public class X4ODebugWriterTest {
|
|||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
X4OWriter<TestObjectRoot> writer = driver.createWriter();
|
||||
TestObjectRoot object = reader.readResource("tests/attributes/test-bean.xml");
|
||||
|
||||
|
||||
try (OutputStream out = new FileOutputStream(debugFile)) {
|
||||
writer.setProperty(DefaultX4OWriter.DEBUG_OUTPUT_STREAM, out);
|
||||
writer.writeFile(object, writeFile);
|
||||
}
|
||||
|
||||
|
||||
Assertions.assertTrue(debugFile.exists(), "Debug file does not exists.");
|
||||
String debug = readFile(debugFile);
|
||||
Assertions.assertNotNull(debug);
|
||||
Assertions.assertFalse(debug.length()==0, "no debug content");
|
||||
Assertions.assertTrue(debug.length()>20, "debug content to small");
|
||||
|
||||
//System.out.println("=================== Writer Output ======================");
|
||||
//System.out.println(debug);
|
||||
Assertions.assertFalse(debug.length() == 0, "no debug content");
|
||||
Assertions.assertTrue(debug.length() > 20, "debug content to small");
|
||||
|
||||
// System.out.println("=================== Writer Output ======================");
|
||||
// System.out.println(debug);
|
||||
debugFile.delete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,12 +47,12 @@ import org.xml.sax.SAXException;
|
|||
* @version 1.0 Aug 27, 2012
|
||||
*/
|
||||
public class X4OEntityResolverTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testElementLangugeNull() throws Exception {
|
||||
Exception e = null;
|
||||
try {
|
||||
new X4OEntityResolver(null,null);
|
||||
new X4OEntityResolver(null, null);
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ public class X4OEntityResolverTest {
|
|||
Assertions.assertEquals(NullPointerException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("null"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResolve() throws Exception {
|
||||
X4ODriver<?> driver = new CelDriver();
|
||||
|
|
@ -68,19 +68,19 @@ public class X4OEntityResolverTest {
|
|||
try (X4OLanguageSession session = language.createLanguageSession()) {
|
||||
X4OLanguageLocal.class.cast(language).init(session);
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(session, DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
|
||||
InputSource input = resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd");
|
||||
InputSource input = resolver.resolveEntity("", "http://cel.x4o.org/xml/ns/cel-root-1.0.xsd");
|
||||
Assertions.assertNotNull(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResolveMissing() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = new TestDriver();
|
||||
// NOTE: this session is not inited, see fix code above.
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguage().createLanguageSession(),DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguage().createLanguageSession(), DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
|
||||
Exception e = null;
|
||||
try {
|
||||
resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-missing-resource");
|
||||
resolver.resolveEntity("", "http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-missing-resource");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
|
|
@ -88,35 +88,35 @@ public class X4OEntityResolverTest {
|
|||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("missing-resource"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResolveProperty() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = new TestDriver();
|
||||
X4OLanguageSession language = driver.createLanguage().createLanguageSession();
|
||||
SAX3PropertyConfig conf = new SAX3PropertyConfig(DefaultX4OReader.DEFAULT_PROPERTY_CONFIG,SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"reader/x4o/");
|
||||
SAX3PropertyConfig conf = new SAX3PropertyConfig(DefaultX4OReader.DEFAULT_PROPERTY_CONFIG, SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "reader/x4o/");
|
||||
conf.setProperty(DefaultX4OReader.SAX_ENTITY_RESOLVER, new TestEntityResolver());
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(language,conf);
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(language, conf);
|
||||
Exception e = null;
|
||||
InputSource input = null;
|
||||
try {
|
||||
input = resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd");
|
||||
input = resolver.resolveEntity("", "http://cel.x4o.org/xml/ns/cel-root-1.0.xsd");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
Assertions.assertNull(e);
|
||||
Assertions.assertNotNull(input);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResolvePropertyNull() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = new TestDriver();
|
||||
X4OLanguageSession language = driver.createLanguage().createLanguageSession();
|
||||
SAX3PropertyConfig conf = new SAX3PropertyConfig(DefaultX4OReader.DEFAULT_PROPERTY_CONFIG,SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"reader/x4o/");
|
||||
SAX3PropertyConfig conf = new SAX3PropertyConfig(DefaultX4OReader.DEFAULT_PROPERTY_CONFIG, SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "reader/x4o/");
|
||||
conf.setProperty(DefaultX4OReader.SAX_ENTITY_RESOLVER, new TestEntityResolver());
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(language,conf);
|
||||
X4OEntityResolver resolver = new X4OEntityResolver(language, conf);
|
||||
Exception e = null;
|
||||
try {
|
||||
resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-null");
|
||||
resolver.resolveEntity("", "http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-null");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ public class X4OEntityResolverTest {
|
|||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
Assertions.assertTrue(e.getMessage().contains("null"));
|
||||
}
|
||||
|
||||
|
||||
public class TestEntityResolver implements EntityResolver {
|
||||
|
||||
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
|
||||
|
|
@ -134,6 +134,6 @@ public class X4OEntityResolverTest {
|
|||
return new InputSource();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,31 +38,31 @@ import org.x4o.xml.test.TestDriver;
|
|||
* @version 1.0 Jan 20, 2012
|
||||
*/
|
||||
public class X4OParserConfigurationTest {
|
||||
|
||||
|
||||
static TestDriver driver;
|
||||
static X4OLanguageConfiguration config;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
driver = TestDriver.getInstance();
|
||||
config = driver.createLanguage().getLanguageConfiguration();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParserConfigurationLanguage() {
|
||||
Assertions.assertEquals("test",driver.getLanguageName());
|
||||
Assertions.assertEquals(X4OLanguageConfiguration.DEFAULT_LANG_MODULES_FILE,config.getLanguageResourceModulesFileName());
|
||||
Assertions.assertEquals(X4OLanguageConfiguration.DEFAULT_LANG_PATH_PREFIX,config.getLanguageResourcePathPrefix());
|
||||
Assertions.assertEquals("test", driver.getLanguageName());
|
||||
Assertions.assertEquals(X4OLanguageConfiguration.DEFAULT_LANG_MODULES_FILE, config.getLanguageResourceModulesFileName());
|
||||
Assertions.assertEquals(X4OLanguageConfiguration.DEFAULT_LANG_PATH_PREFIX, config.getLanguageResourcePathPrefix());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParserConfigurationElement() {
|
||||
Assertions.assertNotNull(config.getDefaultElement());
|
||||
Assertions.assertTrue(Element.class.isAssignableFrom(config.getDefaultElement()), "No Element Interface");
|
||||
|
||||
|
||||
Assertions.assertNotNull(config.getDefaultElementClass());
|
||||
Assertions.assertTrue(ElementClass.class.isAssignableFrom(config.getDefaultElementClass()), "No ElementClass Interface");
|
||||
|
||||
|
||||
Assertions.assertNotNull(config.getDefaultElementClassAttribute());
|
||||
Assertions.assertTrue(ElementClassAttribute.class.isAssignableFrom(config.getDefaultElementClassAttribute()), "No ElementClassAttribute Interface");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,50 +35,41 @@ import org.x4o.xml.lang.phase.X4OPhaseType;
|
|||
import org.x4o.xml.test.TestDriver;
|
||||
|
||||
/**
|
||||
* Tests some code for testing x4o phases.
|
||||
* *
|
||||
* Tests some code for testing x4o phases. *
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 15, 2009
|
||||
*/
|
||||
public class X4OPhaseManagerTest {
|
||||
|
||||
|
||||
static boolean phaseRunned = false;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
phaseRunned = false;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPhases() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
X4OLanguageSession context = driver.createLanguage().createLanguageSession();
|
||||
DefaultX4OPhaseManager manager = (DefaultX4OPhaseManager)context.getLanguage().getPhaseManager();
|
||||
DefaultX4OPhaseManager manager = (DefaultX4OPhaseManager) context.getLanguage().getPhaseManager();
|
||||
Collection<X4OPhase> phasesAll = manager.getAllPhases();
|
||||
List<X4OPhase> phases = manager.getOrderedPhases(X4OPhaseType.XML_READ);
|
||||
Assertions.assertNotNull(phases);
|
||||
Assertions.assertFalse(phases.isEmpty());
|
||||
Assertions.assertNotNull(phasesAll);
|
||||
Assertions.assertFalse(phasesAll.isEmpty());
|
||||
for (X4OPhase phase:phases) {
|
||||
for (X4OPhase phase : phases) {
|
||||
Assertions.assertNotNull(phase);
|
||||
Assertions.assertNotNull(phase.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void testPhaseManager() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
ElementLanguage context = driver.createLanguageSession();
|
||||
X4OPhaseManager manager = context.getLanguage().getPhaseManager();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
manager.addX4OPhaseHandler(null);
|
||||
} catch (NullPointerException ee) {
|
||||
e = ee;
|
||||
}
|
||||
Assertions.assertEquals(true, e!=null );
|
||||
}
|
||||
*/
|
||||
* public void testPhaseManager() throws Exception { TestDriver driver = TestDriver.getInstance(); ElementLanguage context = driver.createLanguageSession();
|
||||
* X4OPhaseManager manager = context.getLanguage().getPhaseManager();
|
||||
*
|
||||
* Exception e = null; try { manager.addX4OPhaseHandler(null); } catch (NullPointerException ee) { e = ee; } Assertions.assertEquals(true, e!=null ); }
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 Aug 22, 2012
|
||||
*/
|
||||
public class EldValidatingTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidation() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
//reader.getContentConfig().setProperty("",true);
|
||||
// reader.getContentConfig().setProperty("",true);
|
||||
reader.setProperty(DefaultX4OReader.VALIDATION_INPUT_DOC, true);
|
||||
//parser.setProperty(DefaultX4OReader.VALIDATION_SCHEMA_PATH, "/tmp");
|
||||
// parser.setProperty(DefaultX4OReader.VALIDATION_SCHEMA_PATH, "/tmp");
|
||||
try {
|
||||
// TODO: reader.readResource("META-INF/eld/eld-lang.eld");
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -36,66 +36,54 @@ import org.x4o.xml.lang.task.run.X4OTaskRunner;
|
|||
import org.x4o.xml.test.TestDriver;
|
||||
|
||||
/**
|
||||
* Test for eld doc generation
|
||||
* Test for eld doc generation
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 26, 2010
|
||||
*/
|
||||
public class X4OWriteLanguageDocExecutorTest {
|
||||
|
||||
|
||||
private File createOutputPath(String dir) throws Exception {
|
||||
File result = new File("target/tests"+File.separator+dir);
|
||||
if (result.exists()==false) {
|
||||
File result = new File("target/tests" + File.separator + dir);
|
||||
if (result.exists() == false) {
|
||||
result.mkdirs();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void testDoc(String language,String outputPostfix) throws Exception {
|
||||
|
||||
public void testDoc(String language, String outputPostfix) throws Exception {
|
||||
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(language);
|
||||
X4OLanguageTask task = driver.getLanguageTask(EldDocLanguageTask.TASK_ID);
|
||||
SAX3PropertyConfig config = task.createTaskConfig();
|
||||
File outputPath = createOutputPath(outputPostfix);
|
||||
config.setProperty(EldDocWriter.OUTPUT_PATH,outputPath);
|
||||
config.setProperty(EldDocWriter.OUTPUT_PATH, outputPath);
|
||||
X4OTaskRunner.runTaskLanguage(task, driver.createLanguage(), config);
|
||||
Assertions.assertTrue(outputPath.exists());
|
||||
Assertions.assertTrue(outputPath.list()!=null);
|
||||
Assertions.assertTrue(outputPath.list().length>2);
|
||||
Assertions.assertTrue(outputPath.list() != null);
|
||||
Assertions.assertTrue(outputPath.list().length > 2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCelDoc() throws Exception {
|
||||
testDoc(CelDriver.LANGUAGE_NAME,"junit-doc-cel");
|
||||
testDoc(CelDriver.LANGUAGE_NAME, "junit-doc-cel");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEldDoc() throws Exception {
|
||||
testDoc(EldDriver.LANGUAGE_NAME,"junit-doc-eld");
|
||||
testDoc(EldDriver.LANGUAGE_NAME, "junit-doc-eld");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUnitDoc() throws Exception {
|
||||
testDoc(TestDriver.LANGUAGE_NAME,"junit-doc-test");
|
||||
testDoc(TestDriver.LANGUAGE_NAME, "junit-doc-test");
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
public void testSwiXml2Doc() throws Exception {
|
||||
testDoc(EldDriver.LANGUAGE_NAME,"junit-doc-eld");
|
||||
EldDocLanguageTask writer = new EldDocLanguageTask();
|
||||
writer.setBasePath(createOutputTargetPath("junit-swixml2"));
|
||||
writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
|
||||
writer.setLanguageVersion(SwiXmlDriver.LANGUAGE_VERSION_2);
|
||||
writer.execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwiXml3Doc() throws Exception {
|
||||
testDoc(EldDriver.LANGUAGE_NAME,"junit-doc-eld");
|
||||
EldDocLanguageTask writer = new EldDocLanguageTask();
|
||||
writer.setBasePath(createOutputTargetPath("junit-swixml3"));
|
||||
writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
|
||||
writer.setLanguageVersion(SwiXmlDriver.LANGUAGE_VERSION_3);
|
||||
writer.execute();
|
||||
}
|
||||
*/
|
||||
/*
|
||||
* @Test public void testSwiXml2Doc() throws Exception { testDoc(EldDriver.LANGUAGE_NAME,"junit-doc-eld"); EldDocLanguageTask writer = new
|
||||
* EldDocLanguageTask(); writer.setBasePath(createOutputTargetPath("junit-swixml2")); writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
|
||||
* writer.setLanguageVersion(SwiXmlDriver.LANGUAGE_VERSION_2); writer.execute(); }
|
||||
*
|
||||
* @Test public void testSwiXml3Doc() throws Exception { testDoc(EldDriver.LANGUAGE_NAME,"junit-doc-eld"); EldDocLanguageTask writer = new
|
||||
* EldDocLanguageTask(); writer.setBasePath(createOutputTargetPath("junit-swixml3")); writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
|
||||
* writer.setLanguageVersion(SwiXmlDriver.LANGUAGE_VERSION_3); writer.execute(); }
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,72 +49,72 @@ import org.x4o.xml.test.swixml.SwiXmlDriver;
|
|||
public class EldXsdLanguageTaskTest {
|
||||
|
||||
private File createOutputPath(String dir) throws Exception {
|
||||
File result = new File("target/tests"+File.separator+dir);
|
||||
if (result.exists()==false) {
|
||||
File result = new File("target/tests" + File.separator + dir);
|
||||
if (result.exists() == false) {
|
||||
result.mkdirs();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
private File testSchema(String language,String outputPostfix,Map<String,Object> props) throws Exception {
|
||||
private File testSchema(String language, String outputPostfix, Map<String, Object> props) throws Exception {
|
||||
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(language);
|
||||
X4OLanguageTask task = driver.getLanguageTask(EldXsdLanguageTask.TASK_ID);
|
||||
SAX3PropertyConfig config = task.createTaskConfig();
|
||||
File outputPath = createOutputPath(outputPostfix);
|
||||
config.setProperty(EldXsdWriter.OUTPUT_PATH,outputPath);
|
||||
config.setProperty(EldXsdWriter.OUTPUT_DOCUMENTATION,false);
|
||||
config.setProperty(SAX3WriterXml.PROLOG_LICENCE_FILE,new File("../licence.txt"));
|
||||
config.setProperty(SAX3WriterXml.PROLOG_USER_COMMENT,"Generated by junit-test-run in class: "+this.getClass().getSimpleName());
|
||||
if (props!=null) {
|
||||
for (String key:props.keySet()) {
|
||||
File outputPath = createOutputPath(outputPostfix);
|
||||
config.setProperty(EldXsdWriter.OUTPUT_PATH, outputPath);
|
||||
config.setProperty(EldXsdWriter.OUTPUT_DOCUMENTATION, false);
|
||||
config.setProperty(SAX3WriterXml.PROLOG_LICENCE_FILE, new File("../licence.txt"));
|
||||
config.setProperty(SAX3WriterXml.PROLOG_USER_COMMENT, "Generated by junit-test-run in class: " + this.getClass().getSimpleName());
|
||||
if (props != null) {
|
||||
for (String key : props.keySet()) {
|
||||
Object value = props.get(key);
|
||||
config.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
X4OTaskRunner.runTaskLanguage(task, driver.createLanguage(), config);
|
||||
Assertions.assertTrue(outputPath.exists());
|
||||
Assertions.assertTrue(outputPath.list()!=null);
|
||||
Assertions.assertTrue(outputPath.list() != null);
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEldSchema() throws Exception {
|
||||
File outputPath = testSchema(EldDriver.LANGUAGE_NAME,"junit-xsd-eld",null);
|
||||
Assertions.assertTrue(outputPath.list().length>2);
|
||||
File outputPath = testSchema(EldDriver.LANGUAGE_NAME, "junit-xsd-eld", null);
|
||||
Assertions.assertTrue(outputPath.list().length > 2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEldCoreSchema() throws Exception {
|
||||
File outputPath = testSchema(CelDriver.LANGUAGE_NAME,"junit-xsd-cel",null);
|
||||
Assertions.assertTrue(outputPath.list().length>1);
|
||||
File outputPath = testSchema(CelDriver.LANGUAGE_NAME, "junit-xsd-cel", null);
|
||||
Assertions.assertTrue(outputPath.list().length > 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwiXmlSchema() throws Exception {
|
||||
File outputPath = testSchema(SwiXmlDriver.LANGUAGE_NAME,"junit-xsd-swixml",null);
|
||||
Assertions.assertTrue(outputPath.list().length>1);
|
||||
File outputPath = testSchema(SwiXmlDriver.LANGUAGE_NAME, "junit-xsd-swixml", null);
|
||||
Assertions.assertTrue(outputPath.list().length > 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFilterNamespace() throws Exception {
|
||||
Map<String,Object> props = new HashMap<String,Object>();
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
props.put(EldXsdWriter.FILTER_NAMESPACE, EldModuleLoaderCore.CEL_ROOT_URI);
|
||||
File outputPath = testSchema(CelDriver.LANGUAGE_NAME,"junit-one-ns",props);
|
||||
Assertions.assertTrue(outputPath.list().length==1);
|
||||
File outputPath = testSchema(CelDriver.LANGUAGE_NAME, "junit-one-ns", props);
|
||||
Assertions.assertTrue(outputPath.list().length == 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFilterElement() throws Exception {
|
||||
Map<String,Object> props = new HashMap<String,Object>();
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
props.put(EldXsdWriter.FILTER_NAMESPACE, EldModuleLoaderCore.CEL_CORE_URI);
|
||||
props.put(EldXsdWriter.FILTER_ELEMENT, "elementInterface");
|
||||
props.put(EldXsdWriter.PROLOG_GENERATED_ENABLE, false);
|
||||
props.put(EldXsdWriter.PROLOG_XMLNS_INFO_ENABLE, false);
|
||||
props.put(SAX3WriterXml.PROLOG_LICENCE_ENABLE,false);
|
||||
File outputPath = testSchema(CelDriver.LANGUAGE_NAME,"junit-one-element",props);
|
||||
Assertions.assertTrue(outputPath.list().length==1);
|
||||
|
||||
props.put(SAX3WriterXml.PROLOG_LICENCE_ENABLE, false);
|
||||
File outputPath = testSchema(CelDriver.LANGUAGE_NAME, "junit-one-element", props);
|
||||
Assertions.assertTrue(outputPath.list().length == 1);
|
||||
|
||||
String text = X4OWriterTest.readFile(new File("target/tests/junit-one-element/cel-core-1.0.xsd"));
|
||||
Assertions.assertNotNull(text);
|
||||
Assertions.assertTrue(text.contains("elementInterface"));
|
||||
|
|
@ -122,7 +122,7 @@ public class EldXsdLanguageTaskTest {
|
|||
Assertions.assertFalse(text.contains("attributeAlias"));
|
||||
Assertions.assertFalse(text.contains("bindingHandler"));
|
||||
Assertions.assertFalse(text.contains("classConverter"));
|
||||
|
||||
Assertions.assertTrue(text.length()<10000);
|
||||
|
||||
Assertions.assertTrue(text.length() < 10000);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,62 +38,62 @@ import org.x4o.xml.test.models.TestObjectChild;
|
|||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class DefaultElementObjectPropertyValueTest {
|
||||
|
||||
|
||||
DefaultElementObjectPropertyValue helper = new DefaultElementObjectPropertyValue();
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
// enable all logs
|
||||
InputStream loggingProperties = DefaultElementObjectPropertyValueTest.class.getResourceAsStream("/META-INF/logging.properties");
|
||||
LogManager.getLogManager().readConfiguration( loggingProperties );
|
||||
LogManager.getLogManager().readConfiguration(loggingProperties);
|
||||
loggingProperties.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNullValue() throws Exception {
|
||||
|
||||
TestObjectChild obj = new TestObjectChild();
|
||||
obj.setName("test");
|
||||
|
||||
|
||||
Assertions.assertEquals("test", obj.getName()); // test org value
|
||||
Assertions.assertEquals("test", helper.getProperty(obj, "name")); // test null get value
|
||||
|
||||
|
||||
helper.setProperty(obj, "name", null);
|
||||
|
||||
|
||||
Assertions.assertEquals(null, obj.getName()); // test null value
|
||||
Assertions.assertEquals(null, helper.getProperty(obj, "name")); // test null get value
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIntegerValue() throws Exception {
|
||||
TestObjectChild obj = new TestObjectChild();
|
||||
helper.setProperty(obj, "price", 666);
|
||||
|
||||
Assertions.assertEquals(666,helper.getProperty(obj, "price"));
|
||||
|
||||
Assertions.assertEquals(666, helper.getProperty(obj, "price"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testException() throws Exception {
|
||||
TestObjectChild obj = new TestObjectChild();
|
||||
helper.setProperty(obj, "price", 666);
|
||||
|
||||
|
||||
boolean error = false;
|
||||
try {
|
||||
helper.getProperty(obj, "price2");
|
||||
} catch (ElementObjectPropertyValueException not) {
|
||||
error = true;
|
||||
}
|
||||
Assertions.assertEquals(true,error);
|
||||
Assertions.assertEquals(true, error);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChinees() throws Exception {
|
||||
TestBean obj = new TestBean();
|
||||
|
||||
|
||||
helper.setProperty(obj, "privateStringObjectField", "foo");
|
||||
Assertions.assertEquals("foo",helper.getProperty(obj, "privateStringObjectField"));
|
||||
|
||||
Assertions.assertEquals("foo", helper.getProperty(obj, "privateStringObjectField"));
|
||||
|
||||
helper.setProperty(obj, "privateStringObjectFieldUnicode仙上主天", "bar");
|
||||
Assertions.assertEquals("bar",helper.getProperty(obj, "privateStringObjectFieldUnicode仙上主天"));
|
||||
Assertions.assertEquals("bar", helper.getProperty(obj, "privateStringObjectFieldUnicode仙上主天"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 Apr 28, 2013
|
||||
*/
|
||||
public class X4OConnectionTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testReaderPropertyFailRead() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -51,7 +51,7 @@ public class X4OConnectionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("key"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("No"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReaderPropertyFail() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -67,7 +67,7 @@ public class X4OConnectionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("key"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("No"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriterPropertyFail() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 Apr 15, 2013
|
||||
*/
|
||||
public class X4OReaderSessionTest {
|
||||
|
||||
|
||||
private File copyResourceToTempFile() throws IOException {
|
||||
File tempFile = File.createTempFile("test-resource", ".xml");
|
||||
tempFile.deleteOnExit();
|
||||
|
|
@ -56,7 +56,7 @@ public class X4OReaderSessionTest {
|
|||
}
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileName() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -64,11 +64,11 @@ public class X4OReaderSessionTest {
|
|||
File xmlFile = copyResourceToTempFile();
|
||||
TestObjectRoot root = reader.readFile(xmlFile.getAbsolutePath());
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileNameNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -85,7 +85,7 @@ public class X4OReaderSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("fileName"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFile() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -93,11 +93,11 @@ public class X4OReaderSessionTest {
|
|||
File xmlFile = copyResourceToTempFile();
|
||||
TestObjectRoot root = reader.readFile(xmlFile);
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -114,7 +114,7 @@ public class X4OReaderSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("file"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileNotExists() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -132,7 +132,7 @@ public class X4OReaderSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("exists"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("File"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileNotReadable() throws Exception {
|
||||
if (File.separatorChar != '/') {
|
||||
|
|
@ -151,7 +151,7 @@ public class X4OReaderSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("exists"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("read"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadResource() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -159,7 +159,7 @@ public class X4OReaderSessionTest {
|
|||
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
|
||||
Assertions.assertNotNull(root);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadResourceNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -175,24 +175,21 @@ public class X4OReaderSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("resourceName"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadString() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
X4OReaderSession<TestObjectRoot> reader = driver.createReaderSession();
|
||||
TestObjectRoot root = reader.readString(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
|
||||
"<root:root xmlns:root=\"http://test.junit.x4o.org/xml/ns/junit-test-root\" xmlns=\"http://test.junit.x4o.org/xml/ns/junit-test-lang\">"+
|
||||
"<testBean privateIntegerTypeField=\"987654321\"/>"+
|
||||
"</root:root>"
|
||||
);
|
||||
TestObjectRoot root = reader.readString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
+ "<root:root xmlns:root=\"http://test.junit.x4o.org/xml/ns/junit-test-root\" xmlns=\"http://test.junit.x4o.org/xml/ns/junit-test-lang\">"
|
||||
+ "<testBean privateIntegerTypeField=\"987654321\"/>" + "</root:root>");
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
Assertions.assertEquals("987654321", ""+bean.getPrivateIntegerTypeField());
|
||||
Assertions.assertEquals("987654321", "" + bean.getPrivateIntegerTypeField());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadStringNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -208,7 +205,7 @@ public class X4OReaderSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("string"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadUrl() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -216,11 +213,11 @@ public class X4OReaderSessionTest {
|
|||
URL xmlUrl = Thread.currentThread().getContextClassLoader().getResource("tests/attributes/test-bean.xml");
|
||||
TestObjectRoot root = reader.readUrl(xmlUrl);
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadUrlNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import org.x4o.xml.test.models.TestObjectRoot;
|
|||
* @version 1.0 Apr 15, 2013
|
||||
*/
|
||||
public class X4OReaderTest {
|
||||
|
||||
|
||||
private File copyResourceToTempFile() throws IOException {
|
||||
File tempFile = File.createTempFile("test-resource", ".xml");
|
||||
tempFile.deleteOnExit();
|
||||
|
|
@ -56,7 +56,7 @@ public class X4OReaderTest {
|
|||
}
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadInputStream() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -71,11 +71,11 @@ public class X4OReaderTest {
|
|||
inputStream.close();
|
||||
}
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadResource() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -83,7 +83,7 @@ public class X4OReaderTest {
|
|||
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
|
||||
Assertions.assertNotNull(root);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadResourceNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -99,24 +99,21 @@ public class X4OReaderTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("resourceName"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadString() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
TestObjectRoot root = reader.readString(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
|
||||
"<root:root xmlns:root=\"http://test.junit.x4o.org/xml/ns/junit-test-root\" xmlns=\"http://test.junit.x4o.org/xml/ns/junit-test-lang\">"+
|
||||
"<testBean privateIntegerTypeField=\"987654321\"/>"+
|
||||
"</root:root>"
|
||||
);
|
||||
TestObjectRoot root = reader.readString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
+ "<root:root xmlns:root=\"http://test.junit.x4o.org/xml/ns/junit-test-root\" xmlns=\"http://test.junit.x4o.org/xml/ns/junit-test-lang\">"
|
||||
+ "<testBean privateIntegerTypeField=\"987654321\"/>" + "</root:root>");
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
Assertions.assertEquals("987654321", ""+bean.getPrivateIntegerTypeField());
|
||||
Assertions.assertEquals("987654321", "" + bean.getPrivateIntegerTypeField());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadStringNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -132,7 +129,7 @@ public class X4OReaderTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("string"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadUrl() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -140,11 +137,11 @@ public class X4OReaderTest {
|
|||
URL xmlUrl = Thread.currentThread().getContextClassLoader().getResource("tests/attributes/test-bean.xml");
|
||||
TestObjectRoot root = reader.readUrl(xmlUrl);
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadUrlNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -160,7 +157,7 @@ public class X4OReaderTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("url"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileName() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -168,11 +165,11 @@ public class X4OReaderTest {
|
|||
File xmlFile = copyResourceToTempFile();
|
||||
TestObjectRoot root = reader.readFile(xmlFile.getAbsolutePath());
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileNameNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -189,7 +186,7 @@ public class X4OReaderTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("fileName"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFile() throws Exception {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
|
|
@ -197,11 +194,11 @@ public class X4OReaderTest {
|
|||
File xmlFile = copyResourceToTempFile();
|
||||
TestObjectRoot root = reader.readFile(xmlFile);
|
||||
Assertions.assertNotNull(root);
|
||||
Assertions.assertTrue(root.getTestBeans().size()>0);
|
||||
Assertions.assertTrue(root.getTestBeans().size() > 0);
|
||||
TestBean bean = root.getTestBeans().get(0);
|
||||
Assertions.assertNotNull(bean);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadFileNull() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@ import org.xml.sax.SAXException;
|
|||
* @version 1.0 Apr 28, 2013
|
||||
*/
|
||||
public class X4OWriterSessionTest {
|
||||
|
||||
|
||||
private File createOutputFile() throws IOException {
|
||||
File outputFile = File.createTempFile("test-writer-context", ".xml");
|
||||
outputFile.deleteOnExit();
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
|
||||
private X4OLanguageSession createContext() throws SAXException, X4OConnectionException, IOException {
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
|
|
@ -57,7 +57,7 @@ public class X4OWriterSessionTest {
|
|||
X4OLanguageSession context = driver.createLanguage().createLanguageSession();
|
||||
Element rootElement = null;
|
||||
try {
|
||||
rootElement = (Element)context.getLanguage().getLanguageConfiguration().getDefaultElement().newInstance();
|
||||
rootElement = (Element) context.getLanguage().getLanguageConfiguration().getDefaultElement().newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
|
|
@ -67,7 +67,7 @@ public class X4OWriterSessionTest {
|
|||
context.setRootElement(rootElement);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteFile() throws Exception {
|
||||
File outputFile = createOutputFile();
|
||||
|
|
@ -75,7 +75,7 @@ public class X4OWriterSessionTest {
|
|||
X4OWriterSession<TestObjectRoot> writer = driver.createWriterSession();
|
||||
|
||||
writer.writeFileSession(createContext(), outputFile);
|
||||
String text = X4OWriterTest.readFile( outputFile );
|
||||
String text = X4OWriterTest.readFile(outputFile);
|
||||
outputFile.delete();
|
||||
|
||||
Assertions.assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
|
|
@ -83,7 +83,7 @@ public class X4OWriterSessionTest {
|
|||
Assertions.assertTrue(text.contains("<junit-test-lang:parent name=\"test-bean.xml\"/>"));
|
||||
Assertions.assertTrue(text.contains("<junit-test-lang:configBean"), text);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteFileNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -100,15 +100,15 @@ public class X4OWriterSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("file"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteFileName() throws Exception {
|
||||
File outputFile = createOutputFile();
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OWriterSession<TestObjectRoot> writer = driver.createWriterSession();
|
||||
|
||||
|
||||
writer.writeFileSession(createContext(), outputFile.getAbsolutePath());
|
||||
String text = X4OWriterTest.readFile( outputFile );
|
||||
String text = X4OWriterTest.readFile(outputFile);
|
||||
outputFile.delete();
|
||||
|
||||
Assertions.assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
|
|
@ -116,7 +116,7 @@ public class X4OWriterSessionTest {
|
|||
Assertions.assertTrue(text.contains("<junit-test-lang:parent name=\"test-bean.xml\"/>"));
|
||||
Assertions.assertTrue(text.contains("<junit-test-lang:configBean"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteFileNameNull() throws Exception {
|
||||
TestDriver driver = TestDriver.getInstance();
|
||||
|
|
@ -133,20 +133,20 @@ public class X4OWriterSessionTest {
|
|||
Assertions.assertTrue(e.getMessage().contains("null"), "Wrong exception message");
|
||||
Assertions.assertTrue(e.getMessage().contains("fileName"), "Wrong exception message");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteStream() throws Exception {
|
||||
File outputFile = createOutputFile();
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OWriterSession<TestObjectRoot> writer = driver.createWriterSession();
|
||||
|
||||
|
||||
OutputStream outputStream = new FileOutputStream(outputFile);
|
||||
try {
|
||||
writer.writeSession(createContext(),outputStream);
|
||||
writer.writeSession(createContext(), outputStream);
|
||||
} finally {
|
||||
outputStream.close();
|
||||
}
|
||||
String text = X4OWriterTest.readFile( outputFile );
|
||||
String text = X4OWriterTest.readFile(outputFile);
|
||||
outputFile.delete();
|
||||
|
||||
Assertions.assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
|
|
|
|||
|
|
@ -48,15 +48,15 @@ import org.x4o.xml.test.swixml.SwingEngine;
|
|||
* @version 1.0 Apr 28, 2013
|
||||
*/
|
||||
public class X4OWriterTest {
|
||||
|
||||
|
||||
private File createOutputFile() throws IOException {
|
||||
File outputFile = File.createTempFile("test-writer", ".xml");
|
||||
outputFile.deleteOnExit();
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
|
||||
static public String readFile(File file) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),Charset.forName("UTF-8")));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")));
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
|
|
@ -66,48 +66,48 @@ public class X4OWriterTest {
|
|||
line = br.readLine();
|
||||
}
|
||||
String out = sb.toString();
|
||||
//System.out.println(out);
|
||||
// System.out.println(out);
|
||||
return out;
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriterSwiXmlOutput() throws Exception {
|
||||
Accelerator3 ac3 = new Accelerator3(false);
|
||||
SwingEngine engine = new SwingEngine(ac3);
|
||||
|
||||
|
||||
File outputFile = createOutputFile();
|
||||
X4ODriver<Component> driver = SwiXmlDriver.getInstance();
|
||||
X4OReader<Component> reader = driver.createReader();
|
||||
X4OWriter<Component> writer = driver.createWriter(SwiXmlDriver.LANGUAGE_VERSION_3);
|
||||
|
||||
//reader.setProperty(key, value);
|
||||
//writer.setProperty(key, value);
|
||||
|
||||
|
||||
// reader.setProperty(key, value);
|
||||
// writer.setProperty(key, value);
|
||||
|
||||
reader.addELBeanInstance(SwiXmlDriver.LANGUAGE_EL_SWING_ENGINE, engine);
|
||||
Component root = reader.readResource("tests/swixml/swixml-accelerator-3.0.xml");
|
||||
writer.writeFile(root, outputFile);
|
||||
|
||||
|
||||
Assertions.assertTrue(outputFile.exists(), "Debug file does not exists.");
|
||||
|
||||
//String text = new Scanner( outputFile ).useDelimiter("\\A").next();
|
||||
//System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath());
|
||||
|
||||
|
||||
// String text = new Scanner( outputFile ).useDelimiter("\\A").next();
|
||||
// System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath());
|
||||
|
||||
outputFile.delete();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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 = readFile( outputFile );
|
||||
String text = readFile(outputFile);
|
||||
outputFile.delete();
|
||||
|
||||
Assertions.assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
|
|
@ -115,17 +115,17 @@ public class X4OWriterTest {
|
|||
Assertions.assertTrue(text.contains("<junit-test-lang:parent name=\"test-bean.xml\"/>"));
|
||||
Assertions.assertTrue(text.contains("<junit-test-lang:configBean"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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 = readFile( outputFile );
|
||||
String text = readFile(outputFile);
|
||||
outputFile.delete();
|
||||
|
||||
Assertions.assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
|
|
@ -133,24 +133,24 @@ public class X4OWriterTest {
|
|||
Assertions.assertTrue(text.contains("<junit-test-lang:parent name=\"test-bean.xml\"/>"));
|
||||
Assertions.assertTrue(text.contains("<junit-test-lang:configBean"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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);
|
||||
writer.write(root, outputStream);
|
||||
} finally {
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
|
||||
writer.writeFile(root, outputFile.getAbsolutePath());
|
||||
String text = readFile( outputFile );
|
||||
String text = readFile(outputFile);
|
||||
outputFile.delete();
|
||||
|
||||
Assertions.assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
|
|
|
|||
|
|
@ -45,16 +45,16 @@ public class DefaultX4OLanguageLoaderTest {
|
|||
static X4OLanguageLocal language;
|
||||
static X4OLanguageSession session;
|
||||
static DefaultX4OLanguageLoader loader;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
driver = TestDriver.getInstance();
|
||||
language = (X4OLanguageLocal)driver.createLanguage();
|
||||
language = (X4OLanguageLocal) driver.createLanguage();
|
||||
session = language.createLanguageSession();
|
||||
language.init(session);
|
||||
loader = (DefaultX4OLanguageLoader)language.getLanguageConfiguration().getDefaultLanguageLoader().newInstance();
|
||||
loader = (DefaultX4OLanguageLoader) language.getLanguageConfiguration().getDefaultLanguageLoader().newInstance();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLoadingDuplicate() throws Exception {
|
||||
Exception e = null;
|
||||
|
|
@ -66,75 +66,75 @@ public class DefaultX4OLanguageLoaderTest {
|
|||
Assertions.assertNotNull(e, "no duplicate module exception");
|
||||
Assertions.assertTrue(e.getMessage().contains("test"), "wrong module id.");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModulesSimple() throws Exception {
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-simple.xml");
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-simple.xml");
|
||||
Assertions.assertNotNull(in);
|
||||
List<VersionedResources> result = loader.loadLanguageModulesXml(in, "test-modules-simple.xml");
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertFalse(result.isEmpty());
|
||||
Assertions.assertTrue(result.size()==1, "Simple test returned non-one result: "+result.size());
|
||||
Assertions.assertTrue(result.size() == 1, "Simple test returned non-one result: " + result.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModulesFull() throws Exception {
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-full.xml");
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-full.xml");
|
||||
Assertions.assertNotNull(in);
|
||||
List<VersionedResources> result = loader.loadLanguageModulesXml(in, "test-modules-full.xml");
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertFalse(result.isEmpty());
|
||||
VersionedResources vr = result.get(0);
|
||||
Assertions.assertTrue(vr.eldResources.size()>1);
|
||||
Assertions.assertTrue(vr.moduleLoaders.size()>1);
|
||||
Assertions.assertTrue(vr.elbResources.size()>1);
|
||||
Assertions.assertTrue(vr.siblingLoaders.size()==1);
|
||||
Assertions.assertTrue(vr.eldResources.size() > 1);
|
||||
Assertions.assertTrue(vr.moduleLoaders.size() > 1);
|
||||
Assertions.assertTrue(vr.elbResources.size() > 1);
|
||||
Assertions.assertTrue(vr.siblingLoaders.size() == 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModulesDuplicateLoaderNoError() throws Exception {
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-err-loader.xml");
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-err-loader.xml");
|
||||
Assertions.assertNotNull(in);
|
||||
List<VersionedResources> result = loader.loadLanguageModulesXml(in, "test-modules-err-loader.xml");
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertFalse(result.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModulesDuplicateLoader() throws Exception {
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-err-loader.xml");
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-err-loader.xml");
|
||||
Assertions.assertNotNull(in);
|
||||
List<VersionedResources> result = loader.loadLanguageModulesXml(in, "test-modules-err-loader.xml");
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertFalse(result.isEmpty());
|
||||
|
||||
Exception e=null;
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
loader.validateModules(result);
|
||||
} catch (Exception ee) {
|
||||
e=ee;
|
||||
e = ee;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertTrue(e.getMessage().contains("Duplicate"), "No 'Duplicate' found in message: "+e.getMessage());
|
||||
Assertions.assertTrue(e.getMessage().contains("module-loader"), "No 'module-loader' found in message: "+e.getMessage());
|
||||
Assertions.assertTrue(e.getMessage().contains("Duplicate"), "No 'Duplicate' found in message: " + e.getMessage());
|
||||
Assertions.assertTrue(e.getMessage().contains("module-loader"), "No 'module-loader' found in message: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModulesDuplicateSiblingLoader() throws Exception {
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-err-sibling.xml");
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tests/modules/test-modules-err-sibling.xml");
|
||||
Assertions.assertNotNull(in);
|
||||
List<VersionedResources> result = loader.loadLanguageModulesXml(in, "test-modules-err-sibling.xml");
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertFalse(result.isEmpty());
|
||||
|
||||
Exception e=null;
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
loader.validateModules(result);
|
||||
} catch (Exception ee) {
|
||||
e=ee;
|
||||
e = ee;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertTrue(e.getMessage().contains("Duplicate"), "No 'Duplicate' found in message: "+e.getMessage());
|
||||
Assertions.assertTrue(e.getMessage().contains("sibling-loader"), "No 'sibling-loader' found in message: "+e.getMessage());
|
||||
Assertions.assertTrue(e.getMessage().contains("Duplicate"), "No 'Duplicate' found in message: " + e.getMessage());
|
||||
Assertions.assertTrue(e.getMessage().contains("sibling-loader"), "No 'sibling-loader' found in message: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ import org.junit.jupiter.api.Test;
|
|||
* @version 1.0 Aug 27, 2012
|
||||
*/
|
||||
public class X4OLanguageClassLoaderTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testLoadObject() throws Exception {
|
||||
Object o = X4OLanguageClassLoader.newInstance("java.lang.Object");
|
||||
Assertions.assertNotNull(o);
|
||||
Assertions.assertEquals(Object.class, o.getClass());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tesNullThread() throws Exception {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
|
|
|
|||
|
|
@ -28,19 +28,19 @@ import org.x4o.xml.X4ODriverManager;
|
|||
public class MTestDriver extends X4ODriver<Object> {
|
||||
|
||||
public static final String LANGUAGE_NAME = "mtest";
|
||||
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
|
||||
public String getLanguageName() {
|
||||
return LANGUAGE_NAME;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getLanguageVersions() {
|
||||
return LANGUAGE_VERSIONS;
|
||||
}
|
||||
|
||||
|
||||
static public MTestDriver getInstance() {
|
||||
return (MTestDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
||||
return (MTestDriver) X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
|
|||
* @version 1.0 Apr 15, 2012
|
||||
*/
|
||||
public class ParentObjectTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testParentElement() throws Exception {
|
||||
MTestDriver driver = new MTestDriver();
|
||||
|
|
@ -47,35 +47,35 @@ public class ParentObjectTest {
|
|||
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "junit/test-meta-parent-element.xml");
|
||||
Assertions.assertEquals(1,session.getRootElement().getChilderen().size());
|
||||
Assertions.assertEquals(1, session.getRootElement().getChilderen().size());
|
||||
Element childElement = session.getRootElement().getChilderen().get(0);
|
||||
JLabel test = (JLabel)childElement.getElementObject();
|
||||
Assertions.assertEquals("parentTest",test.getText());
|
||||
JLabel test = (JLabel) childElement.getElementObject();
|
||||
Assertions.assertEquals("parentTest", test.getText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParentObjectElement() throws Exception {
|
||||
DefaultElement ep = new DefaultElement();
|
||||
ParentObjectElement e = new ParentObjectElement();
|
||||
Object o;
|
||||
|
||||
|
||||
// test non parent
|
||||
o = e.getElementObject();
|
||||
Assertions.assertNull(o);
|
||||
e.setElementObject("test");
|
||||
o = e.getElementObject();
|
||||
Assertions.assertNull(o);
|
||||
|
||||
|
||||
// test parent
|
||||
e.setParent(ep);
|
||||
o = e.getElementObject();
|
||||
Assertions.assertNull(o);
|
||||
e.setElementObject("test");
|
||||
o = e.getElementObject();
|
||||
Assertions.assertEquals("test",o);
|
||||
Assertions.assertEquals("test", o);
|
||||
o = ep.getElementObject();
|
||||
Assertions.assertEquals("test",o);
|
||||
Assertions.assertEquals(e.getElementObject(),ep.getElementObject());
|
||||
Assertions.assertEquals("test", o);
|
||||
Assertions.assertEquals(e.getElementObject(), ep.getElementObject());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import org.x4o.xml.lang.phase.X4OPhaseLanguageRead;
|
|||
* @version 1.0 Jul 24, 2006
|
||||
*/
|
||||
public class ReferenceStoreTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testMetaGeneric() throws Exception {
|
||||
MTestDriver driver = new MTestDriver();
|
||||
|
|
@ -45,10 +45,10 @@ public class ReferenceStoreTest {
|
|||
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "junit/test-meta-generic.xml");
|
||||
Assertions.assertEquals(Date.class.getName(),session.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(), session.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLoadClass() throws Exception {
|
||||
MTestDriver driver = new MTestDriver();
|
||||
|
|
@ -56,10 +56,10 @@ public class ReferenceStoreTest {
|
|||
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "junit/test-meta-reference.xml");
|
||||
Assertions.assertEquals(Date.class.getName(),session.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(), session.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStoreRef() throws Exception {
|
||||
MTestDriver driver = new MTestDriver();
|
||||
|
|
@ -67,10 +67,10 @@ public class ReferenceStoreTest {
|
|||
reader.addPhaseSkip(X4OPhaseLanguageRead.READ_RELEASE);
|
||||
try (X4OLanguageSession session = reader.createLanguageSession()) {
|
||||
reader.readResourceSession(session, "junit/test-meta-reference.xml");
|
||||
Assertions.assertEquals(Date.class.getName(),session.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(),session.getRootElement().getChilderen().get(1).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(),session.getRootElement().getChilderen().get(2).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(),session.getRootElement().getChilderen().get(3).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(), session.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(), session.getRootElement().getChilderen().get(1).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(), session.getRootElement().getChilderen().get(2).getElementObject().getClass().getName());
|
||||
Assertions.assertEquals(Date.class.getName(), session.getRootElement().getChilderen().get(3).getElementObject().getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue