Added support for loading place-related classes with a custom class

loader.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3255 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2004-11-30 20:04:11 +00:00
parent d29db7765a
commit 3ed8e3cd0e
2 changed files with 35 additions and 2 deletions
@@ -1,5 +1,5 @@
//
// $Id: LocationDirector.java,v 1.33 2004/08/27 02:12:32 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -274,6 +274,12 @@ public class LocationDirector extends BasicDirector
// make a note that we're now mostly in the new location
_placeId = placeId;
// check whether we should use a custom class loader
ClassLoader loader = getClassLoader(config);
if (loader != null) {
config.setClassLoader(loader);
}
Class cclass = config.getControllerClass();
try {
// start up a new place controller to manage the new place
@@ -554,6 +560,18 @@ public class LocationDirector extends BasicDirector
});
}
/**
* By overriding this method, it is possible to customize the location
* director to cause it to load the classes associated with a
* particular place via a custom class loader. That loader may enforce
* restricted privileges or obtain the classes from some special
* source.
*/
protected ClassLoader getClassLoader (PlaceConfig config)
{
return null;
}
/** The context through which we access needed services. */
protected CrowdContext _ctx;
@@ -1,5 +1,5 @@
//
// $Id: PlaceConfig.java,v 1.8 2004/08/27 02:12:33 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -59,6 +59,18 @@ public abstract class PlaceConfig extends TrackedStreamableObject
*/
public abstract String getManagerClassName ();
/**
* The {@link LocationDirector} may be configured to use a custom
* class loader when loading the classes associated with a certain
* {@link PlaceConfig}, in this case this method will be called prior
* to a call to {@link #getControllerClass} to set {@link #_loader}
* which should then be used for any dynamic class loading.
*/
public void setClassLoader (ClassLoader loader)
{
_loader = loader;
}
// documentation inherited
protected void toString (StringBuffer buf)
{
@@ -66,4 +78,7 @@ public abstract class PlaceConfig extends TrackedStreamableObject
buf.append(", ");
super.toString(buf);
}
/** The class loader to use when dynamically loading controller classes. */
protected transient ClassLoader _loader = getClass().getClassLoader();
}