/** * Throws an exception, as stack can not be invoked. */ @Override public Object apply(final ActionRequest actionRequest) { throw new MadvocException("Wrapper stack can not be invoked"); }
private static FileInputStream createFileInputStream(final File file) { try { return new FileInputStream(file); } catch (FileNotFoundException fis) { throw new MadvocException(fis); } }
/** * Registers new path alias. */ public void registerPathAlias(final String alias, final String path) { final String existing = pathAliases.put(alias, path); if (existing != null) { throw new MadvocException("Duplicated alias detected: [" + alias + "] for paths: " + path + ", " + existing); } }
/** * Lookup for the action configuration. Typically, the input argument is either the action type or annotation type. */ public ActionConfig lookup(final Class actionTypeOrAnnotationType) { final ActionConfig actionConfig = actionConfigs.get(actionTypeOrAnnotationType); if (actionConfig == null) { throw new MadvocException("ActionConfiguration not registered:" + actionTypeOrAnnotationType.getName()); } return actionConfig; }
/** * Creates new wrapper. */ protected <R extends T> R createWrapper(final Class<R> wrapperClass) { try { return ClassUtil.newInstance(wrapperClass); } catch (Exception ex) { throw new MadvocException("Invalid Madvoc wrapper: " + wrapperClass, ex); } }
/** * Returns existing component. Throws an exception if component is not registered. */ public <T> T requestComponent(final Class<T> component) { T existingComponent = lookupComponent(component); if (existingComponent == null) { throw new MadvocException("Madvoc component not found: " + component.getName()); } return existingComponent; }
/** * Returns existing component. Throws an exception if component is not registered. */ public <T> T requestComponent(final String componentName) { T existingComponent = (T) lookupComponent(componentName); if (existingComponent == null) { throw new MadvocException("Madvoc component not found: " + componentName); } return existingComponent; }
/** * Creates new {@link jodd.madvoc.result.ActionResult}. */ protected ActionResult createResult(final Class<? extends ActionResult> actionResultClass) { try { return ClassUtil.newInstance(actionResultClass); } catch (Exception ex) { throw new MadvocException("Invalid Madvoc result: " + actionResultClass, ex); } }
protected ActionConfig createActionConfig(final Class<? extends ActionConfig> actionConfigClass) { try { final Constructor<? extends ActionConfig> ctor = actionConfigClass.getDeclaredConstructor(); final ActionConfig actionConfig = ctor.newInstance(); contextInjectorComponent.injectContext(actionConfig); return actionConfig; } catch (Exception ex) { throw new MadvocException("Invalid action configuration class: " + actionConfigClass.getSimpleName(), ex); } } }
/** * Creates new action object from {@link ActionRuntime} using default constructor. */ protected Object createAction(final Class actionClass) { try { return ClassUtil.newInstance(actionClass); } catch (Exception ex) { throw new MadvocException("Invalid Madvoc action", ex); } }
/** * Creates action method arguments. */ @SuppressWarnings({"unchecked", "NullArgumentToVariableArgMethod"}) protected Object createActionMethodArgument(final Class type, final Object action) { try { if (type.getEnclosingClass() == null || Modifier.isStatic(type.getModifiers())) { // regular or static class return ClassUtil.newInstance(type); } else { // member class Constructor ctor = type.getDeclaredConstructor(type.getDeclaringClass()); ctor.setAccessible(true); return ctor.newInstance(action); } } catch (Exception ex) { throw new MadvocException(ex); } }
/** * Performs search for the scope class and returns it's instance. */ protected MadvocScope getOrInitScope(final Class<? extends MadvocScope> madvocScopeType) { for (final MadvocScope s : allScopes) { if (s.getClass().equals(madvocScopeType)) { return s; } } // new scope detected final MadvocScope newScope; try { newScope = madpc.createBean(madvocScopeType); } catch (Exception ex) { throw new MadvocException("Unable to create scope: " + madvocScopeType, ex); } allScopes.add(newScope); return newScope; }
/** * Registers action configuration for given annotation. New {@link ActionConfig} is created * and stored. */ public void registerAnnotation(final Class<? extends Annotation> annotationType) { final ActionConfiguredBy actionConfiguredBy = annotationType.getAnnotation(ActionConfiguredBy.class); if (actionConfiguredBy == null) { throw new MadvocException("Action annotation is missing it's " + ActionConfiguredBy.class.getSimpleName() + " configuration."); } bindAnnotationConfig(annotationType, actionConfiguredBy.value()); }
@Override public void init() { final long startTime = System.currentTimeMillis(); try { log.info("Scanning..."); classScanner.start(); } catch (Exception ex) { throw new MadvocException("Scan classpath error", ex); } madvocComponents.forEach(Runnable::run); log.info("Scanning is complete."); elapsed = System.currentTimeMillis() - startTime; }
/** * Creates new <code>PathMacro</code> instance. */ private PathMacros createPathMacroInstance() { try { return ClassUtil.newInstance(actionsManager.getPathMacroClass()); } catch (Exception ex) { throw new MadvocException(ex); } }
/** * Loads Madvoc component that will be used for configuring the user actions. * If class name is <code>null</code>, default {@link AutomagicMadvocConfigurator} * will be used. */ protected void resolveMadvocConfigClass() { if ((madvocConfiguratorClassName == null) && (madvocConfiguratorClass == null)) { return; } try { if (madvocConfiguratorClassName != null) { madvocConfiguratorClass = ClassLoaderUtil.loadClass(madvocConfiguratorClassName); } log.info("Configuring Madvoc using: " + madvocConfiguratorClass.getName()); } catch (Exception ex) { throw new MadvocException("Unable to load Madvoc configurator class: " + madvocConfiguratorClassName, ex); } }
/** * Resolves action method for given action class ane method name. */ public Method resolveActionMethod(final Class<?> actionClass, final String methodName) { MethodDescriptor methodDescriptor = ClassIntrospector.get().lookup(actionClass).getMethodDescriptor(methodName, false); if (methodDescriptor == null) { throw new MadvocException("Public method not found: " + actionClass.getSimpleName() + "#" + methodName); } return methodDescriptor.getMethod(); }
/** * Creates {@link WebApp}. */ protected WebApp createWebApplication() { if ((webAppClassName == null) && (webAppClass == null)) { return new WebApp(); } final WebApp webApp; try { if (webAppClassName != null) { webAppClass = ClassLoaderUtil.loadClass(webAppClassName); } webApp = (WebApp) ClassUtil.newInstance(webAppClass); } catch (Exception ex) { throw new MadvocException("Unable to load Madvoc web application class: " + webAppClassName, ex); } return webApp; }
/** * Loads Madvoc parameters. New {@link Props} is created from the classpath. */ protected Props loadMadvocParams(final String[] patterns) { if (log.isInfoEnabled()) { log.info("Loading Madvoc parameters from: " + Converter.get().toString(patterns)); } try { return new Props().loadFromClasspath(patterns); } catch (Exception ex) { throw new MadvocException("Unable to load Madvoc parameters from: " + Converter.get().toString(patterns) + ".properties': " + ex.toString(), ex); } }
/** * Parses action class and method and creates {@link ActionDefinition parsed action definition}. */ public ActionDefinition parseActionDefinition(final Class<?> actionClass, final Method actionMethod) { final ActionAnnotationValues annotationValues = detectActionAnnotationValues(actionMethod); final ActionConfig actionConfig = resolveActionConfig(annotationValues); final String[] packageActionNames = readPackageActionPath(actionClass); final String[] classActionNames = readClassActionPath(actionClass); final String[] methodActionNames = readMethodActionPath(actionMethod.getName(), annotationValues, actionConfig); final String method = readMethodHttpMethod(actionMethod); final ActionNames actionNames = new ActionNames(packageActionNames, classActionNames, methodActionNames, method); final ActionNamingStrategy namingStrategy; try { namingStrategy = ClassUtil.newInstance(actionConfig.getNamingStrategy()); contextInjectorComponent.injectContext(namingStrategy); } catch (Exception ex) { throw new MadvocException(ex); } return namingStrategy.buildActionDef(actionClass, actionMethod, actionNames); }