1 25 26 package org.objectweb.jonas_ws.wsgen.generator.axis; 27 28 import java.util.Enumeration ; 29 import java.util.Hashtable ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Map ; 33 import java.util.Vector ; 34 35 import javax.wsdl.Definition; 36 import javax.wsdl.Port; 37 import javax.wsdl.Service; 38 import javax.xml.namespace.QName ; 39 40 import org.apache.velocity.VelocityContext; 41 42 import org.objectweb.jonas_lib.deployment.api.HandlerDesc; 43 44 import org.objectweb.jonas_ws.deployment.api.MappingFile; 45 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc; 46 import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc; 47 import org.objectweb.jonas_ws.deployment.api.ServiceDesc; 48 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 49 50 56 public class VContextFactory { 57 58 61 public static final String PROVIDER = "provider"; 62 63 66 public static final String EJB_PROVIDER = "JOnASEJB"; 67 68 71 public static final String RPC_PROVIDER = "RPC"; 72 73 76 public static final String MAPPINGS = "mappings"; 77 78 81 public static final String PORT_COMPONENTS = "portComponents"; 82 83 86 private static final String WEB_WSDL = "WEB-INF/wsdl/"; 87 88 91 private static final String META_WSDL = "META-INF/wsdl/"; 92 93 96 private VContextFactory() { 97 } 98 99 107 public static VelocityContext getContext(ServiceDesc sd) { 108 109 VelocityContext vc = new VelocityContext(); 110 111 String wsdl; 113 if (sd.getPortComponents().get(0) instanceof SSBPortComponentDesc) { 114 vc.put(PROVIDER, EJB_PROVIDER); 116 wsdl = sd.getWSDL().getName().substring(META_WSDL.length()); 118 } else { 119 vc.put(PROVIDER, RPC_PROVIDER); 121 wsdl = sd.getWSDL().getName().substring(WEB_WSDL.length()); 123 } 124 125 List ports = sd.getPortComponents(); 127 List portComponents = new Vector (); 128 for (Iterator it = ports.iterator(); it.hasNext();) { 129 PortComponentDesc pcd = (PortComponentDesc) it.next(); 130 portComponents.add(new VcPortComponent(pcd, wsdl)); 131 } 132 vc.put(PORT_COMPONENTS, portComponents); 133 134 List mappings = new Vector (); 136 MappingFile mf = sd.getMapping(); 137 for (Iterator m = mf.getXmlTypeMappings(); m.hasNext();) { 138 QName xml = (QName ) m.next(); 139 String classname = mf.getClassname(xml); 140 141 if (classname.endsWith("[]")) { 143 mappings.add(new VcArrayMapping(xml, classname)); 144 } else { 145 mappings.add(new VcBeanMapping(xml, classname)); 146 } 147 } 148 vc.put(MAPPINGS, mappings); 149 150 return vc; 151 } 152 153 161 public static VelocityContext getContext(ServiceRefDesc sr) { 162 163 VelocityContext vc = new VelocityContext(); 164 165 Hashtable pcds = new Hashtable (); 166 167 List hrs = sr.getHandlerRefs(); 169 170 Vector commonh = new Vector (); 171 for (Iterator itHr = hrs.iterator(); itHr.hasNext();) { 172 HandlerDesc hr = (HandlerDesc) itHr.next(); 173 List pcns = hr.getPortNames(); 174 175 if (pcns.size() != 0) { 176 for (Iterator itPcn = pcns.iterator(); itPcn.hasNext();) { 179 String pcn = (String ) itPcn.next(); 180 if (!pcds.containsKey(pcn)) { 181 pcds.put(pcn, new Vector ()); 182 } 183 ((Vector ) pcds.get(pcn)).add(hr); 184 } 185 } else { 186 commonh.add(hr); 189 } 190 } 191 192 Vector portComponents = new Vector (); 194 195 if (pcds.isEmpty()) { 197 Definition def = sr.getWSDLFile().getDefinition(); 198 Service s = def.getService(sr.getServiceQName()); 199 Map ports = s.getPorts(); 200 for (Iterator i = ports.values().iterator(); i.hasNext();) { 202 Port p = (Port) i.next(); 203 portComponents.add(new VcPortComponent(p.getName(), commonh)); 204 } 205 } else { 206 for (Enumeration enPc = pcds.keys(); enPc.hasMoreElements();) { 207 String pcn = (String ) enPc.nextElement(); 208 Vector pchrs = (Vector ) pcds.get(pcn); 210 pchrs.addAll(commonh); 211 portComponents.add(new VcPortComponent(pcn, pchrs)); 212 } 213 } 214 215 vc.put(PORT_COMPONENTS, portComponents); 216 217 List mappings = new Vector (); 219 MappingFile mf = sr.getMappingFile(); 220 if (mf != null) { 221 for (Iterator m = mf.getXmlTypeMappings(); m.hasNext();) { 222 QName xml = (QName ) m.next(); 223 String classname = mf.getClassname(xml); 224 225 if (classname.endsWith("[]")) { 227 mappings.add(new VcArrayMapping(xml, classname)); 228 } else { 229 mappings.add(new VcBeanMapping(xml, classname)); 230 } 231 } 232 } 233 vc.put(MAPPINGS, mappings); 234 235 return vc; 236 } 237 } | Popular Tags |