Examples of InjectionTargetType


Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                        description.setStringValue(descriptionAnnotation);
                    }

                    // injectionTarget
                    if (method != null || field != null) {                            // No class-level injection
                        InjectionTargetType injectionTarget = ejbLocalRef.addNewInjectionTarget();
                        FullyQualifiedClassType qualifiedClass = injectionTarget.addNewInjectionTargetClass();
                        JavaIdentifierType javaType = injectionTarget.addNewInjectionTargetName();
                        if (method != null) {
                            qualifiedClass.setStringValue(method.getDeclaringClass().getName());
                            javaType.setStringValue(method.getName().substring(3));   // method should start with "set"
                            injectionTarget.setInjectionTargetClass(qualifiedClass);
                            injectionTarget.setInjectionTargetName(javaType);
                        }
                        else if (field != null) {
                            qualifiedClass.setStringValue(field.getDeclaringClass().getName());
                            javaType.setStringValue(field.getName());
                            injectionTarget.setInjectionTargetClass(qualifiedClass);
                            injectionTarget.setInjectionTargetName(javaType);
                        }
                    }

                }
                catch (Exception anyException) {
                    log.debug("EJBAnnotationHelper: Exception caught while processing <ejb-local-ref>");
                    anyException.printStackTrace();
                }
            }
        }                                                                           // end if local
        else if (remoteFlag) {                                                      // remote

            //--------------------------------------------------------------------------------------
            // 2. <ejb-ref>
            //--------------------------------------------------------------------------------------

            log.debug("addEJB(): <ejb-ref> found");

            String remoteRefName = annotation.name();
            if (remoteRefName.equals("")) {
                if (method != null) {
                    remoteRefName = method.getDeclaringClass().getName() + "/" + method.getName().substring(3); // method should start with "set"
                } else if (field != null) {
                    remoteRefName = field.getDeclaringClass().getName() + "/" + field.getName();
                }
            }

            boolean exists = false;
            EjbRefType[] ejbRefEntries = annotatedApp.getEjbRefArray();
            for (EjbRefType ejbRefEntry : ejbRefEntries) {
                if (ejbRefEntry.getEjbRefName().getStringValue().trim().equals(remoteRefName)) {
                    exists = true;
                    break;
                }
            }
            if (!exists) {
                try {

                    log.debug("addEJB(): Does not exist in DD: " + remoteRefName);

                    // Doesn't exist in deployment descriptor -- add new
                    EjbRefType ejbRef = annotatedApp.addNewEjbRef();

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

                    // ejb-ref-name
                    EjbRefNameType ejbRefName = ejbRef.addNewEjbRefName();
                    ejbRefName.setStringValue(remoteRefName);
                    ejbRef.setEjbRefName(ejbRefName);

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

                    // remote
                    if (interfce != null) {
                        String remoteAnnotation = interfce.getName();
                        if (!remoteAnnotation.equals("")) {
                            RemoteType remote = ejbRef.addNewRemote();
                            remote.setStringValue(remoteAnnotation);
                            ejbRef.setRemote(remote);
                        }
                    }

                    // ejb-link
                    String beanName = annotation.beanName();
                    if (!beanName.equals("")) {
                        EjbLinkType ejbLink = ejbRef.addNewEjbLink();
                        ejbLink.setStringValue(beanName);
                        ejbRef.setEjbLink(ejbLink);
                    }

                    // mappedName
                    String mappdedNameAnnotation = annotation.mappedName();
                    if (!mappdedNameAnnotation.equals("")) {
                        XsdStringType mappedName = ejbRef.addNewMappedName();
                        mappedName.setStringValue(mappdedNameAnnotation);
                        ejbRef.setMappedName(mappedName);
                    }

                    // description
                    String descriptionAnnotation = annotation.description();
                    if (!descriptionAnnotation.equals("")) {
                        DescriptionType description = ejbRef.addNewDescription();
                        description.setStringValue(descriptionAnnotation);
                    }

                    // injectionTarget
                    if (method != null || field != null) {                            // No class-level injection
                        InjectionTargetType injectionTarget = ejbRef.addNewInjectionTarget();
                        FullyQualifiedClassType qualifiedClass = injectionTarget.addNewInjectionTargetClass();
                        JavaIdentifierType javaType = injectionTarget.addNewInjectionTargetName();
                        if (method != null) {
                            qualifiedClass.setStringValue(method.getDeclaringClass().getName());
                            javaType.setStringValue(method.getName().substring(3));   // method should start with "set"
                            injectionTarget.setInjectionTargetClass(qualifiedClass);
                            injectionTarget.setInjectionTargetName(javaType);
                        }
                        else if (field != null) {
                            qualifiedClass.setStringValue(field.getDeclaringClass().getName());
                            javaType.setStringValue(field.getName());
                            injectionTarget.setInjectionTargetClass(qualifiedClass);
                            injectionTarget.setInjectionTargetName(javaType);
                        }
                    }

                }
                catch (Exception anyException) {
                    log.debug("EJBAnnotationHelper: Exception caught while processing <ejb-ref>");
                    anyException.printStackTrace();
                }
            }
        }                                                                           // end if remote
        else {                                                                      // ambiguous

            //--------------------------------------------------------------------------------------
            // 3. <UNKNOWN>
            //--------------------------------------------------------------------------------------
            log.debug("addEJB(): <UNKNOWN> found");

            String remoteRefName = annotation.name();
            if (remoteRefName.equals("")) {
                if (method != null) {
                    remoteRefName = method.getDeclaringClass().getName() + "/" + method.getName().substring(3); // method should start with "set"
                } else if (field != null) {
                    remoteRefName = field.getDeclaringClass().getName() + "/" + field.getName();
                }
            }

            boolean exists = false;
            EjbRefType[] ejbRefEntries = annotatedApp.getEjbRefArray();
            for (EjbRefType ejbRefEntry : ejbRefEntries) {
                if (ejbRefEntry.getEjbRefName().getStringValue().trim().equals(remoteRefName)) {
                    exists = true;
                    break;
                }
            }
            if (!exists) {
                try {

                    log.debug("addEJB(): Does not exist in DD: " + remoteRefName);

                    // Doesn't exist in deployment descriptor -- add as an <ejb-ref> to the
                    // ambiguous list so that it can be resolved later
                    EjbRefType ejbRef = EjbRefType.Factory.newInstance();
                    annotatedApp.getAmbiguousEjbRefs().add(ejbRef);

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

                    // ejb-ref-name
                    EjbRefNameType ejbRefName = ejbRef.addNewEjbRefName();
                    ejbRefName.setStringValue(remoteRefName);
                    ejbRef.setEjbRefName(ejbRefName);

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

                    // remote
                    if (interfce != null) {
                        String remoteAnnotation = interfce.getName();
                        if (!remoteAnnotation.equals("")) {
                            RemoteType remote = ejbRef.addNewRemote();
                            remote.setStringValue(remoteAnnotation);
                            ejbRef.setRemote(remote);
                        }
                    }

                    // ejb-link
                    String beanName = annotation.beanName();
                    if (!beanName.equals("")) {
                        EjbLinkType ejbLink = ejbRef.addNewEjbLink();
                        ejbLink.setStringValue(beanName);
                        ejbRef.setEjbLink(ejbLink);
                    }

                    // mappedName
                    String mappdedNameAnnotation = annotation.mappedName();
                    if (!mappdedNameAnnotation.equals("")) {
                        XsdStringType mappedName = ejbRef.addNewMappedName();
                        mappedName.setStringValue(mappdedNameAnnotation);
                        ejbRef.setMappedName(mappedName);
                    }

                    // description
                    String descriptionAnnotation = annotation.description();
                    if (!descriptionAnnotation.equals("")) {
                        DescriptionType description = ejbRef.addNewDescription();
                        description.setStringValue(descriptionAnnotation);
                    }

                    // injectionTarget
                    if (method != null || field != null) {                            // No class-level injection
                        InjectionTargetType injectionTarget = ejbRef.addNewInjectionTarget();
                        FullyQualifiedClassType qualifiedClass = injectionTarget.addNewInjectionTargetClass();
                        JavaIdentifierType javaType = injectionTarget.addNewInjectionTargetName();
                        if (method != null) {
                            qualifiedClass.setStringValue(method.getDeclaringClass().getName());
                            javaType.setStringValue(method.getName().substring(3));   // method should start with "set"
                            injectionTarget.setInjectionTargetClass(qualifiedClass);
                            injectionTarget.setInjectionTargetName(javaType);
                        }
                        else if (field != null) {
                            qualifiedClass.setStringValue(field.getDeclaringClass().getName());
                            javaType.setStringValue(field.getName());
                            injectionTarget.setInjectionTargetClass(qualifiedClass);
                            injectionTarget.setInjectionTargetName(javaType);
                        }
                    }

                }
                catch (Exception anyException) {
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                            FullyQualifiedClassType qualifiedClass = resourceRef.addNewResType();
                            qualifiedClass.setStringValue(resourceType);
                        }
                        if (method != null || field != null) {
                            // injectionTarget
                            InjectionTargetType injectionTarget = resourceRef.addNewInjectionTarget();
                            configureInjectionTarget(injectionTarget, method, field);
                        }

                        //------------------------------------------------------------------------------
                        // <resource-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                            FullyQualifiedClassType qualifiedClass = resourceRef.addNewResType();
                            qualifiedClass.setStringValue(resourceType);
                        }
                        if (method != null || field != null) {
                            // injectionTarget
                            InjectionTargetType injectionTarget = resourceRef.addNewInjectionTarget();
                            configureInjectionTarget(injectionTarget, method, field);
                        }

                        //------------------------------------------------------------------------------
                        // <resource-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                qualifiedClass.setStringValue(resourceType);
                resourceEnvRef.setResourceEnvRefType(qualifiedClass);
            }
            if (method != null || field != null) {
                // injectionTarget
                InjectionTargetType injectionTarget = resourceEnvRef.addNewInjectionTarget();
                configureInjectionTarget(injectionTarget, method, field);
            }

            //------------------------------------------------------------------------------
            // <resource-env-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                msgDestType.setStringValue(resourceType);
                messageDestinationRef.setMessageDestinationType(msgDestType);
            }
            if (method != null || field != null) {
                // injectionTarget
                InjectionTargetType injectionTarget = messageDestinationRef.addNewInjectionTarget();
                configureInjectionTarget(injectionTarget, method, field);
            }

            //------------------------------------------------------------------------------
            // <message-destination-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                            FullyQualifiedClassType qualifiedClass = resourceRef.addNewResType();
                            qualifiedClass.setStringValue(resourceType);
                        }
                        if (method != null || field != null) {
                            // injectionTarget
                            InjectionTargetType injectionTarget = resourceRef.addNewInjectionTarget();
                            configureInjectionTarget(injectionTarget, method, field);
                        }

                        //------------------------------------------------------------------------------
                        // <resource-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                qualifiedClass.setStringValue(resourceType);
                resourceEnvRef.setResourceEnvRefType(qualifiedClass);
            }
            if (method != null || field != null) {
                // injectionTarget
                InjectionTargetType injectionTarget = resourceEnvRef.addNewInjectionTarget();
                configureInjectionTarget(injectionTarget, method, field);
            }

            //------------------------------------------------------------------------------
            // <resource-env-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                msgDestType.setStringValue(resourceType);
                messageDestinationRef.setMessageDestinationType(msgDestType);
            }
            if (method != null || field != null) {
                // injectionTarget
                InjectionTargetType injectionTarget = messageDestinationRef.addNewInjectionTarget();
                configureInjectionTarget(injectionTarget, method, field);
            }

            //------------------------------------------------------------------------------
            // <message-destination-ref> optional elements:
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                        EnvEntryTypeValuesType envEntryType = envEntry.addNewEnvEntryType();
                        envEntryType.setStringValue( resourceType );
                    }
                    else if ( !injectionJavaType.equals("") ) {
                        // injectionTarget
                        InjectionTargetType injectionTarget = envEntry.addNewInjectionTarget();
                        configureInjectionTarget(injectionTarget, injectionClass, injectionJavaType);
                    }

                    // env-entry-value
                    XsdStringType value = envEntry.addNewEnvEntryValue();
                    value.setStringValue( annotation.mappedName() );

                    //------------------------------------------------------------------------------
                    // <env-entry> optional elements:
                    //------------------------------------------------------------------------------

                    // description
                    String descriptionAnnotation = annotation.description();
                    if ( descriptionAnnotation != null && descriptionAnnotation.length() > 0 ) {
                        DescriptionType description = envEntry.addNewDescription();
                        description.setStringValue( descriptionAnnotation );
                    }

                }
                catch ( Exception anyException ) {
                    log.debug( "ResourceAnnotationHelper: Exception caught while processing <env-entry>" );
                }
            }
        }

        //------------------------------------------------------------------------------------------
        // 2. <service-ref>
        //------------------------------------------------------------------------------------------
        else if ( resourceType.equals("javax.xml.rpc.Service") ) {

            log.debug( "addResource(): <service-ref> found");

            boolean exists = false;
            ServiceRefType[] serviceRefs = webApp.getServiceRefArray();
            for ( ServiceRefType serviceRef : serviceRefs ) {
                if ( serviceRef.getServiceRefName().getStringValue().equals(resourceName) ) {
                    exists = true;
                    break;
                }
            }
            if ( !exists ) {
                try {

                    // Doesn't exist in deployment descriptor -- add new
                    ServiceRefType serviceRef = webApp.addNewServiceRef();

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

                    // service-ref-name
                    JndiNameType serviceRefName = serviceRef.addNewServiceRefName();
                    serviceRefName.setStringValue( resourceName );

                    if ( !resourceType.equals("") ) {
                        // service-ref-type
                        FullyQualifiedClassType qualifiedClass = serviceRef.addNewServiceInterface();
                        qualifiedClass.setStringValue( resourceType );
                    }
                    else if ( !injectionJavaType.equals("") ) {
                        // injectionTarget
                        InjectionTargetType injectionTarget = serviceRef.addNewInjectionTarget();
                        configureInjectionTarget(injectionTarget, injectionClass, injectionJavaType);
                    }

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

                    // description
                    String descriptionAnnotation = annotation.description();
                    if ( descriptionAnnotation.length() > 0 ) {
                        DescriptionType description = serviceRef.addNewDescription();
                        description.setStringValue( descriptionAnnotation );
                    }

                    // WSDL document location
                    String documentAnnotation = annotation.mappedName();
                    if ( documentAnnotation.length() > 0 ) {
                        XsdAnyURIType wsdlFile = XsdAnyURIType.Factory.newInstance();
                        wsdlFile.setStringValue( annotation.mappedName() );
                        serviceRef.setWsdlFile( wsdlFile );
                    }

                }
                catch ( Exception anyException ) {
                    log.debug( "ResourceAnnotationHelper: Exception caught while processing <service-ref>" );
                    anyException.printStackTrace();
                }
            }
        }

        //------------------------------------------------------------------------------------------
        // 3. <resource-ref>
        //------------------------------------------------------------------------------------------
        else if ( resourceType.equals("javax.sql.DataSource")                   ||
                  resourceType.equals("javax.jms.ConnectionFactory")            ||
                  resourceType.equals("javax.jms.QueueConnectionFactory")       ||
                  resourceType.equals("javax.jms.TopicConnectionFactory")       ||
                  resourceType.equals("javax.mail.Session")                     ||
                  resourceType.equals("java.net.URL")                           ||
                  resourceType.equals("javax.resource.cci.ConnectionFactory")   ||
                  resourceType.equals("org.omg.CORBA_2_3.ORB")                  ||
                  resourceType.endsWith("ConnectionFactory") ) {

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

            boolean exists = false;
            ResourceRefType[] resourceRefs = webApp.getResourceRefArray();
            for ( ResourceRefType resourceRef : resourceRefs ) {
                if ( resourceRef.getResRefName().getStringValue().equals(resourceName) ) {
                    exists = true;
                    break;
                }
            }
            if ( !exists ) {
                try {

                    // Doesn't exist in deployment descriptor -- add new
                    ResourceRefType resourceRef = webApp.addNewResourceRef();

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

                    // resource-ref-name
                    JndiNameType resourceRefName = JndiNameType.Factory.newInstance();
                    resourceRefName.setStringValue( resourceName );
                    resourceRef.setResRefName( resourceRefName );

                    if ( !resourceType.equals("") ) {
                        // resource-ref-type
                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
                        qualifiedClass.setStringValue( resourceType );
                        resourceRef.setResType( qualifiedClass );
                    }
                    else if ( !injectionJavaType.equals("") ) {
                        // injectionTarget
                        InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
                        JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
                        qualifiedClass.setStringValue( injectionClass );
                        javaType.setStringValue( injectionJavaType );
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = resourceRef.sizeOfInjectionTargetArray();
                        resourceRef.insertNewInjectionTarget( arraySize );
                        resourceRef.setInjectionTargetArray( arraySize, injectionTarget );
                    }

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

                    // description
                    String descriptionAnnotation = annotation.description();
                    if ( descriptionAnnotation.length() > 0 ) {
                        DescriptionType description = DescriptionType.Factory.newInstance();
                        description.setStringValue( descriptionAnnotation );
                        int arraySize = resourceRef.sizeOfDescriptionArray();
                        resourceRef.insertNewDescription( arraySize );
                        resourceRef.setDescriptionArray( arraySize,description );
                    }

                    // authentication
                    ResAuthType resAuth = ResAuthType.Factory.newInstance();
                    if ( annotation.authenticationType() == Resource.AuthenticationType.CONTAINER ) {
                        resAuth.setStringValue( "Container" );
                    }
                    else if ( annotation.authenticationType() == Resource.AuthenticationType.APPLICATION ) {
                        resAuth.setStringValue( "Application" );
                    }
                    resourceRef.setResAuth( resAuth );

                    // sharing scope
                    ResSharingScopeType resScope = ResSharingScopeType.Factory.newInstance();
                    resScope.setStringValue( annotation.shareable() ? "Shareable" : "Unshareable" );
                    resourceRef.setResSharingScope( resScope );

                    // mappedName
                    String mappdedNameAnnotation = annotation.mappedName();
                    if ( mappdedNameAnnotation.length() > 0 ) {
                        XsdStringType mappedName = XsdStringType.Factory.newInstance();
                        mappedName.setStringValue( mappdedNameAnnotation );
                        resourceRef.setMappedName( mappedName );
                    }

                }
                catch ( Exception anyException ) {
                    log.debug( "ResourceAnnotationHelper: Exception caught while processing <resource-ref>" );
                    anyException.printStackTrace();
                }
            }
        }

        //------------------------------------------------------------------------------------------
        // 4. <message-destination-ref>
        //------------------------------------------------------------------------------------------
        else if ( resourceType.equals("javax.jms.Queue")    ||
                  resourceType.equals("javax.jms.Topic") ) {

            log.debug( "addResource(): <message-destination-ref> found");

            boolean exists = false;
            MessageDestinationRefType[] messageDestinationRefs = webApp.getMessageDestinationRefArray();
            for ( MessageDestinationRefType messageDestinationRef : messageDestinationRefs ) {
                if ( messageDestinationRef.getMessageDestinationRefName().getStringValue().equals(resourceName) ) {
                    exists = true;
                    break;
                }
            }
            if ( !exists ) {
                try {

                    // Doesn't exist in deployment descriptor -- add new
                    MessageDestinationRefType messageDestinationRef = webApp.addNewMessageDestinationRef();

                    //------------------------------------------------------------------------------
                    // <message-destination-ref> required elements:
                    //------------------------------------------------------------------------------

                    // message-destination-ref-name
                    JndiNameType messageDestinationRefName = JndiNameType.Factory.newInstance();
                    messageDestinationRefName.setStringValue( resourceName );
                    messageDestinationRef.setMessageDestinationRefName( messageDestinationRefName );

                    if ( !resourceType.equals("") ) {
                        // message-destination-ref-type
                        MessageDestinationTypeType msgDestType = MessageDestinationTypeType.Factory.newInstance();
                        msgDestType.setStringValue( resourceType );
                        messageDestinationRef.setMessageDestinationType( msgDestType );
                    }
                    else if ( !injectionJavaType.equals("") ) {
                        // injectionTarget
                        InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
                        JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
                        qualifiedClass.setStringValue( injectionClass );
                        javaType.setStringValue( injectionJavaType );
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = messageDestinationRef.sizeOfInjectionTargetArray();
                        messageDestinationRef.insertNewInjectionTarget( arraySize );
                        messageDestinationRef.setInjectionTargetArray( arraySize, injectionTarget );
                    }

                    //------------------------------------------------------------------------------
                    // <message-destination-ref> optional elements:
                    //------------------------------------------------------------------------------

                    // description
                    String descriptionAnnotation = annotation.description();
                    if ( descriptionAnnotation.length() > 0 ) {
                        DescriptionType description = DescriptionType.Factory.newInstance();
                        description.setStringValue( descriptionAnnotation );
                        int arraySize = messageDestinationRef.sizeOfDescriptionArray();
                        messageDestinationRef.insertNewDescription( arraySize );
                        messageDestinationRef.setDescriptionArray( arraySize,description );
                    }

                    // mappedName
                    String mappdedNameAnnotation = annotation.mappedName();
                    if ( mappdedNameAnnotation.length() > 0 ) {
                        XsdStringType mappedName = XsdStringType.Factory.newInstance();
                        mappedName.setStringValue( mappdedNameAnnotation );
                        messageDestinationRef.setMappedName( mappedName );
                    }

                }
                catch ( Exception anyException ) {
                    log.debug( "ResourceAnnotationHelper: Exception caught while processing <message-destination-ref>" );
                    anyException.printStackTrace();
                }
            }
        }

        //------------------------------------------------------------------------------------------
        // 5. Everything else must be a <resource-env-ref>
        //------------------------------------------------------------------------------------------
        else if ( annotation.type().getCanonicalName().equals("javax.resource.cci.InteractionSpec") ||
                  annotation.type().getCanonicalName().equals("javax.transaction.UserTransaction"|| true ) {

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

            boolean exists = false;
            ResourceEnvRefType[] resourceEnvRefs = webApp.getResourceEnvRefArray();
            for ( ResourceEnvRefType resourceEnvRef : resourceEnvRefs ) {
                if ( resourceEnvRef.getResourceEnvRefName().getStringValue().equals(resourceName) ) {
                    exists = true;
                    break;
                }
            }
            if ( !exists ) {
                try {

                    // Doesn't exist in deployment descriptor -- add new
                    ResourceEnvRefType resourceEnvRef = webApp.addNewResourceEnvRef();

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

                    // resource-env-ref-name
                    JndiNameType resourceEnvRefName = JndiNameType.Factory.newInstance();
                    resourceEnvRefName.setStringValue( resourceName );
                    resourceEnvRef.setResourceEnvRefName( resourceEnvRefName );

                    if ( !resourceType.equals("") ) {
                        // resource-env-ref-type
                        FullyQualifiedClassType classType = FullyQualifiedClassType.Factory.newInstance();
                        classType.setStringValue( resourceType );
                        resourceEnvRef.setResourceEnvRefType( classType );
                    }
                    else if ( !injectionJavaType.equals("") ) {
                        // injectionTarget
                        InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
                        FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
                        JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
                        qualifiedClass.setStringValue( injectionClass );
                        javaType.setStringValue( injectionJavaType );
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = resourceEnvRef.sizeOfInjectionTargetArray();
                        resourceEnvRef.insertNewInjectionTarget( arraySize );
                        resourceEnvRef.setInjectionTargetArray( arraySize, injectionTarget );
                    }
View Full Code Here

Examples of org.apache.geronimo.xbeans.javaee.InjectionTargetType

                        ejbLocalRef.insertNewDescription( arraySize );
                        ejbLocalRef.setDescriptionArray( arraySize,description );
                    }

                    // injectionTarget
                    InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
                    FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
                    JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
                    if ( method != null ) {
                        qualifiedClass.setStringValue( method.getDeclaringClass().getName() );
                        javaType.setStringValue( method.getName().substring(3) );   // method should start with "set"
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = ejbLocalRef.sizeOfInjectionTargetArray();
                        ejbLocalRef.insertNewInjectionTarget( arraySize );
                        ejbLocalRef.setInjectionTargetArray( arraySize,injectionTarget );
                    }
                    else if ( field !=null ) {
                        qualifiedClass.setStringValue( field.getDeclaringClass().getName() );
                        javaType.setStringValue( field.getName() );
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = ejbLocalRef.sizeOfInjectionTargetArray();
                        ejbLocalRef.insertNewInjectionTarget( arraySize );
                        ejbLocalRef.setInjectionTargetArray( arraySize,injectionTarget );
                    }

                }
                catch ( Exception anyException ) {
                    log.debug( "EJBAnnotationHelper: Exception caught while processing <ejb-local-ref>" );
                    anyException.printStackTrace();
                }
            }
        }                                                                           // end if local
        else {                                                                      // else remote

            //--------------------------------------------------------------------------------------
            // 2. <ejb-ref>
            //--------------------------------------------------------------------------------------

            log.debug( "addEJB(): <ejb-ref> found");

            String remoteRefName = annotation.name();
            if ( remoteRefName.equals("") ) {
                if ( method != null ) {
                    remoteRefName = method.getDeclaringClass().getName() + "/" + method.getName().substring(3); // method should start with "set"
                }
                else if ( field != null ) {
                    remoteRefName = field.getDeclaringClass().getName() + "/" + field.getName();
                }
            }

            boolean exists = false;
            EjbRefType[] ejbRefEntries = webApp.getEjbRefArray();
            for ( EjbRefType ejbRefEntry : ejbRefEntries ) {
                if ( ejbRefEntry.getEjbRefName().getStringValue().equals( remoteRefName ) ) {
                    exists = true;
                    break;
                }
            }
            if ( !exists ) {
                try {

                    // Doesn't exist in deployment descriptor -- add new
                    EjbRefType ejbRef = webApp.addNewEjbRef();

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

                    // ejb-ref-name
                    EjbRefNameType ejbRefName = EjbRefNameType.Factory.newInstance();
                    ejbRefName.setStringValue( remoteRefName );
                    ejbRef.setEjbRefName( ejbRefName );

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

                    // remote
                    String remoteAnnotation = interfce.getName();
                    if ( remoteAnnotation.length() > 0 ) {
                        RemoteType remote = RemoteType.Factory.newInstance();
                        remote.setStringValue( remoteAnnotation );
                        ejbRef.setRemote( remote );
                    }

                    // ejb-link
                    String beanName = annotation.beanName();
                    if ( beanName.length() > 0 ) {
                        EjbLinkType ejbLink = EjbLinkType.Factory.newInstance();
                        ejbLink.setStringValue( beanName );
                        ejbRef.setEjbLink( ejbLink );
                    }

                    // mappedName
                    String mappdedNameAnnotation = annotation.mappedName();
                    if ( mappdedNameAnnotation.length() > 0 ) {
                        XsdStringType mappedName = XsdStringType.Factory.newInstance();
                        mappedName.setStringValue( mappdedNameAnnotation );
                        ejbRef.setMappedName( mappedName );
                    }

                    // description
                    String descriptionAnnotation = annotation.description();
                    if ( descriptionAnnotation.length() > 0 ) {
                        DescriptionType description = DescriptionType.Factory.newInstance();
                        description.setStringValue( descriptionAnnotation );
                        int arraySize = ejbRef.sizeOfDescriptionArray();
                        ejbRef.insertNewDescription( arraySize );
                        ejbRef.setDescriptionArray( arraySize,description );
                    }

                    // injectionTarget
                    InjectionTargetType injectionTarget = InjectionTargetType.Factory.newInstance();
                    FullyQualifiedClassType qualifiedClass = FullyQualifiedClassType.Factory.newInstance();
                    JavaIdentifierType javaType = JavaIdentifierType.Factory.newInstance();
                    if ( method != null ) {
                        qualifiedClass.setStringValue( method.getDeclaringClass().getName() );
                        javaType.setStringValue( method.getName().substring(3) );   // method should start with "set"
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = ejbRef.sizeOfInjectionTargetArray();
                        ejbRef.insertNewInjectionTarget( arraySize );
                        ejbRef.setInjectionTargetArray( arraySize, injectionTarget );
                    }
                    else if ( field !=null ) {
                        qualifiedClass.setStringValue( field.getDeclaringClass().getName() );
                        javaType.setStringValue( field.getName() );
                        injectionTarget.setInjectionTargetClass( qualifiedClass );
                        injectionTarget.setInjectionTargetName( javaType );
                        int arraySize = ejbRef.sizeOfInjectionTargetArray();
                        ejbRef.insertNewInjectionTarget( arraySize );
                        ejbRef.setInjectionTargetArray( arraySize, injectionTarget );
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.