@Override protected Class<?> decorateServiceClass(Class<?> serviceClass, ClassLoader classLoader) { try { return RuntimeContextInstantiationStrategyEnhancerHelper.decorateClass(serviceClass, classLoader); } catch (Exception e) { throw new OpenlNotCheckedException("Failed to add runtime context in parameters of each method.", e); } }
/** * Undecorates methods signatures of given class. * * @param clazz interface to undecorate * @param classLoader The classloader where generated class should be * placed. * @return new class with undecorated methods signatures: removed * {@link IRulesRuntimeContext} as the first parameter for each * method. * @throws Exception */ public static Class<?> undecorateClass(Class<?> clazz, ClassLoader classLoader) throws Exception { if (!clazz.isInterface()) { throw new IllegalArgumentException("Supports only interface classes!!!"); } final Logger log = LoggerFactory.getLogger(RuntimeContextInstantiationStrategyEnhancerHelper.class); String className = clazz.getName() + UNDECORATED_CLASS_NAME_SUFFIX; log.debug("Generating interface without runtime context for '{}' class.", clazz.getName()); return innerUndecorateInterface(className, clazz, classLoader); }
@Override protected boolean validateServiceClass(Class<?> serviceClass) throws ValidationServiceClassException { if (RuntimeContextInstantiationStrategyEnhancerHelper.isDecoratedClass(serviceClass)) { return true; } else { throw new ValidationServiceClassException("Runtime context parameter required in each method!"); } }
@Override protected Class<?> undecorateServiceClass(Class<?> serviceClass, ClassLoader classLoader) { try { return RuntimeContextInstantiationStrategyEnhancerHelper.undecorateClass(serviceClass, classLoader); } catch (Exception e) { throw new OpenlNotCheckedException("Failed to remove runtime context from parameters of each method.", e); } }
/** * Decorates methods signatures of given clazz. * * @param clazz class to decorate * @param classLoader The classloader where generated class should be * placed. * @return new class with decorated methods signatures: added * {@link IRulesRuntimeContext} as the first parameter for each * method. * @throws Exception */ public static Class<?> decorateClass(Class<?> clazz, ClassLoader classLoader) throws Exception { final Logger log = LoggerFactory.getLogger(RuntimeContextInstantiationStrategyEnhancerHelper.class); Method[] methods = clazz.getMethods(); List<RuleInfo> rules = getRulesDecorated(methods); String className = clazz.getName() + DECORATED_CLASS_NAME_SUFFIX; RuleInfo[] rulesArray = rules.toArray(new RuleInfo[rules.size()]); log.debug("Generating interface for '{}' class", clazz.getName()); return InterfaceGenerator.generateInterface(className, rulesArray, classLoader); }
/** * Gets list of rules. * * @param methods array of methods what represents rule methods * @return list of rules meta-info */ private static List<RuleInfo> getRulesDecorated(Method[] methods) { List<RuleInfo> rules = new ArrayList<RuleInfo>(methods.length); for (Method method : methods) { // Check that method should be ignored or not. if (isIgnored(method)) { continue; } String methodName = method.getName(); Class<?>[] paramTypes = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); Class<?>[] newParams = new Class<?>[]{IRulesRuntimeContext.class}; Class<?>[] extendedParamTypes = ArrayUtils.addAll(newParams, paramTypes); RuleInfo ruleInfo = InterfaceGenerator.createRuleInfo(methodName, extendedParamTypes, returnType); rules.add(ruleInfo); } return rules; }
@Override protected Class<?> undecorateServiceClass(Class<?> serviceClass, ClassLoader classLoader) { try { return RuntimeContextInstantiationStrategyEnhancerHelper.undecorateClass(serviceClass, classLoader); } catch (Exception e) { throw new OpenlNotCheckedException("Failed to remove runtime context from parameters of each method.", e); } }
/** * Decorates methods signatures of given clazz. * * @param clazz class to decorate * @param classLoader The classloader where generated class should be * placed. * @return new class with decorated methods signatures: added * {@link IRulesRuntimeContext} as the first parameter for each * method. * @throws Exception */ public static Class<?> decorateClass(Class<?> clazz, ClassLoader classLoader) throws Exception { final Logger log = LoggerFactory.getLogger(RuntimeContextInstantiationStrategyEnhancerHelper.class); Method[] methods = clazz.getMethods(); List<RuleInfo> rules = getRulesDecorated(methods); String className = clazz.getName() + DECORATED_CLASS_NAME_SUFFIX; RuleInfo[] rulesArray = rules.toArray(new RuleInfo[rules.size()]); log.debug("Generating interface for '{}' class", clazz.getName()); return InterfaceGenerator.generateInterface(className, rulesArray, classLoader); }
/** * Gets list of rules. * * @param methods array of methods what represents rule methods * @return list of rules meta-info */ private static List<RuleInfo> getRulesDecorated(Method[] methods) { List<RuleInfo> rules = new ArrayList<RuleInfo>(methods.length); for (Method method : methods) { // Check that method should be ignored or not. if (isIgnored(method)) { continue; } String methodName = method.getName(); Class<?>[] paramTypes = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); Class<?>[] newParams = new Class<?>[]{IRulesRuntimeContext.class}; Class<?>[] extendedParamTypes = ArrayUtils.addAll(newParams, paramTypes); RuleInfo ruleInfo = InterfaceGenerator.createRuleInfo(methodName, extendedParamTypes, returnType); rules.add(ruleInfo); } return rules; }
@Override protected boolean validateServiceClass(Class<?> serviceClass) throws ValidationServiceClassException { if (RuntimeContextInstantiationStrategyEnhancerHelper.isDecoratedClass(serviceClass)) { return true; } else { throw new ValidationServiceClassException("Runtime context parameter required in each method!"); } }
@Override protected Class<?> decorateServiceClass(Class<?> serviceClass, ClassLoader classLoader) { try { return RuntimeContextInstantiationStrategyEnhancerHelper.decorateClass(serviceClass, classLoader); } catch (Exception e) { throw new OpenlNotCheckedException("Failed to add runtime context in parameters of each method.", e); } }
/** * Undecorates methods signatures of given class. * * @param clazz interface to undecorate * @param classLoader The classloader where generated class should be * placed. * @return new class with undecorated methods signatures: removed * {@link IRulesRuntimeContext} as the first parameter for each * method. * @throws Exception */ public static Class<?> undecorateClass(Class<?> clazz, ClassLoader classLoader) throws Exception { if (!clazz.isInterface()) { throw new IllegalArgumentException("Supports only interface classes!!!"); } final Logger log = LoggerFactory.getLogger(RuntimeContextInstantiationStrategyEnhancerHelper.class); String className = clazz.getName() + UNDECORATED_CLASS_NAME_SUFFIX; log.debug("Generating interface without runtime context for '{}' class.", clazz.getName()); return innerUndecorateInterface(className, clazz, classLoader); }