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.annotation;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.Iterator;
047: import java.util.Properties;
048:
049: import org.netbeans.modules.classfile.ClassFile;
050: import org.netbeans.modules.classfile.ClassName;
051: import org.netbeans.modules.compapp.javaee.sunresources.ResourceAggregator;
052:
053: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.EJBNode;
054: import org.netbeans.modules.compapp.javaee.sunresources.tool.cmap.MDBNode;
055:
056: /**
057: * this class is responsible for processing annotations in the javax.ejb.* package
058: *
059: * @author echou
060: *
061: */
062: public class EJBAnnotation {
063:
064: private ResourceAggregator resAggregator;
065:
066: public EJBAnnotation(ResourceAggregator resAggregator) {
067: this .resAggregator = resAggregator;
068: }
069:
070: /*
071: public EJBAnnotation(SunResourcesDDJaxbHandler sunResourcesDD) {
072: this.sunResourcesDD = sunResourcesDD;
073: }
074: **/
075:
076: /*
077: public void fillWebServiceNode(EJBNode node, Class<?> cls) {
078: WebService ws = (WebService) cls.getAnnotation(WebService.class);
079: Properties p = node.getProps();
080: p.setProperty("endpointInterface", ws.endpointInterface());
081: p.setProperty("name", ws.name());
082: p.setProperty("portName", ws.portName());
083: p.setProperty("serviceName", ws.serviceName());
084: p.setProperty("targetNamespace", ws.targetNamespace());
085: p.setProperty("wsdlLocation", ws.wsdlLocation());
086: }
087: **/
088:
089: public void fillWebServiceNode(EJBNode node, ClassFile cls) {
090: WebServiceAnnoWrapper ws = new WebServiceAnnoWrapper(
091: cls
092: .getAnnotation(ClassName
093: .getClassName(JavaEEAnnotationProcessor.WEBSERVICE_CLASSTYPE)));
094: Properties p = node.getProps();
095: p.setProperty("endpointInterface", ws.endpointInterface()); // NOI18N
096: p.setProperty("name", ws.name()); // NOI18N
097: p.setProperty("portName", ws.portName()); // NOI18N
098: p.setProperty("serviceName", ws.serviceName()); // NOI18N
099: p.setProperty("targetNamespace", ws.targetNamespace()); // NOI18N
100: p.setProperty("wsdlLocation", ws.wsdlLocation()); // NOI18N
101: }
102:
103: /*
104: public void fillStatelessNode(EJBNode node, Class<?> cls) {
105: Stateless sl = (Stateless) cls.getAnnotation(Stateless.class);
106: Properties p = node.getProps();
107: p.setProperty("description", sl.description());
108: p.setProperty("mappedName", sl.mappedName());
109: p.setProperty("name", sl.name());
110: }
111: **/
112:
113: public void fillStatelessNode(EJBNode node, ClassFile cls) {
114: StatelessAnnoWrapper sl = new StatelessAnnoWrapper(
115: cls
116: .getAnnotation(ClassName
117: .getClassName(JavaEEAnnotationProcessor.STATELESS_CLASSTYPE)));
118: Properties p = node.getProps();
119: p.setProperty("description", sl.description()); // NOI18N
120: p.setProperty("mappedName", sl.mappedName()); // NOI18N
121: p.setProperty("name", sl.name()); // NOI18N
122: }
123:
124: /*
125: public void fillStatefulNode(EJBNode node, Class<?> cls) {
126: Stateful sf = (Stateful) cls.getAnnotation(Stateful.class);
127: Properties p = node.getProps();
128: p.setProperty("description", sf.description());
129: p.setProperty("mappedName", sf.mappedName());
130: p.setProperty("name", sf.name());
131: }
132: **/
133:
134: public void fillStatefulNode(EJBNode node, ClassFile cls) {
135: StatefulAnnoWrapper sf = new StatefulAnnoWrapper(
136: cls
137: .getAnnotation(ClassName
138: .getClassName(JavaEEAnnotationProcessor.STATEFUL_CLASSTYPE)));
139: Properties p = node.getProps();
140: p.setProperty("description", sf.description()); // NOI18N
141: p.setProperty("mappedName", sf.mappedName()); // NOI18N
142: p.setProperty("name", sf.name()); // NOI18N
143: }
144:
145: /*
146: public void fillMessageDrivenNode(MDBNode node, Class<?> cls) {
147: MessageDriven md = (MessageDriven) cls.getAnnotation(MessageDriven.class);
148: Properties p = node.getProps();
149: p.setProperty("description", md.description());
150: p.setProperty("mappedName", md.mappedName());
151: p.setProperty("name", md.name());
152:
153: // fill in mappedName
154: node.setMappedName(md.mappedName());
155:
156: // fill in messageListenerInterface
157: ArrayList<Class> intfs =
158: filterExcludedEJBIntf(cls.getInterfaces());
159: if (intfs.size() == 1) {
160: node.setMsgListenerIntClassName(intfs.get(0).getName());
161: } else {
162: node.setMsgListenerIntClassName(md.messageListenerInterface().getName());
163: }
164:
165: // fill in ActivationConfig
166: Properties nodeAC = node.getActivationConfig();
167: ActivationConfigProperty[] acProps = md.activationConfig();
168: for (int i = 0; i < acProps.length; i++) {
169: nodeAC.setProperty(acProps[i].propertyName(),
170: acProps[i].propertyValue());
171: }
172:
173: // add to server resources jmsra
174: if (!sunResourcesDD.containsResource(md.mappedName())) {
175: String resType = null;
176: for (int i = 0; i < acProps.length; i++) {
177: if (acProps[i].propertyName().equals("destinationType")) {
178: resType = acProps[i].propertyValue();
179: }
180: }
181: Properties adminObjProps = new Properties();
182: adminObjProps.setProperty("Name", cls.getSimpleName());
183: sunResourcesDD.addAdminObjectResource(md.mappedName(), resType, "jmsra", adminObjProps);
184: }
185: }
186: **/
187:
188: public void fillMessageDrivenNode(MDBNode node, ClassFile cls) {
189: MessageDrivenAnnoWrapper md = new MessageDrivenAnnoWrapper(
190: cls
191: .getAnnotation(ClassName
192: .getClassName(JavaEEAnnotationProcessor.MDB_CLASSTYPE)));
193: Properties p = node.getProps();
194: p.setProperty("description", md.description()); // NOI18N
195: p.setProperty("mappedName", md.mappedName()); // NOI18N
196: p.setProperty("name", md.name()); // NOI18N
197:
198: // fill in mappedName
199: node.setMappedName(md.mappedName());
200:
201: // fill in messageListenerInterface
202: ArrayList<String> intfs = filterExcludedEJBIntf(cls
203: .getInterfaces());
204: if (intfs.size() == 1) {
205: node.setMsgListenerIntClassName(intfs.get(0));
206: } else {
207: node.setMsgListenerIntClassName(md
208: .messageListenerInterface());
209: }
210:
211: // fill in ActivationConfig
212: Properties nodeAC = node.getActivationConfig();
213: ActivationConfigPropertyAnnoWrapper[] acProps = md
214: .activationConfig();
215: for (int i = 0; i < acProps.length; i++) {
216: nodeAC.setProperty(acProps[i].propertyName(), acProps[i]
217: .propertyValue());
218: }
219:
220: // add to server resources jmsra
221: ResourceAggregator.ResourceEntry resourceEntry = resAggregator
222: .getAdminObjectResourceEntry(md.mappedName());
223: if (resourceEntry == null) {
224: String resType = null;
225: for (int i = 0; i < acProps.length; i++) {
226: if (acProps[i].propertyName().equals("destinationType")) { // NOI18N
227: resType = acProps[i].propertyValue();
228: }
229: }
230: Properties adminObjProps = new Properties();
231: adminObjProps.setProperty("Name", cls.getName()
232: .getSimpleName()); // NOI18N
233: resourceEntry = resAggregator.addAdminObjectResourceEntry(
234: md.mappedName(), resType, "jmsra", adminObjProps); // NOI18N
235: } else {
236: resourceEntry.obsolete = false;
237: resourceEntry.orphanStatus = ResourceAggregator.OrphanStatus.BOTH;
238: }
239: String sourceName = cls.getName().getPackage()
240: .replace('.', '/')
241: + "/" + cls.getSourceFileName(); // NOI18N
242: resourceEntry.addResourceUsage(sourceName, null);
243: }
244:
245: /* EJB 3.0 Simplied API, 10.1.3
246: * The messageListenerInterface element specifies the message listener
247: * interface of the bean. It must be specified if the bean class does
248: * not implement its message listener interface or implements more than
249: * one interface other than java.io.Serializable, java.io.Externalizable,
250: * or any of the interfaces defined by the javax.ejb package.
251: */
252: /*
253: public static ArrayList<Class> filterExcludedEJBIntf(Class[] intfs) {
254: ArrayList<Class> aList = new ArrayList<Class> ();
255: for (int i = 0; i < intfs.length; i++) {
256: if (intfs[i] == java.io.Serializable.class ||
257: intfs[i] == java.io.Externalizable.class ||
258: intfs[i].getName().startsWith("javax.ejb.")) {
259: continue;
260: } else {
261: aList.add(intfs[i]);
262: }
263: }
264: return aList;
265: }
266: **/
267:
268: // using NetBeans ClassFile API, input is Collection of String
269: public static ArrayList<String> filterExcludedEJBIntf(
270: Collection<ClassName> intfs) {
271: ArrayList<String> aList = new ArrayList<String>();
272: for (Iterator<ClassName> iter = intfs.iterator(); iter
273: .hasNext();) {
274: ClassName intfCN = iter.next();
275: String intf = intfCN.getExternalName();
276: if (intf.equals("java.io.Serializable") || // NOI18N
277: intf.equals("java.io.Externalizable") || // NOI18N
278: intf.startsWith("javax.ejb.")) { // NOI18N
279: continue;
280: } else {
281: aList.add(intf);
282: }
283: }
284: return aList;
285: }
286:
287: }
|