Package org.apache.hivemind.service

Examples of org.apache.hivemind.service.BodyBuilder


                ComponentMessagesSource.class,
                _componentMessagesSource);

        op.addField("_$messages", Messages.class);

        BodyBuilder builder = new BodyBuilder();
        builder.begin();
        builder.addln("if (_$messages == null)");
        builder.addln("  _$messages = {0}.getMessages(this);", sourceField);
        builder.addln("return _$messages;");
        builder.end();

        op.addMethod(Modifier.PUBLIC, _methodSignature, builder.toString(), location);
    }
View Full Code Here


                InitialValueBindingCreator.class, creator);

        String bindingField = fieldName + "$initialValueBinding";
        op.addField(bindingField, IBinding.class);

        BodyBuilder builder = new BodyBuilder();

        builder.addln("{0} = {1}.createBinding(this);", bindingField,
                creatorField);

        op.extendMethodImplementation(IComponent.class,
                EnhanceUtils.FINISH_LOAD_SIGNATURE, builder.toString());

        builder.clear();

        builder.addln("{0} = {1};", fieldName, EnhanceUtils
                .createUnwrapExpression(op, bindingField, propertyType));

        String code = builder.toString();

        // In finishLoad() and pageDetach(), de-reference the binding to get the
        // value
        // for the property.
View Full Code Here

            Class propertyType, String fieldName, boolean persistent,
            Location location)
    {
        String methodName = EnhanceUtils.createMutatorMethodName(propertyName);

        BodyBuilder body = new BodyBuilder();

        body.begin();

        if (persistent)
        {
            body.add("org.apache.tapestry.Tapestry#fireObservedChange(this, ");
            body.addQuoted(propertyName);
            body.addln(", ($w) $1);");
        }

        body.addln(fieldName + " = $1;");

        body.end();

        MethodSignature sig = new MethodSignature(void.class, methodName,
                new Class[] { propertyType }, null);

        op.addMethod(Modifier.PUBLIC, sig, body.toString(), location);
    }
View Full Code Here

        op.addField(fieldName, propertyType);

        String managerField = op.addInjectedField("_$applicationStateManager",
                ApplicationStateManager.class, _applicationStateManager);

        BodyBuilder builder = new BodyBuilder();

        // Accessor

        builder.begin();
        builder.addln("if ({0} == null)", fieldName);
        builder.addln("  {0} = ({1}) {2}.get(\"{3}\");", new Object[] {
                fieldName, ClassFabUtils.getJavaClassName(propertyType),
                managerField, objectName });
        builder.addln("return {0};", fieldName);
        builder.end();

        String methodName = op.getAccessorMethodName(propertyName);

        MethodSignature sig = new MethodSignature(propertyType, methodName,
                null, null);

        op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);

        // Mutator

        builder.clear();
        builder.begin();
        builder.addln("{0}.store(\"{1}\", $1);", managerField, objectName);
        builder.addln("{0} = $1;", fieldName);
        builder.end();

        sig = new MethodSignature(void.class, EnhanceUtils
                .createMutatorMethodName(propertyName),
                new Class[] { propertyType }, null);

        op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);

        // Extend pageDetached() to clean out the cached field value.

        op.extendMethodImplementation(PageDetachListener.class,
                EnhanceUtils.PAGE_DETACHED_SIGNATURE, fieldName + " = null;");
View Full Code Here

    }

    private void addPrimitive(EnhancementOperation op, InjectSpecification spec,
            String propertyName, MethodSignature sig, String sourceName, String parser)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();
        builder.addln(
                "java.lang.String meta = {0}.getComponentProperty(this, \"{1}\");",
                sourceName,
                spec.getObject());
        builder.addln("return {0}(meta);", parser);
        builder.end();

        op.addMethod(Modifier.PUBLIC, sig, builder.toString());
    }
View Full Code Here

    }

    private void addCharacterPrimitive(EnhancementOperation op, InjectSpecification spec,
            String propertyName, MethodSignature sig, String sourceName)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();
        builder.addln(
                "java.lang.String meta = {0}.getComponentProperty(this, \"{1}\");",
                sourceName,
                spec.getObject());
        builder.addln("return meta.charAt(0);");
        builder.end();

        op.addMethod(Modifier.PUBLIC, sig, builder.toString());
    }
View Full Code Here

            Class propertyType, MethodSignature sig, String sourceName)
    {
        String valueConverterName = op.addInjectedField("_$valueConverter", _valueConverter);
        String classRef = op.getClassReference(propertyType);

        BodyBuilder builder = new BodyBuilder();
        builder.begin();
        builder.addln(
                "java.lang.String meta = {0}.getComponentProperty(this, \"{1}\");",
                sourceName,
                spec.getObject());
        builder.addln("return ({0}) {1}.coerceValue(meta, {2});", ClassFabUtils
                .getJavaClassName(propertyType), valueConverterName, classRef);
        builder.end();

        op.addMethod(Modifier.PUBLIC, sig, builder.toString());
    }
View Full Code Here

            String sourceField = op.addInjectedField("_$componentMessagesSource", _componentMessagesSource);

            op.addField("_$messages", Messages.class);

            BodyBuilder builder = new BodyBuilder();
            builder.begin();
            builder.addln("if (_$messages == null)");
            builder.addln("  _$messages = {0}.getMessages(this);", sourceField);
            builder.addln("return _$messages;");
            builder.end();

            op.addMethod(Modifier.PUBLIC, METHOD_SIGNATURE, builder.toString());
        }
        catch (Exception ex)
        {
            _errorLog.error(EnhanceMessages.errorAddingProperty(MESSAGES_PROPERTY, op
                    .getBaseClass(), ex), null, ex);
View Full Code Here

        String creatorField = op.addInjectedField(fieldName + "$initialValueBindingCreator", creator);

        String bindingField = fieldName + "$initialValueBinding";
        op.addField(bindingField, IBinding.class);

        BodyBuilder builder = new BodyBuilder();

        builder.addln("{0} = {1}.createBinding(this);", bindingField, creatorField);

        op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, builder
                .toString());

        builder.clear();

        builder.addln("{0} = {1};", fieldName, EnhanceUtils.createUnwrapExpression(
                op,
                bindingField,
                propertyType));

        String code = builder.toString();

        // In finishLoad() and pageDetach(), de-reference the binding to get the value
        // for the property.

        op.extendMethodImplementation(IComponent.class, EnhanceUtils.FINISH_LOAD_SIGNATURE, code);
View Full Code Here

    private void addMutator(EnhancementOperation op, String propertyName, Class propertyType,
            String fieldName, boolean persistent)
    {
        String methodName = EnhanceUtils.createMutatorMethodName(propertyName);

        BodyBuilder body = new BodyBuilder();

        body.begin();

        if (persistent)
        {
            body.add("org.apache.tapestry.Tapestry#fireObservedChange(this, ");
            body.addQuoted(propertyName);
            body.addln(", ($w) $1);");
        }

        body.addln(fieldName + " = $1;");

        body.end();

        MethodSignature sig = new MethodSignature(void.class, methodName, new Class[]
        { propertyType }, null);

        op.addMethod(Modifier.PUBLIC, sig, body.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.hivemind.service.BodyBuilder

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.