owenb       2003/03/04 10:53:27

  Added:       java/src/org/apache/wsif/mapping
                        ParserMappingConvention.java
  Log:
  Add an implementation of WSIFMappingConvention that uses the same convention as the 
deprectaed getTypeMapping methods on org.apache.schema.Parser
  
  Revision  Changes    Path
  1.1                  
xml-axis-wsif/java/src/org/apache/wsif/mapping/ParserMappingConvention.java
  
  Index: ParserMappingConvention.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2003 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 [EMAIL PROTECTED]
   *
   * 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.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
   
  package org.apache.wsif.mapping;
  
  import java.util.Hashtable;
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.util.WSIFUtils;
  
  /**
   * Implementation of [EMAIL PROTECTED] 
org.apache.wsif.mapping.WSIFMappingConvention} that matches the
   * convention used by the now deprecated getTypeMappings methods on
   * [EMAIL PROTECTED] org.apache.wsif.schema.Parser}<br><br>
   * This convention works as follows:<br>
   * <ul>
   * <li>For all types, the package for the class is determined by in the following 
way:<br>
   * Take the "hostname" part of the namespace uri. Reverse the components. Take the 
remainder 
   * of the uri. Split it by the / character and rebuild with . between each 
component. At 
   * all times strings are checked to make sure that they are valid Java names.<br>
   * </li>
   * <li>Local parts of the xml name are converted to valid Java class names and 
appended to
   * the generated package name</li>
   * <li>Class names for elements are appended with the string "Element"</li>
   * </ul>
   * So for example, the xml name 
   * <br>&nbsp;&nbsp;&nbsp;<tt>http://www.wsif.com/test/types:address</tt>
   * <br>would map to
   * <br>&nbsp;&nbsp;<tt>com.wsif.www.test.types.Address</tt>
   * 
   * @author Owen Burroughs <[EMAIL PROTECTED]>
   */
  public class ParserMappingConvention implements WSIFMappingConvention {
  
      // Table of package mappings: namespace -> packageName
        private Hashtable packageMappings = new Hashtable();
        
      /**
       * @see 
org.apache.wsif.mapping.WSIFMappingConvention#getClassNameForComplexType(QName)
       */
      public String getClassNameForComplexType(QName qn) {
          String namespace = qn.getNamespaceURI();
          String localPart = qn.getLocalPart();
          String packageName = (String) packageMappings.get(namespace);
          if (packageName == null) {
                packageName = WSIFUtils.getPackageNameFromNamespaceURI(namespace);
          }
          String className = WSIFUtils.getJavaClassNameFromXMLName(localPart);
          if (packageName != null
              && !packageName.equals("")
              && className != null
              && !className.equals("")) {
              return packageName + "." + className;
          }
          return null;
      }
  
      /**
       * @see 
org.apache.wsif.mapping.WSIFMappingConvention#getClassNameForSimpleType(QName)
       */
      public String getClassNameForSimpleType(QName qn) {
          String namespace = qn.getNamespaceURI();
          String localPart = qn.getLocalPart();
          String packageName = (String) packageMappings.get(namespace);
          if (packageName == null) {
                packageName = WSIFUtils.getPackageNameFromNamespaceURI(namespace);
          }
          String className = WSIFUtils.getJavaClassNameFromXMLName(localPart);
          if (packageName != null
              && !packageName.equals("")
              && className != null
              && !className.equals("")) {
              return packageName + "." + className;
          }
          return null;
      }
  
      /**
       * @see 
org.apache.wsif.mapping.WSIFMappingConvention#getClassNameForElementType(QName)
       */
      public String getClassNameForElementType(QName qn) {
          String namespace = qn.getNamespaceURI();
          String localPart = qn.getLocalPart();
          String packageName = (String) packageMappings.get(namespace);
          if (packageName == null) {
                packageName = WSIFUtils.getPackageNameFromNamespaceURI(namespace);
          }
          String className = WSIFUtils.getJavaClassNameFromXMLName(localPart);
          if (packageName != null
              && !packageName.equals("")
              && className != null
              && !className.equals("")) {
              return packageName + "." + className;
          }
          return null;
      }
  
        
      /**
       * @see 
org.apache.wsif.mapping.WSIFMappingConvention#overridePackageMapping(String, String)
       */
      public void overridePackageMapping(String namespace, String packageName) {
        if (packageName != null && namespace != null) {
                // Store the namespace as the key and the package name as the value
            packageMappings.put(namespace, packageName);
        }
      }
  }
  
  
  

Reply via email to