if ( this.launcher != null )
{
foreignClassLoader = this.launcher.getSystemClassLoader();
}
ClassRealm curRealm = null;
String line = null;
int lineNo = 0;
boolean mainSet = false;
while ( true )
{
line = reader.readLine();
if ( line == null )
{
break;
}
++lineNo;
line = line.trim();
if ( canIgnore( line ) )
{
continue;
}
if ( line.startsWith( MAIN_PREFIX ) )
{
if ( mainSet )
{
throw new ConfigurationException( "Duplicate main configuration", lineNo, line );
}
String conf = line.substring( MAIN_PREFIX.length() ).trim();
int fromLoc = conf.indexOf( "from" );
if ( fromLoc < 0 )
{
throw new ConfigurationException( "Missing from clause", lineNo, line );
}
String mainClassName = conf.substring( 0, fromLoc ).trim();
String mainRealmName = conf.substring( fromLoc + 4 ).trim();
if ( this.launcher != null )
{
this.launcher.setAppMain( mainClassName, mainRealmName );
}
mainSet = true;
}
else if ( line.startsWith( SET_PREFIX ) )
{
String conf = line.substring( SET_PREFIX.length() ).trim();
int usingLoc = conf.indexOf( " using" ) + 1;
String property = null;
String propertiesFileName = null;
if ( usingLoc > 0 )
{
property = conf.substring( 0, usingLoc ).trim();
propertiesFileName = filter( conf.substring( usingLoc + 5 ).trim() );
conf = propertiesFileName;
}
String defaultValue = null;
int defaultLoc = conf.indexOf( " default" ) + 1;
if ( defaultLoc > 0 )
{
defaultValue = conf.substring( defaultLoc + 7 ).trim();
if ( property == null )
{
property = conf.substring( 0, defaultLoc ).trim();
}
else
{
propertiesFileName = conf.substring( 0, defaultLoc ).trim();
}
}
String value = System.getProperty( property );
if ( value != null )
{
continue;
}
if ( propertiesFileName != null )
{
File propertiesFile = new File( propertiesFileName );
if ( propertiesFile.exists() )
{
Properties properties = new Properties();
try
{
properties.load( new FileInputStream( propertiesFileName ) );
value = properties.getProperty( property );
}
catch ( Exception e )
{
// do nothing
}
}
}
if ( value == null && defaultValue != null )
{
value = defaultValue;
}
if ( value != null )
{
value = filter( value );
System.setProperty( property, value );
}
}
else if ( line.startsWith( "[" ) )
{
int rbrack = line.indexOf( "]" );
if ( rbrack < 0 )
{
throw new ConfigurationException( "Invalid realm specifier", lineNo, line );
}
String realmName = line.substring( 1, rbrack );
curRealm = world.newRealm( realmName, foreignClassLoader );
// Stash the configured realm for subsequent association processing.
configuredRealms.put( realmName, curRealm );
}
else if ( line.startsWith( IMPORT_PREFIX ) )
{
if ( curRealm == null )
{
throw new ConfigurationException( "Unhandled import", lineNo, line );
}
String conf = line.substring( IMPORT_PREFIX.length() ).trim();
int fromLoc = conf.indexOf( "from" );
if ( fromLoc < 0 )
{
throw new ConfigurationException( "Missing from clause", lineNo, line );
}
String importSpec = conf.substring( 0, fromLoc ).trim();
String relamName = conf.substring( fromLoc + 4 ).trim();
curRealm.importFrom( relamName, importSpec );
}
else if ( line.startsWith( LOAD_PREFIX ) )
{
String constituent = line.substring( LOAD_PREFIX.length() ).trim();
constituent = filter( constituent );
if ( constituent.indexOf( "*" ) >= 0 )
{
loadGlob( constituent, curRealm );
}
else
{
File file = new File( constituent );
if ( file.exists() )
{
curRealm.addURL( file.toURI().toURL() );
}
else
{
try
{
curRealm.addURL( new URL( constituent ) );
}
catch ( MalformedURLException e )
{
throw new FileNotFoundException( constituent );
}
}
}
}
else if ( line.startsWith( OPTIONALLY_PREFIX ) )
{
String constituent = line.substring( OPTIONALLY_PREFIX.length() ).trim();
constituent = filter( constituent );
if ( constituent.indexOf( "*" ) >= 0 )
{
loadGlob( constituent, curRealm, true );
}
else
{
File file = new File( constituent );
if ( file.exists() )
{
curRealm.addURL( file.toURI().toURL() );
}
else
{
try
{
curRealm.addURL( new URL( constituent ) );
}
catch ( MalformedURLException e )
{
// swallow
}