JavaTypeConstraintService describes constraints on the Java type that a property can reference, such as the kind of type (class, interface, etc.) and the types that the type must extend or implement. The information provided by this service is used for validation, content assist and other needs.
In majority of situations, the Java type constraint is static and should be configured using @JavaTypeConstraint annotation. The framework provides an implementation of JavaTypeConstraintService that works with this annotation.
Example
@Type( base = JavaTypeName.class )
@Reference( target = JavaType.class )
@JavaTypeConstraint( kind = JavaTypeKind.CLASS, type = "javax.servlet.Filter" )
ValueProperty PROP_SERVLET_FILTER_IMPL = new ValueProperty( TYPE, "ServletFilterImpl" );
ReferenceValue<JavaTypeName,JavaType> getServletFilterImpl();
void setServletFilterImpl( JavaTypeName value );
void setServletFilterImpl( String value );
When the Java type constraint varies due to runtime conditions, a custom implementation of JavaTypeConstraintService can be provided.
Example
public class CustomJavaTypeConstraintService extends JavaTypeConstraintService
{
@Override
protected void initJavaTypeConstraintService()
{
// Register listeners to invoke refresh() method when Java type constraint
// may have changed.
}
@Override
protected JavaTypeConstraintServiceData compute()
{
// Compute Java type constraint.
List<JavaTypeKind> kinds = new ArrayList<JavaTypeKind>();
List<String> types = new ArrayList<String>();
JavaTypeConstraintBehavior behavior;
...
return new JavaTypeConstraintServiceData( kinds, types, behavior );
}
@Override
public void dispose()
{
super.dispose();
// Remove any listeners that were added during initialization.
}
}
@Type( base = JavaTypeName.class )
@Reference( target = JavaType.class )
@Service( impl = CustomJavaTypeConstrainService.class )
ValueProperty PROP_SERVLET_FILTER_IMPL = new ValueProperty( TYPE, "ServletFilterImpl" );
ReferenceValue<JavaTypeName,JavaType> getServletFilterImpl();
void setServletFilterImpl( JavaTypeName value );
void setServletFilterImpl( String value );