You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by sc...@apache.org on 2006/06/02 19:33:13 UTC
svn commit: r411218 [23/34] - in /webservices/muse: branches/1.0/
branches/1.0/src/examples/broker/ branches/1.0/src/examples/broker/WEB-INF/
branches/1.0/src/examples/consumer/ branches/1.0/src/examples/consumer/epr/
branches/1.0/src/examples/consumer...
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanJndiUtils.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,662 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.axis.components.logger.LogFactory;
+import org.apache.commons.logging.Log;
+import org.apache.ws.resource.JndiConstants;
+import org.apache.ws.util.XmlBeanUtils;
+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.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.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * LOG-DONE JNDI Utiltiy methods for use with an XmlBean-generated JNDI-Config file. This class handles the initial
+ * setup of JNDI, it loads the JNDI config file and registers instances of services.
+ *
+ * @author Sal Campana
+ */
+public class XmlBeanJndiUtils
+{
+ private static Log LOG = LogFactory.getLog( XmlBeanJndiUtils.class.getName( ) );
+
+ /**
+ * Apache JNDI URL Package Prefix
+ */
+ public static final String APACHE_URL_PKG_PREFIX = "org.apache.naming";
+
+ /**
+ * Apache JNDI Initial Context Factory Prefix
+ */
+ public static final String APACHE_INITIAL_CONTEXT_FACTORY = "org.apache.naming.java.javaURLContextFactory";
+
+ /**
+ * The file name of the jndi-config file.
+ */
+ public static final String JNDI_CONFIG_FILENAME = "jndi-config.xml";
+ private static final String PROP_FACTORY = "factory";
+ private static boolean s_configLoaded;
+ private static boolean s_jndiInitialized;
+ private static DefaultParameters s_defaultParams;
+
+ /**
+ * Initializes JNDI from a directory tree which contains the jndi-config.xml files....
+ *
+ * @param configDir
+ * @return
+ * @throws Exception
+ */
+ public static synchronized Context initFromDir( String configDir )
+ throws Exception
+ {
+ if ( !s_configLoaded )
+ {
+ LOG.debug( "Initializing JNDI from config directory: " + configDir + " ..." );
+
+ initJNDI( );
+
+ File fDir = new File( configDir );
+ File[] dirs =
+ fDir.listFiles( new FileFilter( )
+ {
+ public boolean accept( File path )
+ {
+ return path.isDirectory( );
+ }
+ } );
+
+ for ( int i = 0; i < dirs.length; i++ )
+ {
+ processJNDIFile( dirs[i], JNDI_CONFIG_FILENAME );
+ }
+
+ s_configLoaded = true;
+ }
+
+ return new InitialContext( );
+ }
+
+ /**
+ * Initializes JNDI given a File name which will attempt to be loaded.
+ *
+ * @param configFilename
+ * @return
+ * @throws Exception
+ */
+ public static synchronized Context initFromFile( String configFilename )
+ throws Exception
+ {
+ LOG.debug( "Initializing JNDI from file: " + configFilename );
+ if ( !s_configLoaded )
+ {
+ initJNDI( );
+
+ InputStream configInput;
+ try
+ {
+ LOG.debug( "Trying to load JNDI configuration from file: " + configFilename );
+ configInput = new FileInputStream( configFilename );
+ }
+ catch ( FileNotFoundException fnfe )
+ {
+ LOG.debug( "Trying to load JNDI configuration from classloader resource: " + configFilename );
+ configInput = XmlBeanJndiUtils.class.getClassLoader( ).getResourceAsStream( configFilename );
+ if ( configInput == null )
+ {
+ throw new IOException( "jndiConfigNotFound" );
+ }
+ }
+
+ Context context = new InitialContext( );
+ parseJNDIConfig( context, configInput );
+ s_configLoaded = true;
+ }
+
+ return new InitialContext( );
+ }
+
+ /**
+ * Initializes JNDI from a given InputStream to a jndi-config.xml file.
+ *
+ * @param inputStream
+ * @return JNDI Context
+ * @throws Exception
+ */
+ public static synchronized Context initFromInputStream( InputStream inputStream )
+ throws Exception
+ {
+ if ( !s_configLoaded )
+ {
+ initJNDI( );
+ LOG.debug( "Trying to load JNDI configuration from inputstream" );
+ parseJNDIConfig( new InitialContext( ),
+ inputStream );
+ s_configLoaded = true;
+ }
+
+ return new InitialContext( );
+ }
+
+ /**
+ * Configure JNDI with the Apache Tomcat naming service classes and
+ * create the WSRF context.
+ *
+ * @return the WSRF context
+ * @throws Exception
+ */
+ public static synchronized Context initJNDI( )
+ throws Exception
+ {
+ if ( !s_jndiInitialized )
+ {
+ initJndiImpl( );
+ initWsrfContext( );
+ s_jndiInitialized = true;
+ }
+
+ return new InitialContext( );
+ }
+
+ /**
+ * Called via parseJNDIConfig(InputStream)
+ * <p/>
+ * Parse the given JNDI configuration and populate the JNDI registry using the parsed configuration
+ *
+ * @param configStream The configuration stream to parse
+ * @throws Exception
+ */
+ public static void parseJNDIConfig( Context initContext,
+ InputStream configStream )
+ throws Exception
+ {
+ if ( configStream == null )
+ {
+ throw new IllegalArgumentException( "nullJNDIConfigInput" );
+ }
+
+ if ( initContext == null )
+ {
+ throw new IllegalArgumentException( );
+ }
+
+ //get the global context
+ Context envContext = (Context) initContext.lookup( JndiConstants.CONTEXT_NAME_GLOBAL );
+ XmlBeanNamingContext namingContext = new XmlBeanNamingContext( envContext );
+
+ //load the config file
+ JndiConfigDocument jndiConfigDoc = (JndiConfigDocument) XmlObject.Factory.parse( configStream );
+ validateJndiConfig( jndiConfigDoc );
+ JndiConfigDocument.JndiConfig jndiConfig = jndiConfigDoc.getJndiConfig( );
+ GlobalDocument.Global global = jndiConfig.getGlobal( );
+
+ //setup the global jndi elements
+ addGlobalElements( namingContext, global );
+
+ //get the service context
+ envContext = (Context) initContext.lookup( JndiConstants.CONTEXT_NAME_SERVICES );
+ namingContext = new XmlBeanNamingContext( envContext );
+
+ //setup the service jndi elements
+ ServiceDocument.Service[] serviceArray = jndiConfig.getServiceArray( );
+ addServiceElements( namingContext, serviceArray );
+ }
+
+ private static void setDefaultParameterValues( ResourceParameters params )
+ {
+ if ( params.getParameter( PROP_FACTORY ) == null )
+ {
+ params.addParameter( PROP_FACTORY,
+ s_defaultParams.getFactory( ) );
+ }
+ }
+
+ private static DefaultParameters getDefaultProperties( GlobalDocument.Global global )
+ throws IllegalAccessException,
+ InstantiationException,
+ ClassNotFoundException
+ {
+ ResourceDocument.Resource defaultConfig = null;
+ ResourceDocument.Resource[] resourceArray = global.getResourceArray( );
+ for ( int i = 0; i < resourceArray.length; i++ )
+ {
+ ResourceDocument.Resource resource = resourceArray[i];
+ if ( DefaultParameters.class.getName( ).equals( resource.getType( ) ) )
+ {
+ defaultConfig = resource;
+ break;
+ }
+ }
+
+ return setupDefaultParams( defaultConfig );
+ }
+
+ private static Environment[] getEnvironmentArray( EnvironmentDocument.Environment[] environmentArray )
+ {
+ List envList = new ArrayList( );
+
+ if ( environmentArray != null )
+ {
+ for ( int i = 0; i < environmentArray.length; i++ )
+ {
+ EnvironmentDocument.Environment environment = environmentArray[i];
+ Environment env = new Environment( );
+ env.setDescription( environment.getDescription( ) );
+ env.setName( environment.getName( ) );
+ env.setType( environment.getType( ) );
+ env.setValue( environment.getValue( ) );
+ envList.add( env );
+ }
+ }
+
+ return (Environment[]) envList.toArray( new Environment[0] );
+ }
+
+ private static ResourceParameters getParameters( ResourceParamsDocument.ResourceParams resourceParams )
+ {
+ ResourceParameters params = new ResourceParameters( );
+ if ( resourceParams != null )
+ {
+ ParameterDocument.Parameter[] parameterArray = resourceParams.getParameterArray( );
+ for ( int i = 0; i < parameterArray.length; i++ )
+ {
+ ParameterDocument.Parameter parameter = parameterArray[i];
+ params.addParameter( parameter.getName( ),
+ parameter.getValue( ) );
+ }
+ }
+
+ return params;
+ }
+
+ private static Resource[] getResourceArray( ResourceDocument.Resource[] resourceArray,
+ String name,
+ XmlBeanNamingContext namingContext )
+ {
+ List resources = new ArrayList( );
+ if ( resourceArray != null )
+ {
+ for ( int i = 0; i < resourceArray.length; i++ )
+ {
+ ResourceDocument.Resource resourceDoc = resourceArray[i];
+
+ //special type of resource....metatdata...handle differently....
+ MetadataConfigDocument.MetadataConfig metadataConfig = resourceDoc.getMetadataConfig( );
+ if ( metadataConfig != null )
+ {
+ try
+ {
+ Class metaConfigClass = Class.forName( resourceDoc.getType( ) );
+ Constructor constructor =
+ metaConfigClass.getConstructor( new Class[]
+ {
+ MetadataConfigDocument.MetadataConfig.class
+ } );
+ 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 );
+ }
+ }
+
+ Resource resource = new Resource( );
+ resource.setName( resourceDoc.getName( ) );
+ resource.setAuth( resourceDoc.getAuth( ) );
+ resource.setDescription( resourceDoc.getDescription( ) );
+ resource.setType( resourceDoc.getType( ) );
+ resource.setScope( resourceDoc.getScope( ) );
+ resource.setParameters( getParameters( resourceDoc.getResourceParams( ) ) );
+ resources.add( resource );
+ }
+ }
+
+ return (Resource[]) resources.toArray( new Resource[0] );
+ }
+
+ private static ResourceLink[] getResourceLinkArray( ResourceLinkDocument.ResourceLink[] resourceLinkArray )
+ {
+ List resourceLinks = new ArrayList( );
+ if ( resourceLinkArray != null )
+ {
+ for ( int i = 0; i < resourceLinkArray.length; i++ )
+ {
+ ResourceLinkDocument.ResourceLink resourceLink = resourceLinkArray[i];
+ ResourceLink link = new ResourceLink( );
+ link.setName( resourceLink.getName( ) );
+ link.setTarget( resourceLink.getTarget( ) );
+ resourceLinks.add( link );
+ }
+ }
+
+ return (ResourceLink[]) resourceLinks.toArray( new ResourceLink[0] );
+ }
+
+ private static ConfigContext[] getServiceArray( ServiceDocument.Service[] serviceArray,
+ XmlBeanNamingContext namingContext )
+ {
+ List services = new ArrayList( );
+ if ( serviceArray != null )
+ {
+ for ( int i = 0; i < serviceArray.length; i++ )
+ {
+ ServiceDocument.Service service = serviceArray[i];
+ ConfigContext context = new ConfigContext( );
+ context.setName( service.getName( ) );
+ Environment[] environmentArray = getEnvironmentArray( service.getEnvironmentArray( ) );
+ for ( int j = 0; j < environmentArray.length; j++ )
+ {
+ context.addEnvironment( environmentArray[j] );
+ }
+
+ Resource[] resourceArray =
+ getResourceArray( service.getResourceArray( ),
+ service.getName( ),
+ namingContext );
+ for ( int j = 0; j < resourceArray.length; j++ )
+ {
+ Resource resource = resourceArray[j];
+ ResourceParameters params = resource.getParameters( );
+ setDefaultParameterValues( params );
+ validateParameterValues( params );
+ }
+
+ for ( int j = 0; j < resourceArray.length; j++ )
+ {
+ context.addResource( resourceArray[j] );
+ }
+
+ ResourceLink[] resourceLinkArray = getResourceLinkArray( service.getResourceLinkArray( ) );
+ for ( int j = 0; j < resourceLinkArray.length; j++ )
+ {
+ context.addResourceLink( resourceLinkArray[j] );
+ }
+
+ services.add( context );
+ }
+ }
+
+ return (ConfigContext[]) services.toArray( new ConfigContext[0] );
+ }
+
+ private static ConfigContext[] getServiceSubContextArray( ConfigContext service )
+ {
+ List subContexts = new ArrayList( );
+ if ( service != null )
+ {
+ Set subContextNames = service.getSubContextNames( );
+ Iterator iterator = subContextNames.iterator( );
+
+ while ( iterator.hasNext( ) )
+ {
+ subContexts.add( service.getSubContext( (String) iterator.next( ) ) );
+ }
+ }
+
+ return (ConfigContext[]) subContexts.toArray( new ConfigContext[0] );
+ }
+
+ private static void addGlobalElements( XmlBeanNamingContext namingContext,
+ GlobalDocument.Global global )
+ throws NamingException,
+ IllegalAccessException,
+ ClassNotFoundException,
+ InstantiationException
+ {
+ if ( global != null )
+ {
+ s_defaultParams = getDefaultProperties( global );
+
+ Environment[] environmentArray = getEnvironmentArray( global.getEnvironmentArray( ) );
+
+ for ( int i = 0; i < environmentArray.length; i++ )
+ {
+ namingContext.addEnvironment( environmentArray[i] );
+ }
+
+ ConfigContext[] subContext = getServiceArray( global.getServiceArray( ),
+ namingContext );
+ for ( int i = 0; i < subContext.length; i++ )
+ {
+ namingContext.addSubContext( subContext[i] );
+ }
+
+ Resource[] resourceArray = getResourceArray( global.getResourceArray( ),
+ null,
+ namingContext );
+ for ( int i = 0; i < resourceArray.length; i++ )
+ {
+ namingContext.addResource( resourceArray[i] );
+ }
+
+ ResourceLink[] resourceLinkArray = getResourceLinkArray( global.getResourceLinkArray( ) );
+ for ( int i = 0; i < resourceLinkArray.length; i++ )
+ {
+ namingContext.addResourceLink( resourceLinkArray[i] );
+ }
+ }
+ }
+
+ private static void addServiceElements( XmlBeanNamingContext namingContext,
+ ServiceDocument.Service[] serviceArray )
+ throws NamingException
+ {
+ if ( serviceArray != null )
+ {
+ ConfigContext[] services = getServiceArray( serviceArray, namingContext );
+ for ( int i = 0; i < services.length; i++ )
+ {
+ ConfigContext service = services[i];
+ namingContext.addService( service );
+ ConfigContext[] serviceSubContextArray = getServiceSubContextArray( service );
+ for ( int j = 0; j < serviceSubContextArray.length; j++ )
+ { //todo not sure if defaults bubble down here...
+ namingContext.addSubContext( serviceSubContextArray[j] );
+ }
+ }
+ }
+ }
+
+ private static void checkValueIsNonEmpty( ResourceParameters params,
+ String paramName )
+ {
+ String paramValue = params.getParameter( paramName );
+ if ( paramValue.trim( ).equals( "" ) )
+ {
+ throw new RuntimeException( paramName + " parameter must have a non-empty value!" );
+ }
+ }
+
+ private static void initJndiImpl( )
+ {
+ String apacheUrlPrefix = APACHE_URL_PKG_PREFIX;
+ String systemUrlPrefix = System.getProperty( Context.URL_PKG_PREFIXES );
+ String systemContextFactory = System.getProperty( Context.INITIAL_CONTEXT_FACTORY );
+
+ if ( ( systemContextFactory == null ) && ( systemUrlPrefix == null ) )
+ {
+ System.setProperty( Context.URL_PKG_PREFIXES, apacheUrlPrefix );
+ System.setProperty( Context.INITIAL_CONTEXT_FACTORY, APACHE_INITIAL_CONTEXT_FACTORY );
+ }
+ }
+
+ private static Context initWsrfContext( )
+ throws NamingException
+ {
+ Context wsrfContext;
+ InitialContext initialContext = new InitialContext( );
+ try
+ {
+ wsrfContext = (Context) initialContext.lookup( JndiConstants.CONTEXT_NAME_BASE );
+ }
+ catch ( NameNotFoundException nnfe )
+ {
+ LOG.debug( "Initializing WSRF JNDI context..." );
+ LOG.debug( "Creating JNDI subcontext: " + JndiConstants.CONTEXT_NAME_BASE + " ..." );
+ wsrfContext = initialContext.createSubcontext( JndiConstants.CONTEXT_NAME_BASE );
+ LOG.debug( "Creating JNDI subcontext: " + JndiConstants.CONTEXT_SERVICES_BASE + " ..." );
+ wsrfContext.createSubcontext( JndiConstants.CONTEXT_SERVICES_BASE );
+ LOG.debug( "Creating JNDI subcontext: " + JndiConstants.CONTEXT_GLOBAL_BASE + " ..." );
+ wsrfContext.createSubcontext( JndiConstants.CONTEXT_GLOBAL_BASE );
+ }
+
+ return wsrfContext;
+ }
+
+ private static void processJNDIFile( File dir,
+ String configFile )
+ throws Exception
+ {
+ Context context = new InitialContext( );
+ File file = new File( dir, configFile );
+ if ( !file.exists( ) )
+ {
+ return;
+ }
+
+ LOG.debug( "Loading JNDI configuration from file: " + file + " ..." );
+
+ InputStream in = null;
+ try
+ {
+ in = new FileInputStream( file );
+ parseJNDIConfig( context, in );
+ }
+ finally
+ {
+ if ( in != null )
+ {
+ try
+ {
+ in.close( );
+ }
+ catch ( IOException ioe )
+ {
+ // ignore
+ }
+ }
+ }
+ }
+
+ private static DefaultParameters setupDefaultParams( ResourceDocument.Resource defaultConfig )
+ throws ClassNotFoundException,
+ IllegalAccessException,
+ InstantiationException
+ {
+ DefaultParameters defaultParams = null;
+ if ( defaultConfig != null )
+ {
+ Object defaultConf = Class.forName( defaultConfig.getType( ) ).newInstance( );
+ if ( defaultConf instanceof DefaultParameters )
+ {
+ defaultParams = (DefaultParameters) defaultConf;
+ ResourceParamsDocument.ResourceParams resourceParams = defaultConfig.getResourceParams( );
+ ParameterDocument.Parameter[] parameterArray = resourceParams.getParameterArray( );
+ for ( int i = 0; i < parameterArray.length; i++ )
+ {
+ ParameterDocument.Parameter parameter = parameterArray[i];
+ String name = parameter.getName( );
+ String value = parameter.getValue( );
+
+ if ( ( value != null ) && !value.equals( "" ) )
+ {
+ if ( PROP_FACTORY.equals( name ) )
+ {
+ defaultParams.setFactory( value );
+ }
+ }
+ }
+ }
+ }
+
+ return defaultParams;
+ }
+
+ private static void validateJndiConfig( XmlObject requestXBean )
+ {
+ XmlOptions validateOptions = new XmlOptions( );
+ List errorList = new ArrayList( );
+ validateOptions.setErrorListener( errorList );
+ boolean isValid = requestXBean.validate( validateOptions );
+ if ( !isValid )
+ {
+ QName bodyElemName = XmlBeanUtils.getName( requestXBean );
+ StringBuffer strBuf = new StringBuffer( "jndi-config.xml is not valid as per its schema: \n\n" );
+ for ( int i = 0; i < errorList.size( ); i++ )
+ {
+ strBuf.append( "\t\t" );
+ strBuf.append( i + 1 );
+ strBuf.append( ") " );
+ strBuf.append( errorList.get( i ) );
+ strBuf.append( "\n" );
+ }
+
+ strBuf.append( "\n" );
+ LOG.fatal( strBuf.toString( ) );
+ }
+ }
+
+ private static void validateParameterValues( ResourceParameters params )
+ {
+ checkValueIsNonEmpty( params, PROP_FACTORY );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanNamingContext.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanNamingContext.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanNamingContext.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanNamingContext.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,373 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.util.jndi;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.naming.ResourceRef;
+import org.apache.ws.util.jndi.tools.ConfigContext;
+import org.apache.ws.util.jndi.tools.Environment;
+import org.apache.ws.util.jndi.tools.Resource;
+import org.apache.ws.util.jndi.tools.ResourceLink;
+import org.apache.ws.util.jndi.tools.ResourceParameters;
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * JNDI naming context.
+ */
+public class XmlBeanNamingContext
+{
+ private static Log LOG = LogFactory.getLog( XmlBeanNamingContext.class.getName( ) );
+ private Context m_context;
+
+ /**
+ * Creates a new {@link XmlBeanNamingContext} object.
+ *
+ * @param context DOCUMENT_ME
+ */
+ public XmlBeanNamingContext( Context context )
+ {
+ m_context = context;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Context getContext( )
+ {
+ return m_context;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param environment DOCUMENT_ME
+ *
+ * @throws IllegalArgumentException DOCUMENT_ME
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void addEnvironment( Environment environment )
+ throws IllegalArgumentException,
+ NamingException
+ {
+ Object value = null;
+
+ // Instantiate a new instance of the correct object type, and
+ // initialize it.
+ String type = environment.getType( );
+ LOG.debug( "Attempting to add environment for type: " + type );
+ try
+ {
+ if ( type.equals( "java.lang.String" ) )
+ {
+ value = environment.getValue( );
+ }
+ else if ( type.equals( "java.lang.Byte" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Byte( (byte) 0 );
+ }
+ else
+ {
+ value = Byte.decode( environment.getValue( ) );
+ }
+ }
+ else if ( type.equals( "java.lang.Short" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Short( (short) 0 );
+ }
+ else
+ {
+ value = Short.decode( environment.getValue( ) );
+ }
+ }
+ else if ( type.equals( "java.lang.Integer" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Integer( 0 );
+ }
+ else
+ {
+ value = Integer.decode( environment.getValue( ) );
+ }
+ }
+ else if ( type.equals( "java.lang.Long" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Long( 0 );
+ }
+ else
+ {
+ value = Long.decode( environment.getValue( ) );
+ }
+ }
+ else if ( type.equals( "java.lang.Boolean" ) )
+ {
+ value = Boolean.valueOf( environment.getValue( ) );
+ }
+ else if ( type.equals( "java.lang.Double" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Double( 0 );
+ }
+ else
+ {
+ value = Double.valueOf( environment.getValue( ) );
+ }
+ }
+ else if ( type.equals( "java.lang.Float" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Float( 0 );
+ }
+ else
+ {
+ value = Float.valueOf( environment.getValue( ) );
+ }
+ }
+ else if ( type.equals( "java.lang.Character" ) )
+ {
+ if ( environment.getValue( ) == null )
+ {
+ value = new Character( (char) 0 );
+ }
+ else
+ {
+ if ( environment.getValue( ).length( ) == 1 )
+ {
+ value = new Character( environment.getValue( ).charAt( 0 ) );
+ }
+ else
+ {
+ throw new IllegalArgumentException( );
+ }
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException( "invalidType : " + type );
+ }
+ }
+ catch ( NumberFormatException e )
+ {
+ String msg = "invalidValueForType : " + environment.getValue( ) + " : " + type;
+ LOG.error( msg, e );
+ throw new IllegalArgumentException( msg );
+ }
+
+ // Bind the object to the appropriate name
+ createSubcontexts( environment.getName( ) );
+ this.m_context.bind( environment.getName( ),
+ value );
+ if ( LOG.isDebugEnabled( ) )
+ {
+ LOG.debug( "Added environment entry with name: " + environment.getName( ) );
+ LOG.debug( "value: " + value + " and type: " + environment.getType( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param resource DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void addResource( Resource resource )
+ throws NamingException
+ {
+ Reference reference =
+ new ResourceRef( resource.getType( ),
+ resource.getDescription( ),
+ resource.getScope( ),
+ resource.getAuth( ) );
+ this.addParameters( reference,
+ resource.getParameters( ) );
+ this.createSubcontexts( resource.getName( ) );
+ this.m_context.bind( resource.getName( ),
+ reference );
+ LOG.debug( "Added resource entry with name: " + resource.getName( ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param resourceLink DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void addResourceLink( ResourceLink resourceLink )
+ throws NamingException
+ {
+ LinkRef link = new LinkRef( resourceLink.getTarget( ) );
+ this.createSubcontexts( resourceLink.getName( ) );
+ this.m_context.bind( resourceLink.getName( ),
+ link );
+ if ( LOG.isDebugEnabled( ) )
+ {
+ LOG.debug( "Added resource link with name: " + resourceLink.getName( ) );
+ LOG.debug( "Pointing to: " + resourceLink.getTarget( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param subContext DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void addService( ConfigContext subContext )
+ throws NamingException
+ {
+ String serviceName = subContext.getName( );
+ Set names;
+ Iterator nameIterator;
+ XmlBeanNamingContext newContext;
+
+ JNDIUtils.createSubcontexts( m_context, serviceName );
+
+ try
+ {
+ newContext = new XmlBeanNamingContext( m_context.createSubcontext( serviceName ) );
+ LOG.debug( "Created new subcontext with name: " + serviceName );
+ }
+ catch ( Exception e )
+ {
+ newContext = new XmlBeanNamingContext( (Context) m_context.lookup( serviceName ) );
+ LOG.debug( "Adding entries to existing subcontext with name: " + serviceName );
+ }
+
+ names = subContext.getEnvironmentNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ newContext.addEnvironment( subContext.getEnvironment( (String) nameIterator.next( ) ) );
+ }
+
+ names = subContext.getResourceNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ newContext.addServiceResource( subContext.getResource( (String) nameIterator.next( ) ),
+ serviceName );
+ }
+
+ names = subContext.getResourceLinkNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ newContext.addResourceLink( subContext.getResourceLink( (String) nameIterator.next( ) ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param resource DOCUMENT_ME
+ * @param serviceName DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void addServiceResource( Resource resource,
+ String serviceName )
+ throws NamingException
+ {
+ Reference reference =
+ new XmlBeanServiceResourceRef( resource.getType( ),
+ resource.getDescription( ),
+ resource.getScope( ),
+ resource.getAuth( ), serviceName );
+ this.addParameters( reference,
+ resource.getParameters( ) );
+ this.createSubcontexts( resource.getName( ) );
+ this.m_context.bind( resource.getName( ),
+ reference );
+ LOG.debug( "Added service resource entry with name: " + resource.getName( ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param subContext DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void addSubContext( ConfigContext subContext )
+ throws NamingException
+ {
+ addService( subContext );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ * @param ref DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ public void bind( String name,
+ Object ref )
+ throws NamingException
+ {
+ this.m_context.bind( name, ref );
+ }
+
+ private void addParameters( Reference reference,
+ ResourceParameters parameters )
+ {
+ if ( parameters != null )
+ {
+ Set names = parameters.getParameterNames( );
+ Iterator nameIterator = names.iterator( );
+ RefAddr parameter;
+ String parameterName;
+ while ( nameIterator.hasNext( ) )
+ {
+ parameterName = (String) nameIterator.next( );
+ parameter = new StringRefAddr( parameterName,
+ parameters.getParameter( parameterName ) );
+ reference.add( parameter );
+ }
+ }
+ }
+
+ private void createSubcontexts( String name )
+ throws NamingException
+ {
+ JNDIUtils.createSubcontexts( this.m_context, name );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanServiceResourceRef.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanServiceResourceRef.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanServiceResourceRef.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/XmlBeanServiceResourceRef.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,58 @@
+/*=============================================================================*
+ * 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;
+
+
+/**LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.2 $
+ */
+public class XmlBeanServiceResourceRef
+ extends org.apache.naming.ResourceRef
+{
+ private String name;
+
+ /**
+ * Creates a new {@link XmlBeanServiceResourceRef} object.
+ *
+ * @param resourceClass DOCUMENT_ME
+ * @param description DOCUMENT_ME
+ * @param scope DOCUMENT_ME
+ * @param auth DOCUMENT_ME
+ * @param serviceName DOCUMENT_ME
+ */
+ public XmlBeanServiceResourceRef( String resourceClass,
+ String description,
+ String scope,
+ String auth,
+ String serviceName )
+ {
+ super( resourceClass, description, scope, auth, null, null );
+ this.name = serviceName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getServiceName( )
+ {
+ return this.name;
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ConfigContext.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ConfigContext.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ConfigContext.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ConfigContext.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,327 @@
+/*=============================================================================*
+ * 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 java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/** LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class ConfigContext
+{
+ /**
+ * DOCUMENT_ME
+ */
+ protected Map subContexts = new HashMap( );
+
+ /**
+ * DOCUMENT_ME
+ */
+ protected Map environmentEntries = new HashMap( );
+
+ /**
+ * DOCUMENT_ME
+ */
+ protected Map resourceEntries = new HashMap( );
+
+ /**
+ * DOCUMENT_ME
+ */
+ protected Map resourceLinks = new HashMap( );
+
+ /**
+ * DOCUMENT_ME
+ */
+ protected String name = null;
+
+ /**
+ * DOCUMENT_ME
+ */
+ protected boolean global;
+
+ /**
+ * Creates a new {@link ConfigContext} object.
+ */
+ public ConfigContext( )
+ {
+ this( false );
+ }
+
+ /**
+ * Creates a new {@link ConfigContext} object.
+ *
+ * @param global DOCUMENT_ME
+ */
+ public ConfigContext( boolean global )
+ {
+ this.global = global;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Environment getEnvironment( String name )
+ {
+ return (Environment) this.environmentEntries.get( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Set getEnvironmentNames( )
+ {
+ return this.environmentEntries.keySet( );
+ }
+
+ /**
+ * @param global The global to set.
+ */
+ public void setGlobal( boolean global )
+ {
+ this.global = global;
+ }
+
+ /**
+ * @return Returns the global.
+ */
+ public boolean isGlobal( )
+ {
+ return this.global;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getName( )
+ {
+ return this.name;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Resource getResource( String name )
+ {
+ return (Resource) this.resourceEntries.get( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public ResourceLink getResourceLink( String name )
+ {
+ return (ResourceLink) this.resourceLinks.get( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Set getResourceLinkNames( )
+ {
+ return this.resourceLinks.keySet( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Set getResourceNames( )
+ {
+ return this.resourceEntries.keySet( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public ConfigContext getSubContext( String name )
+ {
+ return (ConfigContext) this.subContexts.get( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Set getSubContextNames( )
+ {
+ return this.subContexts.keySet( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param environment DOCUMENT_ME
+ */
+ public void addEnvironment( Environment environment )
+ {
+ this.environmentEntries.put( environment.getName( ),
+ environment );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param resource DOCUMENT_ME
+ */
+ public void addResource( Resource resource )
+ {
+ this.resourceEntries.put( resource.getName( ),
+ resource );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param link DOCUMENT_ME
+ */
+ public void addResourceLink( ResourceLink link )
+ {
+ this.resourceLinks.put( link.getName( ),
+ link );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param context DOCUMENT_ME
+ */
+ public void addSubContext( ConfigContext context )
+ {
+ this.subContexts.put( context.getName( ),
+ context );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void removeSubContext( String name )
+ {
+ this.subContexts.remove( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString( )
+ {
+ StringBuffer out = new StringBuffer( );
+ Set names;
+ Iterator nameIterator;
+
+ if ( global == true )
+ {
+ out.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" );
+ out.append( "<jndiConfig xmlns=\"http://wsrf.globus.org/jndi/config\">\r\n" );
+ out.append( " <global>\r\n" );
+ }
+ else
+ {
+ out.append( " <service name=\"" );
+ out.append( this.name );
+ out.append( "\">\r\n" );
+ }
+
+ names = this.getEnvironmentNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ out.append( ( (Environment) this.environmentEntries.get( nameIterator.next( ) ) ).toString( ) );
+ }
+
+ names = this.getResourceNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ out.append( ( (Resource) this.resourceEntries.get( nameIterator.next( ) ) ).toString( ) );
+ }
+
+ names = this.getResourceLinkNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ out.append( ( (ResourceLink) this.resourceLinks.get( nameIterator.next( ) ) ).toString( ) );
+ }
+
+ if ( global == true )
+ {
+ out.append( " </global>\r\n" );
+
+ //process sub contexts
+ names = this.getSubContextNames( );
+ nameIterator = names.iterator( );
+
+ while ( nameIterator.hasNext( ) )
+ {
+ out.append( ( (ConfigContext) this.subContexts.get( nameIterator.next( ) ) ).toString( ) );
+ }
+
+ out.append( "</jndiConfig>\r\n" );
+ }
+ else
+ {
+ out.append( " </service>\r\n" );
+ }
+
+ return out.toString( );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ContextRuleSet.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ContextRuleSet.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ContextRuleSet.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ContextRuleSet.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,72 @@
+/*=============================================================================*
+ * 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.digester.Digester;
+import org.apache.commons.digester.RuleSetBase;
+
+/** LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class ContextRuleSet
+ extends RuleSetBase
+{
+ /**
+ * DOCUMENT_ME
+ */
+ protected String prefix = null;
+
+ /**
+ * Creates a new {@link ContextRuleSet} object.
+ */
+ public ContextRuleSet( )
+ {
+ this( "" );
+ }
+
+ /**
+ * Creates a new {@link ContextRuleSet} object.
+ *
+ * @param prefix DOCUMENT_ME
+ */
+ public ContextRuleSet( String prefix )
+ {
+ super( );
+ this.prefix = prefix;
+ this.namespaceURI = "http://wsrf.globus.org/jndi/config";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.digester.RuleSet#addRuleInstances(org.apache.commons.digester.Digester)
+ */
+ public void addRuleInstances( Digester digester )
+ {
+ digester.addObjectCreate( prefix + "environment", Environment.class );
+ digester.addSetProperties( prefix + "environment" );
+ digester.addSetNext( prefix + "environment", "addEnvironment" );
+ digester.addObjectCreate( prefix + "resource", Resource.class );
+ digester.addSetProperties( prefix + "resource" );
+ digester.addSetNext( prefix + "resource", "addResource" );
+ digester.addRuleSet( new ParameterRuleSet( prefix + "resource/" ) );
+ digester.addObjectCreate( prefix + "resourceLink", ResourceLink.class );
+ digester.addSetProperties( prefix + "resourceLink" );
+ digester.addRuleSet( new ParameterRuleSet( prefix + "resourceLink/" ) );
+ digester.addSetNext( prefix + "resourceLink", "addResourceLink" );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Environment.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Environment.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Environment.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Environment.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,115 @@
+/*=============================================================================*
+ * 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;
+
+
+/** LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class Environment
+{
+ private String description = null;
+ private String name = null;
+ private String type = null;
+ private String value = null;
+
+ /**
+ * @param description The description to set.
+ */
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ /**
+ * @return Returns the description.
+ */
+ public String getDescription( )
+ {
+ return description;
+ }
+
+ /**
+ * @param name The name to set.
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName( )
+ {
+ return name;
+ }
+
+ /**
+ * @param type The type to set.
+ */
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ /**
+ * @return Returns the type.
+ */
+ public String getType( )
+ {
+ return type;
+ }
+
+ /**
+ * @param value The value to set.
+ */
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+
+ /**
+ * @return Returns the value.
+ */
+ public String getValue( )
+ {
+ return value;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString( )
+ {
+ StringBuffer out = new StringBuffer( );
+ out.append( " <environment name=\"" );
+ out.append( this.name );
+ out.append( "\" \r\n" );
+ out.append( " type=\"" );
+ out.append( this.type );
+ out.append( "\"\r\n" );
+ out.append( " value=\"" );
+ out.append( this.value );
+ out.append( "\"/>\r\n" );
+ return out.toString( );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JNDIConfigRuleSet.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JNDIConfigRuleSet.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JNDIConfigRuleSet.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JNDIConfigRuleSet.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,66 @@
+/*=============================================================================*
+ * 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.digester.Digester;
+import org.apache.commons.digester.RuleSetBase;
+
+/** LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class JNDIConfigRuleSet
+ extends RuleSetBase
+{
+ /**
+ * DOCUMENT_ME
+ */
+ protected String prefix = null;
+
+ /**
+ * Creates a new {@link JNDIConfigRuleSet} object.
+ */
+ public JNDIConfigRuleSet( )
+ {
+ this( "" );
+ }
+
+ /**
+ * Creates a new {@link JNDIConfigRuleSet} object.
+ *
+ * @param prefix DOCUMENT_ME
+ */
+ public JNDIConfigRuleSet( String prefix )
+ {
+ super( );
+ this.prefix = prefix;
+ this.namespaceURI = "http://wsrf.globus.org/jndi/config";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.digester.RuleSet#addRuleInstances(org.apache.commons.digester.Digester)
+ */
+ public void addRuleInstances( Digester digester )
+ {
+ digester.addRuleSet( new ContextRuleSet( prefix + "global/" ) );
+ digester.addObjectCreate( prefix + "service", ConfigContext.class );
+ digester.addSetProperties( prefix + "service" );
+ digester.addSetNext( prefix + "service", "addSubContext" );
+ digester.addRuleSet( new ContextRuleSet( prefix + "service/" ) );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JndiConfigUpdater.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JndiConfigUpdater.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JndiConfigUpdater.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/JndiConfigUpdater.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,232 @@
+/*=============================================================================*
+ * 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.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.wsfx.wsrf.jndi.config.JndiConfigDocument;
+import org.apache.wsfx.wsrf.jndi.config.ServiceDocument;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Sal Campana
+ */
+public class JndiConfigUpdater
+ extends MatchingTask
+{
+ /**
+ * Below default can be overridden by setting the below sysprop.
+ */
+ public static final String SYSPROP_JNDI_CONFIG = "wsdd";
+
+ /**
+ * Default to looking for jndi-config.xml in current dir or classpath.
+ */
+ private static final String DEFAULT_JNDI_CONFIG = "jndi-config.xml";
+ private String m_jndiConfig;
+ private List m_jndiConfigFiles = new ArrayList( );
+
+ /**
+ * Creates a new {@link JndiConfigUpdater} object.
+ */
+ public JndiConfigUpdater( )
+ {
+ this( (String) null );
+ }
+
+ /**
+ * Creates a new {@link JndiConfigUpdater} object for updating the specified WSDD file.
+ *
+ * @param jndiConfig DOCUMENT_ME
+ */
+ public JndiConfigUpdater( File jndiConfig )
+ {
+ this( jndiConfig.getPath( ) );
+ }
+
+ /**
+ * Creates a new {@link JndiConfigUpdater} object for updating the specified jndi-config.xml, which may be a a file path or a location in
+ * the classpath.
+ *
+ * @param jndiConfig DOCUMENT_ME
+ */
+ public JndiConfigUpdater( String jndiConfig )
+ {
+ initContextClassLoader( );
+ if ( jndiConfig != null )
+ {
+ m_jndiConfig = jndiConfig;
+ }
+ else
+ {
+ m_jndiConfig =
+ ( System.getProperty( SYSPROP_JNDI_CONFIG ) != null ) ? System.getProperty( SYSPROP_JNDI_CONFIG )
+ : DEFAULT_JNDI_CONFIG;
+ }
+ }
+
+ /**
+ * Sets the JndiConfig fragment to be added to the JNDIonfig file.
+ *
+ * @param deployJndiConfig the JNDIConfigfragment to be added to the JndiConfig file.
+ */
+ public void setDeployJndiConfig( File deployJndiConfig )
+ {
+ m_jndiConfigFiles.add( deployJndiConfig );
+ }
+
+ /**
+ * Sets the WSDD to be updated.
+ *
+ * @param jndiConfig the Jndi-config.xml to be updated
+ */
+ public void setJndiConfig( String jndiConfig )
+ {
+ m_jndiConfig = jndiConfig;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param jndiConfigPaths DOCUMENT_ME
+ */
+ public void addConfiguredJndiConfigPaths( FileSet jndiConfigPaths )
+ {
+ File baseDir = jndiConfigPaths.getDir( getProject( ) );
+ DirectoryScanner dirScanner = jndiConfigPaths.getDirectoryScanner( getProject( ) );
+ String[] includedFiles = dirScanner.getIncludedFiles( );
+ for ( int i = 0; i < includedFiles.length; i++ )
+ {
+ m_jndiConfigFiles.add( new File( baseDir, includedFiles[i] ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param deployJndiConfig DOCUMENT_ME
+ * @throws Exception DOCUMENT_ME
+ */
+ public void deploy( File deployJndiConfig )
+ throws Exception
+ {
+ setDeployJndiConfig( deployJndiConfig );
+ execute( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws BuildException DOCUMENT_ME
+ */
+ public void execute( )
+ throws BuildException
+ {
+ if ( m_jndiConfigFiles.isEmpty( ) )
+ {
+ throw new BuildException( "No deploy jndi-config's were specified!" );
+ }
+
+ try
+ {
+ for ( int i = 0; i < m_jndiConfigFiles.size( ); i++ )
+ {
+ deployJndiConfig( (File) m_jndiConfigFiles.get( i ) );
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new BuildException( e );
+ }
+ }
+
+ /**
+ * Command-line invocation entry point.
+ *
+ * @param args command-line arguments
+ * @throws Exception on fatal error
+ */
+ public static void main( String[] args )
+ throws Exception
+ {
+ //System.setProperty( SYSPROP_JNDI_CONFIG, "C:/jndi-config.xml" );
+ if ( args.length != 1 )
+ {
+ System.err.println( "Usage: " + JndiConfigUpdater.class.getName( ) + " deployJndiConfigFile" );
+ System.exit( 1 );
+ }
+
+ new JndiConfigUpdater( ).deploy( new File( args[0] ) );
+ }
+
+ private void deployJndiConfig( File deployJndiConfig )
+ throws Exception
+ {
+ log( "Deploying Jndi-Config " + deployJndiConfig + " to configuration Jndi-Config " + m_jndiConfig + "..." );
+ File jndiConfigFile = new File( m_jndiConfig );
+ JndiConfigDocument sourceConfig = JndiConfigDocument.Factory.parse( new File( m_jndiConfig ) );
+ JndiConfigDocument.JndiConfig jndiConfig = sourceConfig.getJndiConfig( );
+ Map services = new HashMap( );
+ ServiceDocument.Service[] serviceArray = jndiConfig.getServiceArray( );
+ for ( int i = 0; i < serviceArray.length; i++ )
+ {
+ ServiceDocument.Service service = serviceArray[i];
+ services.put( service.getName( ),
+ service );
+ }
+
+ for ( int i = 0; i < m_jndiConfigFiles.size( ); i++ )
+ {
+ File config = (File) m_jndiConfigFiles.get( i );
+ JndiConfigDocument newConfig = JndiConfigDocument.Factory.parse( config );
+ ServiceDocument.Service[] newServices = newConfig.getJndiConfig( ).getServiceArray( );
+ for ( int j = 0; j < newServices.length; j++ )
+ {
+ ServiceDocument.Service newService = newServices[j];
+ String name = newService.getName( );
+ if ( services.containsKey( name ) )
+ {
+ System.out.println( "The service named: " + name + " is being updated in the jndi-config file: "
+ + m_jndiConfig );
+ }
+
+ services.put( newService.getName( ),
+ newService );
+ }
+ }
+
+ ServiceDocument.Service[] updatedServiceArray =
+ (ServiceDocument.Service[]) services.values( ).toArray( new ServiceDocument.Service[0] );
+ jndiConfig.setServiceArray( updatedServiceArray );
+ sourceConfig.save( jndiConfigFile );
+ }
+
+ private void initContextClassLoader( )
+ {
+ // this is done because for some reason, when run using Maven,
+ // the ContextClassloader is null, which causes an issue with Axis.
+ if ( Thread.currentThread( ).getContextClassLoader( ) == null )
+ {
+ Thread.currentThread( ).setContextClassLoader( MatchingTask.class.getClassLoader( ) );
+ }
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfig.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,62 @@
+/*=============================================================================*
+ * 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.wsfx.wsrf.jndi.config.MetadataConfigDocument;
+import java.util.Map;
+
+/**
+ * @author Sal Campana
+ */
+public abstract class MetadataConfig
+{
+ /**
+ * Creates a new {@link MetadataConfig} object.
+ *
+ * @param metadata DOCUMENT_ME
+ */
+ public MetadataConfig( MetadataConfigDocument.MetadataConfig metadata )
+ {
+ //used to enforce constructor for reflection
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract Map getAllMetadata( );
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param dialect DOCUMENT_ME
+ * @param identifierUri DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract Map getMetadata( String dialect,
+ String identifierUri );
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param dialect DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract Map getMetadata( String dialect );
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/MetadataConfigImpl.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,337 @@
+/*=============================================================================*
+ * 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 {@link 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.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/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ParameterRuleSet.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ParameterRuleSet.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ParameterRuleSet.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/ParameterRuleSet.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,67 @@
+/*=============================================================================*
+ * 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.digester.Digester;
+import org.apache.commons.digester.RuleSetBase;
+
+/** LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class ParameterRuleSet
+ extends RuleSetBase
+{
+ /**
+ * DOCUMENT_ME
+ */
+ protected String prefix = null;
+
+ /**
+ * Creates a new {@link ParameterRuleSet} object.
+ */
+ public ParameterRuleSet( )
+ {
+ this( "" );
+ }
+
+ /**
+ * Creates a new {@link ParameterRuleSet} object.
+ *
+ * @param prefix DOCUMENT_ME
+ */
+ public ParameterRuleSet( String prefix )
+ {
+ super( );
+ this.prefix = prefix;
+ this.namespaceURI = "http://wsrf.globus.org/jndi/config";
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.digester.RuleSet#addRuleInstances(org.apache.commons.digester.Digester)
+ */
+ public void addRuleInstances( Digester digester )
+ {
+ digester.addObjectCreate( prefix + "resourceParams", ResourceParameters.class );
+ digester.addSetProperties( prefix + "resourceParams" );
+ digester.addSetNext( prefix + "resourceParams", "setParameters" );
+ digester.addCallMethod( prefix + "resourceParams/parameter", "addParameter", 2 );
+ digester.addCallParam( prefix + "resourceParams/parameter/name", 0 );
+ digester.addCallParam( prefix + "resourceParams/parameter/value", 1 );
+ }
+}
\ No newline at end of file
Added: webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Resource.java
URL: http://svn.apache.org/viewvc/webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Resource.java?rev=411218&view=auto
==============================================================================
--- webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Resource.java (added)
+++ webservices/muse/branches/1.0/src/java/org/apache/ws/util/jndi/tools/Resource.java Fri Jun 2 10:32:46 2006
@@ -0,0 +1,173 @@
+/*=============================================================================*
+ * 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;
+
+
+/** LOG-DONE
+ * DOCUMENT_ME
+ *
+ * @author $author$
+ * @version $Revision: 1.4 $
+ */
+public class Resource
+{
+ private String description = null;
+ private String name = null;
+ private String scope = null;
+ private String type = null;
+ private String auth = null;
+ private ResourceParameters parameters = null;
+
+ /**
+ * @param auth The auth to set.
+ */
+ public void setAuth( String auth )
+ {
+ this.auth = auth;
+ }
+
+ /**
+ * @return Returns the auth.
+ */
+ public String getAuth( )
+ {
+ return auth;
+ }
+
+ /**
+ * @param description The description to set.
+ */
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ /**
+ * @return Returns the description.
+ */
+ public String getDescription( )
+ {
+ return description;
+ }
+
+ /**
+ * @param name The name to set.
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName( )
+ {
+ return name;
+ }
+
+ /**
+ * @param parameters The parameters to set.
+ */
+ public void setParameters( ResourceParameters parameters )
+ {
+ this.parameters = parameters;
+ }
+
+ /**
+ * @return Returns the parameters.
+ */
+ public ResourceParameters getParameters( )
+ {
+ return parameters;
+ }
+
+ /**
+ * @param scope The scope to set.
+ */
+ public void setScope( String scope )
+ {
+ this.scope = scope;
+ }
+
+ /**
+ * @return Returns the scope.
+ */
+ public String getScope( )
+ {
+ return scope;
+ }
+
+ /**
+ * @param type The type to set.
+ */
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ /**
+ * @return Returns the type.
+ */
+ public String getType( )
+ {
+ return type;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString( )
+ {
+ StringBuffer out = new StringBuffer( );
+ out.append( " <resource name=\"" );
+ out.append( this.name );
+ out.append( "\" \r\n" );
+ out.append( " type=\"" );
+ out.append( this.type );
+ if ( this.scope != null )
+ {
+ out.append( "\"\r\n" );
+ out.append( " scope=\"" );
+ out.append( this.scope );
+ }
+
+ if ( this.auth != null )
+ {
+ out.append( "\"\r\n" );
+ out.append( " auth=\"" );
+ out.append( this.auth );
+ }
+
+ if ( this.description != null )
+ {
+ out.append( "\"\r\n" );
+ out.append( " auth=\"" );
+ out.append( this.description );
+ }
+
+ out.append( "\">\r\n" );
+ if ( this.parameters != null )
+ {
+ out.append( this.parameters.toString( ) );
+ }
+
+ out.append( " </resource>\r\n" );
+ return out.toString( );
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org