Search in sources :

Example 1 with ObjectLocator

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

the class AssetInjectionProvider method provideInjection.

public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
    Path path = field.getAnnotation(Path.class);
    if (path == null) {
        return false;
    }
    final String assetPath = path.value();
    final String libraryName = componentModel.getLibraryName();
    ComputedValue<Asset> computedAsset = new ComputedValue<Asset>() {

        public Asset get(InstanceContext context) {
            ComponentResources resources = context.get(ComponentResources.class);
            // a different library name than the subclass).
            return assetSource.getComponentAsset(resources, assetPath, libraryName);
        }
    };
    field.injectComputed(computedAsset);
    return true;
}
Also used : Path(org.apache.tapestry5.annotations.Path) ComputedValue(org.apache.tapestry5.plastic.ComputedValue) InstanceContext(org.apache.tapestry5.plastic.InstanceContext) Asset(org.apache.tapestry5.Asset) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 2 with ObjectLocator

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

the class DefaultInjectionProvider method provideInjection.

public boolean provideInjection(final PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
    Class fieldType = classCache.forName(field.getTypeName());
    Object injectionValue = masterObjectProvider.provide(fieldType, new AnnotationProvider() {

        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
            return field.getAnnotation(annotationClass);
        }
    }, this.locator, false);
    if (injectionValue != null) {
        field.inject(injectionValue);
        return true;
    }
    return false;
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider)

Example 3 with ObjectLocator

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

the class PageTesterModule method setupTestableOverrides.

@Contribute(ServiceOverride.class)
public static void setupTestableOverrides(MappedConfiguration<Class, Object> configuration, @Local TestableRequest request, @Local TestableResponse response, final ObjectLocator locator) {
    configuration.add(Request.class, request);
    configuration.add(Response.class, response);
    TestableCookieSinkSource cookies = new TestableCookieSinkSource();
    configuration.add(CookieSink.class, cookies);
    configuration.add(CookieSource.class, cookies);
    // With the significant changes to the handling of assets in 5.4, we introduced a problem:
    // We were checking at page render time whether to generate URLs for normal or compressed
    // assets and that peeked at the HttpServletRequest global, which isn't set up by PageTester.
    // What we're doing here is using a hacked version of that code to force GZip support
    // on.
    configuration.add(ResponseCompressionAnalyzer.class, new ResponseCompressionAnalyzer() {

        public boolean isGZipEnabled(ContentType contentType) {
            return locator.getObject(CompressionAnalyzer.class, null).isCompressable(contentType.getMimeType());
        }

        public boolean isGZipSupported() {
            return true;
        }
    });
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ResponseCompressionAnalyzer(org.apache.tapestry5.http.services.ResponseCompressionAnalyzer) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 4 with ObjectLocator

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

the class RegistryImpl method getObject.

@Override
public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator, Module localModule) {
    lock.check();
    AnnotationProvider effectiveProvider = annotationProvider != null ? annotationProvider : new NullAnnotationProvider();
    // We do a check here for known marker/type combinations, so that you can use a marker
    // annotation
    // to inject into a contribution method that contributes to MasterObjectProvider.
    // We also force a contribution into MasterObjectProvider to accomplish the same thing.
    T result = findServiceByMarkerAndType(objectType, annotationProvider, localModule);
    if (result != null)
        return result;
    MasterObjectProvider masterProvider = getService(IOCConstants.MASTER_OBJECT_PROVIDER_SERVICE_ID, MasterObjectProvider.class);
    return masterProvider.provide(objectType, effectiveProvider, locator, true);
}
Also used : NullAnnotationProvider(org.apache.tapestry5.commons.internal.NullAnnotationProvider) NullAnnotationProvider(org.apache.tapestry5.commons.internal.NullAnnotationProvider) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider)

Example 5 with ObjectLocator

use of org.apache.tapestry5.commons.ObjectLocator 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)

Aggregations

Asset (org.apache.tapestry5.Asset)5 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)5 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)5 Test (org.testng.annotations.Test)5 ObjectProvider (org.apache.tapestry5.commons.ObjectProvider)4 Path (org.apache.tapestry5.annotations.Path)3 Map (java.util.Map)2 ComponentResources (org.apache.tapestry5.ComponentResources)2 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 IntermediateType (org.apache.tapestry5.ioc.annotations.IntermediateType)2 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)2 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)2 AssetSource (org.apache.tapestry5.services.AssetSource)2 ObjectStreamException (java.io.ObjectStreamException)1 Annotation (java.lang.annotation.Annotation)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DateFormat (java.text.DateFormat)1