public abstract class ERXFrameworkPrincipal extends Object
Allows you to disregard your framework order in the class path (at least where startup is concerned, if you override actual classes you still need to take care.)
The initialize()
method will be called directly after your principal
is instantiated.
The finishInitialization()
method will be called when the app finishes
startup but before it will begin to process requests.
If you define
public static Class[] REQUIRES = Class[] {...}
all the classes (which must be assignable from this class) will get
loaded before your principal.
NOTE: try to avoid putting code in static initializers. These may lead to unpredictable behaviour when launching. Use one of the methods above to do what you need to do.
Here is an example:
public class ExampleFrameworkPrincipal extends ERXFrameworkPrincipal {
public static final Logger log = Logger.getLogger(ExampleFrameworkPrincipal.class);
protected static ExampleFrameworkPrincipal sharedInstance;
public final static Class REQUIRES[] = new Class[] {ERXExtensions.class, ERDirectToWeb.class, ERJavaMail.class};
// Registers the class as the framework principal
static {
setUpFrameworkPrincipalClass(ExampleFrameworkPrincipal.class);
}
public static ExampleFrameworkPrincipal sharedInstance() {
if (sharedInstance == null) {
sharedInstance = (ExampleFrameworkPrincipal)sharedInstance(ExampleFrameworkPrincipal.class);
}
return sharedInstance;
}
public void initialize() {
// code during startup
}
public void finishInitialization() {
// Initialized shared data
}
}
Finally, you also need to add an entry to your framework build.properties file to set the principal class:
principalClass = com.sample.ExampleFrameworkPrincipal
Modifier and Type | Class and Description |
---|---|
static class |
ERXFrameworkPrincipal.Observer |
Modifier and Type | Field and Description |
---|---|
protected static NSMutableDictionary<String,ERXFrameworkPrincipal> |
initializedFrameworks
holds the mapping between framework principals classes and ERXFrameworkPrincipal objects
|
protected static NSMutableArray<ERXFrameworkPrincipal> |
launchingFrameworks |
protected org.apache.log4j.Logger |
log
logging support
|
Constructor and Description |
---|
ERXFrameworkPrincipal() |
Modifier and Type | Method and Description |
---|---|
void |
didFinishInitialization()
Overridden by subclasses to finalize framework initialization.
|
abstract void |
finishInitialization()
Overridden by subclasses to provide framework initialization.
|
static boolean |
hasFrameworkInstalled(String frameworkName)
指定フレームワークがインストールされているかどうかを確認します。
|
protected void |
initialize()
Called directly after the constructor.
|
static void |
setUpFrameworkPrincipalClass(Class c)
Sets up a given framework principal class to receive notification
when it is safe for the framework to be initialized.
|
static <T extends ERXFrameworkPrincipal> |
sharedInstance(Class<T> c)
Gets the shared framework principal instance for a given
class.
|
String |
toString() |
protected final org.apache.log4j.Logger log
protected static final NSMutableDictionary<String,ERXFrameworkPrincipal> initializedFrameworks
protected static final NSMutableArray<ERXFrameworkPrincipal> launchingFrameworks
public static <T extends ERXFrameworkPrincipal> T sharedInstance(Class<T> c)
c
- principal class for a given frameworkpublic static void setUpFrameworkPrincipalClass(Class c)
c
- principal classprotected void initialize()
public abstract void finishInitialization()
public void didFinishInitialization()
public static boolean hasFrameworkInstalled(String frameworkName)
Copyright © 2002 – 2024 Project Wonder.