You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by sc...@apache.org on 2006/06/02 19:33:13 UTC

svn commit: r411218 [22/34] - in /webservices/muse: branches/1.0/ branches/1.0/src/examples/broker/ branches/1.0/src/examples/broker/WEB-INF/ branches/1.0/src/examples/consumer/ branches/1.0/src/examples/consumer/epr/ branches/1.0/src/examples/consumer...

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/ProjectResourceBundle.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,671 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.i18n;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * <p>Wrapper class for resource bundles. Property files are used to store
+ * resource strings, which are the only types of resources available.
+ * Property files can inherit properties from other files so that
+ * a base property file can be used and a small number of properties
+ * can be over-ridden by another property file. For example you may
+ * create an english version of a resource file named "resource.properties".
+ * You then decide that the British English version of all of the properties
+ * except one are the same, so there is no need to redefine all of the
+ * properties in "resource_en_GB", just the one that is different.</p>
+ * <p>The basename is the name of the property file without the ".properties"
+ * extension.</p>
+ * <p>Properties will be cached for performance.<p>
+ * <p>Property values stored in the property files can also contain dynamic
+ * variables. Any dynamic variable defined in PropertiesUtil.getVariableValue()
+ * can be used (such as {date}), as well as arguments in the form {0}, {1}, etc.
+ * Argument values are specified in the various overloaded getString() methods.</p>
+ *
+ * @author Richard A. Sitze (rsitze@us.ibm.com)
+ * @author Karl Moss (kmoss@macromedia.com)
+ * @author Glen Daniels (gdaniels@apache.org)
+ */
+public class ProjectResourceBundle
+   extends ResourceBundle
+{
+   /** DOCUMENT_ME */
+   protected static Log log = LogFactory.getLog( ProjectResourceBundle.class.getName(  ) );
+
+   // The static cache of ResourceBundles.
+   // The key is the 'basename + locale + default locale'
+   // The element is a ResourceBundle object
+
+   /** DOCUMENT_ME */
+   private static final Hashtable BUNDLE_CACHE = new Hashtable(  );
+
+   /** DOCUMENT_ME */
+   private static final Locale DEFAULT_LOCALE = Locale.getDefault(  );
+
+   /** DOCUMENT_ME */
+   private final ResourceBundle m_resourceBundle;
+
+   /** DOCUMENT_ME */
+   private final String m_resourceName;
+
+   /**
+    * Construct a new ProjectResourceBundle
+    */
+   private ProjectResourceBundle( String         name,
+                                  ResourceBundle bundle )
+   throws MissingResourceException
+   {
+      m_resourceBundle    = bundle;
+      m_resourceName      = name;
+   }
+
+   /**
+    * Construct a new ProjectResourceBundle
+    *
+    * @param projectName The name of the project to which the class belongs.
+    *        It must be a proper prefix of the caller's package.
+    *
+    * @param packageName The calling class.
+    *        This is used to get the package name to further construct
+    *        the basename as well as to get the proper ClassLoader.
+    *
+    * @param resourceName The name of the resource without the
+    *        ".properties" extension
+    *
+    * @throws MissingResourceException if projectName is not a prefix of
+    *         the caller's package name, or if the resource could not be
+    *         found/loaded.
+    */
+   public static ProjectResourceBundle getBundle( String projectName,
+                                                  String packageName,
+                                                  String resourceName )
+   throws MissingResourceException
+   {
+      return getBundle( projectName, packageName, resourceName, null, null, null );
+   }
+
+   /**
+    * Construct a new ProjectResourceBundle
+    *
+    * @param projectName The name of the project to which the class belongs.
+    *        It must be a proper prefix of the caller's package.
+    *
+    * @param caller The calling class.
+    *        This is used to get the package name to further construct
+    *        the basename as well as to get the proper ClassLoader.
+    *
+    * @param resourceName The name of the resource without the
+    *        ".properties" extension
+    *
+    * @throws MissingResourceException if projectName is not a prefix of
+    *         the caller's package name, or if the resource could not be
+    *         found/loaded.
+    */
+   public static ProjectResourceBundle getBundle( String projectName,
+                                                  Class  caller,
+                                                  String resourceName,
+                                                  Locale locale )
+   throws MissingResourceException
+   {
+      return getBundle( projectName, caller, resourceName, locale, null );
+   }
+
+   /**
+    * Construct a new ProjectResourceBundle
+    *
+    * @param projectName The name of the project to which the class belongs.
+    *        It must be a proper prefix of the caller's package.
+    *
+    * @param caller The calling class.
+    *        This is used to get the package name to further construct
+    *        the basename as well as to get the proper ClassLoader.
+    *
+    * @param resourceName The name of the resource without the
+    *        ".properties" extension
+    *
+    * @param locale The locale
+    *
+    * @throws MissingResourceException if projectName is not a prefix of
+    *         the caller's package name, or if the resource could not be
+    *         found/loaded.
+    */
+   public static ProjectResourceBundle getBundle( String      projectName,
+                                                  String      packageName,
+                                                  String      resourceName,
+                                                  Locale      locale,
+                                                  ClassLoader loader )
+   throws MissingResourceException
+   {
+      return getBundle( projectName, packageName, resourceName, locale, loader, null );
+   }
+
+   /**
+    * Construct a new ProjectResourceBundle
+    *
+    * @param projectName The name of the project to which the class belongs.
+    *        It must be a proper prefix of the caller's package.
+    *
+    * @param caller The calling class.
+    *        This is used to get the package name to further construct
+    *        the basename as well as to get the proper ClassLoader.
+    *
+    * @param resourceName The name of the resource without the
+    *        ".properties" extension
+    *
+    * @param locale The locale
+    *
+    * @param extendsBundle If non-null, then this ExtendMessages will
+    *         default to extendsBundle.
+    *
+    * @throws MissingResourceException if projectName is not a prefix of
+    *         the caller's package name, or if the resource could not be
+    *         found/loaded.
+    */
+   public static ProjectResourceBundle getBundle( String         projectName,
+                                                  Class          caller,
+                                                  String         resourceName,
+                                                  Locale         locale,
+                                                  ResourceBundle extendsBundle )
+   throws MissingResourceException
+   {
+      return getBundle( projectName,
+                        getPackage( caller.getClass(  ).getName(  ) ),
+                        resourceName,
+                        locale,
+                        caller.getClass(  ).getClassLoader(  ),
+                        extendsBundle );
+   }
+
+   /**
+    * Construct a new ProjectResourceBundle
+    *
+    * @param projectName The name of the project to which the class belongs.
+    *        It must be a proper prefix of the caller's package.
+    *
+    * @param caller The calling class.
+    *        This is used to get the package name to further construct
+    *        the basename as well as to get the proper ClassLoader.
+    *
+    * @param resourceName The name of the resource without the
+    *        ".properties" extension
+    *
+    * @param locale The locale
+    *
+    * @param extendsBundle If non-null, then this ExtendMessages will
+    *         default to extendsBundle.
+    *
+    * @throws MissingResourceException if projectName is not a prefix of
+    *         the caller's package name, or if the resource could not be
+    *         found/loaded.
+    */
+   public static ProjectResourceBundle getBundle( String         projectName,
+                                                  String         packageName,
+                                                  String         resourceName,
+                                                  Locale         locale,
+                                                  ClassLoader    loader,
+                                                  ResourceBundle extendsBundle )
+   throws MissingResourceException
+   {
+      if ( log.isDebugEnabled(  ) )
+      {
+         log.debug( "getBundle(" + projectName + "," + packageName + "," + resourceName + ","
+                    + String.valueOf( locale ) + ",...)" );
+      }
+
+      Context context = new Context(  );
+      context.setLocale( locale );
+      context.setLoader( loader );
+      context.setProjectName( projectName );
+      context.setResourceName( resourceName );
+      context.setParentBundle( extendsBundle );
+
+      packageName = context.validate( packageName );
+
+      ProjectResourceBundle bundle = null;
+
+      try
+      {
+         bundle = getBundle( context, packageName );
+      }
+      catch ( RuntimeException e )
+      {
+         log.debug( "Exception: ", e );
+         throw e;
+      }
+
+      if ( bundle == null )
+      {
+         throw new MissingResourceException( "Cannot find resource '" + packageName + '.' + resourceName + "'",
+                                             resourceName, "" );
+      }
+
+      return bundle;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public Enumeration getKeys(  )
+   {
+      Enumeration myKeys = m_resourceBundle.getKeys(  );
+
+      if ( parent == null )
+      {
+         return myKeys;
+      }
+      else
+      {
+         final HashSet set = new HashSet(  );
+
+         while ( myKeys.hasMoreElements(  ) )
+         {
+            set.add( myKeys.nextElement(  ) );
+         }
+
+         Enumeration pKeys = parent.getKeys(  );
+
+         while ( pKeys.hasMoreElements(  ) )
+         {
+            set.add( pKeys.nextElement(  ) );
+         }
+
+         return new Enumeration(  )
+            {
+               private Iterator it = set.iterator(  );
+
+               public boolean hasMoreElements(  )
+               {
+                  return it.hasNext(  );
+               }
+
+               public Object nextElement(  )
+               {
+                  return it.next(  );
+               }
+            };
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String getResourceName(  )
+   {
+      return m_resourceName;
+   }
+
+   /**
+    * Clears the internal cache
+    */
+   public static void clearCache(  )
+   {
+      BUNDLE_CACHE.clear(  );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String toString(  )
+   {
+      return m_resourceName;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param key DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws MissingResourceException DOCUMENT_ME
+    */
+   protected Object handleGetObject( String key )
+   throws MissingResourceException
+   {
+      if ( log.isDebugEnabled(  ) )
+      {
+         log.debug( this.toString(  ) + "::handleGetObject(" + key + ")" );
+      }
+
+      //            return resourceBundle.handleGetObject(key);
+      Object obj;
+
+      try
+      {
+         obj = m_resourceBundle.getObject( key );
+      }
+      catch ( MissingResourceException e )
+      {
+         /* catch missing resource, ignore, & return null
+          * if this method doesn't return null, then parents
+          * are not searched
+          */
+         obj = null;
+      }
+
+      return obj;
+   }
+
+   /**
+    * get bundle...
+    * - check cache
+    * - try up hierarchy
+    * - if at top of hierarchy, use (link to) context.getParentBundle()
+    */
+   private static synchronized ProjectResourceBundle getBundle( Context context,
+                                                                String  packageName )
+   throws MissingResourceException
+   {
+      String                cacheKey = context.getCacheKey( packageName );
+
+      ProjectResourceBundle prb = (ProjectResourceBundle) BUNDLE_CACHE.get( cacheKey );
+
+      if ( prb == null )
+      {
+         String         name   = packageName + '.' + context.getResourceName(  );
+         ResourceBundle rb     = context.loadBundle( packageName );
+         ResourceBundle parent = context.getParentBundle( packageName );
+
+         if ( rb != null )
+         {
+            prb = new ProjectResourceBundle( name, rb );
+            prb.setParent( parent );
+
+            if ( log.isDebugEnabled(  ) )
+            {
+               log.debug( "Created " + prb + ", linked to parent " + String.valueOf( parent ) );
+            }
+         }
+         else
+         {
+            if ( parent != null )
+            {
+               if ( parent instanceof ProjectResourceBundle )
+               {
+                  prb = (ProjectResourceBundle) parent;
+               }
+               else
+               {
+                  prb = new ProjectResourceBundle( name, parent );
+               }
+
+               if ( log.isDebugEnabled(  ) )
+               {
+                  log.debug( "Root package not found, cross link to " + parent );
+               }
+            }
+         }
+
+         if ( prb != null )
+         {
+            // Cache the resource
+            BUNDLE_CACHE.put( cacheKey, prb );
+         }
+      }
+
+      return prb;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param name DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   private static final String getPackage( String name )
+   {
+      return name.substring( 0,
+                             name.lastIndexOf( '.' ) ).intern(  );
+   }
+
+   private static class Context
+   {
+      private ClassLoader    _loader;
+      private Locale         _locale;
+      private ResourceBundle _parent;
+      private String         _projectName;
+      private String         _resourceName;
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param packageName DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      String getCacheKey( String packageName )
+      {
+         String loaderName = ( _loader == null ) ? "" : ( ":" + _loader.hashCode(  ) );
+
+         return packageName + "." + _resourceName + ":" + _locale + ":" + DEFAULT_LOCALE + loaderName;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param l DOCUMENT_ME
+       */
+      void setLoader( ClassLoader l )
+      {
+         _loader = ( l != null ) ? l : this.getClass(  ).getClassLoader(  );
+
+         // START FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16868
+         if ( _loader == null )
+         {
+            _loader = ClassLoader.getSystemClassLoader(  );
+         }
+
+         // END FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16868
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      ClassLoader getLoader(  )
+      {
+         return _loader;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param l DOCUMENT_ME
+       */
+      void setLocale( Locale l )
+      {
+         /* 1. Docs indicate that if locale is not specified,
+          *    then the default local is used in it's place.
+          * 2. A null value for locale is invalid.
+          *
+          * Therefore, default...
+          */
+         _locale = ( l == null ) ? DEFAULT_LOCALE : l;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      Locale getLocale(  )
+      {
+         return _locale;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param b DOCUMENT_ME
+       */
+      void setParentBundle( ResourceBundle b )
+      {
+         _parent = b;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      ResourceBundle getParentBundle(  )
+      {
+         return _parent;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param packageName DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      ResourceBundle getParentBundle( String packageName )
+      {
+         ResourceBundle p;
+
+         if ( packageName != _projectName )
+         {
+            p = getBundle( this,
+                           getPackage( packageName ) );
+         }
+         else
+         {
+            p          = _parent;
+            _parent    = null;
+         }
+
+         return p;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param name DOCUMENT_ME
+       */
+      void setProjectName( String name )
+      {
+         _projectName = name.intern(  );
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      String getProjectName(  )
+      {
+         return _projectName;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param name DOCUMENT_ME
+       */
+      void setResourceName( String name )
+      {
+         _resourceName = name.intern(  );
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      String getResourceName(  )
+      {
+         return _resourceName;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param packageName DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      ResourceBundle loadBundle( String packageName )
+      {
+         try
+         {
+            return ResourceBundle.getBundle( packageName + '.' + _resourceName, _locale, _loader );
+         }
+         catch ( MissingResourceException e )
+         {
+            // Deliberately surpressing print stack.. just the string for info.
+            log.debug( "loadBundle: Ignoring MissingResourceException: " + e.getMessage(  ) );
+         }
+
+         return null;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @param packageName DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       *
+       * @throws MissingResourceException DOCUMENT_ME
+       */
+      String validate( String packageName )
+      throws MissingResourceException
+      {
+         if ( ( _projectName == null ) || ( _projectName.length(  ) == 0 ) )
+         {
+            log.debug( "Project name not specified" );
+            throw new MissingResourceException( "Project name not specified", "", "" );
+         }
+
+         if ( ( packageName == null ) || ( packageName.length(  ) == 0 ) )
+         {
+            log.debug( "Package name not specified" );
+            throw new MissingResourceException( "Package not specified", packageName, "" );
+         }
+
+         packageName = packageName.intern(  );
+
+         /* Ensure that project is a proper prefix of class.
+          * Terminate project name with '.' to ensure proper match.
+          */
+         if ( ( packageName != _projectName ) && !packageName.startsWith( _projectName + '.' ) )
+         {
+            log.debug( "Project not a prefix of Package" );
+            throw new MissingResourceException( "Project '" + _projectName + "' must be a prefix of Package '"
+                                                + packageName + "'", packageName + '.' + _resourceName, "" );
+         }
+
+         return packageName;
+      }
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/doclet/ResourcePropertiesGeneratorDoclet.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/doclet/ResourcePropertiesGeneratorDoclet.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/doclet/ResourcePropertiesGeneratorDoclet.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/i18n/doclet/ResourcePropertiesGeneratorDoclet.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,426 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.i18n.doclet;
+
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.Doclet;
+import com.sun.javadoc.FieldDoc;
+import com.sun.javadoc.RootDoc;
+import com.sun.javadoc.Tag;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.Date;
+import java.util.StringTokenizer;
+
+/**
+ * Generates resource.properties files from java files containing @msg Javadoc tags.
+ *
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public class ResourcePropertiesGeneratorDoclet
+   extends Doclet
+{
+   /**
+    * The writer that is used to write the properties files.
+    */
+   protected static BufferedWriter s_file_out;
+
+   /**
+    * The output path for the properties files.
+    */
+   protected static String s_output_path;
+
+   /**
+    * A flag used to mark a file a file that contains resource keys.
+    */
+   protected static boolean s_is_resource_keys_file;
+
+   /**
+    * A flag used to denote when fields are found
+    * in a class that have no @msg tag.  Used
+    * in error checking.
+    */
+   protected static String s_fields_with_no_msg_tag = "";
+
+   /**
+    * It is necessary to over-ride the super class's
+    * method here because we use custom options.
+    * <p>
+    * -d determines the output directory.  -d was
+    * chosen because it coincides with the output directory
+    * for the standard doclet, which allows developers
+    * to leverage certain advantages when using 3rd
+    * party tools like Ant.
+    * <p>
+    * -p sets the flag that will store each resource bundle in its own package directory [--mazz]
+    * <p>
+    * If the option is unrecognized, 0 should be returned
+    * to express that the option is in error.
+    *
+    * @param option
+    *
+    * @return number of params this option contains
+    */
+   public static int optionLength( String option )
+   {
+      int result = 0;
+      if ( option != null )
+      {
+         if ( option.equals( "-d" ) )
+         {
+            result = 2;
+         }
+      }
+
+      return result;
+   }
+
+   /**
+    * The method that gets invoked to process
+    * the javadocs.
+    *
+    * @param root  the root of the document
+    *
+    * @return boolean for success
+    */
+   public static boolean start( RootDoc root )
+   {
+      /*
+       * Note:  One would think that if this method
+       * returned false, that the javadoc system would cite an error
+       * condition.  This is not true.  That is why this code
+       * in this class throws exceptions instead of returning false.
+       */
+      boolean result  = false;
+      String  tagName = "msg";
+      processOptions( root.options(  ) );
+      result = processSourceFiles( root.classes(  ),
+                                   tagName );
+      return result;
+   }
+
+   /**
+    * This method closes the output stream to the .properties file if it is
+    * open.
+    */
+   protected static void closeOutputStream(  )
+   {
+      try
+      {
+         if ( s_file_out != null )
+         {
+            s_file_out.flush(  );
+            s_file_out.close(  );
+            s_file_out = null;
+         }
+      }
+      catch ( IOException e )
+      {
+         e.printStackTrace(  );
+      }
+   }
+
+   /**
+    * Opens a properties file for writing.
+    *
+    * @param sourceFile the javadoc representation of a source file.
+    * Used for determining the name of the properties file.
+    */
+   protected static void openOutputFile( ClassDoc sourceFile )
+   {
+      String fileName    = "resource.properties";
+      String packagePath = sourceFile.containingPackage(  ).name(  ).replace( '.', File.separatorChar );
+      String filePath    = s_output_path + File.separator + packagePath + File.separator + fileName;
+      System.out.println( "Writing " + filePath + " ..." );
+      try
+      {
+         s_file_out = new BufferedWriter( new FileWriter( filePath ) );
+      }
+      catch ( IOException e )
+      {
+         e.printStackTrace(  );
+      }
+   }
+
+   /**
+    * This method prints a standard header into the properties files.
+    *
+    * @param sourceFile
+    */
+   protected static void printStandardFileHeader( ClassDoc sourceFile )
+   {
+      String keysFilePath = sourceFile.qualifiedName(  ).replace( '.', File.separatorChar ) + ".java";
+      try
+      {
+         s_file_out.write( "# Resource bundle for package " + sourceFile.containingPackage(  ).name(  )
+                           + " and its subpackages" );
+         s_file_out.newLine(  );
+         s_file_out.write( "# Auto-generated " + new Date(  ) + " from: " + keysFilePath );
+         s_file_out.newLine(  );
+         s_file_out.newLine(  );
+      }
+      catch ( IOException ioe )
+      {
+         ioe.printStackTrace(  );
+      }
+   }
+
+   /**
+    * From the command line options to javadoc, this method extracts
+    * the output path for the properties files.
+    *
+    * @param options from the command line.
+    */
+   protected static void processOptions( String[][] options )
+   {
+      for ( int i = 0; i < options.length; i++ )
+      {
+         if ( ( options[i][0] != null ) && options[i][0].equals( "-d" ) )
+         {
+            s_output_path = options[i][1];
+         }
+      }
+   }
+
+   /**
+    * This method looks at each
+    * of the <code>java.lang.String</code> fields for each class to see if a @msg tag exists.
+    * If more than one @msg tag exists per field, it's an error.  If even one
+    * <code>String</code> field contains a @msg tag, then the whole document is considered
+    * a resource keys document. If any <code>String</code> fields in the document are then
+    * missing @msg tags, it is considered an error.  Field names must
+    * match their value, otherwise it is an error.  Non-<code>String</code> fields that do not have
+    * @msg tags are ignored.  If a non-<code>String</code> field has a @msg tag, it is considered an error.
+    *
+    * @param classes the array of classes to be processed
+    * @param tagName the name of the tag to check for
+    * @throws IllegalArgumentException if there are too many @msg tags per field,
+    * or if a document is considered a resource keys document, but it contains
+    * fields that do not have @msg tags.
+    */
+   protected static boolean processSourceFiles( ClassDoc[] classes,
+                                                String     tagName )
+   {
+      boolean result = true;
+
+      for ( int i = 0; i < classes.length; i++ )
+      {
+         // get the fields of the class
+         FieldDoc[] fields = classes[i].fields(  );
+
+         for ( int j = 0; j < fields.length; j++ )
+         {
+            Tag[] tags = fields[j].tags( tagName );
+
+            if ( tags.length > 1 )
+            {
+               result = false;
+               throw new IllegalArgumentException( "Only one @" + tagName + " tag allowed per field. " + tags );
+            }
+
+            if ( tags.length > 0 )
+            {
+               s_is_resource_keys_file = true;
+               validate( classes[i], fields[j] );
+               writeToPropertiesFile( fields[j].name(  ) + "=" + tags[0].text(  ), classes[i] );
+
+               // print a warning since ' causes problems with parameter replacement --mazz
+               if ( tags[0].text(  ).indexOf( '\'' ) != -1 )
+               {
+                  System.err.println( "Warning: " + ResourcePropertiesGeneratorDoclet.class.getName(  )
+                                      + " has detected a single quote in '" + classes[i] + "."
+                                      + fields[j].name(  )
+                                      + "'; make sure it does not affect parameter replacement. [" + tags[0] + "]" );
+               }
+            }
+            else if ( tags.length == 0 )
+            {
+               try
+               {
+                  // skip it unless the data member type is a String, since that's the only type that holds a message key constant
+                  Class resourceKeyClass =
+                     Class.forName( classes[i].containingPackage(  ).name(  ) + "." + classes[i].name(  ) );
+                  Field memberField = resourceKeyClass.getField( fields[j].name(  ) );
+
+                  if ( memberField.getType(  ).isAssignableFrom( String.class ) )
+                  {
+                     s_fields_with_no_msg_tag += ( fields[j].name(  ) + " " );
+                  }
+               }
+               catch ( Throwable t )
+               {
+                  // the only way for this to be thrown is if Class.forName failed or Class.getField failed.
+                  // Normally this occurs because a data type is not in the classpath; in which case we should
+                  // ignore this since we only care about String data types (and String is always in classpath).
+                  // This may also fail with classes that have static initializers that fail; again, we typically
+                  // can ignore this since resource key interfaces won't have static initializers that fail.
+               }
+            }
+         }
+
+         if ( s_is_resource_keys_file && ( s_fields_with_no_msg_tag.length(  ) > 0 ) )
+         {
+            result = false;
+            closeOutputStream(  );
+            throw new IllegalArgumentException( classes[i].name(  ) + " in the "
+                                                + classes[i].containingPackage(  ).name(  ) + " package "
+                                                + "contains a key or keys that have no associated value (or @msg tag).  "
+                                                + "Please check the key(s): " + s_fields_with_no_msg_tag );
+         }
+
+         closeOutputStream(  );
+         s_is_resource_keys_file     = false;
+         s_fields_with_no_msg_tag    = "";
+      }
+
+      return result;
+   }
+
+   /**
+    * Strips any newlines and accompanying white space from a string.
+    *
+    * @param message
+    *
+    * @return
+    */
+   protected static String stripNewLines( String message )
+   {
+      if ( message.indexOf( '\n' ) != -1 )
+      {
+         final StringTokenizer tokenizer = new StringTokenizer( message, "\n" );
+         final StringBuffer    buf = new StringBuffer(  );
+
+         while ( tokenizer.hasMoreTokens(  ) )
+         {
+            final String token = tokenizer.nextToken(  ).trim(  );
+
+            if ( !token.equals( "" ) )
+            {
+               buf.append( token );
+               buf.append( ' ' );
+            }
+         }
+
+         message = buf.toString(  );
+      }
+
+      return ( message.trim(  ) );
+   }
+
+   /**
+    * This method makes sure that the field name and its corresponding
+    * String value are identical.  If they are not identical, an
+    * exception is thrown.  If the field is not of type String, an exception is thrown.
+    *
+    * @param classDoc is used for error reporting purposes
+    * @param fieldDoc the field to be validated
+    * @throws IllegalArgumentException if the field name and its String value
+    * are not identical.
+    * @throws RuntimeException if there is a problem with the Introspection
+    * of the field value.
+    * @throws SecurityException if the introspection violates a security policy
+    * of the JVM.
+    */
+   protected static void validate( ClassDoc classDoc,
+                                   FieldDoc fieldDoc )
+   {
+      String fieldValue = null;
+      String errorMsg  = null;
+      String className = classDoc.containingPackage(  ).name(  ) + "." + classDoc.name(  );
+
+      try
+      {
+         Class resourceKeyClass = Class.forName( className );
+         fieldValue = (String) resourceKeyClass.getField( fieldDoc.name(  ) ).get( null );
+      }
+      catch ( ClassCastException e )
+      {
+         errorMsg =
+            "The class " + className + " has a field " + fieldDoc.name(  ) + " that is not of type String "
+            + "but has a Javadoc tag indicating it is a resource key. "
+            + "Resource key fields must be of type String.";
+      }
+      catch ( ClassNotFoundException e )
+      {
+         errorMsg =
+            "The class " + className + " was not found in the classpath for the doclet. "
+            + "To add this class to the classpath, make sure it is included in the -docletpath parameter. "
+            + "(Doclets have their own class loaders which receive this value as their class path.)"
+            + e.getMessage(  );
+      }
+      catch ( IllegalAccessException e )
+      {
+         errorMsg =
+            "The class " + className + " does not allow access to the field " + fieldDoc.name(  )
+            + ".  This field must be public." + e.getMessage(  );
+      }
+      catch ( NoSuchFieldException e )
+      {
+         errorMsg =
+            "The compiled version of class " + className + " does not contain a field (" + fieldDoc.name(  )
+            + ") that was found in the javadocs.  Make sure the compiled" + "version is up-to-date."
+            + e.getMessage(  );
+      }
+
+      if ( errorMsg != null )
+      {
+         // this should, perhaps be a subclass of RuntimeException, however
+         // nobody is going to try to make sense out of this exception, so there's
+         // not much point to it.  We just want to stop processing and report a reason.
+         throw new RuntimeException( errorMsg );
+      }
+
+      if ( ( fieldValue == null ) || ( !fieldValue.equals( fieldDoc.name(  ) ) ) )
+      {
+         throw new IllegalArgumentException( "In class " + className + ", the value of the field '"
+                                             + fieldDoc.name(  ) + "' is '" + fieldValue
+                                             + "', which does not equal the field name (but it must be equal)." );
+      }
+   }
+
+   /**
+    * This method writes to the properties file.  If the file
+    * is not open for writing, it opens it and prints a standard
+    * header.  If the message containes new lines,
+    * the white space information is stripped, before the msg is printed.
+    *
+    * @param msg the message to add to the properties file
+    * @param sourceFile the source javadocs. needed mainly for its name.
+    */
+   protected static void writeToPropertiesFile( String   msg,
+                                                ClassDoc sourceFile )
+   {
+      if ( s_file_out == null )
+      {
+         openOutputFile( sourceFile );
+         printStandardFileHeader( sourceFile );
+      }
+
+      try
+      {
+         msg = stripNewLines( msg );
+         s_file_out.write( msg );
+         s_file_out.newLine(  );
+      }
+      catch ( IOException e )
+      {
+         e.printStackTrace(  );
+      }
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BasicBeanFactory.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,70 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
+/**
+ * An extension of the Commons Naming {@link org.apache.naming.factory.BeanFactory}
+ * that overrides
+ * {@link org.apache.naming.factory.BeanFactory#getObjectInstance(Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)}
+ * to add support for calling init() on any bean that implements the {@link Initializable} interface.
+ *
+ * @author Globus
+ */
+public class BasicBeanFactory
+   extends org.apache.naming.factory.BeanFactory
+{
+   private static final Log LOG = LogFactory.getLog( BasicBeanFactory.class );
+
+   /**
+    * Create a new Bean instance. If the created bean implements
+    * <code>Initializable</code> interface, the <code>initialize()</code>
+    * function will be called after the bean is created and all properties
+    * are set.
+    */
+   public Object getObjectInstance( Object    obj,
+                                    Name      name,
+                                    Context   nameCtx,
+                                    Hashtable environment )
+   throws NamingException
+   {
+      LOG.debug( "Creating instance of " + obj.getClass(  ).getName(  ) + " bean "
+                 + " and adding to JNDI registry with name " + name + " ..." );
+      Object bean = super.getObjectInstance( obj, name, nameCtx, environment );
+      if ( bean instanceof Initializable )
+      {
+         try
+         {
+            LOG.debug( "Calling init() on the bean: " + bean.getClass(  ).getName(  ) );
+            ( (Initializable) bean ).init(  );
+         }
+         catch ( Exception e )
+         {
+            NamingException ex = new NamingException( "beanInitFailed" );
+            ex.setRootCause( e );
+            throw ex;
+         }
+      }
+
+      return bean;
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BeanFactory.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BeanFactory.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BeanFactory.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/BeanFactory.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,180 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.axis.AxisEngine;
+import org.apache.axis.MessageContext;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.security.auth.Subject;
+import java.security.PrivilegedExceptionAction;
+import java.util.Hashtable;
+
+/**
+ * Bean factory.
+ *
+ * @author Globus
+ *
+ * TODO (v1.1): remove Axis dependency from this class
+ */
+public class BeanFactory
+   extends BasicBeanFactory
+{
+   /**
+    * Create a new Bean instance. If <code>obj</code> is of type
+    * {@link ServiceResourceRef}, the bean will be
+    * created and initialized with security credentials associated
+    * with the current thread if the service associated with this bean
+    * has a security descriptor configured.
+    */
+   public Object getObjectInstance( Object    obj,
+                                    Name      name,
+                                    Context   nameCtx,
+                                    Hashtable environment )
+   throws NamingException
+   {
+      Subject        subject = null;
+      MessageContext msgCtx = null;
+
+      if ( obj instanceof ServiceResourceRef )
+      {
+         ServiceResourceRef resource    = (ServiceResourceRef) obj;
+         AxisEngine         engine      = resource.getAxisEngine(  );
+         String             serviceName = resource.getServiceName(  );
+         if ( engine == null )
+         {
+            throw new NamingException( "noServiceSet" );
+         }
+
+         if ( serviceName == null )
+         {
+            throw new NamingException( "noEngineSet" );
+         }
+      }
+
+      /* ServiceManager serviceManager =
+         ServiceManager.getServiceManager((AxisServer)engine);
+         SecurityManager securityManager =
+             SecurityManager.getManager();
+      
+                        try {
+                            msgCtx = serviceManager.createMessageContext(serviceName);
+                            ServiceSecurityConfig.initialize(msgCtx);
+                            subject = securityManager.getServiceSubject(serviceName);
+                        } catch (Exception e) {
+                            NamingException ne =
+                                new NamingException(i18n.getMessage("beanSecInitFailed"));
+                            ne.setRootCause(e);
+                            throw ne;
+                        }
+                    }*/
+      try
+      {
+         if ( subject == null )
+         {
+            return getInstance( msgCtx, obj, name, nameCtx, environment );
+         }
+         else
+         {
+            /*  GetInstanceAction action =
+               new GetInstanceAction(msgCtx, obj, name,
+                                     nameCtx, environment);
+               return JaasSubject.doAs(subject, action);*/
+         }
+      }
+      catch ( NamingException e )
+      {
+         throw e;
+      } /*catch (PrivilegedActionException e) {
+         Exception cause = e.getException();
+         if (cause instanceof NamingException) {
+             throw (NamingException)cause;
+         } else {
+             NamingException nm =
+                 new NamingException("beanInitFailed");
+             nm.setRootCause(cause);
+             throw nm;
+         }
+         } */
+      catch ( Exception e )
+      {
+         NamingException nm = new NamingException( "beanInitFailed" );
+         nm.setRootCause( e );
+         throw nm;
+      }
+
+      //todo fix this method
+      return null;
+   }
+
+   private Object getInstance( MessageContext msgCtx,
+                               Object         obj,
+                               Name           name,
+                               Context        nameCtx,
+                               Hashtable      environment )
+   throws NamingException
+   { //todo fix!
+
+      // MessageContext oldCtx =
+      //    ServiceManager.HelperAxisEngine.getCurrentMessageContext();
+      //  ServiceManager.HelperAxisEngine.setCurrentMessageContext(msgCtx);
+      try
+      {
+         return super.getObjectInstance( obj, name, nameCtx, environment );
+      }
+      finally
+      {
+         // ServiceManager.HelperAxisEngine.setCurrentMessageContext(oldCtx);
+      }
+   }
+
+   private class GetInstanceAction
+      implements PrivilegedExceptionAction
+   {
+      private MessageContext msgCtx;
+      private Object         obj;
+      private Name           name;
+      private Context        nameCtx;
+      private Hashtable      environment;
+
+      private GetInstanceAction( MessageContext msgCtx,
+                                 Object         obj,
+                                 Name           name,
+                                 Context        nameCtx,
+                                 Hashtable      environment )
+      {
+         this.msgCtx         = msgCtx;
+         this.obj            = obj;
+         this.name           = name;
+         this.nameCtx        = nameCtx;
+         this.environment    = environment;
+      }
+
+      /**
+       * DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       *
+       * @throws Exception DOCUMENT_ME
+       */
+      public Object run(  )
+      throws Exception
+      {
+         return getInstance( this.msgCtx, this.obj, this.name, this.nameCtx, this.environment );
+      }
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/DefaultParameters.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/DefaultParameters.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/DefaultParameters.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/DefaultParameters.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,47 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+
+/**
+ * A bean to hold default values for Service config parameters.
+ *
+ * @author Sal Campana
+ */
+public class DefaultParameters
+{
+   private String m_defaultFactory = org.apache.ws.util.jndi.BeanFactory.class.getName(  );
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param defaultFactory DOCUMENT_ME
+    */
+   public void setFactory( String defaultFactory )
+   {
+      m_defaultFactory = defaultFactory;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String getFactory(  )
+   {
+      return m_defaultFactory;
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/Initializable.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/Initializable.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/Initializable.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/Initializable.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,32 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+
+/**
+ * Used with {@link BeanFactory}.
+ * The init() method will be called if the bean implements this interface.
+ */
+public interface Initializable
+{
+   /**
+    * DOCUMENT_ME
+    *
+    * @throws Exception DOCUMENT_ME
+    */
+   void init(  )
+   throws Exception;
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/JNDIUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/JNDIUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/JNDIUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/JNDIUtils.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,410 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.axis.AxisEngine;
+import org.apache.axis.Constants;
+import org.apache.axis.MessageContext;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.naming.ContextBindings;
+import org.apache.ws.util.DeployConstants;
+import org.apache.ws.util.jndi.tools.JNDIConfigRuleSet;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.StringTokenizer;
+
+/**
+ * A utility class containing methods for setting up the JNDI environment and performing JNDI lookups.
+ */
+public abstract class JNDIUtils
+{
+   //TODO (low-priority): many of these methods should be made private
+   private static Log LOG = LogFactory.getLog( JNDIUtils.class.getName(  ) );
+
+   /**
+    * Apache JNDI URL Package Prefix
+    */
+   public static final String APACHE_URL_PKG_PREFIX = "org.apache.naming";
+
+   /**
+    * Apache JNDI Initial Context Factory Prefix
+    */
+   public static final String APACHE_INITIAL_CONTEXT_FACTORY = "org.apache.naming.java.javaURLContextFactory";
+
+   /** DOCUMENT_ME */
+   public static final String JNDI_CONFIG    = "jndi-config.xml";
+   private static Context     initialContext = null;
+
+   /**
+    * Create all intermediate subcontexts.
+    */
+   public static Context createSubcontexts( Context currentContext,
+                                            String  name )
+   throws NamingException
+   {
+      StringTokenizer tokenizer = new StringTokenizer( name, "/" );
+
+      while ( tokenizer.hasMoreTokens(  ) )
+      {
+         String token = tokenizer.nextToken(  );
+         if ( ( !token.equals( "" ) ) && ( tokenizer.hasMoreTokens(  ) ) )
+         {
+            try
+            {
+               currentContext = currentContext.createSubcontext( token );
+            }
+            catch ( NamingException e )
+            {
+               // Silent catch. Probably an object is already bound in
+               // the context.
+               currentContext = (Context) currentContext.lookup( token );
+            }
+         }
+      }
+
+      return currentContext;
+   }
+
+   /**
+    * Configure JNDI with the Apache Tomcat naming service classes and create the comp and env contexts
+    *
+    * @return The initial context
+    *
+    * @throws Exception
+    */
+   public static Context initJNDI(  )
+   throws Exception
+   {
+      LOG.debug( "Initializing JNDI..." );
+      Context result      = null;
+      Context compContext = null;
+
+      // set up naming
+      String value    = APACHE_URL_PKG_PREFIX;
+      String oldValue = System.getProperty( Context.URL_PKG_PREFIXES );
+
+      if ( oldValue != null )
+      {
+         if ( oldValue.startsWith( value + ":" ) )
+         {
+            value = oldValue;
+         }
+         else
+         {
+            value = value + ":" + oldValue;
+         }
+      }
+
+      LOG.debug( "Setting System Property " + Context.URL_PKG_PREFIXES + " to " + value );
+      System.setProperty( Context.URL_PKG_PREFIXES, value );
+
+      value = System.getProperty( Context.INITIAL_CONTEXT_FACTORY );
+
+      if ( value == null )
+      {
+         System.setProperty( Context.INITIAL_CONTEXT_FACTORY, APACHE_INITIAL_CONTEXT_FACTORY );
+         LOG.debug( "Setting System Property " + Context.INITIAL_CONTEXT_FACTORY + " to "
+                    + APACHE_INITIAL_CONTEXT_FACTORY );
+      }
+      else
+      {
+         LOG.debug( "System Property " + Context.INITIAL_CONTEXT_FACTORY + " is set to " + value );
+      }
+
+      result = new InitialContext(  );
+      if ( !ContextBindings.isClassLoaderBound(  ) )
+      {
+         ContextBindings.bindContext( "wsrfContext", result );
+         ContextBindings.bindClassLoader( "wsrfContext" );
+      }
+
+      try
+      {
+         result.lookup( "java:comp/env" );
+      }
+      catch ( NameNotFoundException e )
+      {
+         compContext = result.createSubcontext( "comp" );
+         compContext.createSubcontext( "env" );
+      }
+
+      return result;
+   }
+
+   // multiple file configuration
+   public static synchronized Context initializeDir( MessageContext msgCtx )
+   throws Exception
+   {
+      if ( initialContext == null )
+      {
+         Context context   = initJNDI(  );
+         String  dir       = (String) msgCtx.getProperty( Constants.MC_CONFIGPATH );
+         String  configDir =
+            ( dir == null ) ? DeployConstants.CONFIG_BASE_DIR
+                            : ( dir + File.separator + DeployConstants.CONFIG_BASE_DIR );
+
+         File   fDir = new File( configDir );
+         File[] dirs = fDir.listFiles( new DirFilter(  ) );
+         for ( int i = 0; i < dirs.length; i++ )
+         {
+            processJNDIFile( context,
+                             dirs[i],
+                             msgCtx.getAxisEngine(  ),
+                             JNDI_CONFIG );
+         }
+
+         initialContext = context;
+      }
+
+      return initialContext;
+   }
+
+   // single file configuration
+   public static synchronized Context initializeFile( MessageContext msgCtx )
+   throws Exception
+   {
+      if ( initialContext == null )
+      {
+         Context     context = initJNDI(  );
+
+         InputStream configInput;
+         try
+         {
+            String cfgDir = null;
+            if ( msgCtx != null )
+            {
+               cfgDir = (String) msgCtx.getProperty( Constants.MC_CONFIGPATH );
+            }
+
+            if ( cfgDir == null )
+            {
+               cfgDir = ".";
+            }
+
+            String file = cfgDir + File.separator + JNDI_CONFIG;
+            LOG.debug( "Trying to load JNDI configuration from file: " + file );
+
+            configInput = new FileInputStream( file );
+         }
+         catch ( FileNotFoundException e )
+         {
+            LOG.debug( "Trying to load JNDI configuration from resource stream: " + JNDI_CONFIG );
+
+            configInput = JNDIUtils.class.getClassLoader(  ).getResourceAsStream( JNDI_CONFIG );
+
+            if ( configInput == null )
+            {
+               throw new IOException( "jndiConfigNotFound" );
+            }
+         }
+
+         parseJNDIConfig( context,
+                          configInput,
+                          msgCtx.getAxisEngine(  ) );
+
+         initialContext = context;
+      }
+
+      return initialContext;
+   }
+
+   /**
+    * Retrieves the named object on the specified context. The object returned must be of assignable from the type
+    * specified.
+    *
+    * @param context the context to perform lookup on
+    * @param name    the name of the object to lookup
+    * @param type    the expected type of the object returned
+    */
+   public static Object lookup( Context context,
+                                String  name,
+                                Class   type )
+   throws NamingException
+   {
+      if ( context == null )
+      {
+         throw new IllegalArgumentException( "nullArgument:context" );
+      }
+
+      if ( type == null )
+      {
+         throw new IllegalArgumentException( "nullArgument:type" );
+      }
+
+      Object tmp = context.lookup( name );
+      if ( type.isAssignableFrom( tmp.getClass(  ) ) )
+      {
+         return tmp;
+      }
+      else
+      {
+         throw new NamingException( "expectedType " + type.getName(  ) );
+      }
+   }
+
+   /**
+    * Parse the given JNDI configuration and populate the JNDI registry using the parsed configuration
+    *
+    * @param configInput The configuration stream to parse
+    *
+    * @throws Exception
+    */
+   public static void parseJNDIConfig( InputStream configInput )
+   throws Exception
+   {
+      parseJNDIConfig( new InitialContext(  ),
+                       configInput,
+                       null );
+   }
+
+   /**
+    * Parse the given JNDI configuration and populate the JNDI registry using the parsed configuration
+    *
+    * @param configInput The configuration stream to parse
+    *
+    * @throws Exception
+    */
+   public static void parseJNDIConfig( Context     initContext,
+                                       InputStream configInput,
+                                       AxisEngine  engine )
+   throws Exception
+   {
+      if ( configInput == null )
+      {
+         throw new IllegalArgumentException( "config input stream was null." );
+      }
+
+      if ( initContext == null )
+      {
+         throw new IllegalArgumentException( "initial context was null." );
+      }
+
+      Context  envContext = (Context) initContext.lookup( "java:comp/env" );
+      Digester digester = new Digester(  );
+
+      digester.setNamespaceAware( true );
+      digester.setValidating( false ); // don't do any validation for now
+      digester.addRuleSet( new JNDIConfigRuleSet( "jndiConfig/" ) );
+
+      digester.push( new NamingContext( envContext, engine ) );
+      digester.parse( configInput );
+      digester.clear(  );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param ctx DOCUMENT_ME
+    * @param name DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    *
+    * @throws NamingException DOCUMENT_ME
+    */
+   public static String toString( Context ctx,
+                                  String  name )
+   throws NamingException
+   {
+      StringBuffer buf = new StringBuffer(  );
+      toString( buf, ctx, name, "" );
+      return buf.toString(  );
+   }
+
+   private static void processJNDIFile( Context    context,
+                                        File       dir,
+                                        AxisEngine engine,
+                                        String     configFile )
+   throws Exception
+   {
+      File file = new File( dir, configFile );
+      if ( !file.exists(  ) )
+      {
+         return;
+      }
+
+      LOG.debug( "Loading jndi configuration from file: " + file );
+
+      InputStream in = null;
+      try
+      {
+         in = new FileInputStream( file );
+         parseJNDIConfig( context, in, engine );
+      }
+      finally
+      {
+         if ( in != null )
+         {
+            try
+            {
+               in.close(  );
+            }
+            catch ( IOException e )
+            {
+            }
+         }
+      }
+   }
+
+   private static void toString( StringBuffer buf,
+                                 Context      ctx,
+                                 String       name,
+                                 String       tab )
+   throws NamingException
+   {
+      buf.append( tab ).append( "context: " ).append( name ).append( "\n" );
+      NamingEnumeration list = ctx.list( name );
+      while ( list.hasMore(  ) )
+      {
+         NameClassPair nc = (NameClassPair) list.next(  );
+         if ( nc.getClassName(  ).equals( "org.apache.naming.NamingContext" ) )
+         {
+            toString( buf, ctx, name + "/" + nc.getName(  ), tab + "  " );
+         }
+         else
+         {
+            buf.append( tab ).append( " " ).append( nc ).append( "\n" );
+         }
+      }
+   }
+
+   private static class DirFilter
+      implements FileFilter
+   {
+      /**
+       * DOCUMENT_ME
+       *
+       * @param path DOCUMENT_ME
+       *
+       * @return DOCUMENT_ME
+       */
+      public boolean accept( File path )
+      {
+         return path.isDirectory(  );
+      }
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/NamingContext.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/NamingContext.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/NamingContext.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/NamingContext.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,368 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.axis.AxisEngine;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.naming.ResourceRef;
+import org.apache.ws.util.jndi.tools.ConfigContext;
+import org.apache.ws.util.jndi.tools.Environment;
+import org.apache.ws.util.jndi.tools.Resource;
+import org.apache.ws.util.jndi.tools.ResourceLink;
+import org.apache.ws.util.jndi.tools.ResourceParameters;
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class NamingContext
+{
+   private static Log LOG     = LogFactory.getLog( NamingContext.class.getName(  ) );
+   private Context    context;
+   private AxisEngine engine;
+
+   /**
+    * Creates a new {@link NamingContext} object.
+    *
+    * @param context DOCUMENT_ME
+    * @param engine  DOCUMENT_ME
+    */
+   public NamingContext( Context    context,
+                         AxisEngine engine )
+   {
+      this.context    = context;
+      this.engine     = engine;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param environment DOCUMENT_ME
+    *
+    * @throws IllegalArgumentException DOCUMENT_ME
+    * @throws NamingException          DOCUMENT_ME
+    */
+   public void addEnvironment( Environment environment )
+   throws IllegalArgumentException, 
+          NamingException
+   {
+      Object value = null;
+
+      // Instantiate a new instance of the correct object type, and
+      // initialize it.
+      String type = environment.getType(  );
+      LOG.debug( "Attempting to add environment for type: " + type );
+      try
+      {
+         if ( type.equals( "java.lang.String" ) )
+         {
+            value = environment.getValue(  );
+         }
+         else if ( type.equals( "java.lang.Byte" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Byte( (byte) 0 );
+            }
+            else
+            {
+               value = Byte.decode( environment.getValue(  ) );
+            }
+         }
+         else if ( type.equals( "java.lang.Short" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Short( (short) 0 );
+            }
+            else
+            {
+               value = Short.decode( environment.getValue(  ) );
+            }
+         }
+         else if ( type.equals( "java.lang.Integer" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Integer( 0 );
+            }
+            else
+            {
+               value = Integer.decode( environment.getValue(  ) );
+            }
+         }
+         else if ( type.equals( "java.lang.Long" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Long( 0 );
+            }
+            else
+            {
+               value = Long.decode( environment.getValue(  ) );
+            }
+         }
+         else if ( type.equals( "java.lang.Boolean" ) )
+         {
+            value = Boolean.valueOf( environment.getValue(  ) );
+         }
+         else if ( type.equals( "java.lang.Double" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Double( 0 );
+            }
+            else
+            {
+               value = Double.valueOf( environment.getValue(  ) );
+            }
+         }
+         else if ( type.equals( "java.lang.Float" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Float( 0 );
+            }
+            else
+            {
+               value = Float.valueOf( environment.getValue(  ) );
+            }
+         }
+         else if ( type.equals( "java.lang.Character" ) )
+         {
+            if ( environment.getValue(  ) == null )
+            {
+               value = new Character( (char) 0 );
+            }
+            else
+            {
+               if ( environment.getValue(  ).length(  ) == 1 )
+               {
+                  value = new Character( environment.getValue(  ).charAt( 0 ) );
+               }
+               else
+               {
+                  throw new IllegalArgumentException(  );
+               }
+            }
+         }
+         else
+         {
+            throw new IllegalArgumentException( "invalidType : " + type );
+         }
+      }
+      catch ( NumberFormatException e )
+      {
+         String msg = "invalidValueForType : " + environment.getValue(  ) + " : " + type;
+         LOG.error( msg, e );
+         throw new IllegalArgumentException( msg );
+      }
+
+      // Bind the object to the appropriate name
+      createSubcontexts( environment.getName(  ) );
+      this.context.bind( environment.getName(  ),
+                         value );
+      if ( LOG.isDebugEnabled(  ) )
+      {
+         LOG.debug( "Added environment entry with name: " + environment.getName(  ) );
+         LOG.debug( "value: " + value + " and type: " + environment.getType(  ) );
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param resource DOCUMENT_ME
+    *
+    * @throws NamingException DOCUMENT_ME
+    */
+   public void addResource( Resource resource )
+   throws NamingException
+   {
+      Reference reference =
+         new ResourceRef( resource.getType(  ),
+                          resource.getDescription(  ),
+                          resource.getScope(  ),
+                          resource.getAuth(  ) );
+      this.addParameters( reference,
+                          resource.getParameters(  ) );
+      this.createSubcontexts( resource.getName(  ) );
+      this.context.bind( resource.getName(  ),
+                         reference );
+      LOG.debug( "Added resource entry with name: " + resource.getName(  ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param resourceLink DOCUMENT_ME
+    *
+    * @throws NamingException DOCUMENT_ME
+    */
+   public void addResourceLink( ResourceLink resourceLink )
+   throws NamingException
+   {
+      LinkRef link = new LinkRef( resourceLink.getTarget(  ) );
+      this.createSubcontexts( resourceLink.getName(  ) );
+      this.context.bind( resourceLink.getName(  ),
+                         link );
+      if ( LOG.isDebugEnabled(  ) )
+      {
+         LOG.debug( "Added resource link with name: " + resourceLink.getName(  ) );
+         LOG.debug( "Pointing to: " + resourceLink.getTarget(  ) );
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param subContext DOCUMENT_ME
+    *
+    * @throws NamingException DOCUMENT_ME
+    */
+   public void addService( ConfigContext subContext )
+   throws NamingException
+   {
+      String        serviceName  = subContext.getName(  );
+      Set           names;
+      Iterator      nameIterator;
+      NamingContext newContext;
+
+      Context       servicesContext = null;
+      try
+      {
+         servicesContext = (Context) this.context.lookup( "services" );
+      }
+      catch ( NameNotFoundException e )
+      {
+         servicesContext = this.context.createSubcontext( "services" );
+      }
+
+      JNDIUtils.createSubcontexts( servicesContext, serviceName );
+
+      try
+      {
+         newContext = new NamingContext( servicesContext.createSubcontext( serviceName ),
+                                         this.engine );
+         LOG.debug( "Created new subcontext with name: " + serviceName );
+      }
+      catch ( Exception e )
+      {
+         newContext = new NamingContext( (Context) servicesContext.lookup( serviceName ), this.engine );
+         LOG.debug( "Adding entries to existing subcontext with name: " + serviceName );
+      }
+
+      names           = subContext.getEnvironmentNames(  );
+      nameIterator    = names.iterator(  );
+
+      while ( nameIterator.hasNext(  ) )
+      {
+         newContext.addEnvironment( subContext.getEnvironment( (String) nameIterator.next(  ) ) );
+      }
+
+      names           = subContext.getResourceNames(  );
+      nameIterator    = names.iterator(  );
+
+      while ( nameIterator.hasNext(  ) )
+      {
+         newContext.addServiceResource( subContext.getResource( (String) nameIterator.next(  ) ),
+                                        serviceName );
+      }
+
+      names           = subContext.getResourceLinkNames(  );
+      nameIterator    = names.iterator(  );
+
+      while ( nameIterator.hasNext(  ) )
+      {
+         newContext.addResourceLink( subContext.getResourceLink( (String) nameIterator.next(  ) ) );
+      }
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param resource    DOCUMENT_ME
+    * @param serviceName DOCUMENT_ME
+    *
+    * @throws NamingException DOCUMENT_ME
+    */
+   public void addServiceResource( Resource resource,
+                                   String   serviceName )
+   throws NamingException
+   {
+      Reference reference =
+         new ServiceResourceRef( resource.getType(  ),
+                                 resource.getDescription(  ),
+                                 resource.getScope(  ),
+                                 resource.getAuth(  ), this.engine, serviceName );
+      this.addParameters( reference,
+                          resource.getParameters(  ) );
+      this.createSubcontexts( resource.getName(  ) );
+      this.context.bind( resource.getName(  ),
+                         reference );
+      LOG.debug( "Added service resource entry with name: " + resource.getName(  ) );
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @param subContext DOCUMENT_ME
+    *
+    * @throws NamingException DOCUMENT_ME
+    */
+   public void addSubContext( ConfigContext subContext )
+   throws NamingException
+   {
+      addService( subContext );
+   }
+
+   private void addParameters( Reference          reference,
+                               ResourceParameters parameters )
+   {
+      if ( parameters != null )
+      {
+         Set      names         = parameters.getParameterNames(  );
+         Iterator nameIterator  = names.iterator(  );
+         RefAddr  parameter;
+         String   parameterName;
+         while ( nameIterator.hasNext(  ) )
+         {
+            parameterName    = (String) nameIterator.next(  );
+            parameter        = new StringRefAddr( parameterName,
+                                                  parameters.getParameter( parameterName ) );
+            reference.add( parameter );
+         }
+      }
+   }
+
+   private void createSubcontexts( String name )
+   throws NamingException
+   {
+      JNDIUtils.createSubcontexts( this.context, name );
+   }
+}
\ No newline at end of file

Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/ServiceResourceRef.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/ServiceResourceRef.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/ServiceResourceRef.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/ServiceResourceRef.java Fri Jun  2 10:32:46 2006
@@ -0,0 +1,73 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.axis.AxisEngine;
+
+/**
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.3 $
+ */
+public class ServiceResourceRef
+   extends org.apache.naming.ResourceRef
+{
+   private AxisEngine engine;
+   private String     name;
+
+   /**
+    * Creates a new {@link ServiceResourceRef} object.
+    *
+    * @param resourceClass DOCUMENT_ME
+    * @param description   DOCUMENT_ME
+    * @param scope         DOCUMENT_ME
+    * @param auth          DOCUMENT_ME
+    * @param engine        DOCUMENT_ME
+    * @param serviceName   DOCUMENT_ME
+    */
+   public ServiceResourceRef( String     resourceClass,
+                              String     description,
+                              String     scope,
+                              String     auth,
+                              AxisEngine engine,
+                              String     serviceName )
+   {
+      super( resourceClass, description, scope, auth, null, null );
+      this.engine    = engine;
+      this.name      = serviceName;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public AxisEngine getAxisEngine(  )
+   {
+      return this.engine;
+   }
+
+   /**
+    * DOCUMENT_ME
+    *
+    * @return DOCUMENT_ME
+    */
+   public String getServiceName(  )
+   {
+      return this.name;
+   }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org