axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rku...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/wsdlgen Namespaces.java
Date Sun, 25 Nov 2001 18:59:16 GMT
rkumar      01/11/25 10:59:16

  Added:       java/src/org/apache/axis/wsdlgen Namespaces.java
  Log:
  Initial namespace support
  Some refactoring & modularization to align with wsdl->Emitter style
  
  Namespaces class: keeps track fo packagename to namespace as well as namespace to prefix.
  some utility methods such as to generate namespace from package name
  
  Revision  Changes    Path
  1.1                  xml-axis/java/src/org/apache/axis/wsdlgen/Namespaces.java
  
  Index: Namespaces.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 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 "Axis" 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.wsdlgen;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.StringTokenizer;
  
  /**
   * <p>Description: A HashMap of packageNames and namespaces with some helper methods
</p>
   *
   * @author rkumar@borland.com
   */
  public class Namespaces extends HashMap {
      private static int prefixCount = 1;
      private HashMap namespacePrefixMap = null;
  
      public Namespaces() {
          super();
          namespacePrefixMap  = new HashMap();
      }
  
      /**
       * Get the namespaace for the given package  If there is no entry in the HashMap for
       * this namespace, create one.
       * @param key String representing packagename
       * @param prefix the prefix to use for the generated namespace
       * @return the namespace either created or existing
       */
      public String getCreate(String key, String prefix) {
          Object value = super.get(key);
          if (value == null) {
              value = makeNamespace((String) key);
              put(key, value, prefix);
          }
          return (String) value;
      }
  
      /**
       * adds an entry to the packagename/namespace HashMap.  In addition,
       * also makes an entry in the auxillary namespace/prefix HashMap if an
       * entry doesn't already exists
       * @param key packageName String
       * @param value namespace value
       * @param prefix the prefix to use for the given namespace
       * @return old value for the specified key
       */
      public Object put(Object key, Object value, String prefix) {
          if (prefix != null)
              namespacePrefixMap.put(value, prefix);
          return super.put(key, value);
      }
  
      /**
       * clears existing entries. adds an entry to the packagename/namespace HashMap
       * for each of the entry in the map.  In addition, also add an entries in the
       * auxillary namespace/prefix HashMap
       * @param map packageName/namespace map
       */
      public void putAll(Map map) {
          super.clear();
          namespacePrefixMap.clear();
          Iterator i = map.keySet().iterator();
          while (i.hasNext()) {
              Object key = i.next();
              String namespace = (String) map.get(key);
              put(key, namespace, null);
          }
      }
  
      /**
       * Get the prefix for the given namespace. If one exists, create one
       * @param namespace namespace
       * @return prefix String
       */
      public String  getCreatePrefix(String namespace) {
          if (namespacePrefixMap.get(namespace) == null) {
              namespacePrefixMap.put(namespace, "tns" + prefixCount++);
          }
          return (String)namespacePrefixMap.get(namespace);
      }
  
      /**
       * put the gine namespace / prefix into the appropriate HashMap
       * @param namespace
       * @param prefix
       */
      public void putPrefix(String namespace, String prefix) {
          namespacePrefixMap.put(namespace, prefix);
      }
  
      /**
       * Make namespace from a fully qualified class name
       * use the default protocol for the namespace
       *
       * @param clsName fully qualified class name
       * @return namespace namespace String
       */
      public static String makeNamespace (String clsName) {
          return makeNamespace(clsName, "http");
      }
  
      /**
       * Make namespace from a fully qualified class name
       * and the given protocol
       *
       * @param clsName fully qualified class name
       * @param protocol protocol String
       * @return namespace namespace String
       */
      public static String makeNamespace (String clsName, String protocol) {
          String packageName = clsName.substring(0, clsName.lastIndexOf('.'));
          StringTokenizer st = new StringTokenizer( packageName, "." );
          String[] words = new String[ st.countTokens() ];
          for(int i = 0; i < words.length; ++i)
              words[i] = st.nextToken();
  
          StringBuffer sb = new StringBuffer(80);
          for(int i = words.length-1; i >= 0; --i) {
              String word = words[i];
              // seperate with dot
              if( i != words.length-1 )
                  sb.append('.');
              sb.append( word );
          }
          return protocol + "://" + sb.toString();
      }
  }
  
  
  

Mime
View raw message