Package org.apache.openejb.config.sys

Examples of org.apache.openejb.config.sys.Resource


                            break;
                        }
                    }

                    if (!found) {
                        final Resource newResource;

                        if (DataSource.class.getName().equals(resource.getType())) { // we forward it to TomEE datasources
                            newResource = new Resource(name, resource.getType());

                            boolean jta = false;

                            final Properties properties = newResource.getProperties();
                            final Iterator<String> params = resource.listProperties();
                            while (params.hasNext()) {
                                final String paramName = params.next();
                                final String paramValue = (String) resource.getProperty(paramName);

                                // handling some param name conversion to OpenEJB style
                                if ("driverClassName".equals(paramName)) {
                                    properties.setProperty("JdbcDriver", paramValue);
                                } else if ("url".equals(paramName)) {
                                    properties.setProperty("JdbcUrl", paramValue);
                                } else {
                                    properties.setProperty(paramName, paramValue);
                                }

                                if ("JtaManaged".equalsIgnoreCase(paramName)) {
                                    jta = Boolean.parseBoolean(paramValue);
                                }
                            }

                            if (!jta) {
                                properties.setProperty("JtaManaged", "false");
                            }
                        } else { // custom type, let it be created
                            newResource = new Resource(name, resource.getType(), "org.apache.tomee:ProvidedByTomcat");

                            final Properties properties = newResource.getProperties();
                            properties.setProperty("jndiName", newResource.getId());
                            properties.setProperty("appName", getId(standardContext));
                            properties.setProperty("factory", (String) resource.getProperty("factory"));

                            final Reference reference = createReference(resource);
                            if (reference != null) {
View Full Code Here


    private static final Assembler assembler = new Assembler();
    private static final ConfigurationFactory configurationFactory = new ConfigurationFactory();

    @Test
    public void createNormalDs() throws OpenEJBException, NamingException {
        final Resource resource = new Resource(IgnoreDefaultTest.class.getName() + "#normal");
        resource.setType(DataSource.class.getName());
        final ResourceInfo info = configurationFactory.configureService(resource, ResourceInfo.class);
        assembler.createResource(info);

        check(resource.getId(), "sa", "");
    }
View Full Code Here

        check(resource.getId(), "sa", "");
    }

    @Test
    public void createWithoutDefaultDs() throws OpenEJBException, NamingException {
        final Resource resource = new Resource(IgnoreDefaultTest.class.getName() + "#without-default");
        resource.setType(DataSource.class.getName());
        resource.getProperties().setProperty("IgnoreDefaultValues", "true");
        resource.getProperties().setProperty("JdbcDriver", jdbcDriver.class.getName());
        final ResourceInfo info = configurationFactory.configureService(resource, ResourceInfo.class);
        assembler.createResource(info);

        check(resource.getId(), null, null);
    }
View Full Code Here

        Collections.sort(resourceInfos, new ConfigurationFactory.ResourceInfoComparator(resourceInfos));
        for (final ResourceInfo resourceInfo : resourceInfos) {
            final int originalSize = resourceInfo.aliases.size();
            final String id = installResource(module.getModuleId(), resourceInfo);

            final Resource resource = resourcesMap.remove(resourceInfo);
            resource.setId(id);
            if (resourceInfo.aliases.size() > originalSize) { // an aliases is generally added to be able to bind in global jndi tree
                resource.getAliases().add(resourceInfo.aliases.get(resourceInfo.aliases.size() - 1));
            }
        }

        resourceInfos.clear();
        // resources.clear(); // don't clear it since we want to keep this to be able to undeploy resources with the app
View Full Code Here

                nonJtaDataSourceId = findResourceProviderId(unit.getNonJtaDataSource());

                // if one of them is not null we have a match on at least one
                // we can just create the second resource using the first as a template
                if (jtaDataSourceId != null || nonJtaDataSourceId != null) {
                    final Resource jtaResource = new Resource(jtaDataSourceId, "DataSource", jtaDataSourceId);
                    jtaResource.getProperties().setProperty("JtaManaged", "true");

                    final Resource nonJtaResource = new Resource(nonJtaDataSourceId, "DataSource", nonJtaDataSourceId);
                    nonJtaResource.getProperties().setProperty("JtaManaged", "false");

                    if (jtaDataSourceId == null) {
                        jtaResource.setId(nonJtaDataSourceId + "Jta");
                        jtaResource.setProvider(nonJtaDataSourceId);
                    } else if (nonJtaDataSourceId == null) {
                        nonJtaResource.setId(jtaDataSourceId + "NonJta");
                        nonJtaResource.setProvider(jtaDataSourceId);
                    }

                    final ResourceInfo jtaResourceInfo = configFactory.configureService(jtaResource, ResourceInfo.class);
                    final ResourceInfo nonJtaResourceInfo = configFactory.configureService(nonJtaResource, ResourceInfo.class);
                    if (jtaDataSourceId != null && nonJtaDataSourceId == null) {
View Full Code Here

                return resourceEnvIds.get(0);
            }
            throw new OpenEJBException("No provider available for resource-env-ref '" + resourceId + "' of type '" + type + "' for '" + beanName + "'.");
        }

        final Resource resource = new Resource(resourceId, null, providerId);
        resource.getProperties().setProperty("destination", resourceId);

        final ResourceInfo resourceInfo = configFactory.configureService(resource, ResourceInfo.class);
        logAutoCreateResource(resourceInfo, type, beanName);
        return installResource(beanName, resourceInfo);
    }
View Full Code Here

                final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
                provider.getTypes().add(className);

                ServiceUtils.registerServiceProvider(appId, provider);

                final Resource resource = new Resource(id, className, appId + "#" + id);

                for (final ConfigProperty property : resourceAdapter.getConfigProperty()) {
                    final String name = property.getConfigPropertyName();
                    final String value = property.getConfigPropertyValue();
                    if (value != null) {
                        resource.getProperties().setProperty(name, value);
                    }
                }
                connectorInfo.resourceAdapter = this.configFactory.configureService(resource, ResourceInfo.class);
            }

            final OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
            if (outbound != null) {
                String transactionSupport = "none";
                switch (outbound.getTransactionSupport()) {
                    case LOCAL_TRANSACTION:
                        transactionSupport = "local";
                        break;
                    case NO_TRANSACTION:
                        transactionSupport = "none";
                        break;
                    case XA_TRANSACTION:
                        transactionSupport = "xa";
                        break;
                }
                for (final ConnectionDefinition connection : outbound.getConnectionDefinition()) {

                    final String id = this.getId(connection, outbound, connectorModule);
                    final String className = connection.getManagedConnectionFactoryClass();
                    final String type = connection.getConnectionFactoryInterface();

                    final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
                    provider.getTypes().add(type);

                    ServiceUtils.registerServiceProvider(appId, provider);

                    final Resource resource = new Resource(id, type, appId + "#" + id);
                    final Properties properties = resource.getProperties();
                    for (final ConfigProperty property : connection.getConfigProperty()) {
                        final String name = property.getConfigPropertyName();
                        final String value = property.getConfigPropertyValue();
                        if (value != null) {
                            properties.setProperty(name, value);
                        }
                    }
                    properties.setProperty("TransactionSupport", transactionSupport);
                    if (connectorInfo.resourceAdapter != null) {
                        properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
                    }

                    final ResourceInfo resourceInfo = this.configFactory.configureService(resource, ResourceInfo.class);
                    connectorInfo.outbound.add(resourceInfo);
                }
            }

            final InboundResourceadapter inbound = resourceAdapter.getInboundResourceAdapter();
            if (inbound != null) {
                for (final MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
                    final String id = this.getId(messageListener, inbound, connectorModule);

                    final Container container = new Container(id, "MESSAGE", null);

                    final Properties properties = container.getProperties();
                    properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
                    properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
                    properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());

                    final MdbContainerInfo mdbContainerInfo = this.configFactory.configureService(container, MdbContainerInfo.class);
                    connectorInfo.inbound.add(mdbContainerInfo);
                }
            }

            for (final AdminObject adminObject : resourceAdapter.getAdminObject()) {

                final String id = this.getId(adminObject, resourceAdapter, connectorModule);
                final String className = adminObject.getAdminObjectClass();
                final String type = adminObject.getAdminObjectInterface();

                final ServiceProvider provider = new ServiceProvider(className, id, "Resource");
                provider.getTypes().add(type);

                ServiceUtils.registerServiceProvider(appId, provider);

                final Resource resource = new Resource(id, type, appId + "#" + id);
                final Properties properties = resource.getProperties();
                for (final ConfigProperty property : adminObject.getConfigProperty()) {
                    final String name = property.getConfigPropertyName();
                    final String value = property.getConfigPropertyValue();
                    if (value != null) {
                        properties.setProperty(name, value);
View Full Code Here

        final File jar = subclass(Color.class, className);

        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());

        final Openejb openejb = new Openejb();
        final Resource resource = new Resource();
        openejb.getResource().add(resource);

        resource.setClassName(className);
        resource.setType(className);
        resource.setId("Orange");
        resource.getProperties().put("red", "FF");
        resource.getProperties().put("green", "99");
        resource.getProperties().put("blue", "00");
        resource.setClasspath(jar.getAbsolutePath());

        createEnvrt();

        final ConfigurationFactory config = new ConfigurationFactory();
        final Assembler assembler = new Assembler();
View Full Code Here

    }

    public void testQueue() throws Exception {
        final ConfigurationFactory factory = new ConfigurationFactory();

        final ResourceInfo resourceInfo = factory.configureService(new Resource("myQueue", "Queue"), ResourceInfo.class);

        assertNotNull(resourceInfo);
        assertEquals("myQueue", resourceInfo.id);
        assertNotNull(resourceInfo.constructorArgs);
        assertNotNull(resourceInfo.properties);
View Full Code Here

     *
     * @throws Exception
     */
    public void testFromUnitNameJtaWithClasspath() throws Exception {

        final Resource resource = new Resource("orange-unit", "DataSource");
        final File file = new File("target/" + getClass().getName());
        file.mkdirs();
        resource.setClasspath(file.getPath());
        final ResourceInfo supplied = addDataSource(OrangeDriver.class, "jdbc:orange:some:stuff", true, resource);
        assertSame(supplied, resources.get(0));

        final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
        assertNotNull(unitInfo);
View Full Code Here

TOP

Related Classes of org.apache.openejb.config.sys.Resource

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.