Search in sources :

Example 1 with NSProperties

use of com.webobjects.foundation.NSProperties in project wonder-slim by undur.

the class ERXLoader method bundleDidLoad.

/**
 * Will be called after each bundle load. We use it to know when the last
 * bundle loaded so we can post a notification for it. Note that the bundles
 * will get loaded in the order of the classpath but the main bundle will
 * get loaded last. So in order to set the properties correctly, we first
 * add all the props that are not already set, then we add the main bundle
 * and the WebObjects.properties and finally the command line props.
 */
public void bundleDidLoad(NSNotification n) {
    NSBundle bundle = (NSBundle) n.object();
    if (allFrameworks.contains(bundle.name())) {
        allFrameworks.remove(bundle.name());
        debugMsg("Loaded " + bundle.name() + ". Remaining: " + allFrameworks);
    } else if (bundle.isFramework()) {
        debugMsg("Loaded unexpected framework bundle '" + bundle.name() + "'. Ensure your build.properties settings like project.name match the bundle name (including case).");
    }
    if (allBundleProps == null) {
        allBundleProps = new Properties();
    }
    String userName = propertyFromCommandLineFirst("user.name");
    applyIfUnset(readProperties(bundle, "Properties." + userName));
    applyIfUnset(readProperties(bundle, null));
    if (allFrameworks.size() == 0) {
        mainProps = null;
        mainUserProps = null;
        collectMainProps(userName);
        allBundleProps.putAll(mainProps);
        if (mainUserProps != null) {
            allBundleProps.putAll(mainUserProps);
        }
        String userHome = propertyFromCommandLineFirst("user.home");
        Properties userHomeProps = null;
        if (userHome != null && userHome.length() > 0) {
            userHomeProps = readProperties(new File(userHome, "WebObjects.properties"));
        }
        if (userHomeProps != null) {
            allBundleProps.putAll(userHomeProps);
        }
        Properties props = NSProperties._getProperties();
        props.putAll(allBundleProps);
        NSProperties._setProperties(props);
        insertCommandLineArguments();
        if (userHomeProps != null) {
            urls.add(0, urls.remove(urls.size() - 1));
        }
        if (mainUserProps != null) {
            urls.add(0, urls.remove(urls.size() - 1));
        }
        urls.add(0, urls.remove(urls.size() - 1));
        // System.out.print(urls);
        NSNotificationCenter.defaultCenter().postNotification(new NSNotification(ERXApplication.AllBundlesLoadedNotification, NSKeyValueCoding.NullValue));
    }
}
Also used : NSBundle(com.webobjects.foundation.NSBundle) NSNotification(com.webobjects.foundation.NSNotification) NSProperties(com.webobjects.foundation.NSProperties) Properties(java.util.Properties) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

NSBundle (com.webobjects.foundation.NSBundle)1 NSNotification (com.webobjects.foundation.NSNotification)1 NSProperties (com.webobjects.foundation.NSProperties)1 File (java.io.File)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1