当前位置: 首页>>代码示例>>Java>>正文


Java GroovyClassLoader.loadClass方法代码示例

本文整理汇总了Java中groovy.lang.GroovyClassLoader.loadClass方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyClassLoader.loadClass方法的具体用法?Java GroovyClassLoader.loadClass怎么用?Java GroovyClassLoader.loadClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在groovy.lang.GroovyClassLoader的用法示例。


在下文中一共展示了GroovyClassLoader.loadClass方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createConnectorInstance

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
private BpmConnector createConnectorInstance(String connectorClassName, Map<String, String> inParameters, ScriptEngine scriptEngine) {
    try {
        GroovyClassLoader groovyClassLoader = DevelopmentAPI.getGroovyClassLoader();
        Class clazz = groovyClassLoader.loadClass(connectorClassName);
        BpmConnector connector = (BpmConnector) clazz.newInstance();

        for (String inParam : inParameters.keySet()) {
            Object paramValue = scriptEngine.eval(inParameters.get(inParam));
            connector.setInParameter(inParam, paramValue);
        }
        return connector;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ScriptException ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
        return null;
    }
}
 
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:17,代码来源:InternalAPI.java

示例2: generateDefaultVariableValues

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
protected HashMap<String, Object> generateDefaultVariableValues() {
    HashMap<String, Object> result = new HashMap<>();
    try {
        Map<String, Variable> variableInstances = HybridbpmUI.getBpmAPI().createFirstVariables(processModel);
        for (String name : variableInstances.keySet()) {
            Variable vi = variableInstances.get(name);
            if (FieldModelUtil.isSimple(vi.getClassName())) {

            } else {
                GroovyClassLoader groovyClassLoader = HybridbpmUI.getDevelopmentAPI().getGroovyClassLoader();
                Class clazz = groovyClassLoader.loadClass(vi.getClassName());
                Object object = clazz.newInstance();
                System.out.println("object = " + object);
                result.put(name, object);
            }
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return result;
}
 
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:22,代码来源:TaskForm.java

示例3: canRun

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
/**
 * Utility method to check via reflection if the parsed class appears to be a TestNG
 * test, i.e. checks whether it appears to be using the relevant TestNG annotations.
 *
 * @param scriptClass the class we want to check
 * @param loader the GroovyClassLoader to use to find classes
 * @return true if the class appears to be a test
 */
@Override
public boolean canRun(Class<?> scriptClass, GroovyClassLoader loader) {
    try {
        @SuppressWarnings("unchecked")
        Class<? extends Annotation> testAnnotationClass =
                (Class<? extends Annotation>) loader.loadClass("org.testng.annotations.Test");
        if (scriptClass.isAnnotationPresent(testAnnotationClass)) {
            return true;
        } else {
            Method[] methods = scriptClass.getMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(testAnnotationClass)) {
                    return true;
                }
            }
        }
    } catch (Throwable e) {
        // fall through
    }
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:TestNgRunner.java

示例4: run

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
/**
 * Utility method to run a TestNG test.
 *
 * @param scriptClass the class we want to run as a test
 * @param loader the class loader to use
 * @return the result of running the test
 */
@Override
public Object run(Class<?> scriptClass, GroovyClassLoader loader) {
    try {
        Class<?> testNGClass = loader.loadClass("org.testng.TestNG");
        Object testng = InvokerHelper.invokeConstructorOf(testNGClass, new Object[]{});
        InvokerHelper.invokeMethod(testng, "setTestClasses", new Object[]{scriptClass});
        Class<?> listenerClass = loader.loadClass("org.testng.TestListenerAdapter");
        Object listener = InvokerHelper.invokeConstructorOf(listenerClass, new Object[]{});
        InvokerHelper.invokeMethod(testng, "addListener", new Object[]{listener});
        if (OUTPUT_DIRECTORY != null) {
            InvokerHelper.invokeMethod(testng, "setOutputDirectory", new Object[]{OUTPUT_DIRECTORY});
        }
        return InvokerHelper.invokeMethod(testng, "run", new Object[]{});
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running TestNG test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:TestNgRunner.java

示例5: run

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
/**
 * Run the specified class extending TestCase as a unit test.
 * This is done through reflection, to avoid adding a dependency to the JUnit framework.
 * Otherwise, developers embedding Groovy and using GroovyShell to load/parse/compile
 * groovy scripts and classes would have to add another dependency on their classpath.
 *
 * @param scriptClass the class to be run as a unit test
 * @param loader the class loader
 */
@Override
public Object run(Class<?> scriptClass, GroovyClassLoader loader) {
    try {
        Class<?> junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
        Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
                "runClasses", new Object[]{scriptClass});
        System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
        System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
        System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
        List<?> failures = (List<?>) InvokerHelper.getProperty(result, "failures");
        for (Object f : failures) {
            System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
            System.out.println(InvokerHelper.getProperty(f, "trace"));
        }
        return result;
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:DefaultRunners.java

示例6: realRunJUnit4Test

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
/**
 * Utility method to run a JUnit4 test.
 *
 * @param scriptClass the class we want to run as a test
 * @return the result of running the test
 */
static Object realRunJUnit4Test(Class scriptClass, GroovyClassLoader loader) {
    // invoke through reflection to eliminate mandatory JUnit 4 jar dependency

    try {
        Class junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
        Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
                "runClasses", new Object[]{scriptClass});
        System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
        System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
        System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
        List failures = (List) InvokerHelper.getProperty(result, "failures");
        for (int i = 0; i < failures.size(); i++) {
            Object f = failures.get(i);
            System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
            System.out.println(InvokerHelper.getProperty(f, "trace"));
        }
        return result;
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:JUnit4Utils.java

示例7: createCamelContext

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext answer = super.createCamelContext();

    GroovyClassLoader classLoader = new GroovyClassLoader();
    Class<?> type = classLoader.loadClass(groovyBuilderClass);
    Object object = answer.getInjector().newInstance(type);
    RouteBuilder builder = assertIsInstanceOf(RouteBuilder.class, object);

    log.info("Loaded builder: " + builder);
    answer.addRoutes(builder);

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:GroovyTest.java

示例8: generateFormObject

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
public static Object generateFormObject(Module module) throws RuntimeException {
    try {
        GroovyClassLoader groovyClassLoader = DevelopmentAPI.getGroovyClassLoader();
        Class clazz = groovyClassLoader.loadClass(module.getName());
        Object object = clazz.newInstance();
        return  object;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
}
 
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:12,代码来源:HybridbpmUiUtil.java

示例9: generateTaskFormObject

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
public static TaskForm generateTaskFormObject(String formName) throws RuntimeException {
    try {
        GroovyClassLoader groovyClassLoader = DevelopmentAPI.getGroovyClassLoader();
        Class clazz = groovyClassLoader.loadClass(formName);
        TaskForm taskForm = (TaskForm) clazz.newInstance();
        return  taskForm;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
}
 
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:12,代码来源:HybridbpmUiUtil.java

示例10: canRun

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
/**
 * Utility method to check through reflection if the class appears to be a
 * JUnit 3.8.x test, i.e. checks if it extends JUnit 3.8.x's TestCase.
 *
 * @param scriptClass the class we want to check
 * @param loader the class loader
 * @return true if the class appears to be a test
 */
@Override
public boolean canRun(Class<?> scriptClass, GroovyClassLoader loader) {
    try {
        Class<?> testCaseClass = loader.loadClass("junit.framework.TestCase");
        return testCaseClass.isAssignableFrom(scriptClass);
    } catch (Throwable e) {
        return false;
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:DefaultRunners.java

示例11: findByClassLoading

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
/**
 * Search for classes using class loading
 */
private static LookupResult findByClassLoading(String name, CompilationUnit compilationUnit, GroovyClassLoader loader) {
    Class cls;
    try {
        // NOTE: it's important to do no lookup against script files
        // here since the GroovyClassLoader would create a new CompilationUnit
        cls = loader.loadClass(name, false, true);
    } catch (ClassNotFoundException cnfe) {
        LookupResult lr = tryAsScript(name, compilationUnit, null);
        return lr;
    } catch (CompilationFailedException cfe) {
        throw new GroovyBugError("The lookup for "+name+" caused a failed compilaton. There should not have been any compilation from this call.", cfe);
    }
    //TODO: the case of a NoClassDefFoundError needs a bit more research
    // a simple recompilation is not possible it seems. The current class
    // we are searching for is there, so we should mark that somehow.
    // Basically the missing class needs to be completely compiled before
    // we can again search for the current name.
    /*catch (NoClassDefFoundError ncdfe) {
        cachedClasses.put(name,SCRIPT);
        return false;
    }*/
    if (cls == null) return null;
    //NOTE: we might return false here even if we found a class,
    //      because  we want to give a possible script a chance to
    //      recompile. This can only be done if the loader was not
    //      the instance defining the class.
    ClassNode cn = ClassHelper.make(cls);
    if (cls.getClassLoader() != loader) {
        return tryAsScript(name, compilationUnit, cn);
    }
    return new LookupResult(null,cn);
}
 
开发者ID:apache,项目名称:groovy,代码行数:36,代码来源:ClassNodeResolver.java

示例12: addPhaseOperationsForGlobalTransforms

import groovy.lang.GroovyClassLoader; //导入方法依赖的package包/类
private static void addPhaseOperationsForGlobalTransforms(CompilationUnit compilationUnit,
        Map<String, URL> transformNames, boolean isFirstScan) {
    GroovyClassLoader transformLoader = compilationUnit.getTransformLoader();
    for (Map.Entry<String, URL> entry : transformNames.entrySet()) {
        try {
            Class gTransClass = transformLoader.loadClass(entry.getKey(), false, true, false);
            //no inspection unchecked
            GroovyASTTransformation transformAnnotation = (GroovyASTTransformation) gTransClass.getAnnotation(GroovyASTTransformation.class);
            if (transformAnnotation == null) {
                compilationUnit.getErrorCollector().addWarning(new WarningMessage(
                    WarningMessage.POSSIBLE_ERRORS,
                    "Transform Class " + entry.getKey() + " is specified as a global transform in " + entry.getValue().toExternalForm()
                    + " but it is not annotated by " + GroovyASTTransformation.class.getName()
                    + " the global transform associated with it may fail and cause the compilation to fail.",
                    null,
                    null));
                continue;
            }
            if (ASTTransformation.class.isAssignableFrom(gTransClass)) {
                final ASTTransformation instance = (ASTTransformation)gTransClass.newInstance();
                if (instance instanceof CompilationUnitAware) {
                    ((CompilationUnitAware)instance).setCompilationUnit(compilationUnit);
                }
                CompilationUnit.SourceUnitOperation suOp = new CompilationUnit.SourceUnitOperation() {
                    public void call(SourceUnit source) throws CompilationFailedException {
                        instance.visit(new ASTNode[] {source.getAST()}, source);
                    }
                }; 
                if(isFirstScan) {
                    compilationUnit.addPhaseOperation(suOp, transformAnnotation.phase().getPhaseNumber());
                } else {
                    compilationUnit.addNewPhaseOperation(suOp, transformAnnotation.phase().getPhaseNumber());
                }
            } else {
                compilationUnit.getErrorCollector().addError(new SimpleMessage(
                    "Transform Class " + entry.getKey() + " specified at "
                    + entry.getValue().toExternalForm() + " is not an ASTTransformation.", null));
            }
        } catch (Exception e) {
            compilationUnit.getErrorCollector().addError(new SimpleMessage(
                "Could not instantiate global transform class " + entry.getKey() + " specified at "
                + entry.getValue().toExternalForm() + "  because of exception " + e.toString(), null));
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:46,代码来源:ASTTransformationVisitor.java


注:本文中的groovy.lang.GroovyClassLoader.loadClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。