1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice; 26 27 import java.util.ResourceBundle ; 28 import java.util.regex.Pattern ; 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 44 public class MessageEntry extends GenericTableModel.TableEntry { 45 46 public static String OPERATION_ENTRY = "OperationName"; public static String METHOD_ENTRY = "MethodName"; 49 private static final ResourceBundle webserviceBundle = ResourceBundle.getBundle( 50 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice.Bundle"); 52 56 public static Pattern methodSplitter = Pattern.compile("[\\s,\\(\\)\\[\\]]+"); 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 getEntry(CommonDDBean parent) { 68 Object 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 ) 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 value) { 86 if(value instanceof String && ((String ) 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 getEntry(CommonDDBean parent, int row) { 113 throw new UnsupportedOperationException (); 114 } 115 116 public void setEntry(CommonDDBean parent, int row, Object value) { 117 throw new UnsupportedOperationException (); 118 } 119 120 private String methodToString(JavaMethod jm) { 121 StringBuffer buf = new StringBuffer (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 [] 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 methodDesc) { 149 JavaMethod method = null; 150 151 if(Utils.notEmpty(methodDesc)) { 152 String [] 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 |