Search in sources :

Example 1 with BindingException

use of com.canoo.dp.impl.remoting.BindingException in project dolphin-platform by canoo.

the class PropertyBinderImpl method bind.

public <T> Binding bind(final Property<T> property, final Qualifier<T> qualifier) {
    Assert.requireNonNull(property, "property");
    Assert.requireNonNull(qualifier, "qualifier");
    if (property instanceof PropertyImpl) {
        try {
            final PropertyImpl p = (PropertyImpl) property;
            final Field attributeField = ReflectionHelper.getInheritedDeclaredField(PropertyImpl.class, "attribute");
            final ServerAttribute attribute = (ServerAttribute) ReflectionHelper.getPrivileged(attributeField, p);
            if (attribute == null) {
                throw new NullPointerException("attribute == null");
            }
            attribute.setQualifier(qualifier.getIdentifier());
            return new Binding() {

                @Override
                public void unbind() {
                    attribute.setQualifier(null);
                }
            };
        } catch (Exception e) {
            throw new BindingException("Can not bind the given property to the qualifier! Property: " + property + ", qualifier: " + qualifier, e);
        }
    } else {
        throw new BindingException("Can not bind the given property to the qualifier! Property: " + property + ", qualifier: " + qualifier);
    }
}
Also used : Binding(com.canoo.platform.core.functional.Binding) Field(java.lang.reflect.Field) PropertyImpl(com.canoo.dp.impl.remoting.PropertyImpl) ServerAttribute(com.canoo.dp.impl.server.legacy.ServerAttribute) BindingException(com.canoo.dp.impl.remoting.BindingException) BindingException(com.canoo.dp.impl.remoting.BindingException)

Aggregations

BindingException (com.canoo.dp.impl.remoting.BindingException)1 PropertyImpl (com.canoo.dp.impl.remoting.PropertyImpl)1 ServerAttribute (com.canoo.dp.impl.server.legacy.ServerAttribute)1 Binding (com.canoo.platform.core.functional.Binding)1 Field (java.lang.reflect.Field)1