From 3ed8e3cd0e7c210b2d41bbfaddbc812cc9287987 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 30 Nov 2004 20:04:11 +0000 Subject: [PATCH] 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 --- .../crowd/client/LocationDirector.java | 20 ++++++++++++++++++- .../threerings/crowd/data/PlaceConfig.java | 17 +++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/crowd/client/LocationDirector.java b/src/java/com/threerings/crowd/client/LocationDirector.java index 79c00cc3e..e51a6ee11 100644 --- a/src/java/com/threerings/crowd/client/LocationDirector.java +++ b/src/java/com/threerings/crowd/client/LocationDirector.java @@ -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; diff --git a/src/java/com/threerings/crowd/data/PlaceConfig.java b/src/java/com/threerings/crowd/data/PlaceConfig.java index cfe916c1e..196969b4a 100644 --- a/src/java/com/threerings/crowd/data/PlaceConfig.java +++ b/src/java/com/threerings/crowd/data/PlaceConfig.java @@ -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(); }