00001
00026 package org.objectweb.jonas_ws.wsgen.generator.axis;
00027
00028 import java.util.Enumeration;
00029 import java.util.Hashtable;
00030 import java.util.Iterator;
00031 import java.util.List;
00032 import java.util.Map;
00033 import java.util.Vector;
00034
00035 import javax.wsdl.Definition;
00036 import javax.wsdl.Port;
00037 import javax.wsdl.Service;
00038 import javax.xml.namespace.QName;
00039
00040 import org.apache.velocity.VelocityContext;
00041
00042 import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
00043
00044 import org.objectweb.jonas_ws.deployment.api.MappingFile;
00045 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
00046 import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
00047 import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
00048 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
00049
00056 public class VContextFactory {
00057
00061 public static final String PROVIDER = "provider";
00062
00066 public static final String EJB_PROVIDER = "JOnASEJB";
00067
00071 public static final String RPC_PROVIDER = "RPC";
00072
00076 public static final String MAPPINGS = "mappings";
00077
00081 public static final String PORT_COMPONENTS = "portComponents";
00082
00086 private static final String WEB_WSDL = "WEB-INF/wsdl/";
00087
00091 private static final String META_WSDL = "META-INF/wsdl/";
00092
00096 private VContextFactory() {
00097 }
00098
00107 public static VelocityContext getContext(ServiceDesc sd) {
00108
00109 VelocityContext vc = new VelocityContext();
00110
00111
00112 String wsdl;
00113 if (sd.getPortComponents().get(0) instanceof SSBPortComponentDesc) {
00114
00115 vc.put(PROVIDER, EJB_PROVIDER);
00116
00117 wsdl = sd.getWSDL().getName().substring(META_WSDL.length());
00118 } else {
00119
00120 vc.put(PROVIDER, RPC_PROVIDER);
00121
00122 wsdl = sd.getWSDL().getName().substring(WEB_WSDL.length());
00123 }
00124
00125
00126 List ports = sd.getPortComponents();
00127 List portComponents = new Vector();
00128 for (Iterator it = ports.iterator(); it.hasNext();) {
00129 PortComponentDesc pcd = (PortComponentDesc) it.next();
00130 portComponents.add(new VcPortComponent(pcd, wsdl));
00131 }
00132 vc.put(PORT_COMPONENTS, portComponents);
00133
00134
00135 List mappings = new Vector();
00136 MappingFile mf = sd.getMapping();
00137 for (Iterator m = mf.getXmlTypeMappings(); m.hasNext();) {
00138 QName xml = (QName) m.next();
00139 String classname = mf.getClassname(xml);
00140
00141
00142 if (classname.endsWith("[]")) {
00143 mappings.add(new VcArrayMapping(xml, classname));
00144 } else {
00145 mappings.add(new VcBeanMapping(xml, classname));
00146 }
00147 }
00148 vc.put(MAPPINGS, mappings);
00149
00150 return vc;
00151 }
00152
00161 public static VelocityContext getContext(ServiceRefDesc sr) {
00162
00163 VelocityContext vc = new VelocityContext();
00164
00165 Hashtable pcds = new Hashtable();
00166
00167
00168 List hrs = sr.getHandlerRefs();
00169
00170 Vector commonh = new Vector();
00171 for (Iterator itHr = hrs.iterator(); itHr.hasNext();) {
00172 HandlerDesc hr = (HandlerDesc) itHr.next();
00173 List pcns = hr.getPortNames();
00174
00175 if (pcns.size() != 0) {
00176
00177
00178 for (Iterator itPcn = pcns.iterator(); itPcn.hasNext();) {
00179 String pcn = (String) itPcn.next();
00180 if (!pcds.containsKey(pcn)) {
00181 pcds.put(pcn, new Vector());
00182 }
00183 ((Vector) pcds.get(pcn)).add(hr);
00184 }
00185 } else {
00186
00187
00188 commonh.add(hr);
00189 }
00190 }
00191
00192
00193 Vector portComponents = new Vector();
00194
00195
00196 if (pcds.isEmpty()) {
00197 Definition def = sr.getWSDLFile().getDefinition();
00198 Service s = def.getService(sr.getServiceQName());
00199 Map ports = s.getPorts();
00200
00201 for (Iterator i = ports.values().iterator(); i.hasNext();) {
00202 Port p = (Port) i.next();
00203 portComponents.add(new VcPortComponent(p.getName(), commonh));
00204 }
00205 } else {
00206 for (Enumeration enPc = pcds.keys(); enPc.hasMoreElements();) {
00207 String pcn = (String) enPc.nextElement();
00208
00209 Vector pchrs = (Vector) pcds.get(pcn);
00210 pchrs.addAll(commonh);
00211 portComponents.add(new VcPortComponent(pcn, pchrs));
00212 }
00213 }
00214
00215 vc.put(PORT_COMPONENTS, portComponents);
00216
00217
00218 List mappings = new Vector();
00219 MappingFile mf = sr.getMappingFile();
00220 if (mf != null) {
00221 for (Iterator m = mf.getXmlTypeMappings(); m.hasNext();) {
00222 QName xml = (QName) m.next();
00223 String classname = mf.getClassname(xml);
00224
00225
00226 if (classname.endsWith("[]")) {
00227 mappings.add(new VcArrayMapping(xml, classname));
00228 } else {
00229 mappings.add(new VcBeanMapping(xml, classname));
00230 }
00231 }
00232 }
00233 vc.put(MAPPINGS, mappings);
00234
00235 return vc;
00236 }
00237 }