1 2 package test.rpc; 3 4 import org.apache.axis.client.Call; 5 import org.apache.axis.client.Service; 6 import org.apache.axis.encoding.ser.BeanDeserializerFactory; 7 import org.apache.axis.encoding.ser.BeanSerializerFactory; 8 9 import javax.xml.namespace.QName ; 10 import javax.xml.rpc.ParameterMode ; 11 import java.util.Calendar ; 12 13 public final class IF2SOAPProxy implements IF2SOAP 14 { 15 private String m_service; 16 private String m_url; 17 private QName m_beanQName; 18 private QName m_beanArrayQName; 19 private QName m_stringArrayQName; 20 private QName m_calendarArrayQName; 21 22 public IF2SOAPProxy(String service, String url) 23 { 24 m_service = service; 25 m_url = url; 26 m_beanQName = new QName ("urn:" + m_service, "Bean"); 27 m_beanArrayQName = new QName ("urn:" + m_service, "Bean[]"); 28 m_stringArrayQName = new QName ("urn:" + m_service, "String[]"); 29 m_calendarArrayQName = new QName ("urn:" + m_service, "Calendar[]"); 30 } 31 32 public IF1 getBeanById(String id) 33 throws Exception 34 { 35 IF1 bean = null; 36 37 if (id == null) 38 throw new Exception ("invalid id"); 39 40 Call call = getCall(); 41 call.setTargetEndpointAddress(m_url); 42 call.setOperationName(new QName (m_service, "getBeanById")); 43 call.addParameter("id", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN); 44 call.setReturnType(m_beanQName); 45 bean = (IF1) call.invoke(new Object [] { id }); 46 47 return bean; 48 } 49 50 public IF1[] getAllBeans() 51 throws Exception 52 { 53 return getAllBeans(null); 54 } 55 56 public IF1[] getAllBeans(String [] filter) 57 throws Exception 58 { 59 IF1[] beans = null; 60 61 Call call = getCall(); 62 call.setTargetEndpointAddress(m_url); 63 call.setOperationName(new QName (m_service, "getAllBeans")); 64 call.setReturnType(m_beanArrayQName); 65 if (filter == null) 66 beans = (IF1[]) call.invoke(new Object [0]); 67 else 68 { 69 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN); 70 beans = (IF1[]) call.invoke(new Object [] { filter }); 71 } 72 73 return beans; 74 } 75 76 public String [] getAllCategories() 77 throws Exception 78 { 79 String [] categories = null; 80 81 Call call = getCall(); 82 call.setTargetEndpointAddress(m_url); 83 call.setOperationName(new QName (m_service, "getAllCategories")); 84 call.setReturnType(m_stringArrayQName); 85 categories = (String []) call.invoke(new Object [0]); 86 87 return categories; 88 } 89 90 public IF1[] getBeansByCategory(String category) 91 throws Exception 92 { 93 return getBeansByCategory(category, null); 94 } 95 96 public IF1[] getBeansByCategory(String category, String [] filter) 97 throws Exception 98 { 99 IF1[] beans = null; 100 101 if (category == null) 102 throw new Exception ("invalid category"); 103 104 Call call = getCall(); 105 call.setTargetEndpointAddress(m_url); 106 call.setOperationName(new QName (m_service, "getBeansByCategory")); 107 call.setReturnType(m_beanArrayQName); 108 call.addParameter("category", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN); 109 if (filter == null) 110 beans = (IF1[]) call.invoke(new Object [] { category }); 111 else 112 { 113 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN); 114 beans = (IF1[]) call.invoke(new Object [] { category, filter }); 115 } 116 117 return beans; 118 } 119 120 public IF1[] getBeansByDate(Calendar [] dates) 121 throws Exception 122 { 123 return getBeansByDate(dates, null); 124 } 125 126 public IF1[] getBeansByDate(Calendar [] dates, String [] filter) 127 throws Exception 128 { 129 IF1[] beans = null; 130 131 if (dates == null) 132 throw new Exception ("invalid dates"); 133 134 Call call = getCall(); 135 call.setTargetEndpointAddress(m_url); 136 call.setOperationName(new QName (m_service, "getBeansByDate")); 137 call.setReturnType(m_beanArrayQName); 138 call.addParameter("dates", m_calendarArrayQName, ParameterMode.IN); 139 if (filter == null) 140 beans = (IF1[]) call.invoke(new Object [] { dates }); 141 else 142 { 143 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN); 144 beans = (IF1[]) call.invoke(new Object [] { dates, filter }); 145 } 146 147 return beans; 148 } 149 150 public IF1[] getBeansByExpression(int expType, String expression) 151 throws Exception 152 { 153 return getBeansByExpression(expType, expression, null); 154 } 155 156 public IF1[] getBeansByExpression(int expType, String expression, String [] filter) 157 throws Exception 158 { 159 IF1[] beans = null; 160 161 if (expression == null) 162 throw new Exception ("invalid expression"); 163 164 Call call = getCall(); 165 call.setTargetEndpointAddress(m_url); 166 call.setOperationName(new QName (m_service, "getBeansByExpression")); 167 call.setReturnType(m_beanArrayQName); 168 call.addParameter("expType", org.apache.axis.Constants.XSD_INT, ParameterMode.IN); 169 call.addParameter("expression", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN); 170 if (filter == null) 171 beans = (IF1[]) call.invoke(new Object [] { new Integer (expType), expression }); 172 else 173 { 174 call.addParameter("filter", m_stringArrayQName, ParameterMode.IN); 175 beans = (IF1[]) call.invoke(new Object [] { new Integer (expType), expression, filter }); 176 } 177 178 return beans; 179 } 180 181 public String getXMLForBean(IF1 bean) 182 throws Exception 183 { 184 String xml = null; 185 186 if (bean == null) 187 throw new Exception ("invalid bean"); 188 189 Call call = getCall(); 190 call.setTargetEndpointAddress(m_url); 191 call.setOperationName(new QName (m_service, "getXMLForBean")); 192 call.addParameter("bean", m_beanQName, ParameterMode.IN); 193 call.setReturnType(org.apache.axis.Constants.XSD_STRING); 194 xml = (String ) call.invoke(new Object [] { bean }); 195 196 return xml; 197 } 198 199 private Call getCall() 200 throws Exception 201 { 202 Call call = null; 203 Service service = new Service(); 204 call = (Call) service.createCall(); 205 206 call.registerTypeMapping(Bean.class, m_beanQName, 207 new BeanSerializerFactory(Bean.class, m_beanQName), 208 new BeanDeserializerFactory(Bean.class, m_beanQName)); 209 return call; 210 } 211 } 212 213 | Popular Tags |