FileDocCategorySizeDatePackage
AxisProperties.javaAPI DocApache Axis 1.413109Sat Apr 22 18:57:28 BST 2006org.apache.axis

AxisProperties

public class AxisProperties extends Object

Configuration properties for AXIS.

Manage configuration properties according to a secure scheme similar to that used by classloaders:

  • ClassLoaders are organized in a tree hierarchy.
  • each ClassLoader has a reference to a parent ClassLoader.
  • the root of the tree is the bootstrap ClassLoaderer.
  • the youngest decendent is the thread context class loader.
  • properties are bound to a ClassLoader instance
    • non-default properties bound to a parent ClassLoader instance take precedence over all properties of the same name bound to any decendent. Just to confuse the issue, this is the default case.
    • default properties bound to a parent ClassLoader instance may be overriden by (default or non-default) properties of the same name bound to any decendent.
  • System properties take precedence over all other properties

author
Richard A. Sitze

Fields Summary
protected static Log
log
The Log for all interesting events in this class.
private static org.apache.commons.discovery.resource.names.DiscoverNamesInAlternateManagedProperties
altNameDiscoverer
private static org.apache.commons.discovery.resource.names.DiscoverMappedNames
mappedNames
private static org.apache.commons.discovery.resource.names.NameDiscoverers
nameDiscoverer
private static org.apache.commons.discovery.resource.ClassLoaders
loaders
Constructors Summary
Methods Summary
private static synchronized org.apache.commons.discovery.resource.names.DiscoverNamesInAlternateManagedPropertiesgetAlternatePropertyNameDiscoverer()

        if (altNameDiscoverer == null) {
            altNameDiscoverer = new DiscoverNamesInAlternateManagedProperties();
        }

        return altNameDiscoverer;
    
private static synchronized org.apache.commons.discovery.resource.ClassLoadersgetClassLoaders()

        if (loaders == null) {
            loaders = ClassLoaders.getAppLoaders(AxisProperties.class, null, true);
        }
        return loaders;
    
private static synchronized org.apache.commons.discovery.resource.names.DiscoverMappedNamesgetMappedNames()

        if (mappedNames == null) {
            mappedNames = new DiscoverMappedNames();
        }
        return mappedNames;
    
public static synchronized org.apache.commons.discovery.ResourceNameDiscovergetNameDiscoverer()

        if (nameDiscoverer == null) {
            nameDiscoverer = new NameDiscoverers();
            nameDiscoverer.addResourceNameDiscover(getAlternatePropertyNameDiscoverer());
            nameDiscoverer.addResourceNameDiscover(new DiscoverNamesInManagedProperties());
            nameDiscoverer.addResourceNameDiscover(new DiscoverServiceNames(getClassLoaders()));
            nameDiscoverer.addResourceNameDiscover(getMappedNames());
        }
        return nameDiscoverer;
    
public static java.util.PropertiesgetProperties()
This is an expensive operation.

return
Returns a java.util.Properties instance that is equivalent to the current state of the scoped properties, in that getProperty() will return the same value. However, this is a copy, so setProperty on the returned value will not effect the scoped properties.

        return ManagedProperties.getProperties();
    
public static java.lang.StringgetProperty(java.lang.String propertyName)
Get value for property bound to the current thread context class loader.

param
propertyName property name.
return
property value if found, otherwise default.

        return ManagedProperties.getProperty(propertyName);
    
public static java.lang.StringgetProperty(java.lang.String propertyName, java.lang.String dephault)
Get value for property bound to the current thread context class loader. If not found, then return default.

param
propertyName property name.
param
dephault default value.
return
property value if found, otherwise default.

        return ManagedProperties.getProperty(propertyName, dephault);
    
public static org.apache.commons.discovery.ResourceClassIteratorgetResourceClassIterator(java.lang.Class spi)

        ResourceNameIterator it = getNameDiscoverer().findResourceNames(spi.getName());
        return new DiscoverClasses(loaders).findResourceClasses(it);
    
public static java.lang.ObjectnewInstance(java.lang.Class spiClass, java.lang.Class[] constructorParamTypes, java.lang.Object[] constructorParams)

        return AccessController.doPrivileged(
            new PrivilegedAction() {
                public Object run() {
                    ResourceClassIterator services = getResourceClassIterator(spiClass);

                    Object obj = null;
                    while (obj == null  &&  services.hasNext()) {
                        Class service = services.nextResourceClass().loadClass();

                        /* service == null
                         * if class resource wasn't loadable
                         */
                        if (service != null) {
                            /* OK, class loaded.. attempt to instantiate it.
                             */
                            try {
                                ClassUtils.verifyAncestory(spiClass, service);
                                obj = ClassUtils.newInstance(service, constructorParamTypes, constructorParams);
                            } catch (InvocationTargetException e) {
                                if (e.getTargetException() instanceof java.lang.NoClassDefFoundError) {
                                    log.debug(Messages.getMessage("exception00"), e);
                                } else {
                                    log.warn(Messages.getMessage("exception00"), e);
                                }
                            } catch (Exception e) {
                                log.warn(Messages.getMessage("exception00"), e);
                            }
                        }
                    }

                    return obj;
                }
            });
    
public static java.lang.ObjectnewInstance(java.lang.Class spiClass, java.lang.Class defaultClass)

        return newInstance(new SPInterface(spiClass), new DefaultClassHolder(defaultClass));
    
private static java.lang.ObjectnewInstance(org.apache.commons.discovery.tools.SPInterface spi, org.apache.commons.discovery.tools.DefaultClassHolder defaultClass)
!WARNING! SECURITY issue. See bug 11874 The solution to both is to move doPrivilege UP within AXIS to a class that is either private (cannot be reached by code outside AXIS) or that represents a secure public interface... This is going to require analysis and (probably) rearchitecting. So, I'm taking taking the easy way out until we are at a point where we can reasonably rearchitect for security.

        return AccessController.doPrivileged(
            new PrivilegedAction() {
                public Object run() {
                    try {
                        return DiscoverClass.newInstance(null,
                                                         spi,
                                                         (PropertiesHolder)null,
                                                         defaultClass);
                    } catch (Exception e) {
                        log.error(Messages.getMessage("exception00"), e);
                    }
                    return null;
                }
            });
    
public static java.lang.ObjectnewInstance(java.lang.Class spiClass)
Create a new instance of a service provider class. !WARNING! SECURITY issue. See bug 11874 The solution to both is to move doPrivilege UP within AXIS to a class that is either private (cannot be reached by code outside AXIS) or that represents a secure public interface... This is going to require analysis and (probably) rearchitecting. So, I'm taking taking the easy way out until we are at a point where we can reasonably rearchitect for security.

param
spiClass the service provider class to instantiate
return
a new instance of this class

        return newInstance(spiClass, null, null);
    
public static java.util.EnumerationpropertyNames()

        return ManagedProperties.propertyNames();
    
public static voidsetClassDefault(java.lang.Class clazz, java.lang.String defaultName)

        getMappedNames().map(clazz.getName(), defaultName);
    
public static voidsetClassDefaults(java.lang.Class clazz, java.lang.String[] defaultNames)

        getMappedNames().map(clazz.getName(), defaultNames);
    
public static voidsetClassOverrideProperty(java.lang.Class clazz, java.lang.String propertyName)


           
        getAlternatePropertyNameDiscoverer()
            .addClassToPropertyNameMapping(clazz.getName(), propertyName);
    
public static voidsetProperties(java.util.Map newProperties)
Set property values for Properties bound to the current thread context class loader.

param
newProperties name/value pairs to be bound

        ManagedProperties.setProperties(newProperties);
    
public static voidsetProperties(java.util.Map newProperties, boolean isDefault)
Set property values for Properties bound to the current thread context class loader.

param
newProperties name/value pairs to be bound
param
isDefault determines if properties are default or not. A non-default property cannot be overriden. A default property can be overriden by a property (default or non-default) of the same name bound to a decendent class loader.

        ManagedProperties.setProperties(newProperties, isDefault);
    
public static voidsetProperty(java.lang.String propertyName, java.lang.String value)
Set value for property bound to the current thread context class loader.

param
propertyName property name
param
value property value (non-default) If null, remove the property.

        ManagedProperties.setProperty(propertyName, value);
    
public static voidsetProperty(java.lang.String propertyName, java.lang.String value, boolean isDefault)
Set value for property bound to the current thread context class loader.

param
propertyName property name
param
value property value. If null, remove the property.
param
isDefault determines if property is default or not. A non-default property cannot be overriden. A default property can be overriden by a property (default or non-default) of the same name bound to a decendent class loader.

        ManagedProperties.setProperty(propertyName, value, isDefault);