/** * @see org.lastaflute.di.core.ComponentDef#getComponent() */ public Object getComponent() { return getContainer().getRoot().getExternalContext().getRequestHeaderValuesMap(); } }
/** * @param componentType The component type to find. (NotNull) * @return The array of found components. (NotNull) * @throws CyclicReferenceComponentException When the components refers each other. */ @SuppressWarnings("unchecked") public static <COMPONENT> COMPONENT[] searchComponentsAll(Class<COMPONENT> componentType) { return (COMPONENT[]) SingletonLaContainerFactory.getContainer().findAllComponents(componentType); }
protected LaContainerBuilder createDefaultBuilder(final LaContainer configurationContainer) { if (configurationContainer.hasComponentDef(DEFAULT_BUILDER_NAME)) { return (LaContainerBuilder) configurationContainer.getComponent(DEFAULT_BUILDER_NAME); } if (configurationContainer.hasComponentDef(ResourceResolver.class) && defaultBuilder instanceof AbstractLaContainerBuilder) { final ResourceResolver resolver = (ResourceResolver) configurationContainer.getComponent(ResourceResolver.class); ((AbstractLaContainerBuilder) defaultBuilder).setResourceResolver(resolver); } return defaultBuilder; }
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 LaContainer include(LaContainer parent, String path) { final String realPath = pathResolver.resolvePath(parent.getPath(), path); assertCircularInclude(parent, realPath); enter(realPath); try { final LaContainer root = parent.getRoot(); final LaContainer child; synchronized (root) { if (root.hasDescendant(realPath)) { showReadingLog(parent, path, realPath, true); child = root.getDescendant(realPath); parent.include(child); } else { showReadingLog(parent, path, realPath, false); final String ext = getExtension(realPath); final LaContainerBuilder builder = getBuilder(ext); child = builder.include(parent, realPath); root.registerDescendant(child); if (child.isInitializeOnCreate()) { child.init(); } } } return child; } finally { leave(realPath); } }
if (!exp.startsWith(DQ) && !exp.startsWith("[") && !exp.startsWith("{") && exp.contains(".")) { final String componentName = exp.substring(0, exp.indexOf(".")); final LaContainer namedContainer = container.getRoot().findChild(componentName); // in all container if (namedContainer != null) { // first element is named container final String rear = exp.substring(exp.indexOf(".") + ".".length()); if (rear.contains(".")) { // has more chain final String nextName = rear.substring(0, rear.indexOf(".")); if (namedContainer.hasComponentDef(nextName)) { // in named container filteredExp = rear; firstName = nextName; firstComponent = namedContainer.getComponent(nextName); } else { // may be JavaScript expression (but basically mistake...) filteredExp = exp; if (namedContainer.hasComponentDef(rear)) { // in named container return namedContainer.getComponent(rear); // resolved without evaluation } else { // may be JavaScript expression (but basically mistake...) filteredExp = exp; if (container.hasComponentDef(componentName)) { // in current container only firstName = componentName; firstComponent = container.getComponent(componentName);
return; if (container.getRoot().hasComponentDef(clazz)) { if (clazz.isInterface() || LdiModifierUtil.isAbstract(clazz)) { return; final ComponentDef cd = container.getRoot().getComponentDef(clazz); if (clazz == cd.getComponentClass()) { return; return; container.getRoot().register(cd); registeredClasses.add(cd.getComponentClass()); ComponentUtil.putRegisterLog(cd);
public void registerAll() { for (int i = 0; i < container.getComponentDefSize(); ++i) { ComponentDef cd = container.getComponentDef(i); register(cd); } }
public DataSource getSelectedDataSource() { return container.getRoot().getComponent(getDataSourceComponentName()); }
public void start(TagHandlerContext context, Attributes attributes) { final LaContainer container = createContainer(); final String path = (String) context.getParameter("path"); container.setPath(path); final String namespace = attributes.getValue("namespace"); if (!LdiStringUtil.isEmpty(namespace)) { container.setNamespace(namespace); } final String initializeOnCreate = attributes.getValue("initializeOnCreate"); if (!LdiStringUtil.isEmpty(initializeOnCreate)) { container.setInitializeOnCreate(Boolean.valueOf(initializeOnCreate).booleanValue()); } LaContainer parent = (LaContainer) context.getParameter("parent"); if (parent != null) { container.setRoot(parent.getRoot()); } context.push(container); }
final String propName = field.getName(); final Class<?> propType = field.getType(); final boolean hasComponentByType = container.hasComponentDef(propType); if (hasComponentByType) { final ComponentDef cd = container.getComponentDef(propType); if (isSimpleNamingAutoBindable(propName, propType, cd)) { Object value = getComponent(componentDef, propType, component, propName); if (container.hasComponentDef(propName)) { final Object value = getComponent(componentDef, propName, component, propName); if (propType.isInstance(value)) { final Object[] values = container.findAllComponents(clazz); if (values.length > 0) { setResourceFieldValue(componentDef, field, component, values);
protected static void setupExternalContext() { if (container.getExternalContext() == null) { if (externalContext != null) { container.setExternalContext(externalContext); } } else if (container.getExternalContext().getApplication() == null && externalContext != null) { container.getExternalContext().setApplication(externalContext.getApplication()); } if (container.getExternalContextComponentDefRegister() == null && externalContextComponentDefRegister != null) { container.setExternalContextComponentDefRegister(externalContextComponentDefRegister); } }
public LaContainer create(String path) { final LaContainer configurationContainer = LaContainerFactory.getConfigurationContainer(); final ClassLoader classLoader; if (configurationContainer != null && configurationContainer.hasComponentDef(ClassLoader.class)) { classLoader = (ClassLoader) configurationContainer.getComponent(ClassLoader.class); } else { classLoader = Thread.currentThread().getContextClassLoader(); } final LaContainer container = LdiStringUtil.isEmpty(path) ? new LaContainerImpl() : build(path, classLoader); if (container.isInitializeOnCreate()) { container.init(); } return container; }
@SuppressWarnings("unchecked") public final <T> T getComponent(Class<T> key) { return (T) container.getComponent(key); }
/** * @param container */ public void setContainer(LaContainer container) { this.container = container.getRoot(); }
protected static void doConfigure(String configFile) { show("...Reading {}", configFile); // first configuration so no indent (see LaContainerDefaultProvider) final LaContainerBuilder builder = newConfigurationContainerBuilder(); configurationContainer = builder.build(configFile); configurationContainer.init(); final Configurator configurator; if (configurationContainer.hasComponentDef(Configurator.class)) { configurator = (Configurator) configurationContainer.getComponent(Configurator.class); } else { configurator = newDefaultConfigurator(); } configurator.configure(configurationContainer); }
protected void xclearRequestMockContext() { final LaContainer container = SingletonLaContainerFactory.getContainer(); final ExternalContext externalContext = container.getExternalContext(); if (externalContext != null) { // just in case externalContext.setRequest(null); externalContext.setResponse(null); } xreleaseMockRequestInstance(); }
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); } }
/** * @param componentName The component name to find. (NotNull) * @return The determination, true or false. */ public static boolean proveComponentByName(String componentName) { return SingletonLaContainerFactory.getContainer().hasComponentDef(componentName); }