# VersionCompatibilityService

VersionCompatibilityService determines whether a property is compatible with the version compatibility target. This in turn controls property enablement, validation and visibility.

In most situations, version compatibility can be expressed using an @Since or an @VersionCompatibility annotation. Both of these annotations support the expression language.

Example

    @Type( base = Date.class )
    @Since( "1.5" )

    ValueProperty PROP_INITIAL_QUOTE_DATE = new ValueProperty( TYPE, "InitialQuoteDate" );

    Value<Date> getInitialQuoteDate();
    void setInitialQuoteDate( String value );
    void setInitialQuoteDate( Date value );

When more control is necessary, a custom implementation of VersionCompatibilityService can be provided. A typical implementation will utilize VersionCompatibilityTargetService to determine the current version.

Example

    @Type( base = Date.class )
    @Service( impl = ExampleVersionCompatibilityService.class )

    ValueProperty PROP_INITIAL_QUOTE_DATE = new ValueProperty( TYPE, "InitialQuoteDate" );

    Value<Date> getInitialQuoteDate();
    void setInitialQuoteDate( String value );
    void setInitialQuoteDate( Date value );

    public class ExampleVersionCompatibilityService extends VersionCompatibilityService
    {
        private VersionCompatibilityTargetService versionCompatibilityTargetService;
        private Listener versionCompatibilityTargetServiceListener;

        protected void initVersionCompatibilityService()
        {
            final Element element = context( Element.class );
            final ModelProperty property = context( ModelProperty.class );

            this.versionCompatibilityTargetService = VersionCompatibilityTargetService.find( element, property );

            this.versionCompatibilityTargetServiceListener = new Listener()
            {
                @Override
                public void handle( final Event event )
                {
                    refresh();
                }
            };

            this.versionCompatibilityTargetService.attach( this.versionCompatibilityTargetServiceListener );
        }

        @Override
        protected Data compute()
        {
            final Version version = this.versionCompatibilityTargetService.version();
            final String versioned = this.versionCompatibilityTargetService.versioned();

            final boolean compatible = ...

            return new Data( compatible, version, versioned );
        }

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

            if( this.versionCompatibilityTargetService != null )
            {
                this.versionCompatibilityTargetService.detach( this.versionCompatibilityTargetServiceListener );
            }
        }
    }

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