Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 85357 invoked by uid 500); 12 Oct 2001 21:24:12 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 85293 invoked from network); 12 Oct 2001 21:24:07 -0000 Message-ID: <00b101c1536c$84425e80$6b00a8c0@ne.mediaone.net> From: "Glen Daniels" To: References: <20011012210448.85729.qmail@icarus.apache.org> Subject: Re: cvs commit: xml-axis/java/src/org/apache/axis/resolver/sd/schema/providers EJBProvider.java JWSProvider.java JavaProvider.java Date: Fri, 12 Oct 2001 17:23:27 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hm. Too late. :) Oh well, I'll still give you comments over the weekend. --G ----- Original Message ----- From: To: Sent: Friday, October 12, 2001 4:04 PM Subject: cvs commit: xml-axis/java/src/org/apache/axis/resolver/sd/schema/providers EJBProvider.java JWSProvider.java JavaProvider.java > jmsnell 01/10/12 14:04:48 > > Added: java/src/org/apache/axis/resolver AxisResolver.java > ConfigurationResolver.java Resolver.java > ResolverContext.java ResolverException.java > java/src/org/apache/axis/resolver/ejb EJBResolver.java > java/src/org/apache/axis/resolver/java JavaResolver.java > java/src/org/apache/axis/resolver/jws JWSResolver.java > java/src/org/apache/axis/resolver/sd SDResolver.java > ServiceDescriptor.java > java/src/org/apache/axis/resolver/sd/schema Fault.java > HandlerList.java Provider.java SDConstants.java > SDElement.java Service.java > java/src/org/apache/axis/resolver/sd/schema/providers > EJBProvider.java JWSProvider.java JavaProvider.java > Log: > This is the first of the resolver stuff. More later. > > Revision Changes Path > 1.1 xml-axis/java/src/org/apache/axis/resolver/AxisResolver.java > > Index: AxisResolver.java > =================================================================== > package org.apache.axis.resolver; > > import java.util.Vector; > import java.util.Iterator; > import java.util.HashMap; > import org.apache.axis.Handler; > > /** > * This is the primary top level resolver in Axis. > * It maintains a list of registered Resolvers and > * loops through them when a resolve request is made > * The first non-null result is returned. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class AxisResolver implements Resolver { > > private Vector resolvers = new Vector(); > private HashMap resolved = new HashMap(); > > /** > * Register a new resolver > */ > public void registerResolver(Resolver resolver) { > resolvers.add(resolver); > } > > /** > * Resolve a handler by looping through the list of > * registered resolvers. The first non-null result > * is returned. Resolved handlers are cached so > * we don't have to resolve them every time. > */ > public Handler resolve(ResolverContext context) throws ResolverException { > if (resolved.containsKey(context.getKey())) { > return (Handler)resolved.get(context.getKey()); > } > context.setResolver(this); > for (Iterator i = resolvers.iterator();i.hasNext();) { > Resolver r = (Resolver)i.next(); > Handler h = r.resolve(context); > if (h != null && r.getAllowCaching()) { > resolved.put(context.getKey(), h); > return h; > } > } > return null; > } > > public boolean getAllowCaching() { > for (Iterator i = resolvers.iterator(); i.hasNext();) { > if (!((Resolver)i.next()).getAllowCaching()) return false; > } > return true; > } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/ConfigurationResolver.java > > Index: ConfigurationResolver.java > =================================================================== > package org.apache.axis.resolver; > > import org.apache.axis.Handler; > > /** > * > * Resolves handlers, chains, transports, and services > * that are listed in the Axis configuration file. > * > * Will be finished soon. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class ConfigurationResolver implements Resolver { > > public Handler resolve(ResolverContext context) throws ResolverException { > return null; > } > > public boolean getAllowCaching() { return true; } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/Resolver.java > > Index: Resolver.java > =================================================================== > package org.apache.axis.resolver; > > import org.apache.axis.Handler; > > /** > * The Resolver interface is used to locate a handler instance. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public interface Resolver { > > /** > * Resolves a handler instance > * > */ > public Handler resolve(ResolverContext context) throws ResolverException; > > public boolean getAllowCaching(); > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/ResolverContext.java > > Index: ResolverContext.java > =================================================================== > package org.apache.axis.resolver; > > import java.util.HashMap; > import java.util.Map; > > /** > * Contains the information necessary for resolving a specific handler. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class ResolverContext { > > private String key = null; > private Map properties = null; > private Resolver resolver; > > public ResolverContext() {} > > public ResolverContext(String key) { > setKey(key); > } > > /** > * Return the top level resolver > */ > public Resolver getResolver() { > return this.resolver; > } > > /** > * Set the top level resolver > */ > public void setResolver(Resolver resolver) { > this.resolver = resolver; > } > > /** > * Return the handler key > */ > public String getKey() { > return this.key; > } > > /** > * Set the handler key > */ > public void setKey(String key) { > this.key = key; > } > > /** > * Context properties are used to provide additional information > * that may be needed to either resolve or instantiate a handler > */ > public void setProperty(String name, Object value) { > if (properties == null) properties = new HashMap(); > properties.put(name,value); > } > > /** > * Return a context property > */ > public Object getProperty(String name) { > if (properties == null) return null; > return properties.get(name); > } > > /** > * Get all of the context properties > */ > public Map getProperties() { > return this.properties; > } > > /** > * Set the context properties > */ > public void setProperties(Map properties) { > this.properties = properties; > } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/ResolverException.java > > Index: ResolverException.java > =================================================================== > package org.apache.axis.resolver; > > import java.io.StringWriter; > import java.io.PrintWriter; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public class ResolverException extends Exception { > > private String message = null; > > public ResolverException() {} > > public ResolverException(String message) { > this.message = message; > } > > public ResolverException(Exception e) { > StringWriter sw = new StringWriter(); > PrintWriter pw = new PrintWriter(sw); > e.printStackTrace(pw); > this.message = sw.toString(); > } > > public String getMessage() { > return this.message; > } > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/ejb/EJBResolver.java > > Index: EJBResolver.java > =================================================================== > package org.apache.axis.resolver.ejb; > > import org.apache.axis.Handler; > import org.apache.axis.resolver.Resolver; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.ResolverException; > import org.apache.axis.providers.java.EJBProvider; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public class EJBResolver implements Resolver { > > public static final String CONTEXT_JNDICONTEXTCLASS = "jndiContextClass"; > public static final String CONTEXT_JNDIURL = "jndiURL"; > public static final String CONTEXT_JNDIUSER = "jndiUser"; > public static final String CONTEXT_JNDIPASSWORD = "jndiPassword"; > public static final String CONTEXT_PREFIX = "ejb:"; > > public Handler resolve(ResolverContext context) throws ResolverException { > try { > String beanName = context.getKey(); > if (!beanName.startsWith(CONTEXT_PREFIX)) return null; > beanName = beanName.substring(CONTEXT_PREFIX.length()); > Handler h = new EJBProvider(); > String jndiContextClass = (String)context.getProperty(CONTEXT_JNDICONTEXTCLASS); > String jndiUrl = (String)context.getProperty(CONTEXT_JNDIURL); > String jndiUser = (String)context.getProperty(CONTEXT_JNDIUSER); > String jndiPassword = (String)context.getProperty(CONTEXT_JNDIPASSWORD); > h.addOption("beanNameOption", beanName); > if (jndiContextClass != null) > h.addOption("jndiContextClass", jndiContextClass); > if (jndiUrl != null) > h.addOption("jndiURL", jndiUrl); > if (jndiUser != null) > h.addOption("jndiUser", jndiUser); > if (jndiPassword != null) > h.addOption("jndiPassword", jndiPassword); > return h; > } catch (Exception e) { > return null; > } > } > > public boolean getAllowCaching() { return true; } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/java/JavaResolver.java > > Index: JavaResolver.java > =================================================================== > package org.apache.axis.resolver.java; > > import org.apache.axis.Handler; > import org.apache.axis.resolver.Resolver; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.ResolverException; > import org.apache.axis.utils.AxisClassLoader; > import org.apache.axis.providers.java.RPCProvider; > import org.apache.axis.providers.java.MsgProvider; > > /** > * Resolves a Java class as either a RPCProvider or MSGProvider. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class JavaResolver implements Resolver { > > public static final String CONTEXT_STYLE = "style"; > public static final String CONTEXT_STATIC = "isStatic"; > public static final String CONTEXT_CLASSPATH = "classPath"; > public static final String CONTEXT_SCOPE = "scope"; > public static final String CONTEXT_PREFIX = "java:"; > public static final String CONTEXT_STYLE_RPC = "rpc"; > public static final String CONTEXT_STYLE_MSG = "message"; > public static final String CONTEXT_STYLE_DEFAULT = CONTEXT_STYLE_RPC; > > public Handler resolve(ResolverContext context) throws ResolverException { > try { > String clsName = context.getKey(); > if (!clsName.startsWith(CONTEXT_PREFIX)) return null; > clsName = clsName.substring(CONTEXT_PREFIX.length()); > String style = (String)context.getProperty(CONTEXT_STYLE); > String isStatic = (String)context.getProperty(CONTEXT_STATIC); > String classPath = (String)context.getProperty(CONTEXT_CLASSPATH); > String scope = (String)context.getProperty(CONTEXT_SCOPE); > if (style == null) style = CONTEXT_STYLE_DEFAULT; > Handler h = null; > if (CONTEXT_STYLE_RPC.equals(style)) { > h = new RPCProvider(); > } > if (CONTEXT_STYLE_MSG.equals(style)) { > h = new MsgProvider(); > } > if (clsName != null) h.addOption("className", clsName); > if (isStatic != null) h.addOption("isStatic", isStatic); > if (classPath != null) h.addOption("classPath", classPath); > if (scope != null) h.addOption("scope", scope); > return h; > } catch (Exception e) { > return null; > } > } > > public boolean getAllowCaching() { return true; } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/jws/JWSResolver.java > > Index: JWSResolver.java > =================================================================== > package org.apache.axis.resolver.jws; > > import java.io.File; > import java.io.FileWriter; > import java.io.FileReader; > import java.io.FileOutputStream; > import java.io.FileInputStream; > import java.io.InputStream; > import java.io.IOException; > import java.net.URL; > import java.net.URLClassLoader; > import java.util.StringTokenizer; > import java.util.jar.Attributes; > import java.util.jar.JarFile; > import java.util.jar.JarInputStream; > import java.util.jar.Manifest; > import javax.servlet.http.HttpServlet; > import org.apache.axis.Handler; > import org.apache.axis.resolver.Resolver; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.ResolverException; > import org.apache.axis.utils.AxisClassLoader; > import org.apache.axis.transport.http.HTTPConstants; > import sun.tools.javac.Main; > > /** > * The JWSResolver checks to see if a JWS file has been compiled > * and is up to date. If not, it compiles it and makes sure that > * it is properly loaded by the AxisClassLoader. Once done, it > * asks the top level resolver to resolve the compiled Java class > * as a handler. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class JWSResolver implements Resolver { > > public Handler resolve(ResolverContext context) throws ResolverException { > try { > String jwsFile = context.getKey(); > if (!jwsFile.substring(jwsFile.length() - 4).equals("jws")) return null; > > Runtime runtime = Runtime.getRuntime(); > > String jFile = jwsFile.substring(0, jwsFile.length()-3) + "java"; > String cFile = jwsFile.substring(0, jwsFile.length()-3) + "class"; > File f1 = new File(cFile); > File f2 = new File(jwsFile); > String clsName = f2.getName(); > clsName = clsName.substring( 0, clsName.length()-4 ); > > if (!f1.exists() || > (f2.lastModified() > f1.lastModified())) { > // if the compiled JWS file does not exist, or > // is out of date, we need to recompile > FileReader fr = new FileReader(jwsFile); > FileWriter fw = new FileWriter(jFile); > char[] buf = new char[4096]; > int rc ; > while ( (rc = fr.read( buf, 0, 4095)) >= 0 ) > fw.write( buf, 0, rc ); > fw.close(); > fr.close(); > > // now we do the compile > FileOutputStream fos = new FileOutputStream("jws.err"); > Main compiler = new Main(fos, "javac"); > String outdir = f1.getParent(); > String[] args = null; > if (outdir == null) outdir = "."; > args = new String[] {"-d", outdir, "-classpath", getDefaultClasspath(context), jFile }; > boolean result = compiler.compile( args ); > > // delete the tempoary .java file > (new File(jFile)).delete(); > > // check the result of the compile > if (!result) { > /* Delete the *class file - sometimes it gets created even */ > /* when there are errors - so erase it so it doesn't */ > /* confuse us. */ > /***********************************************************/ > (new File(cFile)).delete(); > return null; > } > AxisClassLoader.removeClassLoader(clsName); > } > AxisClassLoader cl = AxisClassLoader.getClassLoader(); > if (!cl.isClassRegistered(clsName)) > cl.registerClass(clsName, cFile); > ResolverContext rc = new ResolverContext("java:" + clsName); > rc.setProperties(context.getProperties()); > return context.getResolver().resolve(rc); > } catch (Exception e) { > return null; > } > } > > private String getDefaultClasspath(ResolverContext context) > { > StringBuffer classpath = new StringBuffer(); > ClassLoader cl = Thread.currentThread().getContextClassLoader(); > > while(cl != null) > { > if(cl instanceof URLClassLoader) > { > URL[] urls = ((URLClassLoader) cl).getURLs(); > > for(int i=0; (urls != null) && i < urls.length; i++) > { > classpath.append(urls[i].getPath()); > classpath.append(File.pathSeparatorChar); > > > // if its a jar extract Class-Path entries from manifest > File file = new File(urls[i].getFile()); > if(file.isFile()) > { > FileInputStream fis = null; > > try > { > fis = new FileInputStream(file); > > if(isJar(fis)) > { > JarFile jar = new JarFile(file); > Manifest manifest = jar.getManifest(); > if (manifest != null) > { > Attributes attributes = manifest. > getMainAttributes(); > if (attributes != null) > { > String s = attributes. > getValue(java.util.jar.Attributes.Name.CLASS_PATH); > String base = file.getParent(); > > if (s != null) > { > StringTokenizer st = > new StringTokenizer(s, " "); > while(st.hasMoreTokens()) > { > String t = st.nextToken(); > classpath.append(base + > File.separatorChar + t); > classpath.append( > File.pathSeparatorChar); > } > } > } > } > } > } > catch(IOException ioe) > { > if(fis != null) > try { > fis.close(); > } catch (IOException ioe2) {} > } > } > } > } > > cl = cl.getParent(); > } > > // Just to be safe (the above doesn't seem to return the webapp > // classpath in all cases), manually do this: > > HttpServlet servlet = (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET); > if (servlet != null) { > String webBase = servlet.getServletContext(). > getRealPath("/WEB-INF"); > classpath.append(webBase + File.separatorChar + "classes" + > File.pathSeparatorChar); > try { > String libBase = webBase + File.separatorChar + "lib"; > File libDir = new File(libBase); > String [] jarFiles = libDir.list(); > for (int i = 0; i < jarFiles.length; i++) { > String jarFile = jarFiles[i]; > if (jarFile.endsWith(".jar")) { > classpath.append(libBase + > File.separatorChar + > jarFile + > File.pathSeparatorChar); > } > } > } catch (Exception e) { > // Oh well. No big deal. > } > } > > // boot classpath isn't found in above search > if(System.getProperty("sun.boot.class.path") != null) > { > classpath.append(System.getProperty("sun.boot.class.path")); > } > > return classpath.toString(); > } > > // an exception or emptiness signifies not a jar > public static boolean isJar(InputStream is) > { > try > { > JarInputStream jis = new JarInputStream(is); > if(jis.getNextEntry() != null) > { > return true; > } > } > catch(IOException ioe) > { > } > > return false; > } > > /** > * we're not going to allow caching because we need > * to know if the JWS file has changed > */ > public boolean getAllowCaching() { return false; } > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/SDResolver.java > > Index: SDResolver.java > =================================================================== > package org.apache.axis.resolver.sd; > > import org.apache.axis.Handler; > import org.apache.axis.resolver.Resolver; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.ResolverException; > > /** > * Resolves services defined using the simplified service descriptor (sd) > * format. Resolution is based on the file path or URL of the sd. > * If the sd is loaded properly, a new handler instance is returned. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class SDResolver implements Resolver { > > public Handler resolve(ResolverContext context) throws ResolverException { > try { > ServiceDescriptor sd = new ServiceDescriptor(context.getKey(), context.getResolver()); > return sd.newInstance(); > } catch (Exception e) { > return null; } > } > > public boolean getAllowCaching() { return true; } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/ServiceDescriptor.java > > Index: ServiceDescriptor.java > =================================================================== > package org.apache.axis.resolver.sd; > > import java.io.InputStream; > import java.util.Stack; > import java.util.ArrayList; > import javax.xml.parsers.SAXParser; > import org.apache.axis.Handler; > import org.apache.axis.resolver.Resolver; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.sd.schema.Service; > import org.apache.axis.resolver.sd.schema.Fault; > import org.apache.axis.resolver.sd.schema.Provider; > import org.apache.axis.resolver.sd.schema.HandlerList; > import org.apache.axis.resolver.sd.schema.SDElement; > import org.apache.axis.resolver.sd.schema.SDConstants; > import org.apache.axis.utils.QName; > import org.apache.axis.utils.NSStack; > import org.apache.axis.utils.Mapping; > import org.xml.sax.helpers.DefaultHandler; > import org.xml.sax.SAXException; > > /** > * A simplified deployment descriptor format. It uses SAX to read > * in the format and to create a very simple object model for the > * service. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class ServiceDescriptor { > > protected Service service = null; > protected Resolver resolver = null; > > /** > * Create the service descriptor from a resolver context > */ > public ServiceDescriptor(ResolverContext context) { > setResolver(context.getResolver()); > parse(context.getKey()); > } > > /** > * Create the service descriptor from an input stream > */ > public ServiceDescriptor(InputStream in, Resolver resolver) { > setResolver(resolver); > parse(in); > } > > /** > * Create the service descriptor from a URL/filepath > */ > public ServiceDescriptor(String in, Resolver resolver) { > setResolver(resolver); > parse(in); > } > > /** > * Return the top level resolver > */ > public Resolver getResolver() { > return this.resolver; > } > > /** > * Set the top level resolver > */ > public void setResolver(Resolver resolver) { > this.resolver = resolver; > } > > /** > * Return a new instance of this service (this will be a > * SimpleTargetedChain) > */ > public Handler newInstance() { > if (service == null) return null; > return service.newInstance(); > } > > /** > * Return the Service object > */ > public Service getService() { > return this.service; > } > > /** > * Set the service object > */ > public void setService(Service service) { > this.service = service; > } > > /** > * Parse the service descriptor > */ > private void parse(InputStream in) { > try { > SAXParser parser = org.apache.axis.utils.XMLUtils.getSAXParser(); > parser.parse(in, new SDHandler()); > } catch (Exception e) {} > } > > /** > * Parse the service descriptor > */ > private void parse(String in) { > try { > SAXParser parser = org.apache.axis.utils.XMLUtils.getSAXParser(); > parser.parse(in, new SDHandler()); > } catch (Exception e) {} > } > > /** > * SAX handler that deals with parsing the service descriptor > */ > private class SDHandler extends DefaultHandler { > > private Stack stack = new Stack(); > private DefaultHandler handler = null; > private int depth = 0; > private NSStack namespaces = new NSStack(); > private ArrayList ns = null; > > public void startElement(String uri, String ln, String rn, org.xml.sax.Attributes attr) throws SAXException { > if (ns == null) ns = new ArrayList(); > namespaces.push(ns); > if (handler != null) { > handler.startElement(uri, ln, rn, attr); > depth++; > return; > } > SDElement current = null; > if (stack.size() > 0) { > current = (SDElement)stack.peek(); > } > if (SDConstants.SDNS.equals(uri)) { > if ("service".equals(ln)) { > if (current != null) { > throw new SAXException("Unexpected service descriptor"); > } > current = new Service(); > stack.push(current); > service = (Service)current; > } > if ("request".equals(ln)) { > if (current == null) > throw new SAXException("Unexpected request descriptor"); > if (!(current instanceof Service)) > throw new SAXException("Unexpected request descriptor"); > Service service = (Service)current; > current = new HandlerList(); > service.setRequest((HandlerList)current); > stack.push(current); > } > if ("response".equals(ln)) { > if (current == null) > throw new SAXException("Unexpected response descriptor"); > if (!(current instanceof Service)) > throw new SAXException("Unexpected response descriptor"); > Service service = (Service)current; > current = new HandlerList(); > service.setResponse((HandlerList)current); > stack.push(current); > } > if ("fault".equals(ln)) { > if (current == null) > throw new SAXException("Unexpected fault descriptor"); > if (!(current instanceof Service)) > throw new SAXException("Unexpected fault descriptor"); > Service service = (Service)current; > Fault fault = new Fault(); > String qname = attr.getValue("faultCode"); > if (qname != null) { > fault.setFaultCode(getQName(qname)); > } > service.setFault(fault.getFaultCode(), fault); > current = fault; > stack.push(current); > } > if ("handler".equals(ln)) { > if (current == null) > throw new SAXException("Unexpected handler descriptor"); > if (!(current instanceof HandlerList)) > throw new SAXException("Unexpected handler descriptor"); > HandlerList handlerList = (HandlerList)current; > try { > String key = attr.getValue("key"); > if (key != null) { > ResolverContext context = new ResolverContext(key); > Handler h = resolver.resolve(context); > if (h != null) { > handlerList.addHandler(h); > } else { > throw new SAXException("Cannot resolve handler"); > } > } else { > throw new SAXException("Handler key not specified"); > } > } catch (Exception e) { > throw new SAXException("Cannot resolve handler"); > } > } > if ("chain".equals(ln)) { > if (current == null) > throw new SAXException("Unexpected chain descriptor"); > if (!(current instanceof HandlerList)) > throw new SAXException("Unexpected chain descriptor"); > HandlerList handlerList = (HandlerList)current; > current = new HandlerList(); > stack.push(current); > handlerList.addHandlerList((HandlerList)current); > try { > String key = attr.getValue("key"); > if (key != null) { > ResolverContext context = new ResolverContext(key); > Handler h = resolver.resolve(context); > if (h != null) { > handlerList.addHandler(h); > } else { > throw new SAXException("Cannot resolve chain"); > } > } > } catch (Exception e) { > throw new SAXException("Cannot resolve chain"); > } > } > } else { > if (current == null) > throw new SAXException("Unexpected unknown element"); > if (!(current instanceof Service)) > throw new SAXException("Unexpected unknown element"); > QName type = new QName(uri, ln); > Provider provider = Provider.newProvider(type); > provider.setResolver(resolver); > if (provider != null) { > service.setProvider(provider); > handler = provider.getDefaultHandler(); > handler.startElement(uri, ln, rn, attr); > } else { > throw new SAXException("Unexpected unknown element"); > } > } > } > > public void endElement(String uri, String ln, String rn) throws SAXException { > if (SDConstants.SDNS.equals(uri)) { > if ("service".equals(ln) || > "request".equals(ln) || > "response".equals(ln) || > "fault".equals(ln) || > "chain".equals(ln)) { > stack.pop(); > } > } else { > if (handler != null && depth == 0) { > handler = null; > depth = 0; > } > if (handler != null && depth > 0) { > depth--; > } > } > namespaces.pop(); > ns = null; > } > > public void characters(char[] arr, int start, int len) throws SAXException { > if (handler != null) > handler.characters(arr, start,len); > } > > public void startPrefixMapping(String px, String uri) throws SAXException { > if (ns == null) ns = new ArrayList(); > ns.add(new Mapping(uri, px)); > if (handler != null) { > handler.startPrefixMapping(px,uri); > } > } > > public void endPrefixMapping(String px) throws SAXException { > if (handler != null) { > handler.endPrefixMapping(px); > } > } > > private QName getQName(String qname) { > try { > String prefix = qname.substring(0, qname.indexOf(":")); > String local = qname.substring(qname.lastIndexOf(":")+1); > return new QName(namespaces.getNamespaceURI(prefix), local); > } catch (Exception e) { > return new QName(null, qname); > } > } > > } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/Fault.java > > Index: Fault.java > =================================================================== > package org.apache.axis.resolver.sd.schema; > > import org.apache.axis.Handler; > import org.apache.axis.utils.QName; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public class Fault extends HandlerList { > > private QName faultCode; > > public QName getFaultCode() { > return this.faultCode; > } > > public void setFaultCode(QName faultCode) { > this.faultCode = faultCode; > } > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/HandlerList.java > > Index: HandlerList.java > =================================================================== > package org.apache.axis.resolver.sd.schema; > > import java.util.Vector; > import java.util.Iterator; > import org.apache.axis.Handler; > import org.apache.axis.SimpleChain; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public class HandlerList extends SDElement { > > private Vector handlers = new Vector(); > > public void addHandler(Handler handler) { > handlers.add(handler); > } > > public void addHandlerList(HandlerList handlerList) { > handlers.add(handlerList); > } > > public Handler newInstance() { > SimpleChain chain = new SimpleChain(); > for (Iterator i = handlers.iterator();i.hasNext();) { > Object o = i.next(); > if (o instanceof Handler) > chain.addHandler((Handler)o); > if (o instanceof HandlerList) > chain.addHandler(((HandlerList)o).newInstance()); > } > return chain; > } > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/Provider.java > > Index: Provider.java > =================================================================== > package org.apache.axis.resolver.sd.schema; > > import java.util.HashMap; > import org.apache.axis.Handler; > import org.apache.axis.utils.QName; > import org.apache.axis.resolver.Resolver; > import org.xml.sax.helpers.DefaultHandler; > > /** > * Providers are pluggable. They must register here in order > * to be recognized during the parse procedure. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public abstract class Provider extends SDElement { > > private static HashMap providers = new HashMap(); > protected DefaultHandler handler; > protected Resolver resolver; > > public static void registerProvider(QName type, Class providerClass) { > providers.put(type, providerClass); > } > > public static Provider newProvider(QName type) { > try { > Class c = (Class)providers.get(type); > if (c != null) { > return (Provider)c.newInstance(); > } > } catch (Exception e) {} > return null; > } > > public DefaultHandler getDefaultHandler() { > return handler; > } > > public void setResolver(Resolver resolver) { > this.resolver = resolver; > } > > public Resolver getResolver() { > return this.resolver; > } > > public abstract Handler newInstance(); > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/SDConstants.java > > Index: SDConstants.java > =================================================================== > package org.apache.axis.resolver.sd.schema; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public class SDConstants { > > public static final String SDNS = "http://xml.apache.org/axis/sd/"; > public static final String SDNS_JAVA = "http://xml.apache.org/axis/sd/java"; > public static final String SDNS_JWS = "http://xml.apache.org/axis/sd/jws"; > public static final String SDNS_EJB = "http://xml.apache.org/axis/sd/ejb"; > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/SDElement.java > > Index: SDElement.java > =================================================================== > package org.apache.axis.resolver.sd.schema; > > import org.apache.axis.Handler; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public abstract class SDElement { > > public abstract Handler newInstance(); > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/Service.java > > Index: Service.java > =================================================================== > package org.apache.axis.resolver.sd.schema; > > import java.util.HashMap; > import org.apache.axis.utils.QName; > import org.apache.axis.Handler; > import org.apache.axis.SimpleTargetedChain; > > /** > * @author James Snell (jasnell@us.ibm.com) > */ > > public class Service extends SDElement { > > private HandlerList request; > private Provider provider; > private HandlerList response; > private HashMap faults; > private TypeMappings typeMappings; > > public HandlerList getRequest() { > return this.request; > } > > public void setRequest(HandlerList request) { > this.request = request; > } > > public Provider getProvider() { > return this.provider; > } > > public void setProvider(Provider provider) { > this.provider = provider; > } > > public HandlerList getResponse() { > return this.response; > } > > public void setResponse(HandlerList response) { > this.response = response; > } > > public Fault getFault(QName faultCode) { > if (faults == null) return null; > return (Fault)faults.get(faultCode); > } > > public void setFault(QName faultCode, Fault fault) { > if (faults == null) faults = new HashMap(); > faults.put(faultCode, fault); > } > > public HashMap getFaults() { > return this.faults; > } > > public Handler newInstance() { > SimpleTargetedChain service = new SimpleTargetedChain(); > if (request != null) service.setRequestHandler(request.newInstance()); > if (provider != null) service.setPivotHandler(provider.newInstance()); > if (response != null) service.setResponseHandler(response.newInstance()); > return service; > } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/providers/EJBProvider.j ava > > Index: EJBProvider.java > =================================================================== > package org.apache.axis.resolver.sd.schema.providers; > > import org.apache.axis.utils.QName; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.sd.schema.SDConstants; > import org.apache.axis.resolver.sd.schema.Provider; > import org.apache.axis.resolver.ejb.EJBResolver; > import org.apache.axis.Handler; > import org.xml.sax.helpers.DefaultHandler; > import org.xml.sax.SAXException; > > /** > * EJB provider extension. > * > * Example: > * * xmlns:ejb="http://xml.apache.org/axis/sd/ejb"> > * > * * contextClass="context.class.name" > * url="jndi.url" > * user="user.id" > * password="password" /> > * > * > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class EJBProvider extends Provider { > > public static final QName qname = new QName(SDConstants.SDNS_EJB, "provider"); > static { > Provider.registerProvider(qname, EJBProvider.class); > } > > public EJBProvider() { > handler = new EJBProviderHandler(); > } > > private String beanName; > private String contextClass; > private String url; > private String user; > private String password; > > public Handler newInstance() { > try { > ResolverContext context = new ResolverContext(EJBResolver.CONTEXT_PREFIX + beanName); > if (contextClass != null) > context.setProperty(EJBResolver.CONTEXT_JNDICONTEXTCLASS, contextClass); > if (url != null) > context.setProperty(EJBResolver.CONTEXT_JNDIURL, url); > if (user != null) > context.setProperty(EJBResolver.CONTEXT_JNDIUSER, user); > if (password != null) > context.setProperty(EJBResolver.CONTEXT_JNDIPASSWORD, password); > return resolver.resolve(context); > } catch (Exception e) { return null; } > } > > private class EJBProviderHandler extends DefaultHandler { > public void startElement(String uri, String ln, String rn, org.xml.sax.Attributes attr) throws SAXException { > beanName = attr.getValue("beanName"); > contextClass = attr.getValue("contextClass"); > url = attr.getValue("url"); > user = attr.getValue("user"); > password = attr.getValue("password"); > } > } > > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/providers/JWSProvider.j ava > > Index: JWSProvider.java > =================================================================== > package org.apache.axis.resolver.sd.schema.providers; > > import org.apache.axis.utils.QName; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.sd.schema.SDConstants; > import org.apache.axis.resolver.sd.schema.Provider; > import org.apache.axis.resolver.java.JavaResolver; > import org.apache.axis.Handler; > import org.xml.sax.helpers.DefaultHandler; > import org.xml.sax.SAXException; > > /** > * JWS provider extension. > * > * Example: > * * xmlns:jws="http://xml.apache.org/axis/sd/jws"> > * > * * jwsFile="jws.file.path" > * static="false" > * classPath="some;class;path" > * scope="Request" /> > * > * > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class JWSProvider extends Provider { > > public static final QName qname = new QName(SDConstants.SDNS_JWS, "provider"); > static { > Provider.registerProvider(qname, JWSProvider.class); > } > > private String jwsFile; > private String isStatic; > private String classPath; > private String scope; > private String style; > > public JWSProvider() { > handler = new JWSProviderHandler(); > } > > public Handler newInstance() { > try { > ResolverContext context = new ResolverContext(jwsFile); > if (style != null) > context.setProperty(JavaResolver.CONTEXT_STYLE, style); > else > context.setProperty(JavaResolver.CONTEXT_STYLE, JavaResolver.CONTEXT_STYLE_DEFAULT); > if (isStatic != null) > context.setProperty(JavaResolver.CONTEXT_STATIC, isStatic); > if (classPath != null) > context.setProperty(JavaResolver.CONTEXT_CLASSPATH, classPath); > if (scope != null) > context.setProperty(JavaResolver.CONTEXT_SCOPE, scope); > return resolver.resolve(context); > } catch (Exception e) { return null; } > } > > private class JWSProviderHandler extends DefaultHandler { > public void startElement(String uri, String ln, String rn, org.xml.sax.Attributes attr) throws SAXException { > jwsFile = attr.getValue("jwsFile"); > isStatic = attr.getValue("static"); > classPath = attr.getValue("classPath"); > scope = attr.getValue("scope"); > style = attr.getValue("style"); > } > } > } > > > > 1.1 xml-axis/java/src/org/apache/axis/resolver/sd/schema/providers/JavaProvider. java > > Index: JavaProvider.java > =================================================================== > package org.apache.axis.resolver.sd.schema.providers; > > import org.apache.axis.utils.QName; > import org.apache.axis.resolver.ResolverContext; > import org.apache.axis.resolver.sd.schema.SDConstants; > import org.apache.axis.resolver.sd.schema.Provider; > import org.apache.axis.resolver.java.JavaResolver; > import org.apache.axis.Handler; > import org.xml.sax.helpers.DefaultHandler; > import org.xml.sax.SAXException; > > /** > * Java provider extension. > * > * Example: > * * xmlns:java="http://xml.apache.org/axis/sd/java"> > * > * * className="some.class.name" > * static="false" > * classPath="some;class;path" > * scope="Request" /> > * > * > * > * The style attribute determines whether or not a Java > * RPCProvider or MsgProvider is used. > * > * @author James Snell (jasnell@us.ibm.com) > */ > > public class JavaProvider extends Provider { > > public static final QName qname = new QName(SDConstants.SDNS_JAVA, "provider"); > static { > Provider.registerProvider(qname, JavaProvider.class); > } > > private String className; > private String isStatic; > private String classPath; > private String scope; > private String style; > > public JavaProvider() { > handler = new JavaProviderHandler(); > } > > public Handler newInstance() { > try { > ResolverContext context = new ResolverContext(JavaResolver.CONTEXT_PREFIX + className); > if (style != null) > context.setProperty(JavaResolver.CONTEXT_STYLE, style); > else > context.setProperty(JavaResolver.CONTEXT_STYLE, JavaResolver.CONTEXT_STYLE_DEFAULT); > if (isStatic != null) > context.setProperty(JavaResolver.CONTEXT_STATIC, isStatic); > if (classPath != null) > context.setProperty(JavaResolver.CONTEXT_CLASSPATH, classPath); > if (scope != null) > context.setProperty(JavaResolver.CONTEXT_SCOPE, scope); > return resolver.resolve(context); > } catch (Exception e) { return null; } > } > > private class JavaProviderHandler extends DefaultHandler { > public void startElement(String uri, String ln, String rn, org.xml.sax.Attributes attr) throws SAXException { > className = attr.getValue("className"); > isStatic = attr.getValue("static"); > classPath = attr.getValue("classPath"); > scope = attr.getValue("scope"); > style = attr.getValue("style"); > } > } > } > > > > >