001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.javaee.sunresources.tool.archive;
043:
044: import java.util.ArrayList;
045: import java.util.Iterator;
046: import java.util.List;
047:
048: import org.netbeans.modules.compapp.javaee.sunresources.generated.ejb21.*;
049: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.CMapNode;
050: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.EJBDepend;
051: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.EJBInterface;
052: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.EJBNode;
053: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.MDBNode;
054: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.ResourceDepend;
055: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.CMapNode.CMapNodeType;
056: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.EJBInterface.EJBInterfaceType;
057: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.ResourceNode.ResourceType;
058: import org.openide.util.NbBundle;
059:
060: /**
061: * @author echou
062: *
063: */
064: public class EjbDDJaxbHandler {
065:
066: // sun-ejb-jar.xml handle
067: private SunEjbDDJaxbHandler sunEjbDD;
068: // webservices.xml handle
069: private WebservicesDDJaxbHandler webservicesDD;
070: private EjbJarType root;
071:
072: private ArrayList<CMapNode> nodes = new ArrayList<CMapNode>();
073:
074: public EjbDDJaxbHandler(Object root, SunEjbDDJaxbHandler sunEjbDD,
075: WebservicesDDJaxbHandler webservicesDD) throws Exception {
076: this .sunEjbDD = sunEjbDD;
077: this .webservicesDD = webservicesDD;
078: if (root instanceof EjbJarType) {
079: this .root = (EjbJarType) root;
080: } else {
081: throw new Exception(NbBundle.getMessage(
082: EjbDDJaxbHandler.class, "EXC_bad_jaxbroot", root
083: .getClass()));
084: }
085: init();
086: }
087:
088: private void init() {
089: // iterator through all the session, mdb, entity beans
090: for (Iterator<Object> i = root.getEnterpriseBeans()
091: .getSessionOrEntityOrMessageDriven().iterator(); i
092: .hasNext();) {
093: Object obj = i.next();
094:
095: if (obj instanceof SessionBeanType) { // Session Beans
096: SessionBeanType sb = (SessionBeanType) obj;
097: EJBNode node = new EJBNode();
098:
099: // check session type
100: if ("Stateful".equals(sb.getSessionType().getValue())) { // NOI18N
101: node.setType(CMapNodeType.STATEFUL);
102: } else if ("Stateless".equals(sb.getSessionType()
103: .getValue())) { // NOI18N
104: node.setType(CMapNodeType.STATELESS);
105: }
106: // check ejb name
107: node.setLogicalName(sb.getEjbName().getValue());
108: // check ejb class
109: node.setNodeClass(sb.getEjbClass().getValue());
110: // check local intf exists
111: if (sb.getLocal() != null) {
112: node.addImplementedIntfs(new EJBInterface(sb
113: .getLocal().getValue(),
114: EJBInterfaceType.LOCAL));
115: }
116: // check remote intf exists
117: if (sb.getRemote() != null) {
118: node.addImplementedIntfs(new EJBInterface(sb
119: .getRemote().getValue(),
120: EJBInterfaceType.REMOTE));
121: }
122: // check ejb local refs
123: checkEjbLocalRefs(node, sb.getEjbLocalRef());
124: // check ejb refs
125: checkEjbRefs(node, sb.getEjbRef());
126: // check resource refs
127: checkResourceRefs(node, sb.getResourceRef());
128: // check service refs
129: checkServiceRefs(node, sb.getServiceRef());
130: // check message destination refs
131: checkMsgDestRefs(node, sb.getMessageDestinationRef());
132: // check service endpoint exists
133: if (sb.getServiceEndpoint() != null) {
134: node.setIsWebService(true);
135: java.lang.String serviceEndpoint = sb
136: .getServiceEndpoint().getValue();
137: node.getProps().setProperty("endpointInterface",
138: serviceEndpoint); // NOI18N
139: // resolve using sunEjbDD
140: if (sunEjbDD != null) {
141: sunEjbDD.resolveWebservice(node, node
142: .getLogicalName(), serviceEndpoint,
143: webservicesDD);
144: }
145: }
146:
147: nodes.add(node);
148:
149: } else if (obj instanceof MessageDrivenBeanType) { // MDBs
150: MessageDrivenBeanType mdb = (MessageDrivenBeanType) obj;
151: MDBNode node = new MDBNode();
152: node.setType(CMapNodeType.MDB);
153: // check ejb name
154: node.setLogicalName(mdb.getEjbName().getValue());
155: // check ejb class
156: node.setNodeClass(mdb.getEjbClass().getValue());
157: // check ejb local refs
158: checkEjbLocalRefs(node, mdb.getEjbLocalRef());
159: // check ejb refs
160: checkEjbRefs(node, mdb.getEjbRef());
161: // check resource refs
162: checkResourceRefs(node, mdb.getResourceRef());
163: // check service refs
164: checkServiceRefs(node, mdb.getServiceRef());
165: // check message destination refs
166: checkMsgDestRefs(node, mdb.getMessageDestinationRef());
167: // check activation config
168: if (mdb.getActivationConfig() != null) {
169: for (Iterator<ActivationConfigPropertyType> acIter = mdb
170: .getActivationConfig()
171: .getActivationConfigProperty().iterator(); acIter
172: .hasNext();) {
173: ActivationConfigPropertyType acProp = acIter
174: .next();
175: node
176: .getActivationConfig()
177: .setProperty(
178: acProp
179: .getActivationConfigPropertyName()
180: .getValue(),
181: acProp
182: .getActivationConfigPropertyValue()
183: .getValue());
184: }
185: }
186:
187: // resolve using sunEjbDD
188: if (sunEjbDD != null) {
189: node.setMappedName(sunEjbDD.findJndiByEjbName(node
190: .getLogicalName()));
191: }
192:
193: nodes.add(node);
194:
195: } else if (obj instanceof EntityBeanType) {
196: // ignore entity beans for now
197: }
198: }
199: }
200:
201: // check ejb local refs
202: private void checkEjbLocalRefs(CMapNode node,
203: List<EjbLocalRefType> localRefs) {
204: for (Iterator<EjbLocalRefType> lrefIter = localRefs.iterator(); lrefIter
205: .hasNext();) {
206: EjbLocalRefType localRef = lrefIter.next();
207: EJBDepend ejbDepend = new EJBDepend(node);
208: ejbDepend.setTargetIntfName(localRef.getLocal().getValue());
209: node.getEjbDepends().add(ejbDepend);
210: }
211: }
212:
213: // check ejb refs
214: private void checkEjbRefs(CMapNode node, List<EjbRefType> refs) {
215: for (Iterator<EjbRefType> refIter = refs.iterator(); refIter
216: .hasNext();) {
217: EjbRefType ref = refIter.next();
218: EJBDepend ejbDepend = new EJBDepend(node);
219: ejbDepend.setTargetIntfName(ref.getRemote().getValue());
220: node.getEjbDepends().add(ejbDepend);
221: }
222: }
223:
224: // check resource refs
225: private void checkResourceRefs(CMapNode node,
226: List<ResourceRefType> resRefs) {
227: for (Iterator<ResourceRefType> resRefIter = resRefs.iterator(); resRefIter
228: .hasNext();) {
229: ResourceRefType resRef = resRefIter.next();
230: java.lang.String resRefName = resRef.getResRefName()
231: .getValue();
232: java.lang.String resType = resRef.getResType().getValue();
233: if (ignoreResType(resType)) {
234: // if this resource ref points to jms connection factory
235: // we need to ignore them, since we want the destination
236: // instead
237: continue;
238: }
239: ResourceDepend resDepend = new ResourceDepend(node);
240: resDepend.setType(ResourceType.OTHER);
241: resDepend.setTargetResType(resType);
242: // resolve using sunEjbDD
243: if (sunEjbDD != null) {
244: java.lang.String jndi = sunEjbDD.resolveResRef(node
245: .getLogicalName(), resRefName);
246: resDepend.setMappedName(jndi);
247: resDepend.setTargetResJndiName(jndi);
248: } else {
249: resDepend.setMappedName(resRefName);
250: }
251: node.getResDepends().add(resDepend);
252: }
253: }
254:
255: // check service refs
256: private void checkServiceRefs(CMapNode node,
257: List<ServiceRefType> serviceRefs) {
258: // TODO
259: }
260:
261: // check message destination refs
262: private void checkMsgDestRefs(CMapNode node,
263: List<MessageDestinationRefType> msgDestRefs) {
264: for (Iterator<MessageDestinationRefType> msgDestRefIter = msgDestRefs
265: .iterator(); msgDestRefIter.hasNext();) {
266: MessageDestinationRefType msgDestRef = msgDestRefIter
267: .next();
268: java.lang.String msgDestRefName = msgDestRef
269: .getMessageDestinationRefName().getValue();
270: java.lang.String msgDestRefType = msgDestRef
271: .getMessageDestinationType().getValue();
272: java.lang.String msgDestRefLink = msgDestRef
273: .getMessageDestinationLink().getValue();
274: ResourceDepend resDepend = new ResourceDepend(node);
275: resDepend.setType(ResourceType.JMS);
276: resDepend.setTargetResType(msgDestRefType);
277: // resolve using sunEjbDD
278: if (sunEjbDD != null) {
279: java.lang.String jndi = sunEjbDD.resolveMsgDestRef(node
280: .getLogicalName(), msgDestRefLink);
281: resDepend.setMappedName(jndi);
282: resDepend.setTargetResJndiName(jndi);
283: } else {
284: resDepend.setMappedName(msgDestRefName);
285: }
286: node.getResDepends().add(resDepend);
287: }
288: }
289:
290: private boolean ignoreResType(java.lang.String resType) {
291: if (resType.equals("javax.jms.ConnectionFactory") || // NOI18N
292: resType.equals("javax.jms.QueueConnectionFactory") || // NOI18N
293: resType.equals("javax.jms.TopicConnectionFactory") // NOI18N
294: ) {
295: return true;
296: } else {
297: return false;
298: }
299: }
300:
301: public ArrayList<CMapNode> getNodes() {
302: return this.nodes;
303: }
304: }
|