private void invokeExpression(Object component, MethodDef methodDef) { Map<String, Object> ctx = new HashMap<String, Object>(); ctx.put("self", component); ctx.put("out", System.out); ctx.put("err", System.err); LaContainer container = getComponentDef().getContainer(); methodDef.getExpression().evaluate(ctx, container, Object.class); }
public static LaContainerPreparer getPreparer(ComponentDef componentDef) { final LaContainer container = componentDef.getContainer(); final ComponentDef[] componentDefs = container.findLocalComponentDefs(LaContainerPreparer.class); if (componentDefs.length == 0) { return null; } return (LaContainerPreparer) componentDefs[0].getComponent(); }
protected Object getComponent(ComponentDef componentDef, Object key, Object component, String propertyName) throws BeanIllegalPropertyException { try { return componentDef.getContainer().getComponent(key); } catch (RuntimeException cause) { throwPropertyComponentGetFailureException(componentDef, key, component, propertyName, cause); return null; // unreachable } }
protected Object assembleExpression() throws ClassUnmatchRuntimeException { final ComponentDef cd = getComponentDef(); final LaContainer container = cd.getContainer(); final Expression expression = cd.getExpression(); final Object component = expression.evaluate(Collections.emptyMap(), container, Object.class); // #expression_point final Class<?> componentClass = cd.getComponentClass(); if (componentClass != null && !componentClass.isInstance(component)) { throw new ClassUnmatchRuntimeException(componentClass, component != null ? component.getClass() : null); } if (componentClass == null) { // expression lazy type cd.setComponentClass(component.getClass()); // related to sub-class type cd.getContainer().registerByClass(cd); // to get the component by type } return component; }
public void register0(ComponentDef componentDef) { // #component_point if (componentDef.getContainer() == null) { componentDef.setContainer(this); } registerByClass(componentDef); registerByName(componentDef); }
protected Object[] getArgs(Class<?>[] argTypes) { final Object[] args = new Object[argTypes.length]; for (int i = 0; i < argTypes.length; ++i) { try { args[i] = getComponentDef().getContainer().getComponent(argTypes[i]); } catch (ComponentNotFoundException e) { logger.log("WSSR0007", new Object[] { getComponentDef().getComponentClass().getName(), e.getComponentKey() }); args[i] = null; } } return args; }
public Object invoke(final MethodInvocation invocation) throws Throwable { final LaContainer container = getComponentDef(invocation).getContainer().getRoot(); final MethodInterceptor[] interceptors = new MethodInterceptor[interceptorNames.length]; for (int i = 0; i < interceptors.length; ++i) { interceptors[i] = (MethodInterceptor) container.getComponent(interceptorNames[i]); } final MethodInvocation nestInvocation = new NestedMethodInvocation((LaMethodInvocation) invocation, interceptors); return nestInvocation.proceed(); } }
protected void bindExternally(final BeanDesc beanDesc, final ComponentDef componentDef, final Object component, final Set<String> names) throws EmptyRuntimeException { final ExternalContext extCtx = componentDef.getContainer().getRoot().getExternalContext(); if (extCtx == null) { throw new EmptyRuntimeException("externalContext"); } for (int i = 0; i < beanDesc.getPropertyDescSize(); ++i) { final PropertyDesc pd = beanDesc.getPropertyDesc(i); if (!pd.isWritable()) { continue; } final String name = pd.getPropertyName(); if (names.contains(name)) { continue; } final Object value = getValue(name, pd.getPropertyType(), extCtx); if (value == null) { continue; } try { pd.setValue(component, value); names.add(name); } catch (final BeanIllegalPropertyException ignore) {} } }
public Object deploy() { ComponentDef cd = getComponentDef(); ExternalContext extCtx = cd.getContainer().getRoot().getExternalContext(); if (extCtx == null) { throw new EmptyRuntimeException("externalContext"); } Map<String, Object> applicationMap = extCtx.getApplicationMap(); String componentName = getComponentName(); Object component = applicationMap.get(componentName); if (component == null) { component = getConstructorAssembler().assemble(); getPropertyAssembler().assemble(component); getInitMethodAssembler().assemble(component); applicationMap.put(componentName, component); } return component; }
public Object deploy() { ComponentDef cd = getComponentDef(); ExternalContext extCtx = cd.getContainer().getRoot().getExternalContext(); if (extCtx == null) { throw new EmptyRuntimeException("externalContext"); } Map<String, Object> sessionMap = extCtx.getSessionMap(); String componentName = getComponentName(); Object component = sessionMap.get(componentName); if (component == null) { component = getConstructorAssembler().assemble(); getPropertyAssembler().assemble(component); getInitMethodAssembler().assemble(component); sessionMap.put(componentName, component); } return component; }
protected boolean bindAutoResourceField(ComponentDef componentDef, Field field, Object component) { // #injection_point final LaContainer container = componentDef.getContainer(); final String propName = field.getName(); final Class<?> propType = field.getType();
public Object deploy() { ComponentDef cd = getComponentDef(); ExternalContext extCtx = cd.getContainer().getRoot().getExternalContext(); if (extCtx == null) { RuntimeException re = new EmptyRuntimeException("externalContext"); logger.log(re); throw re; } Map<String, Object> requestMap = extCtx.getRequestMap(); String componentName = getComponentName(); Object component = null; component = requestMap.get(componentName); if (component != null) { return component; } component = getConstructorAssembler().assemble(); requestMap.put(componentName, component); getPropertyAssembler().assemble(component); getInitMethodAssembler().assemble(component); return component; }
protected void throwTooManyRegistrationComponentException() { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Too many registration components."); br.addItem("Component Key"); br.addElement(key); br.addItem("Registered Components"); for (ComponentDef def : getComponentDefs()) { final String componentName = def.getComponentName(); final String componentType = def.getComponentClass().getName(); Object componentInstance = null; try { componentInstance = def.getComponent(); } catch (RuntimeException ignored) { // nested too many...no way but just in case } final String definedDiXml = def.getContainer().getPath(); br.addElement("componentName: " + componentName); br.addElement(" componentType: " + componentType); if (componentInstance != null) { // just in case br.addElement(" componentInstance: " + componentInstance); br.addElement(" classLoader: " + componentInstance.getClass().getClassLoader()); } br.addElement(" definedDiXml: " + definedDiXml); } final String msg = br.buildExceptionMessage(); throw new TooManyRegistrationComponentException(msg, key, componentDefs); }
protected void throwPropertyValueGetFailureException(ComponentDef componentDef, PropertyDef propertyDef, Object component, RuntimeException cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to get the value for the property."); if (componentDef != null) { br.addItem("Component Def"); final String componentName = componentDef.getComponentName(); final String typeName = componentDef.getComponentClass().getName(); final String definedPath = componentDef.getContainer().getPath(); br.addElement("name=" + componentName + ", type=" + typeName + ", path=" + definedPath); } br.addItem("Property Owner"); br.addElement(component); br.addItem("Property Definition"); br.addElement(propertyDef); final String msg = br.buildExceptionMessage(); throw new IllegalPropertyDefinitionException(msg, cause); }
protected boolean bindAutoProperty(ComponentDef componentDef, PropertyDesc propertyDesc, Object component) { final LaContainer container = componentDef.getContainer(); final String propName = propertyDesc.getPropertyName(); final Class<?> propType = propertyDesc.getPropertyType();
protected void throwPropertyComponentGetFailureException(ComponentDef componentDef, Object key, Object component, String propertyName, RuntimeException cause) { final LdiExceptionMessageBuilder br = new LdiExceptionMessageBuilder(); br.addNotice("Failed to get the component for the property by the key."); br.addItem("Component Key"); br.addElement(key); if (componentDef != null) { br.addItem("Component Def"); final String componentName = componentDef.getComponentName(); final String typeName = componentDef.getComponentClass().getName(); final String definedPath = componentDef.getContainer().getPath(); br.addElement("name=" + componentName + ", type=" + typeName + ", path=" + definedPath); } br.addItem("Property Owner"); br.addElement(component); br.addItem("Property Name"); br.addElement(propertyName); final String msg = br.buildExceptionMessage(); throw new IllegalPropertyDefinitionException(msg, cause); }