diff --git a/src/helma/framework/core/TypeManager.java b/src/helma/framework/core/TypeManager.java index 51320c87..da46df0e 100644 --- a/src/helma/framework/core/TypeManager.java +++ b/src/helma/framework/core/TypeManager.java @@ -61,17 +61,12 @@ public final class TypeManager { */ public void createPrototypes () { // create standard prototypes. - registerPrototype ("root", new File (appDir, "root"), - new Prototype ("root", app)); - registerPrototype ("user", new File (appDir, "user"), - new Prototype ("user", app)); - // hopobject prototype is special in that we keep a reference - // to it, since we need it regularly when setting parent prototypes. - hopobjectProto = new Prototype ("hopobject", app); - registerPrototype ("hopobject", new File (appDir, "hopobject"), hopobjectProto); - // same with global prototype - globalProto = new Prototype ("global", app); - registerPrototype ("global", new File (appDir, "global"), globalProto); + createPrototype ("root"); + createPrototype ("user"); + // get references to hopobject and global protos, + // since we need it regularly when setting parent prototypes. + hopobjectProto = createPrototype ("hopobject"); + globalProto = createPrototype ("global"); // loop through directories and create prototypes checkFiles (); } @@ -122,8 +117,7 @@ public final class TypeManager { File f = new File (appDir, list[i]); if (f.isDirectory ()) { // create new prototype - proto = new Prototype (list[i], app); - registerPrototype (list[i], f, proto); + createPrototype (list[i], f); } } } @@ -159,6 +153,17 @@ public final class TypeManager { } + protected void removeZipFile (String zipname) { + zipfiles.remove (zipname); + for (Iterator i=prototypes.values().iterator(); i.hasNext(); ) { + Prototype proto = (Prototype) i.next (); + // update prototype's type mapping + DbMapping dbmap = proto.getDbMapping (); + SystemProperties props = dbmap.getProperties(); + props.removeProps (zipname); + } + } + private boolean isValidTypeName (String str) { if (str == null) @@ -183,33 +188,26 @@ public final class TypeManager { * caller (e.g. ZippedAppFile). */ public Prototype createPrototype (String typename) { - Prototype p = getPrototype (typename); - if (p == null) { - p = new Prototype (typename, app); - prototypes.put (typename, p); - } - return p; + return createPrototype (typename, new File (appDir, typename)); } /** * Create a prototype from a directory containing scripts and other stuff */ - public void registerPrototype (String name, File dir, Prototype proto) { - // System.err.println ("REGISTER PROTO: "+app.getName()+"/"+name); - // app.logEvent ("registering prototype "+name); - - // Create and register type properties file - File propfile = new File (dir, "type.properties"); - SystemProperties props = new SystemProperties (propfile.getAbsolutePath ()); - DbMapping dbmap = new DbMapping (app, name, props); - // we don't need to put the DbMapping into proto.updatables, because - // dbmappings are checked separately in checkFiles for each request - // proto.updatables.put ("type.properties", dbmap); - proto.setDbMapping (dbmap); - - // put the prototype into our map - prototypes.put (name, proto); + public Prototype createPrototype (String typename, File dir) { + Prototype proto = new Prototype (typename, app); + // Create and register type properties file + File propfile = new File (dir, "type.properties"); + SystemProperties props = new SystemProperties (propfile.getAbsolutePath ()); + DbMapping dbmap = new DbMapping (app, typename, props); + // we don't need to put the DbMapping into proto.updatables, because + // dbmappings are checked separately in checkFiles for each request + // proto.updatables.put ("type.properties", dbmap); + proto.setDbMapping (dbmap); + // put the prototype into our map + prototypes.put (typename, proto); + return proto; } diff --git a/src/helma/framework/core/ZippedAppFile.java b/src/helma/framework/core/ZippedAppFile.java index a59f5389..2b8e4e89 100644 --- a/src/helma/framework/core/ZippedAppFile.java +++ b/src/helma/framework/core/ZippedAppFile.java @@ -22,6 +22,7 @@ public class ZippedAppFile implements Updatable { Application app; File file; long lastmod; + Set updatables; public ZippedAppFile (File file, Application app) { @@ -55,6 +56,7 @@ public class ZippedAppFile implements Updatable { lastmod = file.lastModified (); // System.err.println ("UPDATING ZIP FILE "+this); zip = new ZipFile (file); + updatables = new HashSet (); for (Enumeration en = zip.entries (); en.hasMoreElements (); ) { ZipEntry entry = (ZipEntry) en.nextElement (); String ename = entry.getName (); @@ -74,6 +76,7 @@ public class ZippedAppFile implements Updatable { // System.err.println ("["+content+"]"); ActionFile act = new ActionFile (content, name, proto); proto.actions.put (name, act); + updatables.add (act); // mark prototype as updated proto.markUpdated (); } @@ -83,6 +86,7 @@ public class ZippedAppFile implements Updatable { // System.err.println ("["+content+"]"); Template tmp = new Template (content, name, proto); proto.templates.put (name, tmp); + updatables.add (tmp); // mark prototype as updated proto.markUpdated (); } @@ -92,6 +96,7 @@ public class ZippedAppFile implements Updatable { // System.err.println ("["+content+"]"); SkinFile skin = new SkinFile (content, name, proto); proto.skins.put (name, skin); + updatables.add (skin); } else if (fname.endsWith (".js")) { String name = fname.substring (0, fname.lastIndexOf (".")); @@ -99,35 +104,20 @@ public class ZippedAppFile implements Updatable { // System.err.println ("["+content+"]"); FunctionFile ff = new FunctionFile (content, name, proto); proto.functions.put (name, ff); + updatables.add (ff); // mark prototype as updated proto.markUpdated (); } else if ("type.properties".equalsIgnoreCase (fname)) { String name = fname.substring (0, fname.lastIndexOf (".")); DbMapping dbmap = proto.getDbMapping (); - if (dbmap == null) { - SystemProperties props = new SystemProperties (zip.getInputStream (entry)); - dbmap = new DbMapping (app, proto.getName (), props); - proto.setDbMapping (dbmap); - } else { - // FIXME: provide a way to let zip files add to - // type.properties files of existing prototypes. - // SystemProperties props = dbmap.getProperties (); - // props.add (zip.getInputStream (entry)); - } + SystemProperties props = dbmap.getProperties (); + props.addProps (file.getName(), zip.getInputStream (entry)); // mark prototype as updated proto.markUpdated (); } } } - for (Iterator it = newPrototypes.iterator (); it.hasNext (); ) { - Prototype proto = (Prototype) it.next (); - if (proto.getDbMapping() == null) { - // DbMapping doesn't exist, we still need to create one - SystemProperties props = new SystemProperties (); - proto.setDbMapping (new DbMapping (app, proto.getName (), props)); - } - } } catch (Throwable x) { System.err.println ("Error updating ZipFile: "+x); } finally { @@ -139,8 +129,12 @@ public class ZippedAppFile implements Updatable { } - void remove () { - app.typemgr.zipfiles.remove (file.getName()); + public void remove () { + if (updatables != null) { + for (Iterator it = updatables.iterator(); it.hasNext(); ) + ((Updatable) it.next()).remove (); + } + app.typemgr.removeZipFile (file.getName()); // System.err.println ("REMOVING ZIP FILE "+this); }