FileDocCategorySizeDatePackage
DataCollectorBase.javaAPI DocJava SE 5 API13350Fri Aug 26 14:54:28 BST 2005com.sun.corba.se.impl.orb

DataCollectorBase

public abstract class DataCollectorBase extends Object implements DataCollector

Fields Summary
private PropertyParser
parser
private Set
propertyNames
private Set
propertyPrefixes
private Set
URLPropertyNames
protected String
localHostName
protected String
configurationHostName
private boolean
setParserCalled
private Properties
originalProps
private Properties
resultProps
Constructors Summary
public DataCollectorBase(Properties props, String localHostName, String configurationHostName)

	// XXX This is fully initialized here.  So do we ever want to 
	// generalize this (or perhaps this is the wrong place for this?)
	URLPropertyNames = new HashSet() ;
	URLPropertyNames.add( ORBConstants.INITIAL_SERVICES_PROPERTY ) ;

	propertyNames = new HashSet() ;

	// Make sure that we are ready to handle -ORBInitRef.  This is special
	// due to the need to handle multiple -ORBInitRef args as prefix
	// parsing.
	propertyNames.add( ORBConstants.ORB_INIT_REF_PROPERTY ) ;

	propertyPrefixes = new HashSet() ;

	this.originalProps = props ;
	this.localHostName = localHostName ;
	this.configurationHostName = configurationHostName ;
	setParserCalled = false ;
	resultProps = new Properties() ;
    
Methods Summary
protected voidcheckPropertyDefaults()

        String host =
            resultProps.getProperty( ORBConstants.INITIAL_HOST_PROPERTY ) ;

        if ((host == null) || (host.equals(""))) 
            setProperty( ORBConstants.INITIAL_HOST_PROPERTY, 
		configurationHostName );

        String serverHost =
            resultProps.getProperty( ORBConstants.SERVER_HOST_PROPERTY ) ;

        if (serverHost == null || 
	    serverHost.equals("") ||
	    serverHost.equals("0.0.0.0") ||
	    serverHost.equals("::") ||
	    serverHost.toLowerCase().equals("::ffff:0.0.0.0"))
	{
            setProperty(ORBConstants.SERVER_HOST_PROPERTY,
			localHostName);
	    setProperty(ORBConstants.LISTEN_ON_ALL_INTERFACES,
			ORBConstants.LISTEN_ON_ALL_INTERFACES);
	}
    
private voidcheckSetParserCalled()

	if (!setParserCalled)
	    throw new IllegalStateException( "setParser not called." ) ;
    
protected abstract voidcollect()

private voiddoProperties(java.util.Properties props)

        PropertyCallback callback =  new PropertyCallback() {
	    public String get(String name) {
		return props.getProperty(name);
	    }
	} ;
	
	findPropertiesByName( propertyNames.iterator(), callback ) ;

        findPropertiesByPrefix( propertyPrefixes, 
	    makeIterator( props.propertyNames()), callback );
    
private java.lang.StringfindMatchingPropertyName(java.util.Set names, java.lang.String suffix)

	Iterator iter = names.iterator() ;
	while (iter.hasNext()) {
	    String name = (String)(iter.next()) ;
	    if (name.endsWith( suffix ))
		return name ;
	}

	return null ;
    
private voidfindPropertiesByName(java.util.Iterator names, com.sun.corba.se.impl.orb.PropertyCallback getProperty)

	while (names.hasNext()) {
	    String name = (String)(names.next()) ;
	    String value = getProperty.get( name ) ;
	    if (value != null)
		setProperty( name, value ) ;
	}
    
private voidfindPropertiesByPrefix(java.util.Set prefixes, java.util.Iterator propertyNames, com.sun.corba.se.impl.orb.PropertyCallback getProperty)

	while (propertyNames.hasNext()) {
	    String name = (String)(propertyNames.next()) ;
	    Iterator iter = prefixes.iterator() ;
	    while (iter.hasNext()) {
		String prefix = (String)(iter.next()) ;
		if (name.startsWith( prefix )) {
		    String value = getProperty.get( name ) ;

                    // Note: do a put even if value is null since just
                    // the presence of the property may be significant.
		    setProperty( name, value ) ;
		}
	    }
	}
    
protected voidfindPropertiesFromApplet(java.applet.Applet app)

        // Cannot use propertyPrefixes here, since there is no
	// way to fetch properties by prefix from an Applet.
        if (app == null)
            return;

        PropertyCallback callback = new PropertyCallback() {
	    public String get(String name) {
		return app.getParameter(name);
	    }
	} ;

	findPropertiesByName( propertyNames.iterator(), callback ) ;
    
        // Special Case:
        //
        // Convert any applet parameter relative URLs to an
        // absolute URL based on the Document Root. This is so HTML 
	// URLs can be kept relative which is sometimes useful for 
	// managing the Document Root layout.
	PropertyCallback URLCallback = new PropertyCallback() {
	    public String get( String name ) {
		String value = resultProps.getProperty(name);
		if (value == null)
		    return null ;

		try {
		    URL url = new URL( app.getDocumentBase(), value ) ;
		    return url.toExternalForm() ;
		} catch (java.net.MalformedURLException exc) {
		    // Just preserve the original (malformed) value:
		    // the error will be handled later.
		    return value ;
		}
	    }
	} ;

	findPropertiesByName( URLPropertyNames.iterator(), 
	    URLCallback ) ;
    
protected voidfindPropertiesFromArgs(java.lang.String[] params)

        if (params == null)
            return;

        // All command-line args are of the form "-ORBkey value".
        // The key is mapped to <prefix>.ORBkey.

        String name ;
        String value ;

        for ( int i=0; i<params.length; i++ ) {
            value = null ;
            name = null ;

            if ( params[i] != null && params[i].startsWith("-ORB") ) {
                String argName = params[i].substring( 1 ) ;
                name = findMatchingPropertyName( propertyNames, argName ) ;

                if (name != null)
                    if ( i+1 < params.length && params[i+1] != null ) {
                        value = params[++i];
                    }
            }

            if (value != null) {
		setProperty( name, value ) ;
            }
        }
    
protected voidfindPropertiesFromFile()

        final Properties fileProps = getFileProperties() ;
        if (fileProps==null)
            return ;

	doProperties( fileProps ) ;
    
protected voidfindPropertiesFromProperties()

        if (originalProps == null)
            return;

	doProperties( originalProps ) ;
    
protected voidfindPropertiesFromSystem()

	Set normalNames = getCORBAPrefixes( propertyNames ) ;
	Set prefixNames = getCORBAPrefixes( propertyPrefixes ) ;

	PropertyCallback callback = new PropertyCallback() {
	    public String get(String name) {
		return getSystemProperty(name);
	    }
	} ;

	findPropertiesByName( normalNames.iterator(), callback ) ;

        findPropertiesByPrefix( prefixNames,
	    getSystemPropertyNames(), callback ) ;
    
private java.util.SetgetCORBAPrefixes(java.util.Set prefixes)

	Set result = new HashSet() ;
	Iterator iter = prefixes.iterator() ;
	while (iter.hasNext()) {
	    String element = (String)(iter.next()) ;
	    if (hasCORBAPrefix( element )) 
		result.add( element ) ;
	}

	return result ;
    
private java.util.PropertiesgetFileProperties()

        Properties defaults = new Properties() ;

	String javaHome = getSystemProperty( "java.home" ) ;
	String fileName = javaHome + File.separator + "lib" + File.separator +
	    "orb.properties" ;

	getPropertiesFromFile( defaults, fileName ) ;

	Properties results = new Properties( defaults ) ;

        String userHome = getSystemProperty( "user.home" ) ;
        fileName = userHome + File.separator + "orb.properties" ;

	getPropertiesFromFile( results, fileName ) ;
	return results ;
    
public java.util.PropertiesgetProperties()

	checkSetParserCalled() ;
	return resultProps ;
    
private voidgetPropertiesFromFile(java.util.Properties props, java.lang.String fileName)

        try {
	    File file = new File( fileName ) ;
	    if (!file.exists())
		return ;

            FileInputStream in = new FileInputStream( file ) ;
	    
	    try {
		props.load( in ) ;
	    } finally {
		in.close() ;
	    }
        } catch (Exception exc) {
            // if (ORBInitDebug)
                // dprint( "ORB properties file " + fileName + " not found: " + 
		    // exc) ;
        }
    
private static java.lang.StringgetSystemProperty(java.lang.String name)

        return (String)AccessController.doPrivileged(
	    new GetPropertyAction(name));
    
private static java.util.IteratorgetSystemPropertyNames()

        // This will not throw a SecurityException because this
        // class was loaded from rt.jar using the bootstrap classloader.
        Enumeration enumeration = (Enumeration)
            AccessController.doPrivileged(
                new PrivilegedAction() {
                      public java.lang.Object run() {
                          return System.getProperties().propertyNames();
                      }
                }
	    );

	return makeIterator( enumeration ) ;
    
private booleanhasCORBAPrefix(java.lang.String prefix)

	return prefix.startsWith( ORBConstants.ORG_OMG_PREFIX ) ||
	    prefix.startsWith( ORBConstants.SUN_PREFIX ) ||
	    prefix.startsWith( ORBConstants.SUN_LC_PREFIX ) ||
	    prefix.startsWith( ORBConstants.SUN_LC_VERSION_PREFIX ) ;
    
public booleaninitialHostIsLocal()

	checkSetParserCalled() ;
	return localHostName.equals( resultProps.getProperty( 
	    ORBConstants.INITIAL_HOST_PROPERTY ) ) ;
    
public abstract booleanisApplet()

private static java.util.IteratormakeIterator(java.util.Enumeration enumeration)

	return new Iterator() {
	    public boolean hasNext() { return enumeration.hasMoreElements() ; }
	    public Object next() { return enumeration.nextElement() ; }
	    public void remove() { throw new UnsupportedOperationException() ; }
	} ;
    
public voidsetParser(com.sun.corba.se.spi.orb.PropertyParser parser)

	Iterator iter = parser.iterator() ;
	while (iter.hasNext()) {
	    ParserAction pa = (ParserAction)(iter.next()) ;
	    if (pa.isPrefix())
		propertyPrefixes.add( pa.getPropertyName() ) ;
	    else
		propertyNames.add( pa.getPropertyName() ) ;
	}

	collect() ;
	setParserCalled = true ;
    
private voidsetProperty(java.lang.String name, java.lang.String value)

	if( name.equals( ORBConstants.ORB_INIT_REF_PROPERTY ) ) {
	    // Value is <name>=<URL>
	    StringTokenizer st = new StringTokenizer( value, "=" ) ;
	    if (st.countTokens() != 2)
		throw new IllegalArgumentException() ;

	    String refName = st.nextToken() ;
	    String refValue = st.nextToken() ;

	    resultProps.setProperty( name + "." + refName, refValue ) ;
	} else {
	    resultProps.setProperty( name, value ) ;
	}