THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
The DataBinding SPI:
Code Block |
---|
public interface DataBinding {    /**     * TheDataBinding namerepresents of 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 object     databinding * @param source object to copy     * @return An copyarray of thealiases object passed in as argument     */    Object copy(Object object String[] getAliases(); } |
Transformer SPI
Code Block |
---|
/** * A transformer provides the* dataIntrospect transformationand frompopulate sourceinformation typeto toa targetDataType type.model The cost of the transformation* is * modeled as weight. */ public interface@param TransformerjavaType { The java class or /** interface to be introspected * Get the source* type@param thatannotations thisThe transformerjava transformsannotations data from. The type is* used@return astrue theif key when the transformer databinding has recognized the given * is registered with TransformerRegistry.data type */ boolean * @return A key indentifying the source type */ String getSourceDataBinding(introspect(DataType dataType, Annotation[] annotations); /** * GetIntrospect the targetdata typeto thatfigure thisout transformerthe transformscorresponding data into. The type is used as the key* when the transformer * is@param registeredvalue withThe TransformerRegistry. object to be *checked * @return The DataType Aor keynull indentifyingif the targetjava type is not supported by this databinding */ StringDataType getTargetDataBindingintrospect(Object value); /** * GetProvide thea costWrapperHandler offor thethis transformation.databinding The weight can be used* to@return chooseA thewrapper mosthandler efficientwhich pathcan ifhandle therewrapping/wrapping arefor morethis databinding */ than one available from the source to the target.WrapperHandler getWrapperHandler(); /** * @returnMake Ana integercopy representingof the costobject of the transformationfor "pass-by-value" semantics */ @param source object to 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 {copy * @return copy of the object passed in as argument */ Object copy(Object object); /** * TransformGet sourcethe datatype intomapper thefor resultsimple type.types * @return The databinding-specific simple type mapper */ @param source The source dataSimpleTypeMapper getSimpleTypeMapper(); * @param context/** The context for the transformation * Get the handler that *can @returnhandle Theexceptions/faults transformedin resultthe */ databinding-specific way R transform(S source, TransformationContext context * * @return An instance of the exception handler */ ExceptionHandler 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> |