# RequiredConstraintService

RequiredConstraintService determines whether a value or an element property is required to have content.

Although custom implementations are supported, in most cases the supplied implementation that is configured via @Required annotation should be sufficient.

Example

    @Required

    ValueProperty PROP_CATEGORY = new ValueProperty( TYPE, "Category" );

    Value<String> getCategory();
    void setCategory( String value );

If necessary, an expression can be used to specify the constraint.

Example

In this example, the Category property is required only if the Version property is in the given range.

    @Required( "${ VersionMatches( Version, '[1.0-2.1)' ) }" )

    ValueProperty PROP_CATEGORY = new ValueProperty( TYPE, "Category" );

    Value<String> getCategory();
    void setCategory( String value );

If declarative approach is not sufficient, a custom RequiredConstraintService implementation can be supplied.

Example

    public class CustomRequiredConstraintService extends RequiredConstraintService
    {
        @Override
        protected void initRequiredConstraintService()
        {
            // Optionally register listeners to invoke refresh method when the required constraint
            // may need to be updated.
        }

        @Override
        protected Boolean compute()
        {
            ...
        }

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

            // Remove any listeners that were added during initialization.
        }
    }

    @Service( impl = CustomRequiredConstraintService.class )

    ValueProperty PROP_CATEGORY = new ValueProperty( TYPE, "Category" );

    Value<String> getCategory();
    void setCategory( String value );

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