Package org.apache.hivemind.service

Examples of org.apache.hivemind.service.BodyBuilder


        Iterator i = _incompleteMethods.entrySet().iterator();
        while (i.hasNext())
        {
            Map.Entry e = (Map.Entry) i.next();
            MethodSignature sig = (MethodSignature) e.getKey();
            BodyBuilder builder = (BodyBuilder) e.getValue();

            // Each BodyBuilder is created and given a begin(), this is
            // the matching end()

            builder.end();

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


    public void extendMethodImplementation(Class interfaceClass, MethodSignature methodSignature,
            String code)
    {
        addInterfaceIfNeeded(interfaceClass);

        BodyBuilder builder = (BodyBuilder) _incompleteMethods.get(methodSignature);

        if (builder == null)
        {
            builder = createIncompleteMethod(methodSignature);

            _incompleteMethods.put(methodSignature, builder);
        }

        builder.addln(code);
    }
View Full Code Here

        return false;
    }

    private BodyBuilder createIncompleteMethod(MethodSignature sig)
    {
        BodyBuilder result = new BodyBuilder();

        // Matched inside finalizeIncompleteMethods()

        result.begin();

        if (existingImplementation(sig))
            result.addln("super.{0}($$);", sig.getName());

        return result;
    }
View Full Code Here

    private void extendCleanupAfterRender(EnhancementOperation op, String parameterName,
            String propertyName, Class propertyType, String fieldName, String defaultFieldName,
            String cachedFieldName)
    {
        BodyBuilder cleanupBody = new BodyBuilder();

        // Cached is only set when the field is updated in the accessor or mutator.
        // After rendering, we want to clear the cached value and cached flag
        // unless the binding is invariant, in which case it can stick around
        // for some future render.

        String bindingName = propertyName + "Binding";

        addBindingReference(cleanupBody, bindingName, parameterName);

        cleanupBody.addln("if ({0} && ! {1}.isInvariant())", cachedFieldName, bindingName);
        cleanupBody.begin();
        cleanupBody.addln("{0} = false;", cachedFieldName);
        cleanupBody.addln("{0} = {1};", fieldName, defaultFieldName);
        cleanupBody.end();

        op.extendMethodImplementation(
                IComponent.class,
                EnhanceUtils.CLEANUP_AFTER_RENDER_SIGNATURE,
                cleanupBody.toString());
    }
View Full Code Here

    }

    private void buildMutator(EnhancementOperation op, String parameterName, String propertyName,
            Class propertyType, String fieldName, String defaultFieldName, String cachedFieldName)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();

        // The mutator method may be invoked from finishLoad(), in which
        // case it changes the default value for the parameter property, if the parameter
        // is not bound.

        builder.addln("if (! isInActiveState())");
        builder.begin();
        builder.addln("{0} = $1;", defaultFieldName);
        builder.addln("return;");
        builder.end();

        // In the normal state, we update the binding firstm, and it's an error
        // if the parameter is not bound.

        addBindingReference(builder, "binding", parameterName);

        builder.addln("if (binding == null)");
        builder.addln(
                "  throw new {0}(\"Parameter ''{1}'' is not bound and can not be updated.\");",
                ApplicationRuntimeException.class.getName(),
                parameterName);

        // Always updated the binding first (which may fail with an exception).

        builder.addln("binding.setObject(($w) $1);");

        // While rendering, we store the updated value for fast
        // access again (while the component is still rendering).
        // The property value will be reset to default by cleanupAfterRender().

        builder.addln("if (isRendering())");
        builder.begin();
        builder.addln("{0} = $1;", fieldName);
        builder.addln("{0} = true;", cachedFieldName);
        builder.end();

        builder.end();

        String mutatorMethodName = EnhanceUtils.createMutatorMethodName(propertyName);

        op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, mutatorMethodName,
                new Class[]
                { propertyType }, null), builder.toString());
    }
View Full Code Here

    // Package private for testing

    void buildAccessor(EnhancementOperation op, String parameterName, String propertyName,
            Class propertyType, String fieldName, String defaultFieldName, String cachedFieldName)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();

        builder.addln("if ({0}) return {1};", cachedFieldName, fieldName);

        addBindingReference(builder, "binding", parameterName);

        builder.addln("if (binding == null) return {0};", defaultFieldName);

        String javaTypeName = ClassFabUtils.getJavaClassName(propertyType);

        builder.addln("{0} result = {1};", javaTypeName,
                EnhanceUtils.createUnwrapExpression(
                op,
                "binding",
                propertyType));

        // Values read via the binding are cached during the render of
        // the component, or when the binding is invariant
        // (such as a StringBinding or MessageBinding).

        builder.addln("if (isRendering() || binding.isInvariant())");
        builder.begin();
        builder.addln("{0} = result;", fieldName);
        builder.addln("{0} = true;", cachedFieldName);
        builder.end();

        builder.addln("return result;");

        builder.end();

        String accessorMethodName = op.getAccessorMethodName(propertyName);

        op.addMethod(Modifier.PUBLIC, new MethodSignature(propertyType, accessorMethodName, null,
                null), builder.toString());
    }
View Full Code Here

    }

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

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

    }

    void extendCleanupAfterRender(EnhancementOperation op, String bindingFieldName,
                                  String fieldName, String defaultFieldName, String cachedFieldName)
    {
        BodyBuilder cleanupBody = new BodyBuilder();

        // Cached is only set when the field is updated in the accessor or
        // mutator.
        // After rendering, we want to clear the cached value and cached flag
        // unless the binding is invariant, in which case it can stick around
        // for some future render.

        cleanupBody.addln("if ({0} && ! {1}.isInvariant())", cachedFieldName, bindingFieldName);
        cleanupBody.begin();
        cleanupBody.addln("{0} = false;", cachedFieldName);
        cleanupBody.addln("{0} = {1};", fieldName, defaultFieldName);
        cleanupBody.end();

        op.extendMethodImplementation(IComponent.class,
                                      EnhanceUtils.CLEANUP_AFTER_RENDER_SIGNATURE, cleanupBody.toString());
    }
View Full Code Here

    private void buildMutator(EnhancementOperation op, String parameterName,
                              String propertyName, Class propertyType, String fieldName,
                              String defaultFieldName, String cachedFieldName,
                              String bindingFieldName, Location location)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();

        // The mutator method may be invoked from finishLoad(), in which
        // case it changes the default value for the parameter property, if the
        // parameter
        // is not bound.

        builder.addln("if (! isInActiveState())");
        builder.begin();
        builder.addln("{0} = $1;", defaultFieldName);
        builder.addln("return;");
        builder.end();

        // In the normal state, we update the binding first - and it's an error
        // if the parameter is not bound.

        builder.addln("if ({0} == null)", bindingFieldName);
        builder.addln("  throw new {0}(\"Parameter ''{1}'' is not bound and can not be updated.\");",
                      ApplicationRuntimeException.class.getName(), parameterName);

        // Always updated the binding first (which may fail with an exception).

        builder.addln("{0}.setObject(($w) $1);", bindingFieldName);

        // While rendering, we store the updated value for fast
        // access again (while the component is still rendering).
        // The property value will be reset to default by cleanupAfterRender().

        builder.addln("if (isRendering())");
        builder.begin();
        builder.addln("{0} = $1;", fieldName);
        builder.addln("{0} = true;", cachedFieldName);
        builder.end();

        builder.end();

        String mutatorMethodName = EnhanceUtils.createMutatorMethodName(propertyName);

        op.addMethod(Modifier.PUBLIC,
                     new MethodSignature(void.class, mutatorMethodName, new Class[] { propertyType }, null),
                     builder.toString(), location);
    }
View Full Code Here

    void buildAccessor(EnhancementOperation op, String propertyName, Class propertyType,
                       String fieldName, String defaultFieldName, String cachedFieldName,
                       String bindingFieldName, boolean cache, Location location)
    {
        BodyBuilder builder = new BodyBuilder();
        builder.begin();

        builder.addln("if ({0}) return {1};", cachedFieldName, fieldName);
        builder.addln("if ({0} == null) return {1};", bindingFieldName, defaultFieldName);

        String javaTypeName = ClassFabUtils.getJavaClassName(propertyType);

        builder.addln("{0} result = {1};", javaTypeName, EnhanceUtils.createUnwrapExpression(op, bindingFieldName, propertyType));

        // Values read via the binding are cached during the render of
        // the component (if the parameter defines cache to be true, which
        // is the default), or any time the binding is invariant
        // (such as most bindings besides ExpressionBinding.

        String expression = cache ? "isRendering() || {0}.isInvariant()" : "{0}.isInvariant()";

        builder.addln("if (" + expression + ")", bindingFieldName);
        builder.begin();
        builder.addln("{0} = result;", fieldName);
        builder.addln("{0} = true;", cachedFieldName);
        builder.end();

        builder.addln("return result;");

        builder.end();

        String accessorMethodName = op.getAccessorMethodName(propertyName);

        op.addMethod(Modifier.PUBLIC, new MethodSignature(propertyType,
                                                          accessorMethodName, null, null), builder.toString(), location);
    }
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.