protected boolean isMatchTargetInterface(final ComponentDef componentDef) { if (targetInterface == null) { return true; } final Class<?> clazz = componentDef.getComponentClass(); if (clazz == null) { return false; } return targetInterface.isAssignableFrom(clazz); }
protected String buildActionName(ComponentDef actionDef) { return actionDef.getComponentName(); }
public Object createAction() { return actionDef.getComponent(); }
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 ComponentDef createComponentDef(Class<?> componentClass, String name, InstanceDef instanceDef, AutoBindingDef autoBindingDef, boolean externalBinding) { ComponentDef componentDef = new ComponentDefImpl(componentClass); if (!LdiStringUtil.isEmpty(name)) { componentDef.setComponentName(name); } if (instanceDef != null) { componentDef.setInstanceDef(instanceDef); } if (autoBindingDef != null) { componentDef.setAutoBindingDef(autoBindingDef); } componentDef.setExternalBinding(externalBinding); return componentDef; }
protected String getComponentName() { String componentName = componentDef.getComponentName(); if (componentName == null) { componentName = LdiClassUtil.getShortClassName(componentDef.getComponentClass()); componentName = LdiStringUtil.decapitalize(componentName); } return componentName; }
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); }
public ComponentDef createComponentDef(Class<?> componentClass) { if (!namingConvention.isTargetClassName(componentClass.getName(), nameSuffix)) { return null; } final Class<?> targetClass = namingConvention.toCompleteClass(componentClass); if (targetClass.isInterface()) { if (!isEnableInterface()) { return null; } } else if (Modifier.isAbstract(targetClass.getModifiers())) { if (!isEnableAbstract()) { return null; } } final AnnotationHandler handler = AnnotationHandlerFactory.getAnnotationHandler(); final ComponentDef cd = handler.createComponentDef(targetClass, instanceDef, autoBindingDef, externalBinding); if (cd.getComponentName() == null) { cd.setComponentName(namingConvention.fromClassNameToComponentName(targetClass.getName())); } setupCompleteComponent(handler, cd); return cd; }
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 ComponentDef doGetComponentDef(LaContainer container, Object key) { ComponentDef cd = super.getComponentDef(container, key); if (cd != null) { return cd; } if (container != container.getRoot()) { return null; } cd = getComponentDefFromCache(key); if (cd != null) { return cd; } if (key instanceof Class<?>) { cd = createComponentDef((Class<?>) key); } else if (key instanceof String) { cd = createComponentDef((String) key); if (cd != null && !key.equals(cd.getComponentName())) { logger.log("WSSR0011", new Object[] { key, cd.getComponentClass().getName(), cd.getComponentName() }); cd = null; } } else { throw new IllegalArgumentException("Illegal component key: " + key); } if (cd != null) { register(cd); ComponentUtil.putRegisterLog(cd); cd.init(); } return cd; }
componentDef.setComponentName(componentName); annoHandler.appendDI(componentDef); annoHandler.appendAspect(componentDef); componentDef.setInstanceDef(InstanceDefFactory.getInstanceDef(componentAnnotation.instance().getName())); componentDef.setAutoBindingDef(AutoBindingDefFactory.getAutoBindingDef(componentAnnotation.autoBinding().getName())); componentDef.setExternalBinding(componentAnnotation.externalBinding()); if (aspectAnnotation != null) { AspectDef aspectDef = AspectDefFactory.createAspectDef(aspectAnnotation.value(), aspectAnnotation.pointcut()); componentDef.addAspectDef(aspectDef); ArgDef argDef = new ArgDefImpl(preparer); initMethodDef.addArgDef(argDef); componentDef.addInitMethodDef(initMethodDef); argDef = new ArgDefImpl(preparer); destroyMethodDef.addArgDef(argDef); componentDef.addDestroyMethodDef(destroyMethodDef);
expression = body.trim(); if (!LdiStringUtil.isEmpty(expression)) { componentDef.setExpression(createExpression(context, expression)); } else { expression = null; if (componentDef.getComponentClass() == null && !InstanceDefFactory.OUTER.equals(componentDef.getInstanceDef()) && expression == null) { throw new TagAttributeNotDefinedRuntimeException("component", "class"); if (componentDef.getComponentName() != null) { final String basePath = (String) context.getParameter(PARAMETER_BASEPATH); final RedefinableXmlLaContainerBuilder builder = (RedefinableXmlLaContainerBuilder) context.getParameter(PARAMETER_BUILDER);
protected Object assembleManual() { final Object[] args = new Object[getComponentDef().getArgDefSize()]; for (int i = 0; i < args.length; ++i) { try { args[i] = getComponentDef().getArgDef(i).getValue(Object.class); } catch (ComponentNotFoundException cause) { throw new IllegalConstructorRuntimeException(getComponentDef().getComponentClass(), cause); } } final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(getComponentDef().getConcreteClass()); return beanDesc.newInstance(args); }
final int defSize = cd.getPropertyDefSize(); final Set<String> names = new HashSet<String>(); for (int i = 0; i < defSize; ++i) { final PropertyDef propDef = cd.getPropertyDef(i); final AccessTypeDef accessTypeDef = propDef.getAccessTypeDef(); accessTypeDef.bind(cd, propDef, component); names.addAll(Arrays.asList(getManualBindingProperties(preparer, getComponentDef().getComponentName()))); if (cd.isExternalBinding()) { bindExternally(beanDesc, cd, component, names);
public static Class<?> getConcreteClass(final ComponentDef componentDef) { if (componentDef.getAspectDefSize() == 0 && componentDef.getInterTypeDefSize() == 0) { return componentDef.getComponentClass(); } final Map<String, ComponentDef> parameters = new HashMap<String, ComponentDef>(); parameters.put(ContainerConstants.COMPONENT_DEF_NAME, componentDef); AopProxy proxy = new AopProxy(componentDef.getComponentClass(), getAspects(componentDef), getInterTypes(componentDef), parameters); return proxy.getEnhancedClass(); }
protected Object newInstance(LaContainerPreparer preparer, ComponentDef componentDef) { final Class<? extends LaContainerPreparer> preparerType = preparer.getClass(); final String componentName = componentDef.getComponentName(); final String methodprefixNew = ClassS2ContainerBuilder.METHODPREFIX_NEW; final Method method = ClassBuilderUtils.findMethod(preparerType, componentName, methodprefixNew); if (method != null) { try { if (method.getParameterTypes().length == 0) { return method.invoke(preparer, new Object[0]); } else { // needs to create from concrete class when aspect component // then the method that can accept concrete class is used return method.invoke(preparer, new Object[] { componentDef.getConcreteClass() }); } } catch (IllegalArgumentException e) { throw new RuntimeException("Can't invoke method for instanciating component: " + method.getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Can't invoke method for instanciating component: " + method.getName(), e); } catch (InvocationTargetException e) { throw new RuntimeException("Can't invoke method for instanciating component: " + method.getName(), e); } } else { return null; } } }
@Override public void appendInitMethodDef(AnnotationHandler annotationHandler, ComponentDef componentDef) { final Class<?> componentClass = componentDef.getComponentClass(); if (componentClass == null) { return; } for (final Method method : componentClass.getMethods()) { if (method.isBridge() || method.isSynthetic()) { continue; } final PostConstruct initMethod = method.getAnnotation(PostConstruct.class); if (initMethod == null) { continue; } if (method.getParameterTypes().length != 0) { throw new IllegalInitMethodAnnotationRuntimeException(componentClass, method.getName()); } if (!annotationHandler.isInitMethodRegisterable(componentDef, method.getName())) { continue; } componentDef.addInitMethodDef(newInitMethodDefImpl(method)); } }
@Override public void appendDestroyMethodDef(AnnotationHandler annotationHandler, ComponentDef componentDef) { final Class<?> componentClass = componentDef.getComponentClass(); if (componentClass == null) { return; } for (final Method method : componentClass.getMethods()) { if (method.isBridge() || method.isSynthetic()) { continue; } final PreDestroy destroyMethod = method.getAnnotation(PreDestroy.class); if (destroyMethod == null) { continue; } if (method.getParameterTypes().length != 0) { throw new IllegalDestroyMethodAnnotationRuntimeException(componentClass, method.getName()); } if (!annotationHandler.isDestroyMethodRegisterable(componentDef, method.getName())) { continue; } componentDef.addDestroyMethodDef(newDestroyMethodDefImpl(method)); } }
public void appendIntertypeDef(final AnnotationHandler annotationHandler, final ComponentDef componentDef) { final Class<?> componentClass = componentDef.getComponentClass(); if (componentClass == null) { return; } final InterType interType = componentClass.getAnnotation(InterType.class); if (interType != null) { for (String interTypeName : interType.value()) { final InterTypeDef interTypeDef = new InterTypeDefImpl(); interTypeDef.setExpression(new ScriptingExpression(interTypeName)); componentDef.addInterTypeDef(interTypeDef); } } }
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; }