protected void bind(final String[] names, final Object obj) throws NamingException { final StringBuffer buf = new StringBuffer(100); try { LaContainer context = SingletonLaContainerFactory.getContainer(); for (int i = 0; i < names.length - 1; ++i) { buf.append(names[i]); context = (LaContainer) context.getComponent(names[i]); buf.append('/'); } final String name = names[names.length - 1]; buf.append(name); if (context.hasComponentDef(name)) { throw new NameAlreadyBoundException(new String(buf)); } context.register(obj, name); } catch (final ComponentNotFoundException e) { throw createNamingException(new String(buf), e); } catch (final SRuntimeException e) { throw createNamingException(e.getMessage(), e); } }
void registerComponentDef(LaContainer container, Method method, LaContainerPreparer preparer) { ComponentDef componentDef = constructComponentDef(method, preparer); if (componentDef.getComponentName() != null) { componentDef = redefine(componentDef, container.getPath()); } container.register(componentDef); }
LaContainer build(LaContainer parent, String path) { LaContainer container = createContainer(parent, path); Class<? extends LaContainerPreparer> preparerClass = getPreparerClass(path); LaContainerPreparer preparer; try { preparer = preparerClass.newInstance(); } catch (InstantiationException ex) { throw new RuntimeException("Can't instanciate Preparer: " + path, ex); } catch (IllegalAccessException ex) { throw new RuntimeException("Can't instanciate Preparer: " + path, ex); } container.register(preparer); preparer.setContainer(container); Dicon dicon = preparerClass.getAnnotation(Dicon.class); if (dicon != null && dicon.namespace().length() > 0) { container.setNamespace(dicon.namespace()); } preparer.include(); registerComponentDefs(container, preparer); String additionalDiconPath = constructAdditionalDiconPath(path); if (LaContainerBuilderUtils.resourceExists(additionalDiconPath, this)) { LaContainerBuilderUtils.mergeContainer(container, LaContainerFactory.create(additionalDiconPath)); } return container; }
protected ComponentDef getComponentDef(LaContainer container, Object key) { synchronized (container.getRoot()) { ComponentDef cd = super.getComponentDef(container, key); if (cd != null) { return cd; } if (container != container.getRoot()) { return null; } 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("key"); } if (cd != null) { SingletonLaContainerFactory.getContainer().register(cd); ComponentUtil.putRegisterLog(cd); cd.init(); } return cd; } }
return; container.getRoot().register(cd); registeredClasses.add(cd.getComponentClass()); ComponentUtil.putRegisterLog(cd);
public static void mergeContainer(LaContainer container, LaContainer merged) { int size = merged.getChildSize(); for (int i = 0; i < size; i++) { container.include(merged.getChild(i)); } size = merged.getMetaDefSize(); for (int i = 0; i < size; i++) { MetaDef metaDef = merged.getMetaDef(i); metaDef.setContainer(container); container.addMetaDef(metaDef); } // cannot override, always add size = merged.getComponentDefSize(); for (int i = 0; i < size; i++) { ComponentDef componentDef = merged.getComponentDef(i); componentDef.setContainer(container); container.register(componentDef); } }
public void end(TagHandlerContext context, String body) { ComponentDef componentDef = (ComponentDef) context.pop(); AnnotationHandler annoHandler = AnnotationHandlerFactory.getAnnotationHandler(); annoHandler.appendInitMethod(componentDef); annoHandler.appendDestroyMethod(componentDef); annoHandler.appendAspect(componentDef); annoHandler.appendInterType(componentDef); String expression = null; if (body != null) { 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 (context.peek() instanceof LaContainer) { LaContainer container = (LaContainer) context.peek(); container.register(componentDef); } else { ArgDef argDef = (ArgDef) context.peek(); argDef.setChildComponentDef(componentDef); } }
protected void register(final String className) { final AnnotationHandler annoHandler = AnnotationHandlerFactory.getAnnotationHandler(); final ComponentDef cd = annoHandler.createComponentDef(className, instanceDef, autoBindingDef, externalBinding); if (cd.getComponentName() == null) { String[] names = LdiClassUtil.splitPackageAndShortClassName(className); cd.setComponentName(autoNaming.defineName(names[0], names[1])); } annoHandler.appendDI(cd); customize(cd); annoHandler.appendInitMethod(cd); annoHandler.appendDestroyMethod(cd); annoHandler.appendAspect(cd); annoHandler.appendInterType(cd); getContainer().register(cd); }