Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.ResourceRef$JAXB


                || DataSource.class.getSimpleName().equals(resource.getType())) {
                trimNotSupportedDataSourceProperties(properties);
            }

            ResourceInfo resourceInfo = configFactory.configureService(resource, ResourceInfo.class);
            final ResourceRef resourceRef = new ResourceRef();
            resourceRef.setResType(resource.getType());

            if (DataSource.class.getName().equals(resource.getType())
                    && resource.getProperties().containsKey(ORIGIN_FLAG)
                    && resource.getProperties().getProperty(ORIGIN_FLAG).equals(ORIGIN_ANNOTATION)) {
                properties.remove(ORIGIN_FLAG);

                resourceInfo.id = module.getModuleId() + "/" + resourceInfo.id;

                if (properties.get("JdbcUrl") == null) {
                    final String url = getVendorUrl(properties);
                    if (url != null) {
                        properties.put("JdbcUrl", url);
                    }
                }

                resourceRef.setResRefName(dataSourceLookupName(resource));
            } else {
                resourceRef.setResRefName(OPENEJB_RESOURCE_JNDI_PREFIX + resourceInfo.id);
            }

            resourceRef.setMappedName(resourceInfo.id);

            for (JndiConsumer consumer : jndiConsumers) {
                final ResourceRef existing = consumer.getResourceRefMap().get(resourceRef.getKey());
                if (existing != null) {
                    existing.setMappedName(resourceRef.getMappedName());
                } else {
                    consumer.getResourceRef().add(resourceRef);
                }
            }
View Full Code Here


        Map<String, GerResourceRefType> refMap = mapResourceRefs(gerResourceRefsUntyped);
        List<String> unresolvedRefs = new ArrayList<String>();
        Bundle bundle = module.getEarContext().getDeploymentBundle();
        for (Map.Entry<String, ResourceRef> entry : specDD.getResourceRefMap().entrySet()) {
            String name = entry.getKey();
            ResourceRef resourceRef = entry.getValue();
            if (lookupJndiContextMap(module, name) != null) {
                // some other builder handled this entry already

                // Always merge injections. This is for example where data source is defined as
                // @DataSource(name='foo') and it is injected via @Resource(name='foo')
                addInjections(normalize(name), ReferenceType.RESOURCE, resourceRef.getInjectionTarget(), NamingBuilder.INJECTION_KEY.get(sharedContext));

                continue;
            }
            String type = getStringValue(resourceRef.getResType());
            type = inferAndCheckType(module, bundle, resourceRef.getInjectionTarget(), name, type);
            GerResourceRefType gerResourceRef = refMap.get(name);
            if (log.isDebugEnabled()) {
                log.debug("trying to resolve " + name + ", type " + type + ", resourceRef " + gerResourceRef);
            }
            Object value = null;
            if (gerResourceRef == null) {
                String lookupName = getStringValue(resourceRef.getLookupName());
                if (lookupName != null) {
                    if (lookupName.equals(getJndiName(name))) {
                        throw new DeploymentException("resource-ref lookup name refers to itself");
                    }
                    value = new JndiReference(lookupName);
                }
            }

            if (value == null) {
                value = buildReference(module, name, type, gerResourceRef);
            }

            if (value == null) {
                unresolvedRefs.add(name);
            } else {
                put(name, value, ReferenceType.RESOURCE, module.getJndiContext(), resourceRef.getInjectionTarget(), sharedContext);
            }

        }

        if (unresolvedRefs.size() > 0) {
View Full Code Here

                    resourceType.endsWith("ConnectionFactory") ||
                    isManagedBeanReference(resourceTypeClass, annotation)) {

                log.debug("processResource(): <resource-ref> found");

                ResourceRef resourceRef = annotatedApp.getResourceRefMap().get(getJndiName(resourceName));

                if (resourceRef == null) {
                    try {

                        log.debug("processResource(): Does not exist in DD: " + resourceName);

                        // Doesn't exist in deployment descriptor -- add new
                        resourceRef = new ResourceRef();

                        //------------------------------------------------------------------------------
                        // <resource-ref> required elements:
                        //------------------------------------------------------------------------------

                        // resource-ref-name
                        resourceRef.setResRefName(resourceName);

                        if (!resourceType.isEmpty()) {
                            // resource-ref-type
                            resourceRef.setResType(resourceType);
                        }

                        //------------------------------------------------------------------------------
                        // <resource-ref> optional elements:
                        //------------------------------------------------------------------------------

                        // description
                        String descriptionAnnotation = annotation.description();
                        if (!descriptionAnnotation.equals("")) {
                            resourceRef.setDescriptions(new Text[]{new Text(null, descriptionAnnotation)});
                        }

                        // authentication
                        if (annotation.authenticationType() == Resource.AuthenticationType.CONTAINER) {
                            resourceRef.setResAuth(ResAuth.CONTAINER);
                        } else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) {
                            resourceRef.setResAuth(ResAuth.APPLICATION);
                        }

                        // sharing scope
                        resourceRef.setResSharingScope(annotation.shareable() ? ResSharingScope.SHAREABLE : ResSharingScope.UNSHAREABLE);

                        // mappedName
                        String mappdedNameAnnotation = annotation.mappedName();
                        if (!mappdedNameAnnotation.equals("")) {
                            resourceRef.setMappedName(mappdedNameAnnotation);
                        }

                        // lookup
                        String lookup = annotation.lookup();
                        if (!lookup.equals("")) {
                            resourceRef.setLookupName(lookup);
                        }
                        annotatedApp.getResourceRef().add(resourceRef);
                    }
                    catch (Exception anyException) {
                        log.debug("ResourceRefBuilder: Exception caught while processing <resource-ref>");
                    }
                }

                if (method != null || field != null) {
                    Set<InjectionTarget> targets = resourceRef.getInjectionTarget();
                    if (!hasTarget(method, field, targets)) {
                        resourceRef.getInjectionTarget().add(configureInjectionTarget(method, field));
                    }
                }

                return true;
            }
View Full Code Here

            if (mergeItem != null) {
                if (mergeItem.isFromWebFragment()) {
                    throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("resource-ref", resourceRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
                } else if (mergeItem.isFromWebXml() && !isResourceRefInjectTargetsConfiguredInInitialWebXML(resourceRefName, mergeContext)) {
                    //Merge InjectTarget
                    ResourceRef resourceRef = (ResourceRef) mergeItem.getValue();
                    for (InjectionTarget injectTarget : srcResourceRef.getInjectionTarget()) {
                        String resourceRefInjectTargetKey = createResourceRefInjectTargetKey(resourceRefName, injectTarget.getInjectionTargetClass(), injectTarget
                                .getInjectionTargetName());
                        if (!mergeContext.containsAttribute(resourceRefInjectTargetKey)) {
                            resourceRef.getInjectionTarget().add(injectTarget);
                            mergeContext.setAttribute(resourceRefInjectTargetKey, Boolean.TRUE);
                        }
                    }
                }
            } else {
View Full Code Here

                    reference = resourceEnvRef;
                } else if (!knownEnvironmentEntries.contains(type)) {
                    /*
                     * @Resource <resource-ref>
                     */
                    ResourceRef resourceRef = consumer.getResourceRefMap().get(refName);

                    if (resourceRef == null) {
                        resourceRef = new ResourceRef();
                        resourceRef.setName(refName);
                        consumer.getResourceRef().add(resourceRef);
                    }

                    if (resourceRef.getResAuth() == null) {
                        if (resource.authenticationType() == Resource.AuthenticationType.APPLICATION) {
                            resourceRef.setResAuth(ResAuth.APPLICATION);
                        } else {
                            resourceRef.setResAuth(ResAuth.CONTAINER);
                        }
                    }

                    if (resourceRef.getResType() == null || ("").equals(resourceRef.getResType())) {
                        if (resource.type() != java.lang.Object.class) {
                            resourceRef.setResType(resource.type().getName());
                        } else {
                            resourceRef.setResType(member.getType().getName());
                        }
                    }

                    if (resourceRef.getResSharingScope() == null) {
                        if (resource.shareable()) {
                            resourceRef.setResSharingScope(ResSharingScope.SHAREABLE);
                        } else {
                            resourceRef.setResSharingScope(ResSharingScope.UNSHAREABLE);
                        }
                    }
                    reference = resourceRef;
                }
            }
View Full Code Here

    @Test
    public void testSLSBwithUserTransaction() {

        // "@Resource UserTransaction tx" declaration
        ResourceRef resourceRef = new ResourceRef();
        resourceRef.setResRefName("org.acme.CheeseEjb/tx");
        resourceRef.setResType("javax.transaction.UserTransaction");
        resourceRef.getInjectionTarget().add(new InjectionTarget("org.acme.CheeseEjb", "org.acme.CheeseEjb/tx"));
        bean.getResourceRef().add(resourceRef);

        rule.validate(module);

        Assert.assertThat(module.getValidation().getErrors().length, is(1));
View Full Code Here

                            resourceEnvRef.setResourceEnvRefType(member.getType().getName());
                        }
                    }
                    reference = resourceEnvRef;
                } else if (!knownEnvironmentEntries.contains(type)) {
                    ResourceRef resourceRef = null;
                    List<ResourceRef> resourceRefs = consumer.getResourceRef();
                    for (ResourceRef resRef : resourceRefs) {
                        if (resRef.getName().equals(refName)) {
                            resourceRef = resRef;
                            break;
                        }
                    }

                    if (resourceRef == null) {
                        resourceRef = new ResourceRef();
                        resourceRef.setName(refName);
                        resourceRefs.add(resourceRef);
                    }

                    if (resourceRef.getResAuth() == null) {
                        if (resource.authenticationType() == Resource.AuthenticationType.APPLICATION) {
                            resourceRef.setResAuth(ResAuth.APPLICATION);
                        } else {
                            resourceRef.setResAuth(ResAuth.CONTAINER);
                        }
                    }

                    if (resourceRef.getResType() == null || ("").equals(resourceRef.getResType())) {
                        if (resource.type() != java.lang.Object.class) {
                            resourceRef.setResType(resource.type().getName());
                        } else {
                            resourceRef.setResType(member.getType().getName());
                        }
                    }

                    if (resourceRef.getResSharingScope() == null) {
                        if (resource.shareable()) {
                            resourceRef.setResSharingScope(ResSharingScope.SHAREABLE);
                        } else {
                            resourceRef.setResSharingScope(ResSharingScope.UNSHAREABLE);
                        }
                    }
                    reference = resourceRef;
                }
            }
View Full Code Here

                    }
                } else {
                    /*
                     * @Resource <resource-ref>
                     */
                    ResourceRef resourceRef = consumer.getResourceRefMap().get(refName);

                    if (resourceRef == null) {
                        resourceRef = new ResourceRef();
                        resourceRef.setName(refName);
                        consumer.getResourceRef().add(resourceRef);
                    }

                    if (member != null) {
                        resourceRef.setOrigin(member.getDeclaringClass() + "#" + member.getName());
                    } // TODO: else @Resource on a class

                    if (resourceRef.getResAuth() == null) {
                        if (resource.authenticationType() == Resource.AuthenticationType.APPLICATION) {
                            resourceRef.setResAuth(ResAuth.APPLICATION);
                        } else {
                            resourceRef.setResAuth(ResAuth.CONTAINER);
                        }
                    }

                    if (resourceRef.getResType() == null || "".equals(resourceRef.getResType())) {
                        resourceRef.setResType(type.getName());
                    }

                    if (resourceRef.getResSharingScope() == null) {
                        if (resource.shareable()) {
                            resourceRef.setResSharingScope(ResSharingScope.SHAREABLE);
                        } else {
                            resourceRef.setResSharingScope(ResSharingScope.UNSHAREABLE);
                        }
                    }
                    reference = resourceRef;
                }
            }
View Full Code Here

                .user("sa")
                .password("")
                .url("jdbc:hsqldb:mem:superDS")
        );

        orange.getResourceRef().add(new ResourceRef()
                .lookup("java:comp/env/superDS")
                .injectionTarget(OrangeBean.class, "ds")
        );

        final StatelessBean yellow = ejbJar.addEnterpriseBean(new StatelessBean(YellowBean.class));

        yellow.getDataSource().add(new org.apache.openejb.jee.DataSource()
                .name("java:comp/env/superMegaDS")
                .className("org.hsqldb.jdbc.jdbcDataSource")
                .user("sa")
                .password("")
                .url("jdbc:hsqldb:mem:superDS")
        );

        yellow.getResourceRef().add(new ResourceRef()
                .lookup("java:comp/env/superMegaDS")
                .injectionTarget(YellowBean.class, "mega")
        );


        yellow.getDataSource().add(new org.apache.openejb.jee.DataSource()
                .name("java:comp/env/superGigaDS")
                .className("org.hsqldb.jdbc.jdbcDataSource")
                .user("sa")
                .password("")
                .url("jdbc:hsqldb:mem:superDS")
        );

        yellow.getResourceRef().add(new ResourceRef()
                .lookup("java:comp/env/superGigaDS")
                .injectionTarget(YellowBean.class, "giga")
        );

View Full Code Here

       
        EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
        lookupEntry.setLookupName("java:app/AppName");
        bean.getEnvEntry().add(lookupEntry);

        bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));

        bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));

        bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.ResourceRef$JAXB

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.