001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.config;
017:
018: import org.apache.openejb.OpenEJBException;
019: import org.apache.openejb.jee.EnterpriseBean;
020: import org.apache.openejb.jee.ResourceRef;
021: import org.apache.openejb.jee.ResourceEnvRef;
022: import org.apache.openejb.jee.MessageDestinationRef;
023: import org.apache.openejb.jee.EjbRef;
024: import org.apache.openejb.jee.EjbLocalRef;
025: import org.apache.openejb.jee.oejb3.EjbDeployment;
026: import org.apache.openejb.jee.oejb3.ResourceLink;
027: import org.apache.openejb.jee.oejb3.EjbLink;
028:
029: import java.util.Map;
030:
031: /**
032: * @version $Rev: 609119 $ $Date: 2008-01-05 02:14:31 -0800 $
033: */
034: public class ApplyOpenejbJar implements DynamicDeployer {
035:
036: public AppModule deploy(AppModule appModule)
037: throws OpenEJBException {
038:
039: for (EjbModule ejbModule : appModule.getEjbModules()) {
040:
041: Map<String, EjbDeployment> ejbDeployments = ejbModule
042: .getOpenejbJar().getDeploymentsByEjbName();
043:
044: for (EnterpriseBean enterpriseBean : ejbModule.getEjbJar()
045: .getEnterpriseBeans()) {
046:
047: // Get the OpenEJB deployment from openejb-jar.xml
048: EjbDeployment ejbDeployment = ejbDeployments
049: .get(enterpriseBean.getEjbName());
050:
051: enterpriseBean.setId(ejbDeployment.getDeploymentId());
052:
053: // Copy all links over to mappedName
054:
055: for (ResourceRef ref : enterpriseBean.getResourceRef()) {
056: ResourceLink resourceLink = ejbDeployment
057: .getResourceLink(ref.getName());
058: if (resourceLink != null
059: && resourceLink.getResId() != null /* don't overwrite with null */) {
060: ref.setMappedName(resourceLink.getResId());
061: }
062: }
063:
064: for (ResourceEnvRef ref : enterpriseBean
065: .getResourceEnvRef()) {
066: ResourceLink resourceLink = ejbDeployment
067: .getResourceLink(ref.getName());
068: if (resourceLink != null
069: && resourceLink.getResId() != null /* don't overwrite with null */) {
070: ref.setMappedName(resourceLink.getResId());
071: }
072: }
073:
074: for (MessageDestinationRef ref : enterpriseBean
075: .getMessageDestinationRef()) {
076: ResourceLink resourceLink = ejbDeployment
077: .getResourceLink(ref.getName());
078: if (resourceLink != null
079: && resourceLink.getResId() != null /* don't overwrite with null */) {
080: ref.setMappedName(resourceLink.getResId());
081: }
082: }
083:
084: for (EjbRef ref : enterpriseBean.getEjbRef()) {
085: EjbLink ejbLink = ejbDeployment.getEjbLink(ref
086: .getName());
087: if (ejbLink != null
088: && ejbLink.getDeployentId() != null /* don't overwrite with null */) {
089: ref.setMappedName(ejbLink.getDeployentId());
090: }
091: }
092:
093: for (EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
094: EjbLink ejbLink = ejbDeployment.getEjbLink(ref
095: .getName());
096: if (ejbLink != null
097: && ejbLink.getDeployentId() != null /* don't overwrite with null */) {
098: ref.setMappedName(ejbLink.getDeployentId());
099: }
100: }
101: }
102: }
103:
104: return appModule;
105: }
106: }
|