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.EjbJar;
020: import org.apache.openejb.jee.EnterpriseBean;
021: import org.apache.openejb.jee.MessageDestinationRef;
022: import org.apache.openejb.jee.PersistenceContextRef;
023: import org.apache.openejb.jee.PersistenceUnitRef;
024: import org.apache.openejb.jee.ResourceRef;
025: import org.apache.openejb.jee.ResourceEnvRef;
026: import org.apache.openejb.jee.ServiceRef;
027: import org.apache.openejb.jee.EjbRef;
028:
029: /**
030: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
031: */
032: public class GeronimoMappedName implements DynamicDeployer {
033:
034: private static final String MAPPED_NAME_PREFIX = "jndi:java:comp/geronimo/env/";
035:
036: public GeronimoMappedName() {
037: }
038:
039: public AppModule deploy(AppModule appModule)
040: throws OpenEJBException {
041: mapReferences(appModule);
042: return appModule;
043: }
044:
045: private void mapReferences(AppModule appModule) {
046: for (EjbModule ejbModule : appModule.getEjbModules()) {
047: mapReferences(ejbModule.getEjbJar());
048: }
049: }
050:
051: private void mapReferences(EjbJar ejbJar) {
052: if (ejbJar == null) {
053: return;
054: }
055:
056: for (EnterpriseBean enterpriseBean : ejbJar
057: .getEnterpriseBeans()) {
058: for (EjbRef ref : enterpriseBean.getEjbRef()) {
059: // remap only corba references
060: String mappedName = ref.getMappedName();
061: if (mappedName != null
062: && (mappedName.startsWith("jndi:corbaloc") || mappedName
063: .startsWith("jndi:corbaname"))) {
064: String refName = ref.getEjbRefName();
065: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
066: }
067: if (null == mappedName
068: && ref.getEjbRefName().equals("ejb/MEJB")) {
069: ref.setMappedName("mejb/ejb/mgmt/MEJB");
070: }
071: }
072: for (MessageDestinationRef ref : enterpriseBean
073: .getMessageDestinationRef()) {
074: String refName = ref.getMessageDestinationRefName();
075: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
076: }
077: for (PersistenceContextRef ref : enterpriseBean
078: .getPersistenceContextRef()) {
079: String refName = ref.getPersistenceContextRefName();
080: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
081: }
082: for (PersistenceUnitRef ref : enterpriseBean
083: .getPersistenceUnitRef()) {
084: String refName = ref.getPersistenceUnitRefName();
085: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
086: }
087: for (ResourceRef ref : enterpriseBean.getResourceRef()) {
088: String refName = ref.getResRefName();
089: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
090: }
091: for (ResourceEnvRef ref : enterpriseBean
092: .getResourceEnvRef()) {
093: String refName = ref.getResourceEnvRefName();
094: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
095: }
096: for (ServiceRef ref : enterpriseBean.getServiceRef()) {
097: String refName = ref.getServiceRefName();
098: ref.setMappedName(MAPPED_NAME_PREFIX + refName);
099: }
100: }
101: }
102:
103: }
|