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 sc...@apache.org on 2005/10/19 19:37:42 UTC
svn commit: r326614 - in /webservices/wsrf/trunk/src/java/org/apache/ws:
resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
util/jndi/tools/MetadataConfig.java util/jndi/tools/MetadataConfigImpl.java
Author: scamp
Date: Wed Oct 19 10:37:37 2005
New Revision: 326614
URL: http://svn.apache.org/viewcvs?rev=326614&view=rev
Log:
updated the metadata config stuff
Removed:
webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java
Modified:
webservices/wsrf/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
webservices/wsrf/trunk/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java?rev=326614&r1=326613&r2=326614&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/metadataexchange/v2004_09/porttype/impl/MetadataExchangePortTypeImpl.java Wed Oct 19 10:37:37 2005
@@ -15,14 +15,23 @@
*=============================================================================*/
package org.apache.ws.resource.metadataexchange.v2004_09.porttype.impl;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import org.apache.ws.resource.AbstractPortType;
+import org.apache.ws.resource.NamespaceVersionHolder;
import org.apache.ws.resource.ResourceContext;
import org.apache.ws.resource.metadataexchange.v2004_09.MetadataExchangeConstants;
import org.apache.ws.resource.metadataexchange.v2004_09.porttype.MetadataExchangePortType;
-import org.apache.ws.resource.NamespaceVersionHolder;
import org.apache.ws.resource.properties.v2004_11.impl.NamespaceVersionHolderImpl;
import org.apache.ws.util.XmlBeanUtils;
-import org.apache.ws.util.jndi.tools.MetadataConfig;
+import org.apache.ws.util.jndi.tools.MetadataConfigImpl;
+import org.apache.ws.util.jndi.tools.MetadataEntry;
import org.apache.ws.util.soap.SoapClient;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
@@ -37,285 +46,247 @@
import org.xmlsoap.schemas.ws.x2004.x09.mex.MetadataDocument;
import org.xmlsoap.schemas.ws.x2004.x09.mex.MetadataReferenceDocument;
import org.xmlsoap.schemas.ws.x2004.x09.mex.MetadataSectionDocument;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
/**
* An implementation of the WS-MEX MetadataExchange portType.
- *
+ *
* @author Sal Campana
*/
-public class MetadataExchangePortTypeImpl
- extends AbstractPortType
- implements MetadataExchangePortType
-{
- private static final NamespaceVersionHolder NAMESPACE_SET = new NamespaceVersionHolderImpl( );
-
- /**
- * Creates a new {@link AbstractPortType} object.
- *
- * @param resourceContext
- */
- public MetadataExchangePortTypeImpl( ResourceContext resourceContext )
- {
- super( resourceContext );
- }
-
- /**
- * WS-MetadataExchange GetMetadata operation.
- *
- * @param request
- * @return MetadataDocument response document
- */
- public MetadataDocument getMetadata( GetMetadataDocument request )
- {
- MetadataConfig metadataConfig = getMetadataConfigFromJNDI( );
-
- //prep the response
- MetadataDocument responseDoc = createMetadataResponseDoc( );
- MetadataDocument.Metadata responseMetadata = responseDoc.addNewMetadata( );
-
- //get the values from the request
- GetMetadataDocument.GetMetadata requestMetadata = request.getGetMetadata( );
- String dialect = requestMetadata.getDialect( );
- String identifier = requestMetadata.getIdentifier( );
-
- //get the metatdata from the config
- // the map is keyed on dialect and keyed to a List of metadata
- // this allows you to build a metadata section per dialect
- Map metadataMap = metadataConfig.getMetadata( dialect, identifier );
-
- //iterate the returned set and add metadata sections
- Iterator iterator = metadataMap.keySet( ).iterator( );
- while ( iterator.hasNext( ) )
- {
- String dialectKey = (String) iterator.next( );
-
- //get the list of metatadata for this dialect
- List metadataList = (List) metadataMap.get( dialectKey );
-
- for ( int i = 0; i < metadataList.size( ); i++ )
- {
- //create a new metadata section
- MetadataSectionDocument.MetadataSection metadataSection = responseMetadata.addNewMetadataSection( );
- Object data = metadataList.get( i );
- metadataSection.setDialect( dialectKey );
- if ( ( identifier != null ) && !"".equals( identifier ) )
- {
- metadataSection.setIdentifier( identifier );
- }
-
- /** Determine type of metadata to add **/
- if ( data instanceof MetadataReferenceDocument )
- {
- //adds a MetadataReference for locating the metadata
- metadataSection.setMetadataReference( (EndpointReferenceType) data );
- }
- else if ( data instanceof LocationDocument )
- {
- //adds a Location for locating the metadata
- metadataSection.setLocation( ( (LocationDocument) data ).getLocation( ) );
- }
- else
- {
- //else its the metadata document and must be added as a child for the "any"
- XmlBeanUtils.addChildElement( metadataSection, (XmlObject) data );
- }
- }
- }
-
- getResourceContext( ).setResponseAction( URI.create( MetadataExchangeConstants.ACTION_GETMETADATA_RESPONSE ) );
- return responseDoc;
- }
-
- /**
- * WS-MetadataExchange Get operation.
- *
- * @return AnyXmlType response document.
- */
- public AnyXmlType get( )
- {
- AnyXmlType anyXmlType = AnyXmlType.Factory.newInstance( );
- MetadataConfig metadataConfig = getMetadataConfigFromJNDI( );
-
- //get all the registered metadata
- Map allMetadata = metadataConfig.getAllMetadata( );
- Iterator iterator = allMetadata.values( ).iterator( );
- while ( iterator.hasNext( ) )
- {
- List metadataList = (List) iterator.next( );
- for ( int i = 0; i < metadataList.size( ); i++ )
- {
- Object metadata = metadataList.get( i );
-
- /** Determine type of metadata to add **/
- if ( metadata instanceof MetadataReferenceDocument )
- {
- //must load actual metadata using MetadataReference
- try
- {
- metadata =
- loadMetadataFromEPR( ( (MetadataReferenceDocument) metadata ).getMetadataReference( ) );
- }
- catch ( Exception e )
- {
- throw new RuntimeException( "Unable to retrieve metadata from the configured EPR: " + metadata, e );
- }
- }
- else if ( metadata instanceof LocationDocument )
- {
- try
- {
- metadata = loadMetadataFromURL( ( (LocationDocument) metadata ).getLocation( ) );
- }
- catch ( Exception e )
- {
- //not sure if we should ignore a problem and send the rest...
- throw new RuntimeException( "Unable to retrieve metadata from the configured URL: "
- + ( (LocationDocument) metadata ).getLocation( ), e );
- }
- }
-
- XmlBeanUtils.addChildElement( anyXmlType, (XmlObject) metadata );
- }
- }
-
- getResourceContext( ).setResponseAction( URI.create( MetadataExchangeConstants.ACTION_GET_RESPONSE ) );
- return anyXmlType;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- protected NamespaceVersionHolder getNamespaceSet( )
- {
- return NAMESPACE_SET;
- }
-
- private MetadataConfig getMetadataConfigFromJNDI( )
- {
- String metadataJndiContextName = getMetadataJndiContextName( );
- try
- {
- return (MetadataConfig) new InitialContext( ).lookup( metadataJndiContextName );
- }
- catch ( NamingException ne )
- {
- throw new RuntimeException( "Unable to retrieve WS-MetadataExchange configuration.", ne );
- }
- }
-
- /**
- * Returns the JNDI Contrext name for looking up the metadata
- *
- * @return
- */
- private String getMetadataJndiContextName( )
- {
- return org.apache.ws.resource.JndiConstants.CONTEXT_NAME_SERVICES + "/"
- + getResourceContext( ).getServiceName( ) + "/"
- + org.apache.ws.resource.JndiConstants.ATOMIC_METADATA_CONTEXT;
- }
-
- /**
- * Builds a SOAP Envelope based on the EPR and makes a request to retrieve the metadata.
- *
- * @param address
- * @param endpointReferenceType
- * @return The SOAP Envelope for making a request.
- */
- private EnvelopeDocument buildSoapEnvelopeForGet( String address,
- EndpointReferenceType endpointReferenceType )
- {
- EnvelopeDocument envelopeDocument = EnvelopeDocument.Factory.newInstance( );
- Envelope envelope = envelopeDocument.addNewEnvelope( );
- envelope.addNewBody( );
- Header header = envelope.addNewHeader( );
- XmlObject toElem;
- XmlObject actionElem;
- org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument toDoc =
- org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument.Factory.newInstance( );
- AttributedURI attributedURI = toDoc.addNewTo( );
- attributedURI.setStringValue( address );
- toElem = toDoc;
- org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument actionDoc =
- org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument.Factory.newInstance( );
- AttributedURI actionType = actionDoc.addNewAction( );
- actionType.setStringValue( MetadataExchangeConstants.ACTION_GET_REQUEST );
- actionElem = actionDoc;
-
- XmlBeanUtils.addChildElement( header, toElem );
- XmlBeanUtils.addChildElement( header, actionElem );
- if ( endpointReferenceType.getReferenceProperties( ) != null )
- {
- XmlObject[] refPropElems =
- XmlBeanUtils.getChildElements( endpointReferenceType.getReferenceProperties( ) );
- for ( int i = 0; i < refPropElems.length; i++ )
- {
- XmlBeanUtils.addChildElement( header, refPropElems[i] );
- }
- }
-
- return envelopeDocument;
- }
-
- /**
- * Creates the response object for a GetMetadata request
- *
- * @return empty MetadataDocument
- */
- private MetadataDocument createMetadataResponseDoc( )
- {
- MetadataDocument metadataDocument = MetadataDocument.Factory.newInstance( );
- return metadataDocument;
- }
-
- /**
- * Loads metadata off of an EPR.
- *
- * @param epr
- * @return
- * @throws IOException
- * @throws URISyntaxException
- * @throws XmlException
- */
- private Object loadMetadataFromEPR( EndpointReferenceType epr )
- throws IOException,
- URISyntaxException,
- XmlException
- {
- String address = epr.getAddress( ).getStringValue( );
-
- //send WS-MEX Get request
- EnvelopeDocument envelope = buildSoapEnvelopeForGet( address, epr );
- String response =
- SoapClient.sendRequest( new URL( address ),
- envelope.newInputStream( ),
- new URI( MetadataExchangeConstants.ACTION_GET_REQUEST ) );
- return XmlObject.Factory.parse( response );
- }
-
- /**
- * Loads metadata off of a URL.
- *
- * @param s
- * @return
- * @throws IOException
- * @throws XmlException
- */
- private Object loadMetadataFromURL( String s )
- throws IOException,
- XmlException
- {
- return XmlObject.Factory.parse( new URL( s ) );
- }
+public class MetadataExchangePortTypeImpl extends AbstractPortType implements
+ MetadataExchangePortType {
+ private static final NamespaceVersionHolder NAMESPACE_SET = new NamespaceVersionHolderImpl();
+
+ /**
+ * Creates a new {@link AbstractPortType} object.
+ *
+ * @param resourceContext
+ */
+ public MetadataExchangePortTypeImpl(ResourceContext resourceContext) {
+ super(resourceContext);
+ }
+
+ /**
+ * WS-MetadataExchange GetMetadata operation.
+ *
+ * @param request
+ * @return MetadataDocument response document
+ */
+ public MetadataDocument getMetadata(GetMetadataDocument request) {
+ MetadataConfigImpl metadataConfig = MetadataConfigImpl
+ .getMetadataConfig();
+
+ // prep the response
+ MetadataDocument responseDoc = createMetadataResponseDoc();
+ MetadataDocument.Metadata responseMetadata = responseDoc
+ .addNewMetadata();
+
+ // get the values from the request
+ GetMetadataDocument.GetMetadata requestMetadata = request
+ .getGetMetadata();
+ String dialect = requestMetadata.getDialect();
+ String identifier = requestMetadata.getIdentifier();
+
+ // get the metatdata from the config
+ // the map is keyed on dialect and keyed to a List of metadata
+ // this allows you to build a metadata section per dialect
+ Map metadataMap = metadataConfig.getMetadata(dialect, identifier);
+
+ // iterate the returned set and add metadata sections
+ Iterator iterator = metadataMap.keySet().iterator();
+ while (iterator.hasNext()) {
+ String dialectKey = (String) iterator.next();
+
+ // get the list of metatadata for this dialect
+ List metadataList = (List) metadataMap.get(dialectKey);
+
+ for (int i = 0; i < metadataList.size(); i++) {
+ // create a new metadata section
+ MetadataSectionDocument.MetadataSection metadataSection = responseMetadata
+ .addNewMetadataSection();
+ Object data = metadataList.get(i);
+ metadataSection.setDialect(dialectKey);
+ if ((identifier != null) && !"".equals(identifier)) {
+ metadataSection.setIdentifier(identifier);
+ }
+
+ /** Determine type of metadata to add * */
+ if (data instanceof MetadataReferenceDocument) {
+ // adds a MetadataReference for locating the metadata
+ metadataSection
+ .setMetadataReference((EndpointReferenceType) data);
+ } else if (data instanceof LocationDocument) {
+ // adds a Location for locating the metadata
+ metadataSection.setLocation(((LocationDocument) data)
+ .getLocation());
+ } else {
+ // else its the metadata document and must be added as a
+ // child for the "any"
+ XmlBeanUtils.addChildElement(metadataSection,
+ (XmlObject) data);
+ }
+ }
+ }
+
+ getResourceContext().setResponseAction(
+ URI.create(MetadataExchangeConstants.ACTION_GETMETADATA_RESPONSE));
+ return responseDoc;
+ }
+
+ /**
+ * WS-MetadataExchange Get operation.
+ *
+ * @return AnyXmlType response document.
+ */
+ public AnyXmlType get() {
+ AnyXmlType anyXmlType = AnyXmlType.Factory.newInstance();
+ MetadataConfigImpl metadataConfig = MetadataConfigImpl
+ .getMetadataConfig();
+
+ // get all the registered metadata
+ List allMetadata = metadataConfig.getAllMetadata();
+ Iterator iterator = allMetadata.iterator();
+ while (iterator.hasNext()) {
+ MetadataEntry metadataEntry = (MetadataEntry) iterator.next();
+
+ XmlObject metadata = metadataEntry.getMetadata();
+
+ /** Determine type of metadata to add * */
+ if (metadata instanceof MetadataReferenceDocument) {
+ // must load actual metadata using MetadataReference
+ try {
+ metadata = loadMetadataFromEPR(((MetadataReferenceDocument) metadata)
+ .getMetadataReference());
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Unable to retrieve metadata from the configured EPR: "
+ + metadata, e);
+ }
+ } else if (metadata instanceof LocationDocument) {
+ try {
+ metadata = loadMetadataFromURL(((LocationDocument) metadata)
+ .getLocation());
+ } catch (Exception e) {
+ // not sure if we should ignore a problem and send the
+ // rest...
+ throw new RuntimeException(
+ "Unable to retrieve metadata from the configured URL: "
+ + ((LocationDocument) metadata)
+ .getLocation(), e);
+ }
+ }
+
+ XmlBeanUtils.addChildElement(anyXmlType, (XmlObject) metadata);
+ }
+
+ getResourceContext().setResponseAction(
+ URI.create(MetadataExchangeConstants.ACTION_GET_RESPONSE));
+ return anyXmlType;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ protected NamespaceVersionHolder getNamespaceSet() {
+ return NAMESPACE_SET;
+ }
+
+ /**
+ * Returns the JNDI Contrext name for looking up the metadata
+ *
+ * @return
+ */
+ private String getMetadataJndiContextName() {
+ return org.apache.ws.resource.JndiConstants.CONTEXT_NAME_SERVICES + "/"
+ + getResourceContext().getServiceName() + "/"
+ + org.apache.ws.resource.JndiConstants.ATOMIC_METADATA_CONTEXT;
+ }
+
+ /**
+ * Builds a SOAP Envelope based on the EPR and makes a request to retrieve
+ * the metadata.
+ *
+ * @param address
+ * @param endpointReferenceType
+ * @return The SOAP Envelope for making a request.
+ */
+ private EnvelopeDocument buildSoapEnvelopeForGet(String address,
+ EndpointReferenceType endpointReferenceType) {
+ EnvelopeDocument envelopeDocument = EnvelopeDocument.Factory
+ .newInstance();
+ Envelope envelope = envelopeDocument.addNewEnvelope();
+ envelope.addNewBody();
+ Header header = envelope.addNewHeader();
+ XmlObject toElem;
+ XmlObject actionElem;
+ org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument toDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ToDocument.Factory
+ .newInstance();
+ AttributedURI attributedURI = toDoc.addNewTo();
+ attributedURI.setStringValue(address);
+ toElem = toDoc;
+ org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument actionDoc = org.xmlsoap.schemas.ws.x2004.x08.addressing.ActionDocument.Factory
+ .newInstance();
+ AttributedURI actionType = actionDoc.addNewAction();
+ actionType.setStringValue(MetadataExchangeConstants.ACTION_GET_REQUEST);
+ actionElem = actionDoc;
+
+ XmlBeanUtils.addChildElement(header, toElem);
+ XmlBeanUtils.addChildElement(header, actionElem);
+ if (endpointReferenceType.getReferenceProperties() != null) {
+ XmlObject[] refPropElems = XmlBeanUtils
+ .getChildElements(endpointReferenceType
+ .getReferenceProperties());
+ for (int i = 0; i < refPropElems.length; i++) {
+ XmlBeanUtils.addChildElement(header, refPropElems[i]);
+ }
+ }
+
+ return envelopeDocument;
+ }
+
+ /**
+ * Creates the response object for a GetMetadata request
+ *
+ * @return empty MetadataDocument
+ */
+ private MetadataDocument createMetadataResponseDoc() {
+ MetadataDocument metadataDocument = MetadataDocument.Factory
+ .newInstance();
+ return metadataDocument;
+ }
+
+ /**
+ * Loads metadata off of an EPR.
+ *
+ * @param epr
+ * @return
+ * @throws IOException
+ * @throws URISyntaxException
+ * @throws XmlException
+ */
+ private XmlObject loadMetadataFromEPR(EndpointReferenceType epr)
+ throws IOException, URISyntaxException, XmlException {
+ String address = epr.getAddress().getStringValue();
+
+ // send WS-MEX Get request
+ EnvelopeDocument envelope = buildSoapEnvelopeForGet(address, epr);
+ String response = SoapClient.sendRequest(new URL(address), envelope
+ .newInputStream(), new URI(
+ MetadataExchangeConstants.ACTION_GET_REQUEST));
+ return XmlObject.Factory.parse(response);
+ }
+
+ /**
+ * Loads metadata off of a URL.
+ *
+ * @param s
+ * @return
+ * @throws IOException
+ * @throws XmlException
+ */
+ private XmlObject loadMetadataFromURL(String s) throws IOException,
+ XmlException {
+ return XmlObject.Factory.parse(new URL(s));
+ }
}
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=326614&r1=326613&r2=326614&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 10:37:37 2005
@@ -15,24 +15,14 @@
*=============================================================================*/
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.io.Serializable;
-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;
+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.
@@ -47,17 +37,6 @@
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";
-
-
- /**
* Internal Map for storing metatdata.
*
* The map will have the structure of:
@@ -78,6 +57,8 @@
private Map m_dialectToMetadataListMap = new HashMap( );
private List m_metadataList = new ArrayList( );
+
+ private static MetadataConfigImpl s_metadataConfig;
/**
* Creates a new {@link MetadataConfigImpl} object.
@@ -88,50 +69,27 @@
{
m_metadataList = metadataEntryList;
loadMetadata( );
+ s_metadataConfig = this;
}
+ public static MetadataConfigImpl getMetadataConfig()
+ {
+ return s_metadataConfig;
+ }
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 );
- }
+ addToMetadataMap( metadataEntry );
}
/**
* Returns all known metadata for all dialects.
*
- * @return A Map keyed on dialect keyed-to a List of metadata
+ * @return A list of all metadata
*/
- public Map getAllMetadata( )
+ public List 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 m_metadataList;
}
/**
@@ -151,9 +109,8 @@
if ( dialectMap != null )
{
if ( identifierUri != null )
- {
- Map identifierMap = (Map) dialectMap.get( IDENTIFIER_MAP );
- Object metatdata = identifierMap.get( identifierUri );
+ {
+ Object metatdata = dialectMap.get(identifierUri);
if ( metatdata != null )
{
List list = new ArrayList( );
@@ -162,17 +119,13 @@
}
}
else
- {
- List metatdataList = (List) dialectMap.get( COMPLETE_METADATA_LIST );
- results.put( dialect, metatdataList );
+ {
+ //based on dialect get all entries
+ results.put( dialect, new ArrayList(dialectMap.values()) );
}
}
}
- else //get all metatdata
- {
- return getAllMetadata( );
- }
-
+
return results;
}
@@ -196,40 +149,27 @@
* @param identifier
* @param metadata The "parsed" metadata (could be XmlObject, MetadataReference or Location )
*/
- protected void addToMetadataMap( String dialect,
- MetadataEntry metadataEntry )
+ protected void addToMetadataMap( MetadataEntry metadataEntry )
{
+ String dialect = metadataEntry.getDialect();
+ String identifier = metadataEntry.getIdentifier();
Map dialectMap = (Map) m_dialectToMetadataListMap.get( dialect );
if ( dialectMap == null )
{
- addStructureForDialect( dialect );
- dialectMap = (Map) m_dialectToMetadataListMap.get( dialect );
+ //build the entries for the maps
+ dialectMap = new HashMap( );
+ m_dialectToMetadataListMap.put( dialect, dialectMap ); //add to metadatamap
+
}
+ //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 ) )
- {
- Map identifierMap = (Map) dialectMap.get( IDENTIFIER_MAP );
- identifierMap.put( identifier, metadata );
+ {
+ dialectMap.put( identifier, metadataEntry );
}
}
/**
- * Builds the lookup structure given a dialect.
- *
- * @param dialect
- */
- private synchronized void addStructureForDialect( String dialect )
- {
- Map dialectMap = new HashMap( );
- m_dialectToMetadataListMap.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
@@ -240,18 +180,7 @@
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 );
- }
+ addToMetadataMap( metadataEntry );
}
}