Package org.apache.openejb.config.provider

Examples of org.apache.openejb.config.provider.ProviderManager


    public static Messages messages = new Messages("org.apache.openejb.util.resources");
    public static Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");

    public static ProviderManager getManager() {
        final ProviderManager manager = SystemInstance.get().getComponent(ProviderManager.class);
        if (manager != null) {
            return manager;
        }

        SystemInstance.get().setComponent(ProviderManager.class, new ProviderManager(new ServiceJarXmlLoader()));
        return getManager();
    }
View Full Code Here


* @version $Rev$ $Date$
*/
public class ProviderGenerator extends Resource {

    public static void main(final String[] args) throws Exception {
        final ProviderManager manager = new ProviderManager(new ServiceJarXmlLoader());

        final Set<String> seen = new HashSet<String>();

        final List<ServiceProvider> providers = manager.load("org.apache.openejb");
        for (final ServiceProvider provider : providers) {
            final List<String> types = provider.getTypes();
            final String name = guessBuilder(types);
            final String builder = name + "Builder";

View Full Code Here

/**
* @version $Rev$ $Date$
*/
public class ProviderManagerTest extends TestCase {
    public void testRegister() throws Exception {
        final ProviderManager manager = new ProviderManager(new ProviderLoader() {
            @Override
            public ServiceProvider load(final ID id) {
                return null;
            }

            @Override
            public List<ServiceProvider> load(final String namespace) {
                return null;
            }
        });

        { // Add Color
            final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
            color.getProperties().setProperty("red", "0");
            color.getProperties().setProperty("green", "0");
            color.getProperties().setProperty("blue", "0");
            manager.register("default", color);
        }

        { // Assert Color
            // Must be able to retrieve provider and properties in a case-insensitive manner
            final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("0", provider.getProperties().getProperty("rEd"));
            assertEquals("0", provider.getProperties().get("grEEn"));
            assertEquals("0", provider.getProperties().get("blUE"));
        }

        { // Add Red
            final ServiceProvider red = new ServiceProvider();
            red.setId("Red");
            red.setParent("Color");
            red.getProperties().setProperty("red", "255");
            manager.register("default", red);
        }

        { // Assert Red

            // Should have inherited green and blue values from Color

            final ServiceProvider provider = manager.get("dEFaulT", "REd");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("255", provider.getProperties().getProperty("rED"));
            assertEquals("0", provider.getProperties().get("grEEN"));
            assertEquals("0", provider.getProperties().get("bLUe"));
        }


        { // Add Orange
            final ServiceProvider orange = new ServiceProvider();
            orange.setId("Orange");
            orange.setParent("Red");
            orange.getProperties().setProperty("green", "200");
            manager.register("default", orange);
        }

        { // Assert Orange

            // Should have inherited from Red

            final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("255", provider.getProperties().getProperty("reD"));
            assertEquals("200", provider.getProperties().get("grEeN"));
            assertEquals("0", provider.getProperties().get("bLue"));
View Full Code Here

        }
    }

    public void testLoader() throws Exception {

        final ProviderManager manager = new ProviderManager(new ProviderLoader() {
            @Override
            public ServiceProvider load(final ID id) {
                if ("color".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
                    color.getProperties().setProperty("red", "0");
                    color.getProperties().setProperty("green", "0");
                    color.getProperties().setProperty("blue", "0");
                    return color;
                }

                if ("red".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider red = new ServiceProvider();
                    red.setId("Red");
                    red.setParent("Color");
                    red.getProperties().setProperty("red", "255");
                    return red;
                }

                if ("orange".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider orange = new ServiceProvider();
                    orange.setId("Orange");
                    orange.setParent("Red");
                    orange.getProperties().setProperty("green", "200");
                    return orange;
                }

                throw new IllegalStateException(id.toString());
            }

            @Override
            public List<ServiceProvider> load(final String namespace) {
                return null;
            }
        });

        assertEquals(0, manager.getAll().size());

        { // Assert Orange

            // Should have inherited from Red

            final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("255", provider.getProperties().getProperty("reD"));
            assertEquals("200", provider.getProperties().get("grEeN"));
            assertEquals("0", provider.getProperties().get("bLue"));
        }

        { // Assert Red

            // Should have inherited green and blue values from Color

            final ServiceProvider provider = manager.get("dEFaulT", "REd");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("255", provider.getProperties().getProperty("rED"));
            assertEquals("0", provider.getProperties().get("grEEN"));
            assertEquals("0", provider.getProperties().get("bLUe"));
        }

        { // Assert Color
            // Must be able to retrieve provider and properties in a case-insensitive manner

            final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("0", provider.getProperties().getProperty("rEd"));
            assertEquals("0", provider.getProperties().get("grEEn"));
            assertEquals("0", provider.getProperties().get("blUE"));
        }

        assertEquals(3, manager.getAll().size());
    }
View Full Code Here

        assertEquals(3, manager.getAll().size());
    }

    public void testLoaderLoadNamespace() throws Exception {

        final ProviderManager manager = new ProviderManager(new ProviderLoader() {
            @Override
            public ServiceProvider load(final ID id) {
                if ("color".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
                    color.getProperties().setProperty("red", "0");
                    color.getProperties().setProperty("green", "0");
                    color.getProperties().setProperty("blue", "0");
                    return color;
                }

                if ("red".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider red = new ServiceProvider();
                    red.setId("Red");
                    red.setParent("Color");
                    red.getProperties().setProperty("red", "255");
                    return red;
                }

                if ("orange".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider orange = new ServiceProvider();
                    orange.setId("Orange");
                    orange.setParent("Red");
                    orange.getProperties().setProperty("green", "200");
                    return orange;
                }

                throw new IllegalStateException(id.toString());
            }

            @Override
            public List<ServiceProvider> load(final String namespace) {
                final List<ServiceProvider> list = new ArrayList<ServiceProvider>();
                list.add(load(new ID(namespace, "color")));
                list.add(load(new ID(namespace, "red")));
                list.add(load(new ID(namespace, "orange")));
                return list;
            }
        });

        assertEquals(0, manager.getAll().size());

        manager.get("default", "Color");

        assertEquals(1, manager.getAll().size());

        manager.load("default");

        assertEquals(3, manager.getAll().size());

        { // Assert Orange

            // Should have inherited from Red

            final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("255", provider.getProperties().getProperty("reD"));
            assertEquals("200", provider.getProperties().get("grEeN"));
            assertEquals("0", provider.getProperties().get("bLue"));
        }

        { // Assert Red

            // Should have inherited green and blue values from Color

            final ServiceProvider provider = manager.get("dEFaulT", "REd");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("255", provider.getProperties().getProperty("rED"));
            assertEquals("0", provider.getProperties().get("grEEN"));
            assertEquals("0", provider.getProperties().get("bLUe"));
        }

        { // Assert Color
            // Must be able to retrieve provider and properties in a case-insensitive manner

            final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("0", provider.getProperties().getProperty("rEd"));
            assertEquals("0", provider.getProperties().get("grEEn"));
            assertEquals("0", provider.getProperties().get("blUE"));
        }

        assertEquals(3, manager.getAll().size());
    }
View Full Code Here

    }


    public void testCircularDependency() throws Exception {

        final ProviderManager manager = new ProviderManager(new ProviderLoader() {
            @Override
            public ServiceProvider load(final ID id) {
                if ("color".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
                    color.setParent("Orange");
                    color.getProperties().setProperty("red", "0");
                    color.getProperties().setProperty("green", "0");
                    color.getProperties().setProperty("blue", "0");
                    return color;
                }

                if ("red".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider red = new ServiceProvider();
                    red.setId("Red");
                    red.setParent("Color");
                    red.getProperties().setProperty("red", "255");
                    return red;
                }

                if ("orange".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider orange = new ServiceProvider();
                    orange.setId("Orange");
                    orange.setParent("Red");
                    orange.getProperties().setProperty("green", "200");
                    return orange;
                }

                throw new IllegalStateException(id.toString());
            }

            @Override
            public List<ServiceProvider> load(final String namespace) {
                return null;
            }
        });

        assertEquals(0, manager.getAll().size());

        try {
            manager.get("dEFAUlT", "orAngE");
            fail("ProviderCircularReferenceException should have been thrown");
        } catch (final ProviderCircularReferenceException e) {
            // pass
        }
    }
View Full Code Here

        }
    }

    public void testInheritedAttributes() throws Exception {

        final ProviderManager manager = new ProviderManager(new ProviderLoader() {
            @Override
            public ServiceProvider load(final ID id) {
                if ("color".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider color = new ServiceProvider();
                    color.setClassName(Color.class.getName());
                    color.setFactoryName("fooFactory");
                    color.setId("Color");
                    color.setService("Resource");
                    color.setConstructor("one, two, three");
                    color.setDescription("the description");
                    color.setDisplayName("the display name");
                    color.getProperties().setProperty("red", "0");
                    color.getProperties().setProperty("green", "0");
                    color.getProperties().setProperty("blue", "0");
                    color.getTypes().add(Color.class.getName());
                    return color;
                }

                if ("red".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider red = new ServiceProvider();
                    red.setId("Red");
                    red.setParent("Color");
                    red.getProperties().setProperty("red", "255");
                    return red;
                }

                if ("orange".equalsIgnoreCase(id.getName())) {
                    final ServiceProvider orange = new ServiceProvider();
                    orange.setId("Orange");
                    orange.setParent("Red");
                    orange.getProperties().setProperty("green", "200");
                    return orange;
                }

                throw new IllegalStateException(id.toString());
            }

            @Override
            public List<ServiceProvider> load(final String namespace) {
                final List<ServiceProvider> list = new ArrayList<ServiceProvider>();
                list.add(load(new ID(namespace, "color")));
                list.add(load(new ID(namespace, "red")));
                list.add(load(new ID(namespace, "orange")));
                return list;
            }
        });

        { // Assert Orange

            // Should have inherited from Red

            final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("Resource", provider.getService());
            assertEquals("one, two, three", provider.getConstructor());
            assertEquals("the description", provider.getDescription());
            assertEquals("the display name", provider.getDisplayName());
            assertEquals("fooFactory", provider.getFactoryName());
            assertEquals("255", provider.getProperties().getProperty("reD"));
            assertEquals("200", provider.getProperties().get("grEeN"));
            assertEquals("0", provider.getProperties().get("bLue"));
            assertEquals(1, provider.getTypes().size());
        }

        { // Assert Red

            // Should have inherited green and blue values from Color

            final ServiceProvider provider = manager.get("dEFaulT", "REd");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("Resource", provider.getService());
            assertEquals("one, two, three", provider.getConstructor());
            assertEquals("the description", provider.getDescription());
            assertEquals("the display name", provider.getDisplayName());
            assertEquals("fooFactory", provider.getFactoryName());
            assertEquals("255", provider.getProperties().getProperty("rED"));
            assertEquals("0", provider.getProperties().get("grEEN"));
            assertEquals("0", provider.getProperties().get("bLUe"));
        }

        { // Assert Color
            // Must be able to retrieve provider and properties in a case-insensitive manner

            final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
            assertNotNull(provider);
            assertEquals(Color.class.getName(), provider.getClassName());
            assertEquals("Resource", provider.getService());
            assertEquals("one, two, three", provider.getConstructor());
            assertEquals("the description", provider.getDescription());
            assertEquals("the display name", provider.getDisplayName());
            assertEquals("fooFactory", provider.getFactoryName());
            assertEquals("0", provider.getProperties().getProperty("rEd"));
            assertEquals("0", provider.getProperties().get("grEEn"));
            assertEquals("0", provider.getProperties().get("blUE"));
        }

        assertEquals(3, manager.getAll().size());
    }
View Full Code Here

        OpenEJB.destroy();
    }

    public void test() throws Exception {

        SystemInstance.get().setComponent(ProviderManager.class, new ProviderManager(new ProviderLoader() {
            final ProviderLoader loader = new ServiceJarXmlLoader();

            @Override
            public ServiceProvider load(final ID id) {
View Full Code Here

    public static Messages messages = new Messages("org.apache.openejb.util.resources");
    public static Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");

    public static ProviderManager getManager() {
        final ProviderManager manager = SystemInstance.get().getComponent(ProviderManager.class);
        if (manager!= null) return manager;

        SystemInstance.get().setComponent(ProviderManager.class, new ProviderManager(new ServiceJarXmlLoader()));
        return getManager();
    }
View Full Code Here

* @version $Rev$ $Date$
*/
public class ProviderGenerator extends Resource {

    public static void main(String[] args) throws Exception {
        final ProviderManager manager = new ProviderManager(new ServiceJarXmlLoader());

        final Set<String> seen = new HashSet<String>();

        final List<ServiceProvider> providers = manager.load("org.apache.openejb");
        for (ServiceProvider provider : providers) {
            final List<String> types = provider.getTypes();
            final String name = guessBuilder(types);
            final String builder = name + "Builder";

View Full Code Here

TOP

Related Classes of org.apache.openejb.config.provider.ProviderManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.