Search in sources :

Example 11 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol in project tapestry-5 by apache.

the class TapestryHttpModule method contributeHttpServletRequestHandler.

/**
 * <dl>
 * <dt>StoreIntoGlobals</dt>
 * <dd>Stores the request and response into {@link org.apache.tapestry5.http.services.RequestGlobals} at the start of the
 * pipeline</dd>
 * <dt>IgnoredPaths</dt>
 * <dd>Identifies requests that are known (via the IgnoredPathsFilter service's configuration) to be mapped to other
 * applications</dd>
 * <dt>GZip</dt>
 * <dd>Handles GZIP compression of response streams (if supported by client)</dd>
 * </dl>
 */
public void contributeHttpServletRequestHandler(OrderedConfiguration<HttpServletRequestFilter> configuration, @Symbol(TapestryHttpSymbolConstants.GZIP_COMPRESSION_ENABLED) boolean gzipCompressionEnabled, @Autobuild GZipFilter gzipFilter) {
    HttpServletRequestFilter storeIntoGlobals = new HttpServletRequestFilter() {

        public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler) throws IOException {
            requestGlobals.storeServletRequestResponse(request, response);
            return handler.service(request, response);
        }
    };
    configuration.add("StoreIntoGlobals", storeIntoGlobals, "before:*");
    configuration.add("GZIP", gzipCompressionEnabled ? gzipFilter : null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequestHandler(org.apache.tapestry5.http.services.HttpServletRequestHandler) HttpServletRequestFilter(org.apache.tapestry5.http.services.HttpServletRequestFilter)

Example 12 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol in project tapestry-5 by apache.

the class SymbolObjectProvider method provide.

@Override
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
    Symbol annotation = annotationProvider.getAnnotation(Symbol.class);
    if (annotation == null)
        return null;
    Object value = symbolSource.valueForSymbol(annotation.value());
    IntermediateType it = annotationProvider.getAnnotation(IntermediateType.class);
    if (it != null)
        value = typeCoercer.coerce(value, it.value());
    return typeCoercer.coerce(value, objectType);
}
Also used : IntermediateType(org.apache.tapestry5.ioc.annotations.IntermediateType) Symbol(org.apache.tapestry5.ioc.annotations.Symbol)

Example 13 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol in project tapestry-5 by apache.

the class AnnotationMapper method mapMethod.

@Override
public Symbol mapMethod(String namespace, Method method) {
    FunctionName annotation = method.getAnnotation(FunctionName.class);
    if (annotation == null) {
        return null;
    }
    String name = annotation.value();
    if (name.contains("/")) {
        return Symbol.create(name);
    }
    return Symbol.create(namespace, name);
}
Also used : FunctionName(org.apache.tapestry5.clojure.FunctionName)

Example 14 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol in project tapestry-5 by apache.

the class ClojureBuilderImpl method build.

@Override
public <T> T build(final Class<T> interfaceType) {
    assert interfaceType != null;
    assert interfaceType.isInterface();
    Namespace annotation = interfaceType.getAnnotation(Namespace.class);
    if (annotation == null) {
        throw new IllegalArgumentException(String.format("Interface type %s does not have the Namespace annotation.", interfaceType.getName()));
    }
    final String namespace = annotation.value();
    ClassInstantiator<T> instantiator = proxyFactory.createProxy(interfaceType, new PlasticClassTransformer() {

        @Override
        public void transform(PlasticClass plasticClass) {
            for (final Method m : interfaceType.getMethods()) {
                bridgeToClojure(plasticClass, m);
            }
        }

        private void bridgeToClojure(final PlasticClass plasticClass, final Method method) {
            final MethodDescription desc = new MethodDescription(method);
            if (method.getReturnType() == void.class) {
                throw new IllegalArgumentException(String.format("Method %s may not be void when bridging to Clojure functions.", desc));
            }
            final Symbol symbol = mapper.mapMethod(namespace, method);
            tracker.run(String.format("Mapping %s method %s to Clojure function %s", interfaceType.getName(), desc.toShortString(), symbol.toString()), new Runnable() {

                @Override
                public void run() {
                    Symbol namespaceSymbol = Symbol.create(symbol.getNamespace());
                    REQUIRE.invoke(namespaceSymbol);
                    IFn clojureFunction = Clojure.var(symbol);
                    final PlasticField fnField = plasticClass.introduceField(IFn.class, method.getName() + "IFn").inject(clojureFunction);
                    plasticClass.introduceMethod(desc).changeImplementation(new InstructionBuilderCallback() {

                        @Override
                        public void doBuild(InstructionBuilder builder) {
                            bridgeToClojure(builder, desc, fnField);
                        }
                    });
                }
            });
        }

        private void bridgeToClojure(InstructionBuilder builder, MethodDescription description, PlasticField ifnField) {
            builder.loadThis().getField(ifnField);
            int count = description.argumentTypes.length;
            Class[] invokeParameterTypes = new Class[count];
            for (int i = 0; i < count; i++) {
                invokeParameterTypes[i] = Object.class;
                builder.loadArgument(i).boxPrimitive(description.argumentTypes[i]);
            }
            Method ifnMethod = null;
            try {
                ifnMethod = IFn.class.getMethod("invoke", invokeParameterTypes);
            } catch (NoSuchMethodException ex) {
                throw new RuntimeException(String.format("Unable to find correct IFn.invoke() method: %s", ExceptionUtils.toMessage(ex)), ex);
            }
            builder.invoke(ifnMethod);
            builder.castOrUnbox(description.returnType);
            builder.returnResult();
        }
    });
    return instantiator.newInstance();
}
Also used : Symbol(clojure.lang.Symbol) Method(java.lang.reflect.Method) Namespace(org.apache.tapestry5.clojure.Namespace) IFn(clojure.lang.IFn)

Example 15 with Symbol

use of org.apache.tapestry5.ioc.annotations.Symbol in project tapestry-5 by apache.

the class TapestryModule method provideCoreAndAppLibraries.

@Contribute(ComponentClassResolver.class)
public static void provideCoreAndAppLibraries(Configuration<LibraryMapping> configuration, @Symbol(TapestryHttpInternalConstants.TAPESTRY_APP_PACKAGE_PARAM) String appRootPackage) {
    configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.corelib"));
    configuration.add(new LibraryMapping("", appRootPackage));
}
Also used : LibraryMapping(org.apache.tapestry5.services.LibraryMapping) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

Contribute (org.apache.tapestry5.ioc.annotations.Contribute)7 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Metamodel (javax.persistence.metamodel.Metamodel)2 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)2 HttpServletRequestFilter (org.apache.tapestry5.http.services.HttpServletRequestFilter)2 ValueEncoderFactory (org.apache.tapestry5.services.ValueEncoderFactory)2 IFn (clojure.lang.IFn)1 Symbol (clojure.lang.Symbol)1 Method (java.lang.reflect.Method)1 Locale (java.util.Locale)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 EntityType (javax.persistence.metamodel.EntityType)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 StreamResponse (org.apache.tapestry5.StreamResponse)1 ValidationDecorator (org.apache.tapestry5.ValidationDecorator)1 FunctionName (org.apache.tapestry5.clojure.FunctionName)1 Namespace (org.apache.tapestry5.clojure.Namespace)1