THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
The DataBinding SPI:
Code Block |
---|
public interface DataBinding {    /**     * TheDataBinding name ofrepresents a databindingdata shouldrepresentation, be case-insensitive and unique     *     * @return The name of the databinding     for example, SDO, JAXB and AXIOM */    public interface String getName();   DataBinding { /**     * Introspect a java class or interface to create a DataType model     *     * @param javaType The java class or interface to be introspected     * @return The DataType or null if the java type is not supported by this databinding     */    DataType introspect(Class<?> javaType);   * A special databinding for input message of an operation */ String IDL_INPUT = "idl:input"; /** * A special databinding for output message of an operation */ String IDL_OUTPUT = "idl:output"; /**     * Introspect the data to* figureA outspecial thedatabinding correspondingfor datafault type     *     * @param value The object to be checked     * @return The DataType or null if the java type is not supported by this databinding     */    DataType introspect(Object value);   /**     * Provide a WrapperHandler for this databinding     * @return A wrapper handler which can handle wrapping/wrapping for this databinding     */    WrapperHandler getWrapperHandler();   message of an operation */ String IDL_FAULT = "idl:fault"; /** * The name of a databinding should be case-insensitive and unique * * @return The name of the databinding */ String getName(); /**     * makeGet athe copyaliases offor the input objectdatabinding     * @param source object to* copy     * @return copyAn array of the objectaliases passed in as argument     */    Object copy(Object object String[] getAliases(); } |
Transformer SPI
Code Block |
---|
/** * A transformer provides the data* transformationIntrospect fromand sourcepopulate typeinformation to targeta type. The cost of the transformation is * modeled as weight. */ public interface Transformer { /**DataType model * * @param javaType The java class or interface to be introspected * Get@param theannotations sourceThe typejava thatannotations this transformer transforms data from.* The@return typetrue isif usedthe asdatabinding thehas key whenrecognized the transformergiven data type * is registered with TransformerRegistry./ boolean introspect(DataType dataType, Annotation[] annotations); /** * Introspect the @returndata Ato keyfigure indentifyingout the corresponding sourcedata type */ * @param String getSourceDataBinding(); /**value The object to be checked * Get@return theThe targetDataType typeor thatnull thisif transformerthe transforms data into. The java type is usednot assupported theby keythis whendatabinding the transformer */ * is registeredDataType with TransformerRegistry.introspect(Object value); /** * @returnProvide Aa keyWrapperHandler indentifyingfor thethis target typedatabinding * @return A wrapper handler which can handle wrapping/wrapping for this databinding */ StringWrapperHandler getTargetDataBindinggetWrapperHandler(); /** * GetMake thea costcopy of the transformation.object The weight can be used to choose the most efficient path if there are morefor "pass-by-value" semantics * @param source object to copy * than@return onecopy availableof fromthe theobject sourcepassed toin theas target.argument */ Object * @return An integer representing the cost of the transformationcopy(Object object); /** */ int getWeight(); } /** * PullTransformer transforms data from one binding format to the other one which can be directly consumed * * @param <S> The source data type * @param <R> the target data type */ public interface PullTransformer<S, R> extends Transformer { /** * Transform source data into the result type. * Get the type mapper for simple types * @return The databinding-specific simple type mapper */ SimpleTypeMapper getSimpleTypeMapper(); /** * Get the handler that can handle exceptions/faults in the * databinding-specific way * @param source The source data * @param@return contextAn Theinstance context forof the transformation * @return The transformed resultexception handler */ RExceptionHandler transform(S source, TransformationContext context);getExceptionHandler(); } |
...
Transformer SPI
Code Block |
---|
/**
* A transformer provides the data transformation from source type to target type. The cost of the transformation is
* modeled as weight.
*/
public interface Transformer {
/**
* Get the source type that this transformer transforms data from. The type is used as the key when the transformer
* is registered with TransformerRegistry.
*
* @return A key indentifying the source type
*/
String getSourceDataBinding();
/**
* Get the target type that this transformer transforms data into. The type is used as the key when the transformer
* is registered with TransformerRegistry.
*
* @return A key indentifying the target type
*/
String getTargetDataBinding();
/**
* Get the cost of the transformation. The weight can be used to choose the most efficient path if there are more
* than one available from the source to the target.
*
* @return An integer representing the cost of the transformation
*/
int getWeight();
}
/**
* PullTransformer transforms data from one binding format to the other one which can be directly consumed
*
* @param <S> The source data type
* @param <R> the target data type
*/
public interface PullTransformer<S, R> extends Transformer {
/**
* Transform source data into the result type.
*
* @param source The source data
* @param context The context for the transformation
* @return The transformed result
*/
R transform(S source, TransformationContext context);
}
|
Register databindings and transformers
Code Block |
---|
/** * Module activator for AXIOM databinding * * @version $Rev: 529327 $ $Date: 2007-04-16 10:10:43 -0700 (Mon, 16 Apr 2007) $ */ public class AxiomDataBindingModuleActivator implements ModuleActivator { public Map<Class, Object> getExtensionPoints() { return null; } public void start(ExtensionPointRegistry registry) { DataBindingExtensionPoint dataBindingRegistry = registry.getExtensionPoint(DataBindingExtensionPoint.class); dataBindingRegistry.register(new AxiomDataBinding()); TransformerExtensionPoint transformerRegistry = registry.getExtensionPoint(TransformerExtensionPoint.class); transformerRegistry.registerTransformer(new Object2OMElement()); transformerRegistry.registerTransformer(new OMElement2Object()); transformerRegistry.registerTransformer(new OMElement2String()); transformerRegistry.registerTransformer(new OMElement2XMLStreamReader()); transformerRegistry.registerTransformer(new String2OMElement()); transformerRegistry.registerTransformer(new XMLStreamReader2OMElement()); } public void stop(ExtensionPointRegistry registry) { } }<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system=http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT name="org.apache.tuscany.databinding.sdo"> <component name="databinding.sdo"> <system:implementation.system class="org.apache.tuscany.databinding.sdo.SDODataBinding" /> </component> <component name="transformer.DataObject2String"> <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2String"/> </component><component name="transformer.String2DataObject"> <system:implementation.system class="org.apache.tuscany.databinding.sdo.String2DataObject"/> </component> ... </composite> |