private void execute(LogicDefinition extendedLogicDefinition, LogicRequest logicRequest) { ComponentType extendedComponentType = extendedLogicDefinition.getComponentType(); LogicMethod extendedLogicMethod = extendedLogicDefinition.getLogicMethod(); WebApplication application = (WebApplication) logicRequest.getServletContext().getAttribute(WebApplication.class.getName()); BeanProvider beanProvider = application.getIntrospector().getBeanProvider(); try { BeanConstructor contructory = extendedComponentType.getConstructor(); Object extendedComponent = contructory.newInstance(logicRequest, beanProvider); Object[] methodParamObjects = this.readParameter(logicRequest, extendedLogicMethod, extendedComponent); extendedLogicMethod.execute(extendedComponent, logicRequest, methodParamObjects); } catch (ComponentInstantiationException e) { e.printStackTrace(); } catch (LogicException e) { e.printStackTrace(); } catch (SettingException e) { e.printStackTrace(); } }
public void register(ComponentType type) throws LogicNotFoundException { LOG.debug( String.format("Registering component %s as %s", type.getComponentClass(), type.getName())); if (!this.components.containsKey(type.getName())) { this.components.put(type.getName(), new ConcurrentHashMap<String, ComponentType>()); } for (LogicMethod logic : type.getLogics()) { this.components.get(type.getName()).put(logic.getName(), type); } }
/** * @see org.vraptor.url.ViewLocator#locate(javax.servlet.http.HttpServletRequest, * org.vraptor.component.LogicMethod, org.vraptor.view.ViewManager) */ public ViewManager locate( VRaptorServletRequest req, LogicMethod method, ViewManager defaultViewManager) throws InvalidURLException, LogicException { /* //TODO allow view managers to be expanded by registering your own managers... // this code should look go for each one as in the converter finder */ if (isXhr(req)) { String viewType = this.getViewType(req); if ((SUPPORTEDXML.equals(viewType) || SUPPORTEDJSON.equals(viewType))) { if (!method.getMetadata().isAnnotationPresent(Remotable.class)) { throw new LogicException("logic method is not @Remotable"); } return new RemoteViewManager( defaultViewManager, RemoteView.valueOf(viewType.toUpperCase())); } } return defaultViewManager; }
private Object[] readParameter( LogicRequest logicRequest, LogicMethod logicMethod, Object componentInstance) throws SettingException { WebApplication application = (WebApplication) logicRequest.getServletContext().getAttribute(WebApplication.class.getName()); Introspector introspector = application.getIntrospector(); List<MethodParameter> methodParams = logicMethod.getParameters(); List<ReadParameter> allParams = new ArrayList<ReadParameter>(); allParams.addAll(methodParams); // instantiate parameters Object[] methodParamObjects = new Object[methodParams.size()]; for (int i = 0; i < methodParamObjects.length; i++) { try { methodParamObjects[i] = methodParams.get(i).newInstance(); } catch (ComponentInstantiationException e) { methodParamObjects[i] = null; } } List<ValidationMessage> problems = introspector.readParameters( allParams, componentInstance, logicRequest, application.getConverterManager(), methodParamObjects); if (problems.size() != 0) { throw new SettingException(problems.toString()); } return methodParamObjects; }