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;
}
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;
}
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;
}
});
}
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);
}
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;
}
Aggregations