@Override public Class<?> getGeneratedRulesClass() throws RulesInstantiationException { // Using project class loader for interface generation. ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().getInterfaceClass(); } catch (Exception e) { throw new RulesInstantiationException("Failed to resolve interface!", e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
@Override public Class<?> getGeneratedRulesClass() throws RulesInstantiationException { // Using project class loader for interface generation. ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().getInterfaceClass(); } catch (Exception e) { throw new RulesInstantiationException("Failed to resolve interface!", e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
@Override public Class<?> getGeneratedRulesClass() throws RulesInstantiationException { // Using project class loader for interface generation. ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().getInterfaceClass(); } catch (Exception e) { throw new RulesInstantiationException("Failed to resolve interface", e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
@Override public ClassLoader getClassLoader() throws RulesInstantiationException { try { return getOriginalInstantiationStrategy().getInstanceClass().getClassLoader(); } catch (ClassNotFoundException e) { throw new RulesInstantiationException(e); } }
@Override public Object instantiate(Class<?> rulesClass) throws RulesInstantiationException { // Ensure that instantiation will be done in strategy classLoader. // ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().newEngineInstance(); } catch (Exception e) { throw new RulesInstantiationException(e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
@Override public Class<?> getGeneratedRulesClass() throws RulesInstantiationException { // Using project class loader for interface generation. ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().getInterfaceClass(); } catch (Exception e) { throw new RulesInstantiationException("Failed to resolve interface", e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
@Override public ClassLoader getClassLoader() throws RulesInstantiationException { try { return getOriginalInstantiationStrategy().getInstanceClass().getClassLoader(); } catch (ClassNotFoundException e) { throw new RulesInstantiationException(e); } }
@Override public Object instantiate(Class<?> rulesClass) throws RulesInstantiationException { // Ensure that instantiation will be done in strategy classLoader. // ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().newEngineInstance(); } catch (Exception e) { throw new RulesInstantiationException(e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
/** * Gets methods map where keys are interface class methods and values - * original service class methods. * * @param interfaceClass class to expose as service class * @param serviceClass original service class * @return methods map */ private Map<Method, Method> makeMethodMap(Class<?> interfaceClass, Class<?> serviceClass) throws Exception { log.debug("Creating methods map for classes: {} <-> {}", interfaceClass, serviceClass); Map<Method, Method> methodMap = new HashMap<Method, Method>(); Method[] serviceMethods = interfaceClass.getDeclaredMethods(); for (Method serviceMethod : serviceMethods) { try { Method originalMethod = VariationInstantiationStrategyEnhancerHelper.getMethodForDecoration(serviceClass, serviceMethod); methodMap.put(serviceMethod, originalMethod); } catch (Exception e) { throw new RulesInstantiationException("Failed to find corresrponding method in original class for method '" + MethodUtil.printMethod(serviceMethod.getName() + "'!", serviceMethod.getParameterTypes())); } } log.debug("{}", methodMap); return methodMap; }
@Override public Class<?> getGeneratedRulesClass() throws RulesInstantiationException { // Service class for current implementation will be class, generated at // runtime by factory. // Using project class loader for interface generation. // ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().getInterfaceClass(); } catch (Exception e) { throw new RulesInstantiationException("Failed to resolve a interface.", e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
/** * Gets methods map where keys are interface class methods and values - * original service class methods. * * @param interfaceClass class to expose as service class * @param serviceClass original service class * @return methods map */ private Map<Method, Method> makeMethodMap(Class<?> interfaceClass, Class<?> serviceClass) throws Exception { log.debug("Creating methods map for classes: {} <-> {}", interfaceClass, serviceClass); Map<Method, Method> methodMap = new HashMap<Method, Method>(); Method[] serviceMethods = interfaceClass.getDeclaredMethods(); for (Method serviceMethod : serviceMethods) { try { Method originalMethod = VariationInstantiationStrategyEnhancerHelper.getMethodForDecoration(serviceClass, serviceMethod); methodMap.put(serviceMethod, originalMethod); } catch (Exception e) { throw new RulesInstantiationException("Failed to find corresrponding method in original class for method '" + MethodUtil.printMethod(serviceMethod.getName() + "'!", serviceMethod.getParameterTypes())); } } log.debug("{}", methodMap); return methodMap; }
@Override public Class<?> getGeneratedRulesClass() throws RulesInstantiationException { // Service class for current implementation will be class, generated at // runtime by factory. // Using project class loader for interface generation. // ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); try { return getEngineFactory().getInterfaceClass(); } catch (Exception e) { throw new RulesInstantiationException("Failed to resolve a interface.", e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
@Override public final Object instantiate() throws RulesInstantiationException, ClassNotFoundException { try { Object originalInstance = getOriginalInstantiationStrategy().instantiate(); InvocationHandler invocationHandler = makeInvocationHandler(originalInstance); return Proxy.newProxyInstance(getClassLoader(), getProxyInterfaces(originalInstance), invocationHandler); } catch (Exception e) { throw new RulesInstantiationException(e.getMessage(), e); } }
@Override public final Object instantiate() throws RulesInstantiationException, ClassNotFoundException { try { Object originalInstance = getOriginalInstantiationStrategy().instantiate(); InvocationHandler invocationHandler = makeInvocationHandler(originalInstance); return Proxy.newProxyInstance(getClassLoader(), getProxyInterfaces(originalInstance), invocationHandler); } catch (Exception e) { throw new RulesInstantiationException(e.getMessage(), e); } }
@Override protected ClassLoader initClassLoader() throws RulesInstantiationException { SimpleBundleClassLoader classLoader = new SimpleBundleClassLoader(Thread.currentThread() .getContextClassLoader()); for (Module module : modules) { try { CompiledDependency compiledDependency = getDependencyManager().loadDependency( new Dependency(DependencyType.MODULE, new IdentifierNode(null, null, module.getName(), null))); CompiledOpenClass compiledOpenClass = compiledDependency.getCompiledOpenClass(); classLoader.addClassLoader(compiledOpenClass.getClassLoader()); } catch (OpenLCompilationException e) { throw new RulesInstantiationException(e.getMessage(), e); } } return classLoader; }
@Override protected ClassLoader initClassLoader() throws RulesInstantiationException { SimpleBundleClassLoader classLoader = new SimpleBundleClassLoader(Thread.currentThread() .getContextClassLoader()); for (Module module : modules) { try { CompiledDependency compiledDependency = getDependencyManager().loadDependency( new Dependency(DependencyType.MODULE, new IdentifierNode(null, null, module.getName(), null))); CompiledOpenClass compiledOpenClass = compiledDependency.getCompiledOpenClass(); classLoader.addClassLoader(compiledOpenClass.getClassLoader()); } catch (OpenLCompilationException e) { throw new RulesInstantiationException(e.getMessage(), e); } } return classLoader; }
throw new RulesInstantiationException("Module hasn't been found in project!"); throw new RulesInstantiationException(ex);
throw new RulesInstantiationException("Module hasn't been found in project!"); throw new RulesInstantiationException(ex);