You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-commits@ws.apache.org by ip...@apache.org on 2005/10/19 18:46:51 UTC

svn commit: r326608 - in /webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools: MetadataConfigImpl.java MetadataEntry.java

Author: ips
Date: Wed Oct 19 09:46:43 2005
New Revision: 326608

URL: http://svn.apache.org/viewcvs?rev=326608&view=rev
Log:
refactoring of WS-MEX code


Added:
    webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java
Modified:
    webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java?rev=326608&r1=326607&r2=326608&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java Wed Oct 19 09:46:43 2005
@@ -43,7 +43,6 @@
  * @author Sal Campana
  */
 public class MetadataConfigImpl
-   extends MetadataConfig implements Serializable
 {
    private static final Log LOG = LogFactory.getLog( MetadataConfigImpl.class );
 
@@ -57,8 +56,6 @@
     */
    private static final String COMPLETE_METADATA_LIST = "COMPLETE_METADATA_LIST";
 
-   /** XmlBean MetadataConfigImpl object */
-   MetadataConfigDocument.MetadataConfig m_metadata;
 
    /**
     * Internal Map for storing metatdata.
@@ -78,41 +75,64 @@
     * value= A List containing ALL metadata given this dialect (this includes all entries from IDENTIFIER_MAP)
     *
     **/
-   private Map m_metatdataMap = new HashMap(  );
+   private Map m_dialectToMetadataListMap = new HashMap(  );
+
+   private List m_metadataList = new ArrayList(  );
 
    /**
     * Creates a new {@link MetadataConfigImpl} object.
     *
     * @param metadata DOCUMENT_ME
     */
-   public MetadataConfigImpl( MetadataConfigDocument.MetadataConfig metadata )
+   public MetadataConfigImpl( List metadataEntryList )
    {
-      super( metadata );
-      m_metadata = metadata;
+      m_metadataList = metadataEntryList;
       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 );
-      }
+    public void addMetadataEntry( MetadataEntry metadataEntry )
+    {
+        m_metadataList.add( metadataEntry );
+        addMetadataEntryToMap( metadataEntry );
+    }
+
+    private void addMetadataEntryToMap( MetadataEntry metadataEntry )
+    {
+        String                    dialect        = metadataEntry.getDialect(  );
+           String                    identifier     = metadataEntry.getIdentifier(  );
+              //see if we already built a map for this dialect, then just add the metatdata
+              if ( m_dialectToMetadataListMap.containsKey( dialect ) )
+              {
+                 addToMetadataMap( dialect, metadataEntry );
+              }
+              else //build the mapping for this dialect
+              {
+                 addStructureForDialect( dialect );
+                 addToMetadataMap( dialect, identifier, parsedMetadata );
+              }
+    }
+
+    /**
+     * 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_dialectToMetadataListMap.keySet(  ).iterator(  );
+       while ( iterator.hasNext(  ) )
+       {
+          String key        = (String) iterator.next(  );
+          Map    dialectMap = (Map) m_dialectToMetadataListMap.get( key );
+          List   all        = (List) dialectMap.get( COMPLETE_METADATA_LIST );
+          allMetatdata.put( key, all );
+       }
 
-      return allMetatdata;
-   }
+       return allMetatdata;
+    }
 
    /**
     * Returns the metadata given a dialect and an identifier.
@@ -127,7 +147,7 @@
       Map results = new HashMap(  );
       if ( ( dialect != null ) && !"".equals( dialect ) ) //only get metatdata for specific dialect
       {
-         Map dialectMap = (Map) m_metatdataMap.get( dialect );
+         Map dialectMap = (Map) m_dialectToMetadataListMap.get( dialect );
          if ( dialectMap != null )
          {
             if ( identifierUri != null )
@@ -177,19 +197,14 @@
     * @param metadata   The "parsed" metadata (could be XmlObject, MetadataReference or Location )
     */
    protected void addToMetadataMap( String    dialect,
-                                    String    identifier,
-                                    XmlObject metadata )
+                                    MetadataEntry metadataEntry )
    {
-      Map dialectMap = (Map) m_metatdataMap.get( dialect );
+      Map dialectMap = (Map) m_dialectToMetadataListMap.get( dialect );
       if ( dialectMap == null )
       {
          addStructureForDialect( dialect );
-         dialectMap = (Map) m_metatdataMap.get( dialect );
+         dialectMap = (Map) m_dialectToMetadataListMap.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 );
@@ -205,7 +220,7 @@
    private synchronized void addStructureForDialect( String dialect )
    {
       Map dialectMap = new HashMap(  );
-      m_metatdataMap.put( dialect, dialectMap ); //add to metadatamap
+      m_dialectToMetadataListMap.put( dialect, dialectMap ); //add to metadatamap
 
       //add parsedMetatdata to the list of metadata for this dialect
       dialectMap.put( COMPLETE_METADATA_LIST,
@@ -222,117 +237,23 @@
     */
    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 );
-            }
-         }
-      }
+       for ( int i = 0; i < m_metadataList.size(); i++ )
+       {
+           MetadataEntry metadataEntry = (MetadataEntry) m_metadataList.get( i );
+           String                    dialect        = metadataEntry.getDialect(  );
+           String                    identifier     = metadataEntry.getIdentifier(  );
+              //see if we already built a map for this dialect, then just add the metatdata
+              if ( m_dialectToMetadataListMap.containsKey( dialect ) )
+              {
+                 addToMetadataMap( dialect, metadataEntry );
+              }
+              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.getReference(  );
-      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

Added: webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java?rev=326608&view=auto
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java (added)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java Wed Oct 19 09:46:43 2005
@@ -0,0 +1,187 @@
+/*=============================================================================*
+ *  Copyright 2005 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.xmlbeans.XmlObject;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.addressing.v2004_08.AddressingConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xmlsoap.schemas.ws.x2004.x09.mex.LocationDocument;
+import org.xmlsoap.schemas.ws.x2004.x09.mex.MetadataReferenceDocument;
+import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
+import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.File;
+
+/**
+ * TODO
+ */
+public class MetadataEntry
+{
+
+    private static final Log LOG = LogFactory.getLog( MetadataEntry.class );
+
+    private String m_dialect;
+    private String m_identifier;
+    private String m_location;
+    private XmlObject m_metadata;
+
+    public String getDialect()
+    {
+        return m_dialect;
+    }
+
+    public void setDialect( String dialect )
+    {
+        m_dialect = dialect;
+    }
+
+    public String getIdentifier()
+    {
+        return m_identifier;
+    }
+
+    public void setIdentifier( String identifier )
+    {
+        m_identifier = identifier;
+    }
+
+    public String getLocation()
+    {
+        return m_location;
+    }
+
+    public void setLocation( String location )
+    {
+        m_location = location;
+    }
+
+    public synchronized XmlObject getMetadata()
+    {
+        if ( m_metadata == null )
+        {
+           initMetadata();
+        }
+        return m_metadata;
+    }
+
+       /**
+    * 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
+    *
+    */
+   private void initMetadata()
+   {
+      //check for MetadataReference...if its there, we're finished.
+      XmlObject             metadata           = null;
+
+
+         //determine if its a valid URL
+         if ( m_location != null )
+         {
+            try
+            {
+               URL url = new URL( m_location );
+
+               //if we get here then is it a file url??? if so load it
+               if ( url.getProtocol().equals( "file" ) )
+               {
+                  try
+                  {
+                     metadata = XmlObject.Factory.parse( url );
+                  }
+                  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( m_location );
+                  metadata = locationDocument;
+               }
+            }
+            catch ( MalformedURLException e )
+            {
+               //not valid..is it a file withoud url prefix? ...load it
+               File f = new File( m_location );
+               if ( f.exists(  ) )
+               {
+                  try
+                  {
+                     metadata = 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( m_location );
+                  try
+                  {
+                     metadata = XmlObject.Factory.parse( resource );
+                  }
+                  catch ( Exception e1 )
+                  {
+                     LOG.fatal( "*********Unable to load file: " + resource + " from classpath." + " CAUSE:", e );
+                  }
+               }
+            }
+            metadata = wrapEndpointReferenceType( metadata );
+         }
+      }
+
+    private XmlObject wrapEndpointReferenceType( XmlObject metadata )
+    {
+        if ( metadata instanceof EndpointReferenceDocument )
+        {
+            EndpointReferenceDocument metadataReferenceDoc = (EndpointReferenceDocument) metadata;
+            metadata = createMetadataReferenceDocument(
+                    metadataReferenceDoc.getEndpointReference() );
+        }
+         else if ( metadata instanceof org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument )
+        {
+            org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument metadataReferenceDoc = (org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument) metadata;
+            XmlBeansEndpointReference xmlBeansEndpointReference = new XmlBeansEndpointReference(
+                    metadataReferenceDoc.getEndpointReference() );
+            EndpointReferenceType epr = (EndpointReferenceType) xmlBeansEndpointReference.getXmlObject( AddressingConstants.NSURI_ADDRESSING_SCHEMA );
+            metadata = createMetadataReferenceDocument( epr );
+        }
+        return metadata;
+    }
+
+    private MetadataReferenceDocument createMetadataReferenceDocument( EndpointReferenceType epr )
+    {
+        MetadataReferenceDocument metadataReferenceDocument = MetadataReferenceDocument.Factory.newInstance(  );
+        metadataReferenceDocument.setMetadataReference( epr );
+        return metadataReferenceDocument;
+    }
+
+}