net.wotonomy.foundation
Class NSBundle

java.lang.Object
  extended by net.wotonomy.foundation.NSBundle

public class NSBundle
extends java.lang.Object

An implementation of NSBundle. Unlike the standard WebObjects NSBundle, this implementation loads bundles dynamically. This means that all bundles do not need to exist in the classpath at startup time. Practically, this means that NSBundle has a custom classloader. This behaviour is not supported in Apple's WebObjects, and should be used only if compatibility is not desired. It is largely intended for internal use within this framework, but is exposed through bundleForURL() Another difference between Wotonomy's NSBundle and Apple's implementation is the ability to initialize the application with a custom resource lookup "path".

Version:
$Revision: 892 $
Author:
cgruber@israfil.net, $Author: cgruber $

Field Summary
protected static NetworkClassLoader _classLoader
           
static java.lang.String BundleDidLoadNotification
           
protected  NSMutableArray classNames
           
protected  NSMutableDictionary info
           
protected  boolean isFramework
           
protected  boolean loaded
           
static java.lang.String LoadedClassesNotification
           
protected  java.lang.String name
           
protected  NSMutableArray packages
           
protected  java.lang.String path
           
protected  java.lang.Class principalClass
           
protected  java.util.Properties properties
           
 
Constructor Summary
NSBundle()
          The default constructor, which is only public to support other framework functionality, and to be API compatible with Apple's WebObjects.
 
Method Summary
static NSArray allBundles()
          Deprecated. use mainBundle() to access the application bundle and frameworkBundles() to access any frameworks.
static NSArray allFrameworks()
          Deprecated. use frameworkBundles() to access any frameworks.
 NSArray bundleClassNames()
           
 NSArray bundleClassPackageNames()
          TODO: figure out what this does.
static NSBundle bundleForClass(java.lang.Class class1)
          Returns the bundle that contains the provided class, if any.
static NSBundle bundleForName(java.lang.String name)
          This method returns a bundle, either from cache, or if it doesn't exist yet, it attempts to look it up - first from the classpath, then from the resource path.
 java.lang.String bundlePath()
           
static NSBundle bundleWithPath(java.lang.String path)
          Deprecated. Apple's WebObjects says you should not load from arbitrary path.
static NSBundle bundleWithURL(java.net.URL url)
          Note:This method is only in Wotonomy.
 byte[] bytesForResourcePath(java.lang.String path)
          Returns a byte array for the given resource path.
protected static java.lang.String defaultLocalePrefix()
          Get the default prefix for locale.
protected static NSBundle findOrCreateBundleWithPath(java.lang.String s)
           
static NSArray frameworkBundles()
           
 NSDictionary infoDictionary()
           
 java.io.InputStream inputStreamForResourcePath(java.lang.String path)
          Returns an input stream for a given resource path.
 boolean isFramework()
           
 boolean load()
           
static NSBundle mainBundle()
           
 java.lang.String name()
           
 java.lang.String pathForResource(java.lang.String aName, java.lang.String anExtension)
          Deprecated. Don't use this method, use resourcePathForLocalizedResourceNamed() instead.
 java.lang.String pathForResource(java.lang.String aName, java.lang.String anExtension, java.lang.String subDir)
          Deprecated. Don't use this method, use resourcePathForLocalizedResourceNamed() instead.
 NSArray pathsForResources(java.lang.String aName, java.lang.String anExtension)
          Deprecated. Don't use this method, use resourcePathsForResources() instead.
 java.lang.Class principalClass()
           
 java.util.Properties properties()
           
 java.lang.String resourcePath()
          Deprecated. Resources are now accessed using the bytesForResourcePath() and inputStreamForResourcePath() methods.
 java.lang.String resourcePathForLocalizedResourceNamed(java.lang.String aName, java.lang.String subDir)
           
 NSArray resourcePathsForDirectories(java.lang.String extension, java.lang.String subdirPath)
           
 NSArray resourcePathsForLocalizedResources(java.lang.String extension, java.lang.String subdirPath)
           
 NSArray resourcePathsForResources(java.lang.String extension, java.lang.String subdirPath)
           
static void setMainBundle(NSBundle aBundle)
          Used to set the "Main" application bundle, in which primary resources are loaded for GUI applications.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BundleDidLoadNotification

public static final java.lang.String BundleDidLoadNotification
See Also:
Constant Field Values

LoadedClassesNotification

public static final java.lang.String LoadedClassesNotification
See Also:
Constant Field Values

_classLoader

protected static NetworkClassLoader _classLoader

name

protected java.lang.String name

info

protected NSMutableDictionary info

path

protected java.lang.String path

classNames

protected NSMutableArray classNames

packages

protected NSMutableArray packages

properties

protected java.util.Properties properties

isFramework

protected boolean isFramework

loaded

protected boolean loaded

principalClass

protected java.lang.Class principalClass
Constructor Detail

NSBundle

public NSBundle()
The default constructor, which is only public to support other framework functionality, and to be API compatible with Apple's WebObjects. Generally, framework users should use bundleForXXXX() methods.

Method Detail

allBundles

public static NSArray allBundles()
Deprecated. use mainBundle() to access the application bundle and frameworkBundles() to access any frameworks.


allFrameworks

public static NSArray allFrameworks()
Deprecated. use frameworkBundles() to access any frameworks.


bundleForClass

public static NSBundle bundleForClass(java.lang.Class class1)
Returns the bundle that contains the provided class, if any. Otherwise, it returns null. Because NSBundles have a specialized class-loader, if any two bundles contain duiplicates of the same class, the second will fail to load. TODO: Determine if class-load scoping of duplicate classes is appropriate.

Parameters:
class1 -
Returns:
NSBundle

bundleWithPath

public static NSBundle bundleWithPath(java.lang.String path)
Deprecated. Apple's WebObjects says you should not load from arbitrary path.

Parameters:
path -
Returns:

bundleWithURL

public static NSBundle bundleWithURL(java.net.URL url)
Note:This method is only in Wotonomy. This method returns a bundle at a given URL, registering that bundle as well. If the bundle has already been loaded/registered, it is simply returned from the cache.

Parameters:
url -
Returns:

bundleForName

public static NSBundle bundleForName(java.lang.String name)
This method returns a bundle, either from cache, or if it doesn't exist yet, it attempts to look it up - first from the classpath, then from the resource path. TODO: Determine if the lookup order is the desired semantic.

Parameters:
name -
Returns:

frameworkBundles

public static NSArray frameworkBundles()

setMainBundle

public static void setMainBundle(NSBundle aBundle)
Used to set the "Main" application bundle, in which primary resources are loaded for GUI applications. This is mostly only relevant for XXApplication objects. This should therefore not be generally used by consumers of the framework.

Parameters:
aBundle -

mainBundle

public static NSBundle mainBundle()

defaultLocalePrefix

protected static java.lang.String defaultLocalePrefix()
Get the default prefix for locale. TODO: This really needs to be made dynamic somehow.

Returns:

findOrCreateBundleWithPath

protected static NSBundle findOrCreateBundleWithPath(java.lang.String s)

bundleClassPackageNames

public NSArray bundleClassPackageNames()
TODO: figure out what this does.

Returns:

bundlePath

public java.lang.String bundlePath()

bytesForResourcePath

public byte[] bytesForResourcePath(java.lang.String path)
Returns a byte array for the given resource path. TODO: Lookup semantics in WebObjects javadocs.

Parameters:
path -
Returns:

bundleClassNames

public NSArray bundleClassNames()

infoDictionary

public NSDictionary infoDictionary()

inputStreamForResourcePath

public java.io.InputStream inputStreamForResourcePath(java.lang.String path)
Returns an input stream for a given resource path. TODO: Lookup semantics in WebObjects javadocs.

Parameters:
path -
Returns:

isFramework

public boolean isFramework()

load

public boolean load()

name

public java.lang.String name()

pathForResource

public java.lang.String pathForResource(java.lang.String aName,
                                        java.lang.String anExtension)
Deprecated. Don't use this method, use resourcePathForLocalizedResourceNamed() instead.


pathForResource

public java.lang.String pathForResource(java.lang.String aName,
                                        java.lang.String anExtension,
                                        java.lang.String subDir)
Deprecated. Don't use this method, use resourcePathForLocalizedResourceNamed() instead.


pathsForResources

public NSArray pathsForResources(java.lang.String aName,
                                 java.lang.String anExtension)
Deprecated. Don't use this method, use resourcePathsForResources() instead.


principalClass

public java.lang.Class principalClass()

properties

public java.util.Properties properties()

resourcePath

public java.lang.String resourcePath()
Deprecated. Resources are now accessed using the bytesForResourcePath() and inputStreamForResourcePath() methods.


resourcePathForLocalizedResourceNamed

public java.lang.String resourcePathForLocalizedResourceNamed(java.lang.String aName,
                                                              java.lang.String subDir)

resourcePathsForDirectories

public NSArray resourcePathsForDirectories(java.lang.String extension,
                                           java.lang.String subdirPath)

resourcePathsForLocalizedResources

public NSArray resourcePathsForLocalizedResources(java.lang.String extension,
                                                  java.lang.String subdirPath)

resourcePathsForResources

public NSArray resourcePathsForResources(java.lang.String extension,
                                         java.lang.String subdirPath)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2006 null. All Rights Reserved.