Search in sources :

Example 6 with PlasticMethod

use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.

the class ImportWorker method processClassAnnotationAtSetupRenderPhase.

private void processClassAnnotationAtSetupRenderPhase(PlasticClass componentClass, MutableComponentModel model) {
    Import annotation = componentClass.getAnnotation(Import.class);
    if (annotation != null) {
        PlasticMethod setupRender = componentClass.introduceMethod(TransformConstants.SETUP_RENDER_DESCRIPTION);
        decorateMethod(componentClass, model, setupRender, annotation);
        model.addRenderPhase(SetupRender.class);
    }
}
Also used : Import(org.apache.tapestry5.annotations.Import)

Example 7 with PlasticMethod

use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.

the class HeartbeatDeferredWorkerTest method testFailure.

private void testFailure(MethodDescription description, String messageFragment) {
    PlasticMethod method = newMock(PlasticMethod.class);
    boolean isVoid = description.returnType.equals("void");
    expect(method.isVoid()).andReturn(isVoid);
    if (isVoid) {
        expect(method.getDescription()).andReturn(description).atLeastOnce();
    }
    expect(method.getMethodIdentifier()).andReturn("<MethodId>");
    replay();
    try {
        worker.deferMethodInvocations(method);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, messageFragment);
    }
    verify();
}
Also used : PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod)

Example 8 with PlasticMethod

use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.

the class CommitAfterWorker method transform.

@Override
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
    for (final PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) {
        PersistenceContext annotation = method.getAnnotation(PersistenceContext.class);
        method.addAdvice(methodAdvices.get(annotation == null ? null : annotation.unitName()));
    }
}
Also used : PersistenceContext(javax.persistence.PersistenceContext) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod)

Example 9 with PlasticMethod

use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.

the class ThunkCreatorImpl method createInstantiator.

private <T> ClassInstantiator<T> createInstantiator(final Class<T> interfaceType) {
    return proxyFactory.createProxy(interfaceType, new PlasticClassTransformer() {

        @Override
        public void transform(PlasticClass plasticClass) {
            final PlasticField objectCreatorField = plasticClass.introduceField(ObjectCreator.class, "creator").injectFromInstanceContext();
            PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(interfaceType.getName(), "delegate", null, null);
            delegateMethod.changeImplementation(new InstructionBuilderCallback() {

                @Override
                public void doBuild(InstructionBuilder builder) {
                    builder.loadThis().getField(objectCreatorField);
                    builder.invoke(CREATE_OBJECT);
                    builder.checkcast(interfaceType).returnResult();
                }
            });
            for (Method method : interfaceType.getMethods()) {
                plasticClass.introduceMethod(method).delegateTo(delegateMethod);
            }
            if (!plasticClass.isMethodImplemented(PlasticUtils.TO_STRING_DESCRIPTION)) {
                final PlasticField descriptionField = plasticClass.introduceField(String.class, "description").injectFromInstanceContext();
                plasticClass.introduceMethod(PlasticUtils.TO_STRING_DESCRIPTION, new InstructionBuilderCallback() {

                    @Override
                    public void doBuild(InstructionBuilder builder) {
                        builder.loadThis().getField(descriptionField).returnResult();
                    }
                });
            }
        }
    });
}
Also used : PlasticClass(org.apache.tapestry5.plastic.PlasticClass) InstructionBuilder(org.apache.tapestry5.plastic.InstructionBuilder) PlasticClassTransformer(org.apache.tapestry5.plastic.PlasticClassTransformer) PlasticField(org.apache.tapestry5.plastic.PlasticField) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) Method(java.lang.reflect.Method) InstructionBuilderCallback(org.apache.tapestry5.plastic.InstructionBuilderCallback)

Example 10 with PlasticMethod

use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.

the class OnEventWorker method createRequestBodyProvider.

@SuppressWarnings({ "unchecked", "rawtypes" })
private EventHandlerMethodParameterProvider createRequestBodyProvider(PlasticMethod method, final int parameterIndex, final String parameterTypeName, final boolean allowEmpty) {
    final String methodIdentifier = method.getMethodIdentifier();
    return (event) -> {
        Invokable<Object> operation = () -> {
            Class parameterType = classCache.forName(parameterTypeName);
            Optional result = restSupport.getRequestBodyAs(parameterType);
            if (!allowEmpty && !result.isPresent()) {
                throw new RuntimeException(String.format("The request has an empty body and %s has one parameter with @RequestBody(allowEmpty=false)", methodIdentifier));
            }
            return result.orElse(null);
        };
        return operationTracker.invoke("Converting HTTP request body for @RequestBody parameter", operation);
    };
}
Also used : PlasticField(org.apache.tapestry5.plastic.PlasticField) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) Flow(org.apache.tapestry5.func.Flow) JSONObject(org.apache.tapestry5.json.JSONObject) MethodInvocation(org.apache.tapestry5.plastic.MethodInvocation) ComponentClassCache(org.apache.tapestry5.internal.services.ComponentClassCache) ExceptionUtils(org.apache.tapestry5.commons.util.ExceptionUtils) PublishServerSideEvents(org.apache.tapestry5.corelib.mixins.PublishServerSideEvents) CollectionFactory(org.apache.tapestry5.commons.util.CollectionFactory) Map(java.util.Map) TransformConstants(org.apache.tapestry5.services.TransformConstants) LocalVariable(org.apache.tapestry5.plastic.LocalVariable) JSONArray(org.apache.tapestry5.json.JSONArray) ValueEncoder(org.apache.tapestry5.ValueEncoder) Event(org.apache.tapestry5.runtime.Event) PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) Predicate(org.apache.tapestry5.func.Predicate) Set(java.util.Set) Invokable(org.apache.tapestry5.ioc.Invokable) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) MethodAdvice(org.apache.tapestry5.plastic.MethodAdvice) List(java.util.List) ComponentClassTransformWorker2(org.apache.tapestry5.services.transform.ComponentClassTransformWorker2) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) EventContext(org.apache.tapestry5.EventContext) InternalConstants(org.apache.tapestry5.internal.InternalConstants) RequestBody(org.apache.tapestry5.annotations.RequestBody) PublishEvent(org.apache.tapestry5.annotations.PublishEvent) MethodParameter(org.apache.tapestry5.plastic.MethodParameter) Request(org.apache.tapestry5.http.services.Request) OnEvent(org.apache.tapestry5.annotations.OnEvent) LocalVariableCallback(org.apache.tapestry5.plastic.LocalVariableCallback) ComponentResources(org.apache.tapestry5.ComponentResources) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) RestSupport(org.apache.tapestry5.http.services.RestSupport) StaticActivationContextValue(org.apache.tapestry5.annotations.StaticActivationContextValue) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Condition(org.apache.tapestry5.plastic.Condition) MethodDescription(org.apache.tapestry5.plastic.MethodDescription) InstructionBuilderCallback(org.apache.tapestry5.plastic.InstructionBuilderCallback) InstructionBuilder(org.apache.tapestry5.plastic.InstructionBuilder) PlasticClass(org.apache.tapestry5.plastic.PlasticClass) TransformationSupport(org.apache.tapestry5.services.transform.TransformationSupport) OperationTracker(org.apache.tapestry5.ioc.OperationTracker) DisableStrictChecks(org.apache.tapestry5.annotations.DisableStrictChecks) F(org.apache.tapestry5.func.F) InternalUtils(org.apache.tapestry5.ioc.internal.util.InternalUtils) Mapper(org.apache.tapestry5.func.Mapper) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) Optional(java.util.Optional) Invokable(org.apache.tapestry5.ioc.Invokable) PlasticClass(org.apache.tapestry5.plastic.PlasticClass)

Aggregations

PlasticMethod (org.apache.tapestry5.plastic.PlasticMethod)7 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)3 ComponentResources (org.apache.tapestry5.ComponentResources)2 ValueEncoder (org.apache.tapestry5.ValueEncoder)2 Import (org.apache.tapestry5.annotations.Import)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 InstructionBuilder (org.apache.tapestry5.plastic.InstructionBuilder)2 InstructionBuilderCallback (org.apache.tapestry5.plastic.InstructionBuilderCallback)2 MethodAdvice (org.apache.tapestry5.plastic.MethodAdvice)2 PlasticField (org.apache.tapestry5.plastic.PlasticField)2 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)2 SessionTracker (com.flowlogix.web.mixins.SessionTracker)1 AJAX (com.flowlogix.web.services.annotations.AJAX)1 IOException (java.io.IOException)1 Array (java.lang.reflect.Array)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 List (java.util.List)1