1 4 5 9 10 package org.openlaszlo.remote.soap; 11 12 import java.util.List ; 13 import java.util.Map ; 14 import java.util.Iterator ; 15 import javax.xml.namespace.QName ; 16 17 20 public class ComplexType 21 { 22 23 final static public int TYPE_UNKNOWN = 0; 24 25 26 final static public int TYPE_SIMPLE = 1; 27 28 29 final static public int TYPE_STRUCT = 2; 30 31 32 final static public int TYPE_ARRAY = 3; 33 34 35 38 QName mName; 39 40 44 int mType = TYPE_UNKNOWN; 45 46 49 ComplexType mArrayItemType = null; 50 51 54 Map mMembers = null; 55 56 59 List mMemberSequence = null; 60 61 65 ComplexType mBase = null; 66 67 68 72 public ComplexType(QName name) { 73 this(name, false); 74 } 75 76 81 public ComplexType(QName name, Map members) { 82 mName = name; 83 mType = TYPE_STRUCT; 84 setMembers(members); 85 } 86 87 93 public ComplexType(QName name, boolean isArray) { 94 mName = name; 95 mType = (isArray ? TYPE_ARRAY : TYPE_SIMPLE); 96 } 97 98 101 public boolean isArray() { 102 return mType == TYPE_ARRAY; 103 } 104 105 108 public boolean isComplex() { 109 return mType == TYPE_STRUCT; 110 } 111 112 115 public QName getName() { 116 return mName; 117 } 118 119 123 public int getType() { 124 return mType; 125 } 126 127 131 public String getTypeString() { 132 switch (mType) { 133 case TYPE_SIMPLE: return "simple"; 134 case TYPE_STRUCT: return "struct"; 135 case TYPE_ARRAY: return "array"; 136 default: 137 return "unknown"; 138 } 139 } 140 141 144 public QName getArrayItemTypeQName() { 145 return mArrayItemType != null ? mArrayItemType.getName() : null; 146 } 147 148 151 public Map getMembers() { 152 return mMembers; 153 } 154 155 159 public void setBase(ComplexType base) { 160 mBase = base; 161 } 162 163 168 public ComplexType getBase() { 169 return mBase; 170 } 171 172 175 public ComplexType getArrayItemType() { 176 return mArrayItemType; 177 } 178 179 183 public void setArrayItemType(ComplexType arrayItemType) { 184 mArrayItemType = arrayItemType; 185 } 186 187 188 191 public void setMembers(Map members) { 192 mMembers = members; 193 } 194 195 199 public void setMembers(Map members, List sequence) { 200 mMembers = members; 201 mMemberSequence = sequence; 202 } 203 204 205 208 void toMembersXML(StringBuffer sb) { 209 if (mMembers != null) { 210 sb.append("<members"); 211 if (mBase != null) { 212 sb.append(" extends=\"").append(mBase.mName).append("\""); 213 } 214 sb.append(">"); 215 216 Iterator iter = mMembers.entrySet().iterator(); 217 while (iter.hasNext()) { 218 Map.Entry entry = (Map.Entry )iter.next(); 219 String key = (String )entry.getKey(); 220 QName qname =(QName )entry.getValue(); 221 sb.append("<member") 222 .append(" name=\"").append(key).append("\"") 223 .append(" type=\"").append(qname).append("\"") 224 .append("/>"); 225 } 226 227 sb.append("</members>"); 228 } 229 } 230 231 232 235 public void toXML(StringBuffer sb) { 236 sb.append("<complex-type") 237 .append(" name=\"").append(mName).append("\"") 238 .append(" type=\"").append(getTypeString()).append("\"") 239 .append(" base=\"").append(mBase == null ? "" : mBase.mName.toString()).append("\""); 240 if (mType == TYPE_ARRAY) { 241 sb.append(" array-type=\"").append(mArrayItemType.getName()).append("\""); 242 } 243 sb.append(">"); 244 toMembersXML(sb); 245 sb.append("</complex-type>"); 246 } 247 } 248 | Popular Tags |