improved creation of custom root object:
- definition of root class is moved from app.properties to class.properties file. - optional use of fields "root.factory.class" and "root.factory.method" in class.properties to retrieve an instance of the root object.
This commit is contained in:
parent
ca66d7ba90
commit
08f702bd40
1 changed files with 19 additions and 11 deletions
|
@ -191,6 +191,10 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
|
|
||||||
// the properties that map java class names to prototype names
|
// the properties that map java class names to prototype names
|
||||||
classMapping = new SystemProperties (new File (appDir, "class.properties").getAbsolutePath ());
|
classMapping = new SystemProperties (new File (appDir, "class.properties").getAbsolutePath ());
|
||||||
|
|
||||||
|
// get class name of root object if defined. Otherwise native Helma objectmodel will be used.
|
||||||
|
rootObjectClass = classMapping.getProperty ("root");
|
||||||
|
|
||||||
// the properties that map allowed public skin extensions to content types
|
// the properties that map allowed public skin extensions to content types
|
||||||
skinExtensions = new SystemProperties (new File (appDir, "mime.properties").getAbsolutePath ());
|
skinExtensions = new SystemProperties (new File (appDir, "mime.properties").getAbsolutePath ());
|
||||||
|
|
||||||
|
@ -200,8 +204,6 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
debug = "true".equalsIgnoreCase (props.getProperty ("debug"));
|
debug = "true".equalsIgnoreCase (props.getProperty ("debug"));
|
||||||
// checkSubnodes = !"false".equalsIgnoreCase (props.getProperty ("subnodeChecking"));
|
// checkSubnodes = !"false".equalsIgnoreCase (props.getProperty ("subnodeChecking"));
|
||||||
|
|
||||||
// get class name of root object if defined. Otherwise native Helma objectmodel will be used.
|
|
||||||
rootObjectClass = props.getProperty ("rootObject");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
requestTimeout = Long.parseLong (props.getProperty ("requestTimeout", "60"))*1000l;
|
requestTimeout = Long.parseLong (props.getProperty ("requestTimeout", "60"))*1000l;
|
||||||
|
@ -478,13 +480,19 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, IPat
|
||||||
// check if we ought to create a rootObject from its class name
|
// check if we ought to create a rootObject from its class name
|
||||||
if (rootObjectClass != null) {
|
if (rootObjectClass != null) {
|
||||||
// create custom root element.
|
// create custom root element.
|
||||||
// NOTE: This is but a very rough first sketch of an implementation
|
if (rootObject == null) {
|
||||||
// and needs much more care.
|
try {
|
||||||
if (rootObject == null) try {
|
if ( classMapping.containsKey("root.factory.class") && classMapping.containsKey("root.factory.method") ) {
|
||||||
Class c = Class.forName (rootObjectClass);
|
Class c = Class.forName( classMapping.getProperty("root.factory.class") );
|
||||||
rootObject = c.newInstance ();
|
Method m = c.getMethod( classMapping.getProperty("root.factory.method"), null );
|
||||||
} catch (Throwable x) {
|
rootObject = m.invoke(c,null);
|
||||||
System.err.println ("ERROR CREATING ROOT OBJECT: "+x);
|
} else {
|
||||||
|
Class c = Class.forName( classMapping.getProperty("root") );
|
||||||
|
rootObject = c.newInstance();
|
||||||
|
}
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
throw new RuntimeException ( "Error creating root object: " + e.toString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return rootObject;
|
return rootObject;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue