Package org.apache.tapestry5.plastic

Examples of org.apache.tapestry5.plastic.ClassInstantiator


        }

        // Let subclasses do more.
        configure(config);

        renderSupport.addInit("autocompleter", new JSONArray(id, menuId, link.toAbsoluteURI(), config));
    }
View Full Code Here


        "class", "t-autocomplete-menu");
        writer.end();

        Link link = resources.createEventLink(EVENT_NAME);

        JSONObject config = new JSONObject();
        config.put("paramName", PARAM_NAME);
        config.put("indicator", loaderId);

        if (resources.isBound("minChars"))
            config.put("minChars", minChars);

        if (resources.isBound("frequency"))
            config.put("frequency", frequency);

        if (resources.isBound("tokens"))
        {
            for (int i = 0; i < tokens.length(); i++)
            {
                config.accumulate("tokens", tokens.substring(i, i + 1));
            }
        }

        // Let subclasses do more.
        configure(config);
View Full Code Here

     * not formatted correct.
     */
    JSONObject onParse(@RequestParameter(INPUT_PARAMETER)
    String input)
    {
        JSONObject response = new JSONObject();

        try
        {
            Date date = format.parse(input);

            response.put(RESULT, date.getTime());
        }
        catch (ParseException ex)
        {
            response.put(ERROR, ex.getMessage());
        }

        return response;
    }
View Full Code Here

     * the result.
     */
    JSONObject onFormat(@RequestParameter(INPUT_PARAMETER)
    String input)
    {
        JSONObject response = new JSONObject();

        try
        {
            long millis = Long.parseLong(input);

            Date date = new Date(millis);

            response.put(RESULT, format.format(date));
        }
        catch (NumberFormatException ex)
        {
            response.put(ERROR, ex.getMessage());
        }

        return response;
    }
View Full Code Here

        if (!propertyType.isAssignableFrom(adapter.getType()))
            throw new RuntimeException(ServiceMessages.propertyTypeMismatch(propertyName, sourceClass,
                    adapter.getType(), propertyType));

        ClassInstantiator instantiator = proxyFactory.createProxy(propertyType, new PlasticClassTransformer()
        {
            public void transform(PlasticClass plasticClass)
            {
                final PlasticField sourceField = plasticClass.introduceField(sourceClass, "source").inject(source);

                PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(propertyType.getName(),
                        "readProperty", null, null);

                // You don't do this using MethodAdvice, because then we'd have to use reflection to access the read
                // method.

                delegateMethod.changeImplementation(new InstructionBuilderCallback()
                {
                    public void doBuild(InstructionBuilder builder)
                    {
                        builder.loadThis().getField(sourceField);
                        builder.invoke(sourceClass, propertyType, adapter.getReadMethod().getName());

                        // Now add the null check.

                        builder.dupe().when(Condition.NULL, new InstructionBuilderCallback()
                        {
                            public void doBuild(InstructionBuilder builder)
                            {
                                builder.throwException(
                                        NullPointerException.class,
                                        String.format(
                                                "Unable to delegate method invocation to property '%s' of %s, because the property is null.",
                                                propertyName, source));
                            }
                        });

                        builder.returnResult();
                    }
                });

                for (Method m : propertyType.getMethods())
                {
                    plasticClass.introduceMethod(m).delegateTo(delegateMethod);
                }

                plasticClass.addToString(String.format("<Shadow: property %s of %s>", propertyName, source));
            }
        });

        return propertyType.cast(instantiator.newInstance());
    }
View Full Code Here

        return build(registry);
    }

    private <S> S createProxy(final Class<S> interfaceType, final StrategyRegistry<S> registry)
    {
        ClassInstantiator instantiator = proxyFactory.createProxy(interfaceType, new PlasticClassTransformer()
        {
            public void transform(PlasticClass plasticClass)
            {
                final PlasticField registryField = plasticClass.introduceField(StrategyRegistry.class, "registry")
                        .inject(registry);

                for (final Method method : interfaceType.getMethods())
                {
                    plasticClass.introduceMethod(new MethodDescription(method), new InstructionBuilderCallback()
                    {
                        public void doBuild(InstructionBuilder builder)
                        {
                            Class returnType = method.getReturnType();

                            builder.loadThis().getField(registryField);

                            // Argument 0 is the selector used to find the adapter and should be an object reference,
                            // not a primitive.

                            builder.loadArgument(0);

                            // Use the StrategyRegistry to get the adapter to re-invoke the method on
                            builder.invoke(StrategyRegistry.class, Object.class, "getByInstance", Object.class)
                                    .checkcast(interfaceType);

                            // That leaves the correct adapter on top of the stack. Get the
                            // selector and the rest of the arguments in place and invoke the method.

                            builder.loadArguments().invoke(interfaceType, returnType, method.getName(),
                                    method.getParameterTypes());

                            builder.returnResult();
                        }
                    });
                }

                plasticClass.addToString(String.format("<Strategy for %s>", interfaceType.getName()));
            }
        });

        return interfaceType.cast(instantiator.newInstance());
    }
View Full Code Here

    /**
     * Creates a class and an instance of that class. Updates the cache and returns the instance.
     */
    private <S> S createInstance(final Class<S> serviceInterface)
    {
        ClassInstantiator instantiator = proxyFactory.createProxy(serviceInterface, new PlasticClassTransformer()
        {
            public void transform(PlasticClass plasticClass)
            {
                plasticClass.addToString(String.format("<NoOp %s>", serviceInterface.getName()));
            }
        });

        return serviceInterface.cast(instantiator.newInstance());
    }
View Full Code Here

        return build(registry);
    }

    private <S> S createProxy(final Class<S> interfaceType, final StrategyRegistry<S> registry)
    {
        ClassInstantiator instantiator = proxyFactory.createProxy(interfaceType, new PlasticClassTransformer()
        {
            @Override
            public void transform(PlasticClass plasticClass)
            {
                final PlasticField registryField = plasticClass.introduceField(StrategyRegistry.class, "registry")
                        .inject(registry);

                for (final Method method : interfaceType.getMethods())
                {
                    plasticClass.introduceMethod(new MethodDescription(method), new InstructionBuilderCallback()
                    {
                        @Override
                        public void doBuild(InstructionBuilder builder)
                        {
                            Class returnType = method.getReturnType();

                            builder.loadThis().getField(registryField);

                            // Argument 0 is the selector used to find the adapter and should be an object reference,
                            // not a primitive.

                            builder.loadArgument(0);

                            // Use the StrategyRegistry to get the adapter to re-invoke the method on
                            builder.invoke(StrategyRegistry.class, Object.class, "getByInstance", Object.class)
                                    .checkcast(interfaceType);

                            // That leaves the correct adapter on top of the stack. Get the
                            // selector and the rest of the arguments in place and invoke the method.

                            builder.loadArguments().invoke(interfaceType, returnType, method.getName(),
                                    method.getParameterTypes());

                            builder.returnResult();
                        }
                    });
                }

                plasticClass.addToString(String.format("<Strategy for %s>", interfaceType.getName()));
            }
        });

        return interfaceType.cast(instantiator.newInstance());
    }
View Full Code Here

    /**
     * Creates a class and an instance of that class. Updates the cache and returns the instance.
     */
    private <S> S createInstance(final Class<S> serviceInterface)
    {
        ClassInstantiator instantiator = proxyFactory.createProxy(serviceInterface, new PlasticClassTransformer()
        {
            @Override
            public void transform(PlasticClass plasticClass)
            {
                plasticClass.addToString(String.format("<NoOp %s>", serviceInterface.getName()));
            }
        });

        return serviceInterface.cast(instantiator.newInstance());
    }
View Full Code Here

        InternalPlasticClassTransformation transformation = getPlasticClassTransformation(className);

        delegate.transform(transformation.getPlasticClass());

        ClassInstantiator createInstantiator = transformation.createInstantiator();
        ClassInstantiator configuredInstantiator = delegate.configureInstantiator(className, createInstantiator);

        instantiators.put(className, configuredInstantiator);

        return transformation.getTransformedClass();
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.plastic.ClassInstantiator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.