Search in sources :

Example 1 with IDecorator

use of org.jowidgets.util.IDecorator in project jo-client-platform by jo-source.

the class ServicesDecoratorProviderImpl method getDecorator.

@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
    Assert.paramNotNull(id, "id");
    final IDecorator typeDecorator = decorators.get(id);
    if (defaultDecorator != null || typeDecorator != null) {
        return new IDecorator<SERVICE_TYPE>() {

            @Override
            public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
                SERVICE_TYPE result = original;
                if (defaultDecorator != null) {
                    result = (SERVICE_TYPE) defaultDecorator.decorate(result);
                }
                if (typeDecorator != null) {
                    result = (SERVICE_TYPE) typeDecorator.decorate(result);
                }
                return result;
            }
        };
    } else {
        return null;
    }
}
Also used : IDecorator(org.jowidgets.util.IDecorator)

Example 2 with IDecorator

use of org.jowidgets.util.IDecorator in project jo-client-platform by jo-source.

the class CancelServicesDecoratorProviderImpl method getDecorator.

@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
    Assert.paramNotNull(id, "id");
    final Class<? extends SERVICE_TYPE> serviceType = id.getServiceType();
    return new IDecorator<SERVICE_TYPE>() {

        @SuppressWarnings("unchecked")
        @Override
        public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
            if (services.contains(serviceType)) {
                final InvocationHandler invocationHandler = new CancelInvocationHandler(original);
                return (SERVICE_TYPE) Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
            } else {
                return original;
            }
        }
    };
}
Also used : AbstractCapServiceInvocationHandler(org.jowidgets.cap.common.tools.proxy.AbstractCapServiceInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) IDecorator(org.jowidgets.util.IDecorator)

Example 3 with IDecorator

use of org.jowidgets.util.IDecorator in project jo-client-platform by jo-source.

the class SecureServiceDecoratorProviderImpl method getDecorator.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
    Assert.paramNotNull(id, "id");
    if (id instanceof ISecureServiceId) {
        final Object authorization = ((ISecureServiceId) id).getAuthorization();
        final Class<? extends SERVICE_TYPE> serviceType = id.getServiceType();
        return new IDecorator<SERVICE_TYPE>() {

            @Override
            public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
                final InvocationHandler invocationHandler = new SecurityInvocationHandler(original, authorization);
                return (SERVICE_TYPE) Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
            }
        };
    } else if (DecorationMode.ALLOW_UNSECURE == decorationMode) {
        return new IdentityTransformationDecorator<SERVICE_TYPE>();
    } else {
        throw new RuntimeException("The service with the id '" + id + "' has not the type '" + ISecureServiceId.class.getName() + "'");
    }
}
Also used : ISecureServiceId(org.jowidgets.cap.security.common.api.ISecureServiceId) InvocationHandler(java.lang.reflect.InvocationHandler) IDecorator(org.jowidgets.util.IDecorator)

Example 4 with IDecorator

use of org.jowidgets.util.IDecorator in project jo-client-platform by jo-source.

the class JpaServicesDecoratorProviderImpl method getDecorator.

@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
    Assert.paramNotNull(id, "id");
    final Class<? extends SERVICE_TYPE> serviceType = id.getServiceType();
    return new IDecorator<SERVICE_TYPE>() {

        @SuppressWarnings("unchecked")
        @Override
        public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
            if (entityManagerServices.contains(serviceType) || transactionalServices.contains(serviceType)) {
                final InvocationHandler invocationHandler = new JpaInvocationHandler(serviceType, original);
                return (SERVICE_TYPE) Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
            } else {
                return original;
            }
        }
    };
}
Also used : AbstractCapServiceInvocationHandler(org.jowidgets.cap.common.tools.proxy.AbstractCapServiceInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) IDecorator(org.jowidgets.util.IDecorator)

Example 5 with IDecorator

use of org.jowidgets.util.IDecorator in project jo-client-platform by jo-source.

the class Neo4JServicesDecoratorProviderImpl method getDecorator.

@Override
public <SERVICE_TYPE> IDecorator<SERVICE_TYPE> getDecorator(final IServiceId<SERVICE_TYPE> id) {
    Assert.paramNotNull(id, "id");
    final Class<? extends SERVICE_TYPE> serviceType = id.getServiceType();
    return new IDecorator<SERVICE_TYPE>() {

        @SuppressWarnings("unchecked")
        @Override
        public SERVICE_TYPE decorate(final SERVICE_TYPE original) {
            final InvocationHandler invocationHandler = new Neo4JInvocationHandler(serviceType, original);
            return (SERVICE_TYPE) Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[] { serviceType }, invocationHandler);
        }
    };
}
Also used : AbstractCapServiceInvocationHandler(org.jowidgets.cap.common.tools.proxy.AbstractCapServiceInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) IDecorator(org.jowidgets.util.IDecorator)

Aggregations

IDecorator (org.jowidgets.util.IDecorator)6 InvocationHandler (java.lang.reflect.InvocationHandler)4 AbstractCapServiceInvocationHandler (org.jowidgets.cap.common.tools.proxy.AbstractCapServiceInvocationHandler)3 IInputComponentValidationLabelBluePrint (org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint)1 ISecureServiceId (org.jowidgets.cap.security.common.api.ISecureServiceId)1 IValidationMessage (org.jowidgets.validation.IValidationMessage)1 IValidationResult (org.jowidgets.validation.IValidationResult)1