Search in sources :

Example 6 with ComponentAdapter

use of org.exoplatform.container.spi.ComponentAdapter in project kernel by exoplatform.

the class TestWeldContainer method testIntegration.

public void testIntegration() {
    URL rootURL = getClass().getResource("test-exo-container.xml");
    URL portalURL = getClass().getResource("test-exo-container2.xml");
    assertNotNull(rootURL);
    assertNotNull(portalURL);
    // 
    new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
    RootContainer root = RootContainer.getInstance();
    testIntegration(root);
    ComponentAdapter<H> adapterH = root.getComponentAdapterOfType(H.class);
    assertNull(adapterH);
    PortalContainer portal = PortalContainer.getInstance();
    adapterH = portal.getComponentAdapterOfType(H.class);
    assertNotNull(adapterH);
    H h = root.getComponentInstanceOfType(H.class);
    assertNull(h);
    h = portal.getComponentInstanceOfType(H.class);
    assertNotNull(h);
    assertSame(h, portal.getComponentInstanceOfType(H.class));
    assertSame(h, adapterH.getComponentInstance());
    List<ComponentAdapter<H>> adapters = root.getComponentAdaptersOfType(H.class);
    assertTrue(adapters == null || adapters.isEmpty());
    adapters = portal.getComponentAdaptersOfType(H.class);
    assertNotNull(adapters);
    assertEquals(1, adapters.size());
    assertSame(h, adapters.get(0).getComponentInstance());
    List<H> allH = root.getComponentInstancesOfType(H.class);
    assertTrue(allH == null || allH.isEmpty());
    allH = portal.getComponentInstancesOfType(H.class);
    assertNotNull(allH);
    assertEquals(1, allH.size());
    assertSame(h, allH.get(0));
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) URL(java.net.URL) ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter) PortalContainer(org.exoplatform.container.PortalContainer)

Example 7 with ComponentAdapter

use of org.exoplatform.container.spi.ComponentAdapter in project kernel by exoplatform.

the class TestSpringContainer method testIntegration.

@SuppressWarnings("unchecked")
private void testIntegration(RootContainer container) {
    assertNotNull(container);
    ComponentAdapter<A> adapterA = container.getComponentAdapterOfType(A.class);
    assertNotNull(adapterA);
    assertSame(adapterA, container.getComponentAdapterOfType(A.class));
    ComponentAdapter<B> adapterB = container.getComponentAdapterOfType(B.class);
    assertNotNull(adapterB);
    ComponentAdapter<C> adapterC = container.getComponentAdapterOfType(C.class);
    assertNotNull(adapterC);
    ComponentAdapter<D> adapterD = container.getComponentAdapterOfType(D.class);
    assertNotNull(adapterD);
    assertSame(adapterD, container.getComponentAdapterOfType(D.class));
    ComponentAdapter<E> adapterE = container.getComponentAdapterOfType(E.class);
    assertNotNull(adapterE);
    adapterE = (ComponentAdapter<E>) container.getComponentAdapter("MyClassE");
    assertNotNull(adapterE);
    assertSame(adapterE, container.getComponentAdapter("MyClassE"));
    ComponentAdapter<F> adapterF = container.getComponentAdapterOfType(F.class);
    assertNotNull(adapterF);
    ComponentAdapter<G> adapterG = container.getComponentAdapterOfType(G.class);
    assertNotNull(adapterG);
    A a = container.getComponentInstanceOfType(A.class);
    assertNotNull(a);
    assertSame(a, container.getComponentInstanceOfType(A.class));
    assertSame(a, adapterA.getComponentInstance());
    B b = container.getComponentInstanceOfType(B.class);
    assertNotNull(b);
    assertSame(b, container.getComponentInstanceOfType(B.class));
    assertSame(b, adapterB.getComponentInstance());
    C c = container.getComponentInstanceOfType(C.class);
    assertNotNull(c);
    assertNotSame(c, container.getComponentInstanceOfType(C.class));
    assertNotSame(c, adapterC.getComponentInstance());
    assertSame(a, c.a);
    assertSame(b, c.b);
    assertSame(a, ((C) adapterC.getComponentInstance()).a);
    assertSame(b, ((C) adapterC.getComponentInstance()).b);
    assertSame(a, container.getComponentInstanceOfType(C.class).a);
    assertSame(b, container.getComponentInstanceOfType(C.class).b);
    assertNotNull(c.a2);
    assertNotNull(c.a2_2);
    assertNotSame(c.a2, c.a2_2);
    assertNotNull(c.d);
    assertSame(c.d, c.d2);
    D d = container.getComponentInstanceOfType(D.class);
    assertNotNull(d);
    assertSame(d, container.getComponentInstanceOfType(D.class));
    assertSame(d, adapterD.getComponentInstance());
    assertSame(a, d.a);
    assertSame(b, d.b);
    assertTrue(d.g instanceof G1);
    assertTrue(d.g_2 instanceof G2);
    assertTrue(d.g2 instanceof G2);
    assertTrue(d.g2_1 instanceof G1);
    assertTrue(d.g3.get() instanceof G3);
    E e = (E) container.getComponentInstance("MyClassE");
    assertNotNull(a);
    assertSame(e, container.getComponentInstance("MyClassE"));
    assertSame(e, adapterE.getComponentInstance());
    F f = container.getComponentInstanceOfType(F.class);
    assertNotNull(f);
    assertSame(f, container.getComponentInstanceOfType(F.class));
    assertSame(f, adapterF.getComponentInstance());
    assertSame(e, f.e);
    assertTrue(f.e instanceof E1);
    assertTrue(f.m instanceof E1);
    assertTrue(f.e2 instanceof E2);
    assertNotNull(f.e3.get());
    assertTrue(f.e3.get() instanceof E);
    assertFalse(f.e3.get() instanceof E1);
    assertFalse(f.e3.get() instanceof E2);
    G g = container.getComponentInstanceOfType(G.class);
    assertNotNull(g);
    assertSame(g, container.getComponentInstanceOfType(G.class));
    assertSame(g, adapterG.getComponentInstance());
    List<ComponentAdapter<Marker>> adapters = container.getComponentAdaptersOfType(Marker.class);
    assertNotNull(adapters);
    assertEquals(4, adapters.size());
    boolean foundE = false, foundF = false, foundE1 = false, foundE2 = false;
    for (ComponentAdapter<Marker> adapter : adapters) {
        if (adapter.getComponentImplementation().equals(E1.class)) {
            foundE1 = true;
            assertSame(e, adapter.getComponentInstance());
        } else if (adapter.getComponentImplementation().equals(E2.class)) {
            foundE2 = true;
            assertSame(f.e2, adapter.getComponentInstance());
        } else if (adapter.getComponentImplementation().equals(E.class)) {
            foundE = true;
            assertSame(f.e3.get(), adapter.getComponentInstance());
        } else if (adapter.getComponentImplementation().equals(F.class)) {
            foundF = true;
            assertSame(f, adapter.getComponentInstance());
        }
    }
    assertTrue(foundE);
    assertTrue(foundE1);
    assertTrue(foundE2);
    assertTrue(foundF);
    List<Marker> markers = container.getComponentInstancesOfType(Marker.class);
    assertNotNull(markers);
    assertEquals(4, markers.size());
    assertTrue(markers.contains(e));
    assertTrue(markers.contains(f.e));
    assertTrue(markers.contains(f.e2));
    assertTrue(markers.contains(f));
    ComponentAdapter<H> adapterH = container.getComponentAdapterOfType(H.class);
    assertNull(adapterH);
    PortalContainer portal = PortalContainer.getInstance();
    adapterH = portal.getComponentAdapterOfType(H.class);
    assertNotNull(adapterH);
    H h = container.getComponentInstanceOfType(H.class);
    assertNull(h);
    h = portal.getComponentInstanceOfType(H.class);
    assertNotNull(h);
    assertSame(h, portal.getComponentInstanceOfType(H.class));
    assertSame(h, adapterH.getComponentInstance());
    List<ComponentAdapter<H>> adaptersH = container.getComponentAdaptersOfType(H.class);
    assertTrue(adaptersH == null || adaptersH.isEmpty());
    adaptersH = portal.getComponentAdaptersOfType(H.class);
    assertNotNull(adaptersH);
    assertEquals(1, adaptersH.size());
    assertSame(h, adaptersH.get(0).getComponentInstance());
    List<H> allH = container.getComponentInstancesOfType(H.class);
    assertTrue(allH == null || allH.isEmpty());
    allH = portal.getComponentInstancesOfType(H.class);
    assertNotNull(allH);
    assertEquals(1, allH.size());
    assertSame(h, allH.get(0));
}
Also used : ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter) PortalContainer(org.exoplatform.container.PortalContainer)

Example 8 with ComponentAdapter

use of org.exoplatform.container.spi.ComponentAdapter in project kernel by exoplatform.

the class ConcurrentContainer method getComponentAdapterOfType.

public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration) {
    // See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115
    ComponentAdapter<T> adapterByKey = (ComponentAdapter<T>) getComponentAdapter(componentType, componentType, autoRegistration);
    if (adapterByKey != null) {
        return adapterByKey;
    }
    List<ComponentAdapter<T>> found = getComponentAdaptersOfType(componentType);
    if (found.size() == 1) {
        return found.get(0);
    } else if (found.size() == 0) {
        if (parent != null) {
            return parent.getComponentAdapterOfType(componentType, autoRegistration);
        } else {
            return null;
        }
    } else {
        Class<?>[] foundClasses = new Class<?>[found.size()];
        for (int i = 0; i < foundClasses.length; i++) {
            ComponentAdapter<T> componentAdapter = found.get(i);
            foundClasses[i] = componentAdapter.getComponentImplementation();
        }
        throw new ContainerException("Several ComponentAdapter found for " + componentType);
    }
}
Also used : ContainerException(org.exoplatform.container.spi.ContainerException) ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter)

Aggregations

ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)8 AbstractComponentAdapter (org.exoplatform.container.AbstractComponentAdapter)3 PortalContainer (org.exoplatform.container.PortalContainer)3 Annotation (java.lang.annotation.Annotation)2 URL (java.net.URL)2 Named (javax.inject.Named)2 ContainerBuilder (org.exoplatform.container.ContainerBuilder)2 RootContainer (org.exoplatform.container.RootContainer)2 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)2 Component (org.exoplatform.container.xml.Component)2 AbstractModule (com.google.inject.AbstractModule)1 Binder (com.google.inject.Binder)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 RunnableFuture (java.util.concurrent.RunnableFuture)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ManageableComponentAdapterFactoryMT (org.exoplatform.container.management.ManageableComponentAdapterFactoryMT)1 ContainerException (org.exoplatform.container.spi.ContainerException)1 QualifierAnnotationAutowireCandidateResolver (org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver)1