Examples of ClassFab


Examples of org.apache.hivemind.service.ClassFab

    {
        ConstructableServicePoint servicePoint = getServicePoint();

        ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint, true);

        ClassFab classFab = proxyBuilder.getClassFab();

        Class serviceInterface = servicePoint.getServiceInterface();

        // This will initally be the inner proxy, then switch over to the
        // service implementation.

        classFab.addField("_inner", serviceInterface);
        classFab.addField("_shutdown", boolean.class);

        classFab.addInterface(RegistryShutdownListener.class);

        classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
                "registryDidShutdown", null, null), "{ _shutdown = true; }");

        classFab.addMethod(
                Modifier.PUBLIC | Modifier.SYNCHRONIZED | Modifier.FINAL,
                new MethodSignature(void.class, "_setInner", new Class[]
                { serviceInterface }, null),
                "{ _inner = $1; }");

        BodyBuilder builder = new BodyBuilder();
        builder.begin();
        builder.addln("if (_shutdown)");
        builder.begin();
        builder.addln("_inner = null;");
        builder.addln("throw org.apache.hivemind.HiveMind#createRegistryShutdownException();");
        builder.end();

        builder.addln("return _inner;");
        builder.end();

        classFab.addMethod(Modifier.PRIVATE, new MethodSignature(serviceInterface, "_getInner",
                null, null), builder.toString());

        proxyBuilder.addServiceMethods("_getInner()");

        return classFab.createClass();
    }
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        ServicePoint servicePoint = getServicePoint();

        Class serviceInterface = servicePoint.getServiceInterface();
        ProxyBuilder builder = new ProxyBuilder("InnerProxy", servicePoint);

        ClassFab classFab = builder.getClassFab();

        classFab.addField("_deferredProxy", deferredProxyClass);
        classFab.addField("_service", serviceInterface);
        classFab.addField("_serviceModel", getClass());

        BodyBuilder body = new BodyBuilder();

        // The constructor remembers the outer proxy and registers itself
        // with the outer proxy.

        body.begin();

        body.addln("super();");
        body.addln("_deferredProxy = $1;");
        body.addln("_serviceModel = $2;");
        body.addln("_deferredProxy._setInner(this);");

        body.end();

        classFab.addConstructor(new Class[]
        { deferredProxyClass, getClass() }, null, body.toString());

        // Method _service() will look up the service implementation,
        // then update the deferred proxy to go directly to the
        // service implementation, bypassing itself!

        body.clear();
        body.begin();

        body.add("if (_service == null)");
        body.begin();

        body.add("_service = (");
        body.add(serviceInterface.getName());
        body.addln(") _serviceModel.getActualServiceImplementation();");

        body.add("_deferredProxy._setInner(_service);");

        body.end();

        body.add("return _service;");

        body.end();

        classFab.addMethod(
                Modifier.PRIVATE | Modifier.FINAL | Modifier.SYNCHRONIZED,
                new MethodSignature(serviceInterface, "_service", null, null),
                body.toString());

        builder.addServiceMethods("_service()");

        // Build the implementation of interface SingletonInnerProxy

        body.clear();
        body.begin();

        body.add("_service();");

        body.end();

        classFab.addMethod(Modifier.PUBLIC | Modifier.FINAL, new MethodSignature(void.class,
                "_instantiateServiceImplementation", null, null), body.toString());

        classFab.addInterface(SingletonInnerProxy.class);

        return classFab.createClass();
    }
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

    private Class constructBridgeProxyClass(Object service)
    {
        ProxyBuilder builder = new ProxyBuilder("BridgeProxy", getServicePoint());

        ClassFab cf = builder.getClassFab();

        Class serviceType = service.getClass();

        cf.addField("_service", serviceType);

        cf.addConstructor(new Class[]
        { serviceType }, null, "{ super(); _service = $1; }");

        builder.addServiceMethods("_service");

        return cf.createClass();
    }
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        Class homeInterface = invokingModule.getClassResolver().findClass(homeInterfaceClassName);

        String proxyClassName = ClassFabUtils.generateClassName("EJBProxy");

        ClassFab classFab =
            _classFactory.newClass(proxyClassName, AbstractEJBProxy.class, invokingModule);

        classFab.addInterface(serviceInterface);

        classFab.addField("_remote", serviceInterface);

        addClearCachedMethod(classFab);

        addLookupMethod(classFab, homeInterface, serviceInterface, jndiName);

        addServiceMethods(classFab, serviceInterface, serviceId, jndiName);

        addConstructor(classFab);

        Class proxyClass = classFab.createClass();

        return invokeConstructor(proxyClass, proxyParameters.getNameLookup(_nameLookup));
    }
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        if (!interfaceType.isInterface())
            throw new ApplicationRuntimeException(ImplMessages.notAnInterface(interfaceType));

        String name = ClassFabUtils.generateClassName("DefaultImpl");

        ClassFab cf = _classFactory.newClass(name, Object.class, module);

        cf.addInterface(interfaceType);

        boolean toString = false;

        Method[] methods = interfaceType.getMethods();

        for (int i = 0; i < methods.length; i++)
        {
            Method m = methods[i];

            toString |= ClassFabUtils.isToString(m);

            addMethod(cf, m);
        }

        if (!toString)
            ClassFabUtils.addToStringMethod(
                cf,
                ImplMessages.defaultImplementationDescription(interfaceType));

        return cf.createClass();
    }
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        }

        Class serviceInterfaceClass = stack.getServiceInterface();

        String name = ClassFabUtils.generateClassName("Interceptor");
        ClassFab classFab =
            _classFactory.newClass(
                name,
                AbstractLoggingInterceptor.class,
                stack.getServiceModule());

        classFab.addInterface(serviceInterfaceClass);
        classFab.addField("_inner", serviceInterfaceClass);

        classFab.addConstructor(
            new Class[] { Log.class, serviceInterfaceClass },
            null,
            "{ super($1); _inner = $2; }");

        Method[] methods = serviceInterfaceClass.getMethods();

        BodyBuilder builder = new BodyBuilder();

        for (int j = 0; j < methods.length; j++)
        {
            Method m = methods[j];
            String methodName = m.getName();

            builder.clear();

            builder.begin();

            if (names.contains(methodName))
            {
                builder.add("_logEntry(");
                builder.addQuoted(methodName);
                builder.addln(", $args);");
            }

            builder.add("return ($r) ");
            builder.add("_inner.");
            builder.add(methodName);
            builder.addln("($$);");

            builder.end();

            classFab.addMethod(Modifier.PUBLIC, new MethodSignature(m), builder.toString());

        }

        Class interceptorClass = classFab.createClass();

        Log log = LogFactory.getLog(stack.getServiceExtensionPointId());

        Object interceptor = null;
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        assertEquals("Buffy", actual);
    }

    public void testConstructorFromBaseClass() throws Exception
    {
        ClassFab cf = newClassFab("MyIntHolder", AbstractIntWrapper.class);

        cf.addField("_intValue", int.class);
        cf.addConstructor(new Class[] { int.class }, null, "{ _intValue = $1; }");

        cf.addMethod(
            Modifier.PUBLIC,
            new MethodSignature(int.class, "getIntValue", null, null),
            "return _intValue;");

        Class targetClass = cf.createClass();
        Constructor c = targetClass.getConstructors()[0];

        AbstractIntWrapper targetBean =
            (AbstractIntWrapper) c.newInstance(new Object[] { new Integer(137)});
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        assertEquals(137, targetBean.getIntValue());
    }

    public void testInvalidSuperClass() throws Exception
    {
        ClassFab cf = newClassFab("InvalidSuperClass", List.class);

        try
        {
            cf.createClass();
            unreachable();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertExceptionSubstring(ex, "Unable to create class InvalidSuperClass");
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        }
    }

    public void testAddInterface() throws Exception
    {
        ClassFab cf = newClassFab("SimpleService", Object.class);

        cf.addInterface(SimpleService.class);

        cf.addMethod(
            Modifier.PUBLIC,
            new MethodSignature(int.class, "add", new Class[] { int.class, int.class }, null),
            "return $1 + $2;");

        Class targetClass = cf.createClass();

        SimpleService s = (SimpleService) targetClass.newInstance();

        assertEquals(207, s.add(99, 108));
    }
View Full Code Here

Examples of org.apache.hivemind.service.ClassFab

        assertEquals(207, s.add(99, 108));
    }

    public void testSubclassFromFinal() throws Exception
    {
        ClassFab cf = newClassFab("StringSubclass", String.class);

        try
        {
            cf.createClass();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertEquals(
                "Unable to create class StringSubclass: Cannot inherit from final class",
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.