jadex.xml.AttributeConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-serialization-xml Show documentation
Show all versions of jadex-serialization-xml Show documentation
Jadex XML is an XML data binding framework for Java and also for other representations. The main idea of Jadex XML is that neither the XML-Schema on the one side nor the Java classes on the other side should define other binding. Instead, a separate mapping between both is used as a mediation. This allows designing the XML representation independent of the Java side but still being able to connect both as desired.
This idea was first put forward by the JiBX data binding framework. Jadex XML pushes it further by combining it with the configuration by exception principle. The framework can detect obvious correspondences between both sides automatically and only needs configuration information when translations are necessary. The configuration information is currently specified directly in form of Java configuration classes.
package jadex.xml;
import jadex.commons.transformation.IObjectStringConverter;
import jadex.commons.transformation.IStringObjectConverter;
/**
* Converter for attributes. Consist of a string-object and a object-string converter.
* The first for reading the second for writing.
*/
public class AttributeConverter implements IAttributeConverter
{
//-------- attributes --------
/** The string object converter. */
protected IStringObjectConverter soconv;
/** The object string converter. */
protected IObjectStringConverter osconv;
//-------- constructors --------
/**
* Create a new attribute converter.
*/
public AttributeConverter(IStringObjectConverter soconv, IObjectStringConverter osconv)
{
this.soconv = soconv;
this.osconv = osconv;
}
//-------- methods --------
/**
* Convert a string value to another type.
* @param val The value to convert.
*/
public Object convertString(String val, Object context) throws Exception
{
return soconv!=null? soconv.convertString(val, context): val;
}
/**
* Convert a value to a string type.
* @param val The value to convert.
*/
public String convertObject(Object val, Object context)
{
return osconv!=null? osconv.convertObject(val, context): ""+val;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy