Author: scamp
Date: Mon Apr 25 08:01:03 2005
New Revision: 164583

URL: http://svn.apache.org/viewcvs?rev=164583&view=rev
Log:
Jira Apollo-30

Added support for WS-MetadataExchange specification.

Added:
    
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
Modified:
    incubator/apollo/trunk/jndi-config/src/schema/jndi-schema.xsd
    
incubator/apollo/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
    
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java
    
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java
    
incubator/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/jndi-config.xml

Modified: incubator/apollo/trunk/jndi-config/src/schema/jndi-schema.xsd
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/jndi-config/src/schema/jndi-schema.xsd?rev=164583&r1=164582&r2=164583&view=diff
==============================================================================
--- incubator/apollo/trunk/jndi-config/src/schema/jndi-schema.xsd (original)
+++ incubator/apollo/trunk/jndi-config/src/schema/jndi-schema.xsd Mon Apr 25 
08:01:03 2005
@@ -32,7 +32,7 @@
                <xs:complexType>
                        <xs:choice>
                                <xs:element ref="tns:resourceParams"/>
-                               <xs:element ref="tns:metadata-config" 
minOccurs="0" maxOccurs="1"/>
+                               <xs:element ref="tns:metadata-config"/>
                        </xs:choice>
                        <xs:attribute name="name" type="xs:string" 
use="required"/>
                        <xs:attribute name="type" type="xs:string" 
use="required"/>

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java?rev=164583&r1=164582&r2=164583&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
 Mon Apr 25 08:01:03 2005
@@ -124,9 +124,9 @@
     }
 
     /**
-     * Attempts to lookup the MetadataConfig from JNDI
+     * Attempts to lookup the MetadataConfigImpl from JNDI
      *
-     * @return MetadataConfig
+     * @return MetadataConfigImpl
      * @throws NamingException
      */
     private MetadataConfig getMetadataConfig()

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java?rev=164583&r1=164582&r2=164583&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java 
(original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java 
Mon Apr 25 08:01:03 2005
@@ -20,19 +20,19 @@
 import org.apache.ws.resource.JndiConstants;
 import org.apache.ws.util.jndi.tools.ConfigContext;
 import org.apache.ws.util.jndi.tools.Environment;
+import org.apache.ws.util.jndi.tools.MetadataConfig;
 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 org.apache.ws.util.jndi.tools.MetadataConfig;
 import org.apache.wsfx.wsrf.jndi.config.EnvironmentDocument;
 import org.apache.wsfx.wsrf.jndi.config.GlobalDocument;
 import org.apache.wsfx.wsrf.jndi.config.JndiConfigDocument;
+import org.apache.wsfx.wsrf.jndi.config.MetadataConfigDocument;
 import org.apache.wsfx.wsrf.jndi.config.ParameterDocument;
 import org.apache.wsfx.wsrf.jndi.config.ResourceDocument;
 import org.apache.wsfx.wsrf.jndi.config.ResourceLinkDocument;
 import org.apache.wsfx.wsrf.jndi.config.ResourceParamsDocument;
 import org.apache.wsfx.wsrf.jndi.config.ServiceDocument;
-import org.apache.wsfx.wsrf.jndi.config.MetadataConfigDocument;
 import org.apache.xmlbeans.XmlObject;
 
 import javax.naming.Context;
@@ -45,6 +45,7 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -377,7 +378,7 @@
 
    }
 
-   private static Resource[] getResourceArray(ResourceDocument.Resource[] 
resourceArray, String name, XmlBeanNamingContext namingContext) throws 
NamingException
+   private static Resource[] getResourceArray(ResourceDocument.Resource[] 
resourceArray, String name, XmlBeanNamingContext namingContext)
    {
       List resources = new ArrayList(  );
       if ( resourceArray != null )
@@ -387,21 +388,30 @@
             ResourceDocument.Resource resourceDoc = resourceArray[i];
              //special type of resource....metatdata...handle differently....
              MetadataConfigDocument.MetadataConfig metadataConfig = 
resourceDoc.getMetadataConfig();
-             if(metadataConfig != null)
+             if (metadataConfig != null)
              {
-                 //Class.forName(resourceDoc.getType()).newInstance() todo 
extract abstract class/intefact..dictate constructor to make configurable.
-                 MetadataConfig metaConfig = new 
MetadataConfig(metadataConfig);
-                //short circuit this here
-                 String contextName = null;
-                if(name != null)
-                {
-                    namingContext.getContext().createSubcontext(name); //add 
subcontext                    
-                    contextName = name + "/";
-                }
-                contextName = contextName + resourceDoc.getName();
+                 try
+                 {
+                     Class metaConfigClass = 
Class.forName(resourceDoc.getType());
+                     Constructor constructor = 
metaConfigClass.getClass().getConstructor(new 
Class[]{metadataConfig.getClass()});
+                     MetadataConfig metaConfig = (MetadataConfig) 
constructor.newInstance(new Object[]{metadataConfig});
+                     String contextName = null;
+                     if (name != null)
+                     {
+                         namingContext.getContext().createSubcontext(name); 
//add subcontext
+                         contextName = name + "/";
+                     }
+                     contextName = contextName + resourceDoc.getName();
+
+                     namingContext.bind(contextName, metaConfig);
+                     continue;
+                 }
+                 catch (Exception e)
+                 {
+                     LOG.error("Unable to find constructor which takes: " + 
metadataConfig.getClass().getName() +
+                               ", in MetadataConfig object: " + 
resourceDoc.getType() + ".  The metadata will be ignored!  Cause:" + e);
+                 }
 
-                namingContext.bind(contextName, metaConfig);
-                continue;
              }
             Resource                  resource = new Resource(  );
             resource.setName( resourceDoc.getName(  ) );

Modified: 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java?rev=164583&r1=164582&r2=164583&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java
 (original)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java
 Mon Apr 25 08:01:03 2005
@@ -1,336 +1,22 @@
-/*=============================================================================*
- *  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.tools;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.wsfx.wsrf.jndi.config.MetadataConfigDocument;
-import org.apache.wsfx.wsrf.jndi.config.MetadataDocument;
-import org.apache.xmlbeans.XmlObject;
-import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
-import org.xmlsoap.schemas.ws.x2004.x09.mex.LocationDocument;
-import org.xmlsoap.schemas.ws.x2004.x09.mex.MetadataReferenceDocument;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 /**
- * A config object to represent the MetadataExchange information from the
- * jndi-config.xml config file.
- * <p/>
- * This class will store any "loadable" metadata documents, this will avoid
- * unnecessary loading of files.
- *
  * @author Sal Campana
  */
-public class MetadataConfig
+public abstract class MetadataConfig
 {
-   private static final Log LOG = LogFactory.getLog( MetadataConfig.class );
+    public MetadataConfig(MetadataConfigDocument.MetadataConfig metadata)
+    {
+        //used to enforce constructor for reflection
+    }
+    public abstract Map getAllMetadata(  );
 
-    /**
-     * Constant used for adding/getting the IDENTIFIER map from the dialect map
-     */
-   private static final String IDENTIFIER_MAP       = "IDENTIFIER_MAP";
-    /**
-     * Constant for pulling the Complete list of metatdata from the dialect 
map.
-     */
-   private static final String COMPLETE_METADATA_LIST = 
"COMPLETE_METADATA_LIST";
+    public abstract Map getMetadata( String dialect,
+                                 String identifierUri );
 
-   /** XmlBean MetadataConfig object */
-   MetadataConfigDocument.MetadataConfig m_metadata;
-
-   /**
-    * Internal Map for storing metatdata.
-    *
-    * The map will have the structure of:
-    *
-    * key=dialect
-    * value=Map (dialect-specific Map)
-    *
-    * The dialect-specific Map will have the structure:
-    *
-    * Two Entries:
-    * key= IDENTIFIER_MAP
-    * value= A Map keyed on Identifier keyed-to the metatdata
-    *
-    * key= COMPLETE_METADATA_LIST
-    * value= A List containing ALL metadata given this dialect (this includes 
all entries from IDENTIFIER_MAP)
-    *
-    **/
-   private Map                           m_metatdataMap = new HashMap(  );
-
-   /**
-    * Creates a new [EMAIL PROTECTED] MetadataConfig} object.
-    *
-    * @param metadata DOCUMENT_ME
-    */
-   public MetadataConfig( MetadataConfigDocument.MetadataConfig metadata )
-   {
-      m_metadata = metadata;
-
-      loadMetadata(  );
-   }
-
-   /**
-    * Returns all known metadata for all dialects.
-    *
-    * @return A Map keyed on dialect keyed-to a List of metadata
-    */
-   public Map getAllMetadata(  )
-   {
-      Map allMetatdata = new HashMap(  );
-
-      //iterate all the metadata
-       Iterator iterator = m_metatdataMap.keySet().iterator();
-       while (iterator.hasNext())
-       {
-           String key = (String) iterator.next();
-           Map dialectMap = (Map) m_metatdataMap.get(key);
-           List all = (List) dialectMap.get(COMPLETE_METADATA_LIST);
-           allMetatdata.put(key, all);
-       }
-
-      return allMetatdata;
-   }
-
-   /**
-    * Returns the metadata given a dialect and an identifier.
-    *
-    * @param dialect
-    * @param identifierUri
-    * @return  A Map keyed on dialect keyed-to a List of metadata
-    */
-   public Map getMetadata( String dialect,
-                                String identifierUri )
-   {
-      Map results = new HashMap(  );
-      if ( ( dialect != null ) && !"".equals( dialect ) ) //only get metatdata 
for specific dialect
-      {
-         Map dialectMap = (Map) m_metatdataMap.get( dialect );
-         if ( dialectMap != null )
-         {
-            if ( identifierUri != null )
-            {
-               Map    identifierMap = (Map) dialectMap.get( IDENTIFIER_MAP );
-               Object metatdata = identifierMap.get( identifierUri );
-               if ( metatdata != null )
-               {
-                   List list = new ArrayList();
-                   list.add(metatdata);
-                   results.put( dialect, list );
-               }
-            }
-            else
-            {
-               List metatdataList = (List) dialectMap.get( 
COMPLETE_METADATA_LIST );
-               results.put( dialect, metatdataList );
-            }
-         }
-      }
-      else //get all metatdata
-      {
-         return getAllMetadata(  );
-      }
-
-      return results;
-   }
-
-   /**
-    * Returns metadata based on dialect
-    *
-    * @param dialect
-    * @return A Map keyed on dialect keyed-to a List of metadata
-    */
-   public Map getMetadata( String dialect )
-   {
-      return getMetadata( dialect, null );
-   }
-
-   /**
-    * Adds the parsed-in metadata to the undelying lookup structures.
-    *
-    * precondition: The structures have already been setup for the metadata
-    *
-    * @param dialect
-    * @param identifier
-    * @param metadata   The "parsed" metadata (could be XmlObject, 
MetadataReference or Location )
-    */
-   protected void addToMetadataMap( String    dialect,
-                                    String    identifier,
-                                    XmlObject metadata )
-   {
-      Map dialectMap = (Map) m_metatdataMap.get( dialect );
-      if ( dialectMap == null )
-      {
-         addStructureForDialect( dialect );
-         dialectMap = (Map) m_metatdataMap.get( dialect );
-      }
-
-      List metatadataList = (List) dialectMap.get( COMPLETE_METADATA_LIST );
-      metatadataList.add( metadata );
-
-      if ( ( identifier != null ) && !"".equals( identifier ) )
-      {
-         Map identifierMap = (Map) dialectMap.get( IDENTIFIER_MAP );
-         identifierMap.put( identifier, metadata );
-      }
-   }
-
-   /**
-    * Builds the lookup structure given a dialect.
-    *
-    * @param dialect
-    */
-   private synchronized void addStructureForDialect( String dialect )
-   {
-      Map dialectMap = new HashMap(  );
-      m_metatdataMap.put( dialect, dialectMap ); //add to metadatamap
-
-      //add parsedMetatdata to the list of metadata for this dialect
-      dialectMap.put( COMPLETE_METADATA_LIST,
-                      new ArrayList(  ) );
-      dialectMap.put( IDENTIFIER_MAP,
-                      new HashMap(  ) );
-   }
-
-   /**
-    * Loads up lookup structures with the metadata.
-    *
-    * This method initializes a Map for a given dialect if it doesn't already 
exist.  The Map is keyed using
-    * 2 constants for pulling a map of identifiers->metatada AND a List of all 
metatdata.
-    */
-   private synchronized void loadMetadata(  )
-   {
-      MetadataDocument.Metadata[] metadataArray = m_metadata.getMetadataArray( 
 );
-      for ( int i = 0; i < metadataArray.length; i++ )
-      {
-         MetadataDocument.Metadata metadata       = metadataArray[i];
-         String                    dialect        = metadata.getDialect(  );
-         String                    identifier     = metadata.getIdentifier(  );
-         XmlObject                 parsedMetadata = parseMetadata( metadata );
-
-         if ( parsedMetadata != null )
-         {
-            //see if we already built a map for this dialect, then just add 
the metatdata
-            if ( m_metatdataMap.containsKey( dialect ) )
-            {
-               addToMetadataMap( dialect, identifier, parsedMetadata );
-            }
-            else //build the mapping for this dialect
-            {
-               addStructureForDialect( dialect );
-               addToMetadataMap( dialect, identifier, parsedMetadata );
-            }
-         }
-      }
-   }
-
-   /**
-    * This method will return either a MetadataReferenceDocument,
-    * LocationDocument or an XmlObject which has the metadata document parsed 
into it.
-    * <p/>
-    * The operation ALWAYS avoids loading the file if the metadata contains a 
MetadataReference.
-    * The operation ALWAYS avoids loading the file if the metadata contains a 
Location which is a standard Http URL.
-    * <p/>
-    * The operation WILL load the file if it is a file or a file URL.
-    * The operation WILL load the file if it is located in the classpath.
-    * <p/>
-    * Note: The "load" scenarios are handled last, and if the documents are 
un-loadable, null will be returned
-    *
-    * @param metadata
-    * @return The XmlObject metadata or null
-    */
-   private XmlObject parseMetadata( MetadataDocument.Metadata metadata )
-   {
-      //check for MetadataReference...if its there, we're finished.
-      XmlObject             result           = null;
-      EndpointReferenceType metadataReferece = metadata.getMetadataReferece(  
);
-      if ( metadataReferece != null )
-      {
-         MetadataReferenceDocument metadataReferenceDocument = 
MetadataReferenceDocument.Factory.newInstance(  );
-         metadataReferenceDocument.setMetadataReference( metadataReferece );
-         result = metadataReferenceDocument;
-      }
-      else //use location instead
-      {
-         String location = metadata.getLocation(  );
-
-         //determine if its a valid URL
-         if ( location != null )
-         {
-            try
-            {
-               URL url = new URL( location );
-
-               //if we get here then is it a file url??? if so load it
-               if ( location.startsWith( "file" ) )
-               {
-                  try
-                  {
-                     result = XmlObject.Factory.parse( new File(url.getFile()) 
);
-                  }
-                  catch ( Exception e )
-                  {
-                     LOG.fatal( "*********Unable to load file from file url: " 
+ url+ " CAUSE:", e );
-                  }
-               }
-               else //if not then return a Location...let them do it....
-               {
-                  LocationDocument locationDocument = 
LocationDocument.Factory.newInstance(  );
-                  locationDocument.setLocation( location );
-                  result = locationDocument;
-               }
-            }
-            catch ( MalformedURLException e )
-            {
-               //not valid..is it a file withoud url prefix? ...load it
-               File f = new File( location );
-               if ( f.exists(  ) )
-               {
-                  try
-                  {
-                     result = XmlObject.Factory.parse( f );
-                  }
-                  catch ( Exception e1 )
-                  {
-                     LOG.fatal( "*********Unable to load file: " + f + " 
CAUSE:", e );
-                  }
-               }
-               else //check classpath
-               {
-                  URL resource = this.getClass(  ).getClassLoader(  
).getResource( location );
-                  try
-                  {
-                     result = XmlObject.Factory.parse( resource );
-                  }
-                  catch ( Exception e1 )
-                  {
-                     LOG.fatal( "*********Unable to load file: " + resource + 
" from classpath."+ " CAUSE:", e );
-                  }
-               }
-            }
-         }
-      }
-
-      return result;
-   }
-}
\ No newline at end of file
+    public abstract Map getMetadata( String dialect );
+}

Added: 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java?rev=164583&view=auto
==============================================================================
--- 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
 (added)
+++ 
incubator/apollo/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
 Mon Apr 25 08:01:03 2005
@@ -0,0 +1,336 @@
+/*=============================================================================*
+ *  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.tools;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.wsfx.wsrf.jndi.config.MetadataConfigDocument;
+import org.apache.wsfx.wsrf.jndi.config.MetadataDocument;
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
+import org.xmlsoap.schemas.ws.x2004.x09.mex.LocationDocument;
+import org.xmlsoap.schemas.ws.x2004.x09.mex.MetadataReferenceDocument;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A config object to represent the MetadataExchange information from the
+ * jndi-config.xml config file.
+ * <p/>
+ * This class will store any "loadable" metadata documents, this will avoid
+ * unnecessary loading of files.
+ *
+ * @author Sal Campana
+ */
+public class MetadataConfigImpl extends MetadataConfig
+{
+   private static final Log LOG = LogFactory.getLog( MetadataConfigImpl.class 
);
+
+    /**
+     * Constant used for adding/getting the IDENTIFIER map from the dialect map
+     */
+   private static final String IDENTIFIER_MAP       = "IDENTIFIER_MAP";
+    /**
+     * Constant for pulling the Complete list of metatdata from the dialect 
map.
+     */
+   private static final String COMPLETE_METADATA_LIST = 
"COMPLETE_METADATA_LIST";
+
+   /** XmlBean MetadataConfigImpl object */
+   MetadataConfigDocument.MetadataConfig m_metadata;
+
+   /**
+    * Internal Map for storing metatdata.
+    *
+    * The map will have the structure of:
+    *
+    * key=dialect
+    * value=Map (dialect-specific Map)
+    *
+    * The dialect-specific Map will have the structure:
+    *
+    * Two Entries:
+    * key= IDENTIFIER_MAP
+    * value= A Map keyed on Identifier keyed-to the metatdata
+    *
+    * key= COMPLETE_METADATA_LIST
+    * value= A List containing ALL metadata given this dialect (this includes 
all entries from IDENTIFIER_MAP)
+    *
+    **/
+   private Map                           m_metatdataMap = new HashMap(  );
+
+   /**
+    * Creates a new [EMAIL PROTECTED] MetadataConfigImpl} object.
+    *
+    * @param metadata DOCUMENT_ME
+    */
+   public MetadataConfigImpl( MetadataConfigDocument.MetadataConfig metadata )
+   {
+      super(metadata);
+      m_metadata = metadata;
+      loadMetadata(  );
+   }
+
+   /**
+    * Returns all known metadata for all dialects.
+    *
+    * @return A Map keyed on dialect keyed-to a List of metadata
+    */
+   public Map getAllMetadata(  )
+   {
+      Map allMetatdata = new HashMap(  );
+
+      //iterate all the metadata
+       Iterator iterator = m_metatdataMap.keySet().iterator();
+       while (iterator.hasNext())
+       {
+           String key = (String) iterator.next();
+           Map dialectMap = (Map) m_metatdataMap.get(key);
+           List all = (List) dialectMap.get(COMPLETE_METADATA_LIST);
+           allMetatdata.put(key, all);
+       }
+
+      return allMetatdata;
+   }
+
+   /**
+    * Returns the metadata given a dialect and an identifier.
+    *
+    * @param dialect
+    * @param identifierUri
+    * @return  A Map keyed on dialect keyed-to a List of metadata
+    */
+   public Map getMetadata( String dialect,
+                                String identifierUri )
+   {
+      Map results = new HashMap(  );
+      if ( ( dialect != null ) && !"".equals( dialect ) ) //only get metatdata 
for specific dialect
+      {
+         Map dialectMap = (Map) m_metatdataMap.get( dialect );
+         if ( dialectMap != null )
+         {
+            if ( identifierUri != null )
+            {
+               Map    identifierMap = (Map) dialectMap.get( IDENTIFIER_MAP );
+               Object metatdata = identifierMap.get( identifierUri );
+               if ( metatdata != null )
+               {
+                   List list = new ArrayList();
+                   list.add(metatdata);
+                   results.put( dialect, list );
+               }
+            }
+            else
+            {
+               List metatdataList = (List) dialectMap.get( 
COMPLETE_METADATA_LIST );
+               results.put( dialect, metatdataList );
+            }
+         }
+      }
+      else //get all metatdata
+      {
+         return getAllMetadata(  );
+      }
+
+      return results;
+   }
+
+   /**
+    * Returns metadata based on dialect
+    *
+    * @param dialect
+    * @return A Map keyed on dialect keyed-to a List of metadata
+    */
+   public Map getMetadata( String dialect )
+   {
+      return getMetadata( dialect, null );
+   }
+
+   /**
+    * Adds the parsed-in metadata to the undelying lookup structures.
+    *
+    * precondition: The structures have already been setup for the metadata
+    *
+    * @param dialect
+    * @param identifier
+    * @param metadata   The "parsed" metadata (could be XmlObject, 
MetadataReference or Location )
+    */
+   protected void addToMetadataMap( String    dialect,
+                                    String    identifier,
+                                    XmlObject metadata )
+   {
+      Map dialectMap = (Map) m_metatdataMap.get( dialect );
+      if ( dialectMap == null )
+      {
+         addStructureForDialect( dialect );
+         dialectMap = (Map) m_metatdataMap.get( dialect );
+      }
+
+      List metatadataList = (List) dialectMap.get( COMPLETE_METADATA_LIST );
+      metatadataList.add( metadata );
+
+      if ( ( identifier != null ) && !"".equals( identifier ) )
+      {
+         Map identifierMap = (Map) dialectMap.get( IDENTIFIER_MAP );
+         identifierMap.put( identifier, metadata );
+      }
+   }
+
+   /**
+    * Builds the lookup structure given a dialect.
+    *
+    * @param dialect
+    */
+   private synchronized void addStructureForDialect( String dialect )
+   {
+      Map dialectMap = new HashMap(  );
+      m_metatdataMap.put( dialect, dialectMap ); //add to metadatamap
+
+      //add parsedMetatdata to the list of metadata for this dialect
+      dialectMap.put( COMPLETE_METADATA_LIST,
+                      new ArrayList(  ) );
+      dialectMap.put( IDENTIFIER_MAP,
+                      new HashMap(  ) );
+   }
+
+   /**
+    * Loads up lookup structures with the metadata.
+    *
+    * This method initializes a Map for a given dialect if it doesn't already 
exist.  The Map is keyed using
+    * 2 constants for pulling a map of identifiers->metatada AND a List of all 
metatdata.
+    */
+   private synchronized void loadMetadata(  )
+   {
+      MetadataDocument.Metadata[] metadataArray = m_metadata.getMetadataArray( 
 );
+      for ( int i = 0; i < metadataArray.length; i++ )
+      {
+         MetadataDocument.Metadata metadata       = metadataArray[i];
+         String                    dialect        = metadata.getDialect(  );
+         String                    identifier     = metadata.getIdentifier(  );
+         XmlObject                 parsedMetadata = parseMetadata( metadata );
+
+         if ( parsedMetadata != null )
+         {
+            //see if we already built a map for this dialect, then just add 
the metatdata
+            if ( m_metatdataMap.containsKey( dialect ) )
+            {
+               addToMetadataMap( dialect, identifier, parsedMetadata );
+            }
+            else //build the mapping for this dialect
+            {
+               addStructureForDialect( dialect );
+               addToMetadataMap( dialect, identifier, parsedMetadata );
+            }
+         }
+      }
+   }
+
+   /**
+    * This method will return either a MetadataReferenceDocument,
+    * LocationDocument or an XmlObject which has the metadata document parsed 
into it.
+    * <p/>
+    * The operation ALWAYS avoids loading the file if the metadata contains a 
MetadataReference.
+    * The operation ALWAYS avoids loading the file if the metadata contains a 
Location which is a standard Http URL.
+    * <p/>
+    * The operation WILL load the file if it is a file or a file URL.
+    * The operation WILL load the file if it is located in the classpath.
+    * <p/>
+    * Note: The "load" scenarios are handled last, and if the documents are 
un-loadable, null will be returned
+    *
+    * @param metadata
+    * @return The XmlObject metadata or null
+    */
+   private XmlObject parseMetadata( MetadataDocument.Metadata metadata )
+   {
+      //check for MetadataReference...if its there, we're finished.
+      XmlObject             result           = null;
+      EndpointReferenceType metadataReferece = metadata.getMetadataReferece(  
);
+      if ( metadataReferece != null )
+      {
+         MetadataReferenceDocument metadataReferenceDocument = 
MetadataReferenceDocument.Factory.newInstance(  );
+         metadataReferenceDocument.setMetadataReference( metadataReferece );
+         result = metadataReferenceDocument;
+      }
+      else //use location instead
+      {
+         String location = metadata.getLocation(  );
+
+         //determine if its a valid URL
+         if ( location != null )
+         {
+            try
+            {
+               URL url = new URL( location );
+
+               //if we get here then is it a file url??? if so load it
+               if ( location.startsWith( "file" ) )
+               {
+                  try
+                  {
+                     result = XmlObject.Factory.parse( new File(url.getFile()) 
);
+                  }
+                  catch ( Exception e )
+                  {
+                     LOG.fatal( "*********Unable to load file from file url: " 
+ url+ " CAUSE:", e );
+                  }
+               }
+               else //if not then return a Location...let them do it....
+               {
+                  LocationDocument locationDocument = 
LocationDocument.Factory.newInstance(  );
+                  locationDocument.setLocation( location );
+                  result = locationDocument;
+               }
+            }
+            catch ( MalformedURLException e )
+            {
+               //not valid..is it a file withoud url prefix? ...load it
+               File f = new File( location );
+               if ( f.exists(  ) )
+               {
+                  try
+                  {
+                     result = XmlObject.Factory.parse( f );
+                  }
+                  catch ( Exception e1 )
+                  {
+                     LOG.fatal( "*********Unable to load file: " + f + " 
CAUSE:", e );
+                  }
+               }
+               else //check classpath
+               {
+                  URL resource = this.getClass(  ).getClassLoader(  
).getResource( location );
+                  try
+                  {
+                     result = XmlObject.Factory.parse( resource );
+                  }
+                  catch ( Exception e1 )
+                  {
+                     LOG.fatal( "*********Unable to load file: " + resource + 
" from classpath."+ " CAUSE:", e );
+                  }
+               }
+            }
+         }
+      }
+
+      return result;
+   }
+}
\ No newline at end of file

Modified: 
incubator/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/jndi-config.xml
URL: 
http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/jndi-config.xml?rev=164583&r1=164582&r2=164583&view=diff
==============================================================================
--- 
incubator/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/jndi-config.xml
 (original)
+++ 
incubator/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/jndi-config.xml
 Mon Apr 25 08:01:03 2005
@@ -1,115 +1,109 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<jndiConfig xmlns="http://www.apache.org/wsfx/wsrf/jndi/config";>
-
-   <global>
-      
-      <resource name="DefaultParameters" 
type="org.apache.ws.util.jndi.DefaultParameters">
-         <resourceParams>
-            <parameter>
-               <name>factory</name>
-               <value>org.apache.ws.util.jndi.BeanFactory</value>
-            </parameter>           
-            <parameter>
-               <name>resourceKeyClassName</name>
-               <value>org.apache.ws.resource.impl.SimpleTypeResourceKey</value>
-            </parameter>
-         </resourceParams>
-      </resource>
-      
-      <resource name="timer/ContainerTimer" 
type="org.apache.ws.util.timer.TimerManagerImpl">
-         <resourceParams>
-            <parameter>
-               <name>factory</name>
-               <value>org.apache.ws.util.jndi.BeanFactory</value>
-            </parameter>
-         </resourceParams>
-      </resource>
-      
-   </global>
-
-<service name="sushi">
-      <resource name="home" type="org.apache.ws.resource.properties.SushiHome">
-         <resourceParams>
-            <parameter>
-               <name>serviceClassName</name>
-               <value>org.apache.ws.resource.properties.SushiService</value>
-            </parameter>
-            <parameter>
-               <name>resourceClassName</name>
-               <value>org.apache.ws.resource.properties.SushiResource</value>
-            </parameter>
-            <parameter>
-               <name>wsdlTargetNamespace</name>
-               
<value>http://ws.apache.org/resource/properties/test/sushi</value>
-            </parameter>            
-            <parameter>
-               <name>resourceKeyName</name>
-               
<value>{http://ws.apache.org/resource/properties/test/sushi}ResourceID</value>
-            </parameter>            
-         </resourceParams>
-      </resource>
-      <resource name="metadata" 
type="org.apache.ws.util.jndi.tools.MetadataConfig">
-         
-         <metadata-config>
-      
-              <!-- classpath -->
-              <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_classpath";>
-            
<Location>org/apache/ws/resource/properties/SushiProperties.xsd</Location>
-              </metadata>
-              <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_classpath";>
-            
<Location>org/apache/ws/resource/metadataexchange/v2004_09/FileSystem.wsdl</Location>
-              </metadata>
-      
-              <!-- file -->
-              <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_file";>
-            
<Location>C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiProperties.xsd</Location>
-              </metadata>
-              <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_file";>
-            
<Location>C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/FileSystem.wsdl</Location>
-              </metadata>
-      
-              <!-- http url -->
-              <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_url";>
-            <Location>http://localhost:8080/wsrf/SushiProperties.xsd</Location>
-              </metadata>
-              <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_url";>
-            <Location>http://localhost:8080/wsrf/FileSystem.wsdl</Location>
-              </metadata>
+<jndiConfig xmlns="http://www.apache.org/wsfx/wsrf/jndi/config";>
+
+   <global>
       
-              <!-- file url -->
-              <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_fileurl";>
-            
<Location>file://C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiProperties.xsd</Location>
-              </metadata>
-              <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_fileurl";>
-            
<Location>file://C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/FileSystem.wsdl</Location>
-              </metadata>
+      <resource name="DefaultParameters" 
type="org.apache.ws.util.jndi.DefaultParameters">
+         <resourceParams>
+            <parameter>
+               <name>factory</name>
+               <value>org.apache.ws.util.jndi.BeanFactory</value>
+            </parameter>           
+            <parameter>
+               <name>resourceKeyClassName</name>
+               <value>org.apache.ws.resource.impl.SimpleTypeResourceKey</value>
+            </parameter>
+         </resourceParams>
+      </resource>
+      
+      <resource name="timer/ContainerTimer" 
type="org.apache.ws.util.timer.TimerManagerImpl">
+         <resourceParams>
+            <parameter>
+               <name>factory</name>
+               <value>org.apache.ws.util.jndi.BeanFactory</value>
+            </parameter>
+         </resourceParams>
+      </resource>
       
-              <!-- EndpointReference -->
-              <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_epr";>
-              
-              <MetadataReferece>
-                <wsa:Address 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"; 
>http://localhost:8080/wsrf/services/sushi</wsa:Address>
-                      <wsa:ReferenceProperties 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing";>
-                    <s:ResourceID 
xmlns:s="http://ws.apache.org/resource/properties/test/sushi";>1</s:ResourceID>
-                 </wsa:ReferenceProperties>
-              </MetadataReferece>    
-                
-                
-              </metadata>
-              
-              <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_epr";>      
-               
-               <MetadataReferece>
-            <wsa:Address 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"; 
>http://localhost:8080/wsrf/services/filesystem</wsa:Address>
-             <wsa:ReferenceProperties 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing";>
-                <s:ResourceID 
xmlns:s="http://ws.apache.org/resource/example/filesystem";>1</s:ResourceID>
-             </wsa:ReferenceProperties>
-              </MetadataReferece>    
-                              
-              </metadata>
+   </global>
+
+<service name="sushi">
+      <resource name="home" type="org.apache.ws.resource.properties.SushiHome">
+         <resourceParams>
+            <parameter>
+               <name>serviceClassName</name>
+               <value>org.apache.ws.resource.properties.SushiService</value>
+            </parameter>
+            <parameter>
+               <name>resourceClassName</name>
+               <value>org.apache.ws.resource.properties.SushiResource</value>
+            </parameter>
+            <parameter>
+               <name>wsdlTargetNamespace</name>
+               
<value>http://ws.apache.org/resource/properties/test/sushi</value>
+            </parameter>            
+            <parameter>
+               <name>resourceKeyName</name>
+               
<value>{http://ws.apache.org/resource/properties/test/sushi}ResourceID</value>
+            </parameter>            
+         </resourceParams>
+      </resource>
+      <resource name="metadata" 
type="org.apache.ws.util.jndi.tools.MetadataConfigImpl">
+         <metadata-config>
+
+            <!-- classpath -->
+            <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_classpath";>
+               
<Location>org/apache/resource/properties/SushiProperties.xsd</Location>
+            </metadata>
+            <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_classpath";>
+               
<Location>org/apache/ws/resource/metadataexchange/v2004_09/FileSystem.wsdl</Location>
+            </metadata>
+                    
+            <!-- file -->
+            <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_file";>
+               
<Location>C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiProperties.xsd</Location>
+            </metadata>
+            <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_file";>
+               
<Location>C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/FileSystem.wsdl</Location>
+            </metadata>
+
+            <!-- http url -->
+            <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_url";>
+               
<Location>http://localhost:8080/wsrf/SushiProperties.xsd</Location>
+            </metadata>
+            <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_url";>
+               <Location>http://localhost:8080/wsrf/FileSystem.wsdl</Location>
+            </metadata>
+
+            <!-- file url -->
+            <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_fileurl";>
+               
<Location>file://C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiProperties.xsd</Location>
+            </metadata>
+            <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_fileurl";>
+               
<Location>file://C:/Projects/apache/apollo/trunk/src/test/org/apache/ws/resource/metadataexchange/v2004_09/FileSystem.wsdl</Location>
+            </metadata>
+
+            <!-- EndpointReference -->
+            <metadata Dialect="http://www.w3.org/2001/XMLSchema"; 
Identifier="http://ws.apache.org/resource/properties/test/sushi_epr";>
+               <MetadataReference>
+                 <Address>http://localhost:8080/wsrf/services/sushi</Address>
+                 <ReferenceProperties>
+                       <s:ResourceID 
xmlns:s="http://ws.apache.org/resource/properties/test/sushi";>1</s:ResourceID>
+                  </ReferenceProperties>
+               </MetadataReference>            
+            </metadata>
+            
+            <metadata Dialect="http://schemas.xmlsoap.org/wsdl"; 
Identifier="http://ws.apache.org/resource/example/filesystem_epr";>
+               <MetadataReference>
+                 
<Address>http://localhost:8080/wsrf/services/filesystem</Address>
+                 <ReferenceProperties>
+                       <s:ResourceID 
xmlns:s="http://ws.apache.org/resource/example/filesystem";>1</s:ResourceID>
+                  </ReferenceProperties>
+               </MetadataReference>                    
+            </metadata>
+
 
-      
          </metadata-config>
-         
+         <resourceParams/>
       </resource>      
    </service></jndiConfig>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to