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.jee.sun.JaxbSun;
019: import org.apache.openejb.jee.sun.SunEjbJar;
020: import org.apache.openejb.jee.sun.SunCmpMappings;
021: import org.apache.openejb.jee.sun.ResourceRef;
022: import org.apache.openejb.jee.sun.ResourceEnvRef;
023: import org.apache.openejb.jee.sun.MessageDestinationRef;
024: import org.apache.openejb.jee.sun.PortInfo;
025: import org.apache.openejb.jee.sun.StubProperty;
026: import org.apache.openejb.jee.sun.SunCmpMapping;
027: import org.apache.openejb.jee.sun.WebserviceEndpoint;
028: import org.apache.openejb.jee.sun.Ejb;
029: import org.apache.openejb.jee.sun.Cmp;
030: import org.apache.openejb.jee.sun.OneOneFinders;
031: import org.apache.openejb.jee.sun.Finder;
032: import org.apache.openejb.jee.sun.EntityMapping;
033: import org.apache.openejb.jee.sun.ColumnPair;
034: import org.apache.openejb.jee.sun.CmpFieldMapping;
035: import org.apache.openejb.jee.sun.ColumnName;
036: import org.apache.openejb.jee.sun.CmrFieldMapping;
037: import org.apache.openejb.jee.ServiceRef;
038: import org.apache.openejb.jee.PortComponentRef;
039: import org.apache.openejb.jee.WebserviceDescription;
040: import org.apache.openejb.jee.PortComponent;
041: import org.apache.openejb.jee.EjbJar;
042: import org.apache.openejb.jee.EnterpriseBean;
043: import org.apache.openejb.jee.ServiceImplBean;
044: import org.apache.openejb.jee.EntityBean;
045: import org.apache.openejb.jee.PersistenceType;
046: import org.apache.openejb.jee.CmpField;
047: import org.apache.openejb.jee.wls.JaxbWls;
048: import org.apache.openejb.jee.wls.WeblogicEjbJar;
049: import org.apache.openejb.jee.wls.WeblogicEnterpriseBean;
050: import org.apache.openejb.jee.oejb3.OpenejbJar;
051: import org.apache.openejb.jee.oejb3.EjbDeployment;
052: import org.apache.openejb.jee.oejb3.EjbLink;
053: import org.apache.openejb.jee.oejb3.ResourceLink;
054: import org.apache.openejb.jee.oejb3.Jndi;
055: import org.apache.openejb.jee.jpa.EntityMappings;
056: import org.apache.openejb.jee.jpa.Entity;
057: import org.apache.openejb.jee.jpa.NamedQuery;
058: import org.apache.openejb.jee.jpa.Table;
059: import org.apache.openejb.jee.jpa.SecondaryTable;
060: import org.apache.openejb.jee.jpa.PrimaryKeyJoinColumn;
061: import org.apache.openejb.jee.jpa.Field;
062: import org.apache.openejb.jee.jpa.Column;
063: import org.apache.openejb.jee.jpa.RelationField;
064: import org.apache.openejb.jee.jpa.OneToOne;
065: import org.apache.openejb.jee.jpa.JoinColumn;
066: import org.apache.openejb.jee.jpa.OneToMany;
067: import org.apache.openejb.jee.jpa.ManyToOne;
068: import org.apache.openejb.jee.jpa.JoinTable;
069: import org.apache.openejb.jee.jpa.Id;
070: import org.apache.openejb.jee.jpa.Attributes;
071: import org.apache.openejb.jee.jpa.Basic;
072: import org.apache.openejb.jee.jpa.AttributeOverride;
073:
074: import javax.xml.bind.JAXBElement;
075: import java.io.ByteArrayInputStream;
076: import java.net.URL;
077: import java.util.Map;
078: import java.util.TreeMap;
079: import java.util.HashMap;
080: import java.util.Collection;
081: import java.util.ArrayList;
082: import java.util.List;
083: import java.util.Collections;
084: import java.util.StringTokenizer;
085: import java.util.Arrays;
086: import java.util.LinkedList;
087:
088: public class WlsConversion implements DynamicDeployer {
089: public AppModule deploy(AppModule appModule) {
090: for (EjbModule ejbModule : appModule.getEjbModules()) {
091: convertModule(ejbModule, appModule.getCmpMappings());
092: }
093: return appModule;
094: }
095:
096: private <T> T getDescriptor(EjbModule ejbModule, String descriptor,
097: Class<T> type) {
098: Object altDD = ejbModule.getAltDDs().get(descriptor);
099: if (altDD instanceof String) {
100: try {
101: altDD = JaxbWls.unmarshal(type,
102: new ByteArrayInputStream(((String) altDD)
103: .getBytes()));
104: } catch (Exception e) {
105: // todo warn about not being able to parse sun descriptor
106: }
107: }
108: if (altDD instanceof URL) {
109: try {
110: altDD = JaxbWls.unmarshal(type, ((URL) altDD)
111: .openStream());
112: } catch (Exception e) {
113: e.printStackTrace();
114: // todo warn about not being able to parse sun descriptor
115: }
116: }
117: if (altDD == null)
118: return null;
119: if (altDD instanceof JAXBElement) {
120: JAXBElement jaxbElement = (JAXBElement) altDD;
121: altDD = jaxbElement.getValue();
122: }
123: return (T) altDD;
124: }
125:
126: public void convertModule(EjbModule ejbModule,
127: EntityMappings entityMappings) {
128:
129: // merge data from weblogic-ejb-jar.xml file
130: WeblogicEjbJar weblogicEjbJar = getDescriptor(ejbModule,
131: "weblogic-ejb-jar.xml", WeblogicEjbJar.class);
132: mergeEjbConfig(ejbModule, weblogicEjbJar);
133:
134: }
135:
136: private void mergeEjbConfig(EjbModule ejbModule,
137: WeblogicEjbJar weblogicEjbJar) {
138: EjbJar ejbJar = ejbModule.getEjbJar();
139: OpenejbJar openejbJar = ejbModule.getOpenejbJar();
140:
141: if (openejbJar == null)
142: return;
143: if (weblogicEjbJar == null)
144: return;
145: if (weblogicEjbJar.getWeblogicEnterpriseBean().size() == 0)
146: return;
147:
148: for (WeblogicEnterpriseBean ejb : weblogicEjbJar
149: .getWeblogicEnterpriseBean()) {
150:
151: EjbDeployment deployment = openejbJar
152: .getDeploymentsByEjbName().get(ejb.getEjbName());
153: if (deployment == null) {
154: // warn no matching deployment
155: continue;
156: }
157:
158: // JNDI name of the remote home (legacy remote interface)
159: if (ejb.getJndiName() != null) {
160: deployment.getJndi().add(
161: new Jndi(ejb.getJndiName(), "RemoteHome"));
162: }
163:
164: // JNDI name of the remote home (legacy remote interface)
165: if (ejb.getLocalJndiName() != null) {
166: deployment.getJndi().add(
167: new Jndi(ejb.getLocalJndiName(), "LocalHome"));
168: }
169:
170: // TODO: What would be the default JNDI name for a business remote interface?
171: //deployment.getJndi().add(new Jndi("{theFormat}", "Remote"));
172:
173: // TODO: What would be the default JNDI name for a business local interface?
174: //deployment.getJndi().add(new Jndi("{theFormat}", "Local"));
175:
176: }
177: }
178:
179: }
|