ws-wsif-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers ModelWSIFProvider.java
Date Thu, 17 Apr 2003 13:53:20 GMT
antelder    2003/04/17 06:53:20

  Added:       java/src/org/apache/wsif/providers ModelWSIFProvider.java
  Log:
  Create a WSIFProvider model for all provider implementer to use
  
  The idea for this is to make it simple(r) to write a WSIF provider. I'd like models to exist
for the WSIFProvider, WSIFPort and WSIFOperation. These models would use design patterns such
as template methods, factory methods, and abstarct factories, to 'force' provider writers
to do things the 'correct' way, and to allow WSIF to do most of the WSDL oriented stuff for
them, allowing the provider to concentrate on just whats required to implement accessing a
particualer service type.
  
  Feel free to chip in with your own ideas or to suggest moving this to proposals etc. The
WSIFProvider model is the easiest which is why i started with that. Unless I hear someone
complain I'm going to start moving the existing WSIF providers to use this. 
  
  Revision  Changes    Path
  1.1                  xml-axis-wsif/java/src/org/apache/wsif/providers/ModelWSIFProvider.java
  
  Index: ModelWSIFProvider.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "WSIF" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, 2002, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.wsif.providers;
  
  import java.security.AccessController;
  import java.security.PrivilegedAction;
  import java.util.Iterator;
  import java.util.List;
  
  import javax.wsdl.Binding;
  import javax.wsdl.Definition;
  import javax.wsdl.Port;
  import javax.wsdl.Service;
  import javax.wsdl.extensions.ExtensibilityElement;
  import javax.wsdl.extensions.ExtensionRegistry;
  
  import org.apache.wsif.WSIFException;
  import org.apache.wsif.WSIFPort;
  import org.apache.wsif.base.WSIFServiceImpl;
  import org.apache.wsif.logging.Trc;
  import org.apache.wsif.spi.WSIFProvider;
  import org.apache.wsif.tools.wsdl.BindingGenerator;
  
  /**
   * Model super class for a WSIFProvider
   * 
   * @author <a href="mailto:ant.elder@uk.ibm.com">Ant Elder</a>
   */
  public abstract class ModelWSIFProvider implements WSIFProvider {
  
      /* the namespaces of the binding the provider supports */
      protected String[] supportedBindings;
  
      /* the namespaces of the addresses the provider supports */
      protected String[] supportedAddresses;
      // TODO: why is that required??? Its a transport thing so not
      // really applicable at this level. Lets try to get rid of it 
  
      /**
       * Construct a new WSIFProvider
       * 
       * This first checks if all the classes required by the provider
       * are available. If so it registers any extension registeries 
       * required by the provider and initialises the binding and address
       * namespaces supported by the provider. If required classes are not
       * available then the provider disables itself by setting the supported
       * binding and address namespaces to empty arrays. 
       */
      protected ModelWSIFProvider() throws WSIFException {
          Trc.entry(this);
          if (isActive()) {
              enableProvider();
          } else {
              disableProvider();
          }
          Trc.exit();
      }
  
      /**
       * Returns the WSDL namespace URIs of any bindings this provider supports.
       * @return String[] of binding namespaces supported by this provider
       */
      public String[] getBindingNamespaceURIs() {
          Trc.entry(this);
          String[] bindings = supportedBindings;
          Trc.exit(bindings);
          return bindings;
      }
  
      /**
       * Returns the WSDL namespace URIs of any port addresses this provider supports.
       * @return String[] of address namespaces supported by this provider
       */
      public String[] getAddressNamespaceURIs() {
          Trc.entry(this);
          String[] addresses = supportedAddresses;
          Trc.exit(addresses);
          return addresses;
      }
  
      /**
       * @see WSIFProvider#createDynamicWSIFPort(Definition, Service, Port, WSIFDynamicTypeMap)
       */
      public WSIFPort createDynamicWSIFPort(
          Definition def,
          Service service,
          Port port,
          WSIFDynamicTypeMap typeMap)
          throws WSIFException {
          Trc.entry(this, def, service, port, typeMap);
  
          Class bindingClass = getImplementedBindingClass();
          if (!(ExtensibilityElement.class.isAssignableFrom(bindingClass))) {
              throw new WSIFException("getImplementedBindingClass must return a subclass of
ExtensibilityElement");
          }
  
          WSIFPort wsifPort = null;
          Binding binding = port.getBinding();
  
          List l = binding.getExtensibilityElements();
          for (Iterator i = l.iterator(); i.hasNext() && wsifPort == null;) {
              Object o = i.next();
              if (bindingClass.isAssignableFrom(o.getClass())) {
                  wsifPort =
                      makeWSIFPort(
                          def,
                          service,
                          port,
                          typeMap,
                          (ExtensibilityElement) o);
              }
          }
  
          Trc.exit(wsifPort);
          return wsifPort;
      }
  
      /**
       * Factory method to create a WSIFPort.
       * By default this calls the short form of makeWSIFPort
       * which takes only a Definition, Port and WSIFDynamicType.
       * Subclass may override this implementation if required. 
       */
      protected WSIFPort makeWSIFPort(
          Definition def,
          Service service,
          Port port,
          WSIFDynamicTypeMap typeMap,
          ExtensibilityElement binding)
          throws WSIFException {
          return makeWSIFPort(def, port, typeMap);
      }
  
      /**
       * Checks if the provider is active.
       * A provider is active when all the classes it requires
       * are available in the classpath. If they are not, then
       * the provider should disable it self.
       * 
       * @return boolean   true if all the classes are available,
       *                    otherwise false
       */
      protected boolean isActive() {
          String[] requiredClasses = getRequiredClasses();
          return isRequiredClassesAvailable(requiredClasses);
      }
  
      /**
       * Register any extension registeries and initialises
       * the supported binding and address namespaces.
       */
      protected void enableProvider() throws WSIFException {
          ExtensionRegistry[] extensionRegistries = getExtensionRegistries();
          for (int i = 0; i < extensionRegistries.length; i++) {
              WSIFServiceImpl.addExtensionRegistry(extensionRegistries[i]);
          }
          supportedBindings = getSupportedBindingNamespaces();
          supportedAddresses = getSupportedAddressNamespaces();
          Trc.event(null, "provider " + getProviderName() + " enabled");
      }
  
      /**
       * Disable the provider by setting the supported
       * namepsaces to empty arrays.
       */
      protected void disableProvider() {
          String[] none = new String[0];
          supportedBindings = none;
          supportedAddresses = none;
          Trc.event(null, "provider " + getProviderName() + " disabled");
      }
  
      /**
       * Returns the binding namespaces the provider implements
       * TODO: perhaps better for subclasses to hard code this?
       */
      protected String[] getSupportedBindingNamespaces() throws WSIFException {
          ExtensibilityElement binding;
          try {
              binding =
                  (ExtensibilityElement) getImplementedBindingClass()
                      .newInstance();
          } catch (InstantiationException e) {
              throw new WSIFException(
                  "InstantiationException creating binding: "
                      + e.getLocalizedMessage());
          } catch (IllegalAccessException e) {
              throw new WSIFException(
                  "IllegalAccessException creating binding: "
                      + e.getLocalizedMessage());
          }
          return new String[] { binding.getElementType().getNamespaceURI()};
      }
  
      /**
       * Returns the address namespaces the provider implements
       * Defaults to the same as the supported binding namespaces.
       */
      protected String[] getSupportedAddressNamespaces() throws WSIFException {
          return getSupportedBindingNamespaces();
      }
  
      /**
       * Checks if classes are available in the classpath.
       * 
       * @param classes   the names of the classes to check are avaliable
       */
      protected static boolean isRequiredClassesAvailable(final String[] classes) {
          boolean classesAvailable = true;
          if (classes != null) {
              for (int i = 0; classesAvailable && i < classes.length; i++) {
                  final String className = classes[i];
                  Class c =
                      (
                          Class) AccessController
                              .doPrivileged(new PrivilegedAction() {
                      public Object run() {
                          try {
                              return Class.forName(
                                  className,
                                  true,
                                  Thread.currentThread().getContextClassLoader());
                          } catch (Throwable ignored) {
                              Trc.ignoredException(ignored);
                          }
                          return null;
                      }
                  });
                  if (c == null) {
                      classesAvailable = false;
                  }
              }
          }
          Trc.event(null, "required classes available=" + classesAvailable);
          return classesAvailable;
      }
  
      /* The following are all the methods subclasses must implement */
  
      /**
       * Returns the name of the provider
       */
      abstract protected String getProviderName();
  
      /**
       * Returns an array of class names the provider requires available
       */
      abstract protected String[] getRequiredClasses();
  
      /**
       * Returns an array of the ExtensionRegistery's to be registered for the provider
       */
      abstract protected ExtensionRegistry[] getExtensionRegistries();
  
      /**
       * Returns the WSDL4J Binding ExtensabilityElement implemented by the provider 
       */
      abstract protected Class getImplementedBindingClass();
  
      /**
       * Returns a tooling BindingGenerator for the provider
       */
      abstract public BindingGenerator getBindingGenerator();
  
      /**
       * Factory method for providers to make a WSIFPort
       */
      abstract protected WSIFPort makeWSIFPort(
          Definition def,
          Port port,
          WSIFDynamicTypeMap typeMap)
          throws WSIFException;
  
  }
  
  
  

Mime
View raw message