KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > webservice > MessageEntry


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * MessageEntry.java
21  *
22  * Created on May 17, 2006, 6:28 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice;
26
27 import java.util.ResourceBundle JavaDoc;
28 import java.util.regex.Pattern JavaDoc;
29
30 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
31 import org.netbeans.modules.j2ee.sun.dd.api.common.JavaMethod;
32 import org.netbeans.modules.j2ee.sun.dd.api.common.Message;
33 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageSecurity;
34 import org.netbeans.modules.j2ee.sun.dd.api.common.MethodParams;
35 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
36
37 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
38
39
40 /**
41  *
42  * @author Peter Williams
43  */

44 public class MessageEntry extends GenericTableModel.TableEntry {
45
46     public static String JavaDoc OPERATION_ENTRY = "OperationName"; // NOI18N
47
public static String JavaDoc METHOD_ENTRY = "MethodName"; // NOI18N
48

49     private static final ResourceBundle JavaDoc webserviceBundle = ResourceBundle.getBundle(
50         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice.Bundle"); // NOI18N
51

52     /** Pattern to split a string representing a JavaMethod up into it's component parts.
53      * This simply breaks the string up on whitespace, commas, left/right parentheses
54      * and left/right square brackets.
55      */

56     public static Pattern JavaDoc methodSplitter = Pattern.compile("[\\s,\\(\\)\\[\\]]+"); // NOI18N
57

58     private boolean saveAsOperation;
59     
60     public MessageEntry(boolean useOperations) {
61         super(null, MessageSecurity.MESSAGE, webserviceBundle,
62                 useOperations ? OPERATION_ENTRY : METHOD_ENTRY, true, true);
63         
64         saveAsOperation = useOperations;
65     }
66
67     public Object JavaDoc getEntry(CommonDDBean parent) {
68         Object JavaDoc result = null;
69
70         CommonDDBean [] message = (CommonDDBean []) parent.getValues(propertyName);
71         if(message != null && message.length > 0 && message[0] != null) {
72             if(saveAsOperation) {
73                 result = message[0].getValue(Message.OPERATION_NAME);
74             } else {
75                 result = methodToString((JavaMethod) message[0].getValue(Message.JAVA_METHOD));
76                 if(!Utils.notEmpty((String JavaDoc) result)) {
77                     result = message[0].getValue(Message.OPERATION_NAME);
78                 }
79             }
80         }
81
82         return result;
83     }
84     
85     public void setEntry(CommonDDBean parent, Object JavaDoc value) {
86         // Set blank strings to null. This object also handles message-security-binding
87
// though, so we have to check it out.
88
if(value instanceof String JavaDoc && ((String JavaDoc) value).length() == 0) {
89             value = null;
90         }
91
92         CommonDDBean [] m = (CommonDDBean []) parent.getValues(propertyName);
93         if(value != null) {
94             if(m == null || m.length == 0 || m[0] == null) {
95                 MessageSecurity ms = (MessageSecurity) parent;
96                 m = new Message [] { ms.newMessage() };
97                 parent.setValue(propertyName, m);
98             }
99
100             if(saveAsOperation) {
101                 m[0].setValue(Message.OPERATION_NAME, value);
102             } else {
103                 m[0].setValue(Message.JAVA_METHOD, stringToMethod((Message) m[0], value.toString()));
104             }
105         } else {
106             if(m != null) {
107                 parent.setValue(propertyName, null);
108             }
109         }
110     }
111
112     public Object JavaDoc getEntry(CommonDDBean parent, int row) {
113         throw new UnsupportedOperationException JavaDoc();
114     }
115
116     public void setEntry(CommonDDBean parent, int row, Object JavaDoc value) {
117         throw new UnsupportedOperationException JavaDoc();
118     }
119     
120     private String JavaDoc methodToString(JavaMethod jm) {
121         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(128);
122
123         if(jm != null) {
124             buf.append(jm.getMethodName());
125             
126             MethodParams mps = jm.getMethodParams();
127             if(mps != null && mps.sizeMethodParam() > 0) {
128                 buf.append("(");
129                 String JavaDoc [] params = mps.getMethodParam();
130                 for(int i = 0; i < params.length; i++) {
131                     if(i > 0) {
132                         buf.append(", ");
133                     }
134                     
135                     if(Utils.notEmpty(params[i])) {
136                         buf.append(params[i]);
137                     } else {
138                         buf.append(" ");
139                     }
140                 }
141                 buf.append(")");
142             }
143         }
144         
145         return buf.toString();
146     }
147     
148     private JavaMethod stringToMethod(Message m, String JavaDoc methodDesc) {
149         JavaMethod method = null;
150         
151         if(Utils.notEmpty(methodDesc)) {
152             String JavaDoc [] parts = methodSplitter.split(methodDesc);
153             if(parts.length > 0) {
154                 method = m.newJavaMethod();
155                 method.setMethodName(parts[0]);
156                 
157                 if(parts.length > 1) {
158                     MethodParams mps = method.newMethodParams();
159                     for(int i = 1; i < parts.length; i++) {
160                         mps.addMethodParam(parts[i]);
161                     }
162                     method.setMethodParams(mps);
163                 }
164             }
165         }
166         
167         return method;
168     }
169 }
170
Popular Tags