Package org.apache.hivemind.service

Examples of org.apache.hivemind.service.MethodFab


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

        MethodSignature s = new MethodSignature(void.class, "run", null, null);
        MethodFab mf = cf.addMethod(Modifier.PUBLIC, s, null);

        assertSame(mf, cf.getMethodFab(s));

        assertNull(cf.getMethodFab(new MethodSignature(void.class, "skip", null, null)));
    }
View Full Code Here


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

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getValue", null, null),
                "return 1;");

        mf.extend("return 2 * $_;", false);

        Object bean = cf.createClass().newInstance();

        assertEquals(new Integer(2), PropertyUtils.read(bean, "value"));
    }
View Full Code Here

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

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getValue", null, null),
                "return 2;");

        mf.extend("$_ = 3 * $_;", false);

        Object bean = cf.createClass().newInstance();

        assertEquals(new Integer(6), PropertyUtils.read(bean, "value"));
    }
View Full Code Here

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

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(int.class, "getValue", null, null),
                "return 1;");

        try
        {
            mf.extend("$_ =", true);
            unreachable();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertExceptionSubstring(
View Full Code Here

    {
        ClassFab cf = newClassFab("Fail", Object.class);

        cf.addInterface(FailService.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(void.class, "fail", null, null),
                "throw new java.lang.RuntimeException(\"Ouch!\");");

        mf.addCatch(RuntimeException.class, "throw new java.io.IOException($e.getMessage());");

        Class targetClass = cf.createClass();

        FailService fs = (FailService) targetClass.newInstance();
View Full Code Here

    {
        ClassFab cf = newClassFab("BadCatch", Object.class);

        cf.addInterface(Runnable.class);

        MethodFab mf =
            cf.addMethod(
                Modifier.PUBLIC,
                new MethodSignature(void.class, "run", null, null),
                "return;");

        try
        {
            mf.addCatch(RuntimeException.class, "woops!");
            unreachable();
        }
        catch (ApplicationRuntimeException ex)
        {
            assertExceptionSubstring(
View Full Code Here

            builder.addln("return result;");
        }

        builder.end();

        MethodFab methodFab = classFab.addMethod(Modifier.PUBLIC, sig, builder.toString());

        builder.clear();

        builder.begin();
        builder.add("org.apache.hivemind.service.impl.LoggingUtils.exception(_log, ");
        builder.addQuoted(methodName);
        builder.addln(", $e);");
        builder.addln("throw $e;");
        builder.end();

        String body = builder.toString();

        Class[] exceptions = sig.getExceptionTypes();

        int count = exceptions.length;

        for (int i = 0; i < count; i++)
        {
            methodFab.addCatch(exceptions[i], body);
        }

        // Catch and log any runtime exceptions, in addition to the
        // checked exceptions.

        methodFab.addCatch(RuntimeException.class, body);
    }
View Full Code Here

    {
        Iterator i = _methods.values().iterator();
        while (i.hasNext())
        {

            MethodFab mf = (MethodFab) i.next();

            buffer.append("\n");
            buffer.append(mf);
            buffer.append("\n");
        }
View Full Code Here

                    ex), ex);
        }

        // Return a MethodFab so the caller can add catches.

        MethodFab result = new MethodFabImpl(getSource(), ms, method, body);

        _methods.put(ms, result);

        return result;
    }
View Full Code Here

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

        MethodSignature s = new MethodSignature(void.class, "run", null, null);
        MethodFab mf = cf.addMethod(Modifier.PUBLIC, s, null);

        assertSame(mf, cf.getMethodFab(s));

        assertNull(cf.getMethodFab(new MethodSignature(void.class, "skip", null, null)));
    }
View Full Code Here

TOP

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

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.