# VersionCompatibilityTargetService

VersionCompatibilityTargetService produces the version compatibility target to be referenced by VersionCompatibilityService.

When looking for the version compatibility target, the framework will first check the property, then the containing element, then the parent property and the parent element, etc. The search continues until version compatibility target is found or the model root is reached.

In most situations, version compatibility target can be expressed using an @VersionCompatibilityTarget annotation, which supports the expression language.

    @VersionCompatibilityTarget( version = "${ Version }", versioned = "Purchase Order" )

    public interface PurchaseOrder extends Element
    {
        ElementType TYPE = new ElementType( PurchaseOrder.class );

        // *** Version ***

        @Type( base = Version.class )
        @DefaultValue( text = "2.0" )

        ValueProperty PROP_VERSION = new ValueProperty( TYPE, "Version" );

        Value<Version> getVersion();
        void setVersion( String value );
        void setVersion( Version value );

        ...
    }

When more control is necessary, a custom implementation of VersionCompatibilityTargetService can be provided.

    @Service( impl = ExampleVersionCompatibilityTargetService.class )

    public interface PurchaseOrder extends Element
    {
        ...
    }

    public class ExampleVersionCompatibilityTargetService extends VersionCompatibilityTargetService
    {
        @Override
        protected void initContextVersionService()
        {
            // Listen on the source of the version and call refresh() when necessary.
        }

        @Override
        protected Data compute()
        {
            Version version = ...
            String versioned = ...

            return new Data( version, versioned );
        }

        @Override
        public void dispose()
        {
            super.dispose();

            // Detach any listeners attached in the initContextVersionService() method.
        }
    }

Copyright (c) 2016 Oracle
Content made available under the terms of Eclipse Public License.