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 22:51:18 UTC
svn commit: r326705 - in
/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools:
MetadataConfigImpl.java MetadataEntry.java
Author: ips
Date: Wed Oct 19 13:51:16 2005
New Revision: 326705
URL: http://svn.apache.org/viewcvs?rev=326705&view=rev
Log:
minor refactoring
Modified:
webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
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
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java?rev=326705&r1=326704&r2=326705&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 13:51:16 2005
@@ -1,5 +1,5 @@
/*=============================================================================*
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2004-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.
@@ -21,20 +21,16 @@
import java.util.List;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
- * 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.
+ * Represents the WS-MetadataExchange configuration information for a
+ * particular type of WS-Resource.
*
* @author Sal Campana
*/
-public class MetadataConfigImpl {
- private static final Log LOG = LogFactory.getLog(MetadataConfigImpl.class);
+public class MetadataConfigImpl
+{
- /**
+ /*
* Internal Map for storing metatdata.
*
* The map will have the structure of:
@@ -50,23 +46,30 @@
* this dialect (this includes all entries from IDENTIFIER_MAP)
*
*/
- private Map m_dialectToMetadataListMap = new HashMap();
+ private Map m_dialectToIdentifierMapMap = new HashMap();
- private List m_metadataList = new ArrayList();
+ /* list of all the MetadataEntry's */
+ private List m_metadataEntryList;
- /**
- * Creates a new {@link MetadataConfigImpl} object.
+ /**
+ * Creates a new <code>MetadataConfigImpl</code> object.
+ */
+ public MetadataConfigImpl() {
+ this( new ArrayList() );
+ }
+
+ /**
+ * Creates a new <code>MetadataConfigImpl</code> object.
*
- * @param metadata
- * DOCUMENT_ME
+ * @param metadataEntryList a list of {@link MetadataEntry}s
*/
public MetadataConfigImpl(List metadataEntryList) {
- m_metadataList = metadataEntryList;
- loadMetadata();
+ m_metadataEntryList = metadataEntryList;
+ initMetadataEntryMap();
}
- public void addMetadataEntry(MetadataEntry metadataEntry) {
- m_metadataList.add(metadataEntry);
+ public void addMetadataEntry(MetadataEntry metadataEntry) {
+ m_metadataEntryList.add(metadataEntry);
addToMetadataMap(metadataEntry);
}
@@ -76,7 +79,7 @@
* @return A list of all metadata
*/
public List getAllMetadata() {
- return m_metadataList;
+ return m_metadataEntryList;
}
/**
@@ -91,7 +94,7 @@
if ((dialect != null) && !"".equals(dialect)) // only get metatdata
// for specific dialect
{
- Map dialectMap = (Map) m_dialectToMetadataListMap.get(dialect);
+ Map dialectMap = (Map) m_dialectToIdentifierMapMap.get(dialect);
if (dialectMap != null) {
if (identifierUri != null) {
Object metatdata = dialectMap.get(identifierUri);
@@ -109,17 +112,17 @@
// if dialect was not defined then they are saying "send all!"
else {
return buildDialectToListMap();
- }
+ }
return results;
}
private Map buildDialectToListMap() {
Map dialectToMetadataList = new HashMap();
- Iterator iter = m_dialectToMetadataListMap.keySet().iterator();
+ Iterator iter = m_dialectToIdentifierMapMap.keySet().iterator();
while (iter.hasNext()) {
String dialect = (String) iter.next();
- Map identifierMap = (Map) m_dialectToMetadataListMap.get(dialect);
+ Map identifierMap = (Map) m_dialectToIdentifierMapMap.get(dialect);
dialectToMetadataList.put(dialect, new ArrayList(identifierMap
.values()));
}
@@ -137,33 +140,26 @@
}
/**
- * Adds the parsed-in metadata to the undelying lookup structures.
+ * Adds the specified metadata entry 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 )
+ * @param metadataEntry
*/
protected void addToMetadataMap(MetadataEntry metadataEntry) {
String dialect = metadataEntry.getDialect();
String identifier = metadataEntry.getIdentifier();
- Map dialectIdentifierMap = (Map) m_dialectToMetadataListMap
+ Map identifierToMetadataEntryMap = (Map) m_dialectToIdentifierMapMap
.get(dialect);
- if (dialectIdentifierMap == null) {
+ if (identifierToMetadataEntryMap == null) {
// build the entries for the maps
- dialectIdentifierMap = new HashMap();
- m_dialectToMetadataListMap.put(dialect, dialectIdentifierMap); // add
- // to
- // metadatamap
-
+ identifierToMetadataEntryMap = new HashMap();
+ m_dialectToIdentifierMapMap.put(dialect, identifierToMetadataEntryMap );
}
// if there is an identifier then the metadata is registered with it
// else it only lives in the list of all metadata
if ((identifier != null) && !"".equals(identifier)) {
- dialectIdentifierMap.put(identifier, metadataEntry);
+ identifierToMetadataEntryMap.put(identifier, metadataEntry);
}
}
@@ -174,9 +170,9 @@
* 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() {
- for (int i = 0; i < m_metadataList.size(); i++) {
- MetadataEntry metadataEntry = (MetadataEntry) m_metadataList.get(i);
+ private synchronized void initMetadataEntryMap() {
+ for (int i = 0; i < m_metadataEntryList.size(); i++) {
+ MetadataEntry metadataEntry = (MetadataEntry) m_metadataEntryList.get(i);
addToMetadataMap(metadataEntry);
}
}
Modified: 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=326705&r1=326704&r2=326705&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataEntry.java Wed Oct 19 13:51:16 2005
@@ -15,22 +15,22 @@
*=============================================================================*/
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.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.addressing.v2004_08.AddressingConstants;
+import org.apache.xmlbeans.XmlObject;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
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.net.URL;
-import java.net.MalformedURLException;
import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
/**
- * TODO
+ * A WS-MEX metadata entry.
*/
public class MetadataEntry
{
@@ -76,113 +76,128 @@
{
if ( m_metadata == null )
{
- initMetadata();
+ 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 )
- {
+ /**
+ * 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 );
+ 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;
- }
+ //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 );
- }
- }
+ //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 );
- }
- m_metadata = metadata;
- }
+ }
+ m_metadata = metadata;
+ }
private XmlObject wrapEndpointReferenceType( XmlObject metadata )
{
- if ( metadata instanceof EndpointReferenceDocument )
+ if ( m_dialect.equals( AddressingConstants.NSURI_ADDRESSING_SCHEMA ) )
{
- EndpointReferenceDocument metadataReferenceDoc = (EndpointReferenceDocument) metadata;
- metadata = createMetadataReferenceDocument(
- metadataReferenceDoc.getEndpointReference() );
+ if ( metadata instanceof EndpointReferenceDocument )
+ {
+ EndpointReferenceDocument metadataReferenceDoc = (EndpointReferenceDocument) metadata;
+ metadata = createMetadataReferenceDocument(
+ metadataReferenceDoc.getEndpointReference() );
+ }
+ else
+ {
+ LOG.error( "Error resolving MetadataEntry - dialect was " + m_dialect + ", but document at location " +
+ m_location + " was not of type {" + m_dialect + "}EndpointReference" );
+ }
}
- else if ( metadata instanceof org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument )
+ else if ( m_dialect.equals( org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA ) )
{
- 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 );
+ 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 );
+ }
+ else
+ {
+ LOG.error( "Error resolving MetadataEntry - dialect was " + m_dialect + ", but document at location " +
+ m_location + " was not of type {" + m_dialect + "}EndpointReference" );
+ }
}
return metadata;
}
private MetadataReferenceDocument createMetadataReferenceDocument( EndpointReferenceType epr )
{
- MetadataReferenceDocument metadataReferenceDocument = MetadataReferenceDocument.Factory.newInstance( );
- metadataReferenceDocument.setMetadataReference( epr );
- return metadataReferenceDocument;
+ MetadataReferenceDocument metadataReferenceDoc = MetadataReferenceDocument.Factory.newInstance();
+ metadataReferenceDoc.setMetadataReference( epr );
+ return metadataReferenceDoc;
}
}