1 24 package org.ofbiz.service; 25 26 import java.util.List ; 27 import java.util.Locale ; 28 import java.io.Serializable ; 29 30 import javax.wsdl.WSDLException; 31 import javax.wsdl.Part; 32 import javax.wsdl.Definition; 33 import javax.xml.namespace.QName ; 34 35 import org.ofbiz.base.util.UtilProperties; 36 import org.ofbiz.base.util.ObjectType; 37 38 46 public class ModelParam implements Serializable { 47 48 49 public String name; 50 51 52 public String type; 53 54 55 public String mode; 56 57 58 public String formLabel; 59 60 61 public String entityName; 62 63 64 public String fieldName; 65 66 67 public String stringMapPrefix; 68 69 70 public String stringListSuffix; 71 72 73 public List validators; 74 75 76 public boolean optional = false; 77 public boolean overrideOptional = false; 78 79 80 public boolean formDisplay = true; 81 public boolean overrideFormDisplay = false; 82 83 84 public boolean internal = false; 85 86 public ModelParam() {} 87 88 public ModelParam(ModelParam param) { 89 this.name = param.name; 90 this.type = param.type; 91 this.mode = param.mode; 92 this.formLabel = param.formLabel; 93 this.entityName = param.entityName; 94 this.fieldName = param.fieldName; 95 this.stringMapPrefix = param.stringMapPrefix; 96 this.stringListSuffix = param.stringListSuffix; 97 this.validators = param.validators; 98 this.optional = param.optional; 99 this.overrideOptional = param.overrideOptional; 100 this.formDisplay = param.formDisplay; 101 this.overrideFormDisplay = param.overrideFormDisplay; 102 this.internal = param.internal; 103 } 104 105 public void addValidator(String className, String methodName, String failMessage) { 106 validators.add(new ModelParamValidator(className, methodName, failMessage, null, null)); 107 } 108 109 public void addValidator(String className, String methodName, String failResource, String failProperty) { 110 validators.add(new ModelParamValidator(className, methodName, null, failResource, failProperty)); 111 } 112 113 public String getPrimaryFailMessage(Locale locale) { 114 if (validators != null && validators.size() > 0) { 115 return ((ModelParamValidator) validators.get(0)).getFailMessage(locale); 116 } else { 117 return null; 118 } 119 } 120 121 public boolean equals(ModelParam model) { 122 if (model.name.equals(this.name)) 123 return true; 124 return false; 125 } 126 127 public String toString() { 128 StringBuffer buf = new StringBuffer (); 129 buf.append(name + "::"); 130 buf.append(type + "::"); 131 buf.append(mode + "::"); 132 buf.append(formLabel + "::"); 133 buf.append(entityName + "::"); 134 buf.append(fieldName + "::"); 135 buf.append(stringMapPrefix + "::"); 136 buf.append(stringListSuffix + "::"); 137 buf.append(validators.toString() + "::"); 138 buf.append(optional + "::"); 139 buf.append(overrideOptional + "::"); 140 buf.append(formDisplay + "::"); 141 buf.append(overrideFormDisplay + "::"); 142 buf.append(internal); 143 return buf.toString(); 144 } 145 146 public Part getWSDLPart(Definition def) throws WSDLException { 147 Part part = def.createPart(); 148 part.setName(this.name); 149 part.setTypeName(new QName (ModelService.XSD, this.java2wsdlType())); 150 return part; 151 } 152 153 protected String java2wsdlType() throws WSDLException { 154 if (ObjectType.instanceOf(java.lang.Character .class, this.type)) { 155 return "string"; 156 } else if (ObjectType.instanceOf(java.lang.String .class, this.type)) { 157 return "string"; 158 } else if (ObjectType.instanceOf(java.lang.Byte .class, this.type)) { 159 return "byte"; 160 } else if (ObjectType.instanceOf(java.lang.Boolean .class, this.type)) { 161 return "boolean"; 162 } else if (ObjectType.instanceOf(java.lang.Integer .class, this.type)) { 163 return "int"; 164 } else if (ObjectType.instanceOf(java.lang.Double .class, this.type)) { 165 return "double"; 166 } else if (ObjectType.instanceOf(java.lang.Float .class, this.type)) { 167 return "float"; 168 } else if (ObjectType.instanceOf(java.lang.Short .class, this.type)) { 169 return "short"; 170 } else if (ObjectType.instanceOf(java.math.BigDecimal .class, this.type)) { 171 return "decimal"; 172 } else if (ObjectType.instanceOf(java.math.BigInteger .class, this.type)) { 173 return "integer"; 174 } else if (ObjectType.instanceOf(java.util.Calendar .class, this.type)) { 175 return "dateTime"; 176 } else if (ObjectType.instanceOf(java.util.Date .class, this.type)) { 177 return "dateTime"; 178 } 179 throw new WSDLException(WSDLException.OTHER_ERROR, "Service cannot be described with WSDL (" + this.name + " / " + this.type + ")"); 181 } 182 183 static class ModelParamValidator implements Serializable { 184 protected String className; 185 protected String methodName; 186 protected String failMessage; 187 protected String failResource; 188 protected String failProperty; 189 190 public ModelParamValidator(String className, String methodName, String failMessage, String failResource, String failProperty) { 191 this.className = className; 192 this.methodName = methodName; 193 this.failMessage = failMessage; 194 this.failResource = failResource; 195 this.failProperty = failProperty; 196 } 197 198 public String getClassName() { 199 return className; 200 } 201 202 public String getMethodName() { 203 return methodName; 204 } 205 206 public String getFailMessage(Locale locale) { 207 if (failMessage != null) { 208 return this.failMessage; 209 } else { 210 if (failResource != null && failProperty != null) { 211 return UtilProperties.getMessage(failResource, failProperty, locale); 212 } 213 } 214 return null; 215 } 216 217 public String toString() { 218 return className + "::" + methodName + "::" + failMessage + "::" + failResource + "::" + failProperty; 219 } 220 } 221 } 222 | Popular Tags |