mcconnell 02/02/04 02:21:21
Added: apps/enterprise/orb/src/java/org/apache/orb
DefaultFactory.java DefaultFactory.xinfo
FactoryService.java Properties.java
Removed: apps/enterprise/orb/src/java/org/apache/orb
ORBConfigurationHelper.java ORBServer.java
ORBServer.xinfo ORBService.java
Log:
inital implementation of the 1.1 proposal
Revision Changes Path
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/DefaultFactory.java
Index: DefaultFactory.java
===================================================================
/**
* File: ORBServer.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights
reserved.
* Copyright: OSM SARL 2001-2002, All Rights Reserved.
*/
package org.apache.orb;
import java.io.File;
import java.net.URL;
import java.io.File;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockContext;
import org.omg.CORBA_2_3.ORB;
/**
* The <code>DefaultFactory</code> class is an Component that provides
support for the
* creation of an new ORB instance.
*
* <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
* <tr bgcolor="#ccccff">
* <td colspan="2"><b><code>ORBServer</code>Lifecycle Phases</b></td>
* <tr><td width="20%"></td><td><b>Description</b></td></tr>
* <tr>
* <td width="20%"><b>Contextualizable</b></td>
* <td>
* The <code>Context</code> value passed to the <code>ORBFactory</code>
during this phase
* provides the runtime execution context including the root application
directory.</td></tr>
* <tr>
* <td width="20%"><b>Configurable</b></td>
* <td>
* The configuration phase handles the internalization of a static
configuration data
* including ORB bootstrap properties.
* </td></tr>
* <tr><td width="20%"><b>Initalizable</b></td>
* <td>
* Signals completion of the Contextualization and Configuration phases.
* </td></tr>
* <tr><td width="20%"><b>Disposable</b></td>
* <td>
* Local cleanup of state memebers.
* </td></tr>
* </table>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
*/
public class DefaultFactory extends AbstractLogEnabled
implements Block, Contextualizable, Configurable, Initializable, Disposable,
FactoryService
{
//=================================================================
// static
//=================================================================
/**
* The default ORB class.
*/
public static final String DEFAULT_ORB_CLASS = "org.openorb.CORBA.ORB";
/**
* The default ORB Singleton class.
*/
public static final String DEFAULT_ORB_SINGLETON =
"org.openorb.CORBA.ORBSingleton";
//=================================================================
// state
//=================================================================
/**
* The static configuration for the factory.
*/
private Configuration m_configuration;
/**
* Runtime context supplied to the factory.
*/
private Context m_context;
/**
* Base directory from where default property statements containing
* file values are resolved.
*/
private File m_root;
/**
* Factory context.
*/
private Properties m_defaults;
//=================================================================
// Contextualizable
//=================================================================
public void contextualize( Context context ) throws ContextException
{
this.m_context = context;
if( context instanceof BlockContext )
{
m_root = ((BlockContext)context).getBaseDirectory();
}
}
//==========================================================================
// Configurable
//==========================================================================
/**
* Configuration of the runtime environment based on a supplied
Configuration arguments
* which contains the general arguments for ORB initalization, PSS
subsystem initialization,
* PSDL type to class mappings, preferences and debug information.
*
* @param config Configuration representing an internalized model of the
assembly.xml file.
* @exception ConfigurationException if the supplied configuration is
incomplete or badly formed.
*/
public void configure( final Configuration config )
throws ConfigurationException
{
this.m_configuration = config;
}
//=================================================================
// Initializable
//=================================================================
/**
* Initialization is invoked by the framework following configuration,
* following which the factory can support ORB creation.
*/
public void initialize()
throws Exception
{
// Create the default Properties instance.
try
{
m_defaults = createFactoryContext( m_context, m_configuration,
m_root );
}
catch (Exception e)
{
final String error = "Failed to establish ORB properties in ";
throw new ConfigurationException( error +
m_root.getAbsolutePath(), e);
}
}
//=================================================================
// ORBService
//=================================================================
/**
* Creation of a new ORB instance based on the supplied properties.
* @param props initialization properties
*/
public ORB createORB( java.util.Properties properties )
{
final String pre = "ORB creation";
if( getLogger().isDebugEnabled() ) getLogger().debug( pre );
try
{
return (ORB) ORB.init(
new String[0], new org.apache.orb.Properties( properties,
m_defaults )
);
}
catch ( Throwable e )
{
final String error = "ORB initialization failure.";
throw new CascadingRuntimeException( error, e );
}
}
//=================================================================
// Disposable
//=================================================================
/**
* Disposal of this component.
*/
public void dispose()
{
m_configuration = null;
m_context = null;
m_root = null;
m_defaults = null;
}
//=================================================================
// internal
//=================================================================
/**
* Return a Context instance based on the ORB class and singleton
delcarations
* together with containing property declarations. The context instance
is
* returned in a form suitable for passing to an ORB.init() method as a
* <code>java.util.Properties</code> instance.
*/
protected Properties createFactoryContext(
Context parent, Configuration configuration, File root ) throws
Exception
{
Properties p = new Properties( parent );
String orbClass =
configuration.getAttribute("org.omg.CORBA.ORBClass", DEFAULT_ORB_CLASS );
String orbSingleton =
configuration.getAttribute("org.omg.CORBA.ORBSingletonClass",
DEFAULT_ORB_SINGLETON );
p.setProperty("org.omg.CORBA.ORBClass", orbClass );
p.setProperty("org.omg.CORBA.ORBSingletonClass", orbSingleton );
//
// resolve any ORB specific properties
//
Configuration[] props = configuration.getChildren("property");
for( int i = 0; i< props.length; i++ )
{
Configuration child = props[i];
//
// every property must have a name
//
String name = "";
try
{
name = child.getAttribute("name");
}
catch( ConfigurationException noName )
{
final String error = "encountered a property without a
name";
throw new Exception ( error, noName );
}
//
// The value of a property is either declared directly under a
value attribute,
// or indirectory under a 'file' attribute. In the case of
'file' attributes
// we need to resolve this relative to this file before setting
the
// property value.
//
String value = "";
try
{
value = child.getAttribute("value");
}
catch( ConfigurationException noValueAttribute )
{
try
{
final String s = child.getAttribute("file");
File f = new File( root, s );
value = f.getAbsolutePath();
}
catch( ConfigurationException noFileAttribute )
{
String s = null;
try
{
s = child.getAttribute("url");
}
catch( Exception noURL )
{
final String error = "Found a property without
a 'value', 'file' or 'url' attribute";
throw new Exception( error, noURL );
}
if( s.startsWith("file:"))
{
try
{
URL base = root.toURL();
URL url = new URL( base, s );
value = url.toString();
}
catch( Exception unknown )
{
final String error = "Unexpected exception
while creating file:// URL value.";
throw new Exception( error, unknown );
}
}
else
{
try
{
URL url = new URL( s );
value = url.toString();
}
catch( Exception unknown )
{
final String error = "Unexpected exception
while creating URL value.";
throw new Exception( error
+ "\n" + "cause: " +
unknown.getClass().getName() + ", "
+ "\n" + unknown.getMessage(), unknown
);
}
}
}
}
p.setProperty( name, value );
}
return p;
}
}
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/DefaultFactory.xinfo
Index: DefaultFactory.xinfo
===================================================================
<?xml version="1.0"?>
<!--
File: DefaultFactory.xinfo
License: etc/LICENSE.TXT
Copyright: Copyright (C) The Apache Software Foundation. All rights reserved.
Copyright: OSM SARL 2001-2002, All Rights Reserved.
@author Stephen McConnell
@version 1.0 12/03/2001
-->
<blockinfo>
<block>
<version>1.0</version>
</block>
<!--
services that are offered by this block
-->
<services>
<service name="org.apache.orb.FactoryService" version="1.0" />
</services>
</blockinfo>
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/FactoryService.java
Index: FactoryService.java
===================================================================
/**
* File: FactoryService.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights
reserved.
* Copyright: OSM SARL 2001-2002, All Rights Reserved.
*/
package org.apache.orb;
import java.util.Properties;
import org.apache.avalon.framework.component.Component;
import org.omg.CORBA_2_3.ORB;
/**
* The FactoryService is an interface facilitating access to
* an ORB factory.
*
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
public interface FactoryService extends Component
{
/**
* Returns a ORB based on the supplied context.
* @return ORB a portable CORBA Object Request Broker (ORB)
*/
public ORB createORB( Properties properties );
}
1.1
jakarta-avalon-cornerstone/apps/enterprise/orb/src/java/org/apache/orb/Properties.java
Index: Properties.java
===================================================================
/**
* File: ORBContext.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights
reserved.
* Copyright: OSM SARL 2001-2002, All Rights Reserved.
*/
package org.apache.orb;
import java.util.Map;
import java.io.InputStream;
import java.io.IOException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
/**
* The ORBContext is an interface facilitating access to the runtime ORB. The
* ORB instance exposed by the <code>getOrb</code> operation is an ORB
supporting
* the CORBA 2.3 portability specification.
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
public class Properties extends java.util.Properties implements Context
{
private final Context m_parent;
private boolean m_readOnly = false;
/**
* Properties constructor.
*/
public Properties()
{
super();
m_parent = null;
}
/**
* Create a Properties context with specified default properties.
*
* @param defaults the default property values
*/
public Properties( final java.util.Properties defaults )
{
super( defaults );
m_parent = null;
}
/**
* Create a Context with specified data and parent.
*
* @param data the context data
* @param parent the parent Context (may be null)
*/
public Properties( final java.util.Properties data, final Context parent )
{
super( data );
m_parent = parent;
}
/**
* Create a Context with specified parent.
*
* @param parent the parent Context (may be null)
*/
public Properties( final Context parent )
{
super();
m_parent = parent;
}
/**
* Retrieve an item from the Context.
*
* @param key the key of item
* @return the item stored in context
* @exception ContextException if item not present
*/
public Object get( final Object key )
{
final Object data = super.get( key );
if( null != data ) return data;
// check the parent
if( null == m_parent ) return null;
try
{
return m_parent.get( key );
}
catch( Exception e )
{
return null;
}
}
/**
* Helper method fo adding items to Context.
*
* @param key the items key
* @param value the item
* @exception IllegalStateException if context is read only
*/
public Object put( final Object key, final Object value )
throws IllegalStateException
{
checkWriteable();
return put( key, value );
}
/**
* Make the context read-only.
* Any attempt to write to the context via put()
* will result in an IllegalStateException.
*/
public void makeReadOnly()
{
m_readOnly = true;
}
/**
* Utility method to check if context is writeable and if not throw
exception.
*
* @exception IllegalStateException if context is read only
*/
protected final void checkWriteable()
throws IllegalStateException
{
if( m_readOnly )
{
throw new IllegalStateException( "Context is read only and can
not be modified" );
}
}
//
// override properties operations
//
public void load(InputStream input ) throws IOException
{
checkWriteable();
super.load( input );
}
public synchronized Object setProperty(String key, String value) {
checkWriteable();
return super.put(key, value);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>