Search in sources :

Example 1 with PlasticProxyFactory

use of org.apache.tapestry5.commons.services.PlasticProxyFactory in project tapestry-5 by apache.

the class ApplicationMessageCatalogObjectProvider method createProxy.

private void createProxy() {
    try {
        upgradeReadLockToWriteLock();
        this.messagesSource = objectLocator.getService(ComponentMessagesSource.class);
        this.threadLocale = objectLocator.getService(ThreadLocale.class);
        PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory", PlasticProxyFactory.class);
        proxy = proxyFactory.createProxy(Messages.class, new ApplicationMessagesObjectCreator(), "<ApplicationMessagesProxy>");
        // Listen for invalidations; clear our cache of localized Messages bundles when
        // an invalidation occurs.
        messagesSource.getInvalidationEventHub().clearOnInvalidation(localeToMessages);
    } finally {
        downgradeWriteLockToReadLock();
    }
}
Also used : ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) PlasticProxyFactory(org.apache.tapestry5.commons.services.PlasticProxyFactory) ComponentMessagesSource(org.apache.tapestry5.services.messages.ComponentMessagesSource)

Example 2 with PlasticProxyFactory

use of org.apache.tapestry5.commons.services.PlasticProxyFactory in project tapestry-5 by apache.

the class EntityManagerObjectProvider method getOrCreateProxy.

@SuppressWarnings({ "unchecked", "rawtypes" })
private EntityManager getOrCreateProxy(final AnnotationProvider annotationProvider, final ObjectLocator objectLocator) {
    final PersistenceContext annotation = annotationProvider.getAnnotation(PersistenceContext.class);
    final String unitName = annotation == null ? null : annotation.unitName();
    EntityManager proxy = emProxyByName.get(unitName);
    if (proxy == null)
        synchronized (this) {
            final PlasticProxyFactory proxyFactory = objectLocator.getService("PlasticProxyFactory", PlasticProxyFactory.class);
            proxy = proxyFactory.createProxy(EntityManager.class, new ObjectCreator() {

                @Override
                public Object createObject() {
                    final EntityManagerManager entityManagerManager = objectLocator.getService(EntityManagerManager.class);
                    return JpaInternalUtils.getEntityManager(entityManagerManager, annotation);
                }
            }, "<EntityManagerProxy>");
            emProxyByName.put(unitName, proxy);
        }
    return proxy;
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) PersistenceContext(javax.persistence.PersistenceContext) PlasticProxyFactory(org.apache.tapestry5.commons.services.PlasticProxyFactory) ObjectCreator(org.apache.tapestry5.commons.ObjectCreator)

Example 3 with PlasticProxyFactory

use of org.apache.tapestry5.commons.services.PlasticProxyFactory in project tapestry-5 by apache.

the class EnvironmentalShadowBuilderImplTest method proxy_class.

@Test
public void proxy_class() {
    JavaScriptSupport delegate = newMock(JavaScriptSupport.class);
    Environment env = mockEnvironment();
    train_peekRequired(env, JavaScriptSupport.class, delegate);
    expect(delegate.allocateClientId("fred")).andReturn("barney");
    replay();
    EnvironmentalShadowBuilder builder = new EnvironmentalShadowBuilderImpl(getService("PlasticProxyFactory", PlasticProxyFactory.class), env);
    JavaScriptSupport proxy = builder.build(JavaScriptSupport.class);
    assertEquals(proxy.allocateClientId("fred"), "barney");
    verify();
}
Also used : JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) Environment(org.apache.tapestry5.services.Environment) EnvironmentalShadowBuilder(org.apache.tapestry5.services.EnvironmentalShadowBuilder) PlasticProxyFactory(org.apache.tapestry5.commons.services.PlasticProxyFactory) Test(org.testng.annotations.Test)

Aggregations

PlasticProxyFactory (org.apache.tapestry5.commons.services.PlasticProxyFactory)3 EntityManager (javax.persistence.EntityManager)1 PersistenceContext (javax.persistence.PersistenceContext)1 ObjectCreator (org.apache.tapestry5.commons.ObjectCreator)1 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)1 EntityManagerManager (org.apache.tapestry5.jpa.EntityManagerManager)1 Environment (org.apache.tapestry5.services.Environment)1 EnvironmentalShadowBuilder (org.apache.tapestry5.services.EnvironmentalShadowBuilder)1 JavaScriptSupport (org.apache.tapestry5.services.javascript.JavaScriptSupport)1 ComponentMessagesSource (org.apache.tapestry5.services.messages.ComponentMessagesSource)1 Test (org.testng.annotations.Test)1