Further cleanup in TypeManager.
Zip files are now very close to work just like unzipped files: They can add to existing type.properties, and the files they contain are removed from Prototypes when the zip files are removed.
This commit is contained in:
parent
2ce2f6fd0c
commit
67c03ca7ae
2 changed files with 46 additions and 54 deletions
|
@ -61,17 +61,12 @@ public final class TypeManager {
|
||||||
*/
|
*/
|
||||||
public void createPrototypes () {
|
public void createPrototypes () {
|
||||||
// create standard prototypes.
|
// create standard prototypes.
|
||||||
registerPrototype ("root", new File (appDir, "root"),
|
createPrototype ("root");
|
||||||
new Prototype ("root", app));
|
createPrototype ("user");
|
||||||
registerPrototype ("user", new File (appDir, "user"),
|
// get references to hopobject and global protos,
|
||||||
new Prototype ("user", app));
|
// since we need it regularly when setting parent prototypes.
|
||||||
// hopobject prototype is special in that we keep a reference
|
hopobjectProto = createPrototype ("hopobject");
|
||||||
// to it, since we need it regularly when setting parent prototypes.
|
globalProto = createPrototype ("global");
|
||||||
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);
|
|
||||||
// loop through directories and create prototypes
|
// loop through directories and create prototypes
|
||||||
checkFiles ();
|
checkFiles ();
|
||||||
}
|
}
|
||||||
|
@ -122,8 +117,7 @@ public final class TypeManager {
|
||||||
File f = new File (appDir, list[i]);
|
File f = new File (appDir, list[i]);
|
||||||
if (f.isDirectory ()) {
|
if (f.isDirectory ()) {
|
||||||
// create new prototype
|
// create new prototype
|
||||||
proto = new Prototype (list[i], app);
|
createPrototype (list[i], f);
|
||||||
registerPrototype (list[i], f, proto);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
private boolean isValidTypeName (String str) {
|
||||||
if (str == null)
|
if (str == null)
|
||||||
|
@ -183,33 +188,26 @@ public final class TypeManager {
|
||||||
* caller (e.g. ZippedAppFile).
|
* caller (e.g. ZippedAppFile).
|
||||||
*/
|
*/
|
||||||
public Prototype createPrototype (String typename) {
|
public Prototype createPrototype (String typename) {
|
||||||
Prototype p = getPrototype (typename);
|
return createPrototype (typename, new File (appDir, typename));
|
||||||
if (p == null) {
|
|
||||||
p = new Prototype (typename, app);
|
|
||||||
prototypes.put (typename, p);
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a prototype from a directory containing scripts and other stuff
|
* Create a prototype from a directory containing scripts and other stuff
|
||||||
*/
|
*/
|
||||||
public void registerPrototype (String name, File dir, Prototype proto) {
|
public Prototype createPrototype (String typename, File dir) {
|
||||||
// System.err.println ("REGISTER PROTO: "+app.getName()+"/"+name);
|
Prototype proto = new Prototype (typename, app);
|
||||||
// app.logEvent ("registering prototype "+name);
|
// Create and register type properties file
|
||||||
|
File propfile = new File (dir, "type.properties");
|
||||||
// Create and register type properties file
|
SystemProperties props = new SystemProperties (propfile.getAbsolutePath ());
|
||||||
File propfile = new File (dir, "type.properties");
|
DbMapping dbmap = new DbMapping (app, typename, props);
|
||||||
SystemProperties props = new SystemProperties (propfile.getAbsolutePath ());
|
// we don't need to put the DbMapping into proto.updatables, because
|
||||||
DbMapping dbmap = new DbMapping (app, name, props);
|
// dbmappings are checked separately in checkFiles for each request
|
||||||
// we don't need to put the DbMapping into proto.updatables, because
|
// proto.updatables.put ("type.properties", dbmap);
|
||||||
// dbmappings are checked separately in checkFiles for each request
|
proto.setDbMapping (dbmap);
|
||||||
// proto.updatables.put ("type.properties", dbmap);
|
// put the prototype into our map
|
||||||
proto.setDbMapping (dbmap);
|
prototypes.put (typename, proto);
|
||||||
|
return proto;
|
||||||
// put the prototype into our map
|
|
||||||
prototypes.put (name, proto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class ZippedAppFile implements Updatable {
|
||||||
Application app;
|
Application app;
|
||||||
File file;
|
File file;
|
||||||
long lastmod;
|
long lastmod;
|
||||||
|
Set updatables;
|
||||||
|
|
||||||
|
|
||||||
public ZippedAppFile (File file, Application app) {
|
public ZippedAppFile (File file, Application app) {
|
||||||
|
@ -55,6 +56,7 @@ public class ZippedAppFile implements Updatable {
|
||||||
lastmod = file.lastModified ();
|
lastmod = file.lastModified ();
|
||||||
// System.err.println ("UPDATING ZIP FILE "+this);
|
// System.err.println ("UPDATING ZIP FILE "+this);
|
||||||
zip = new ZipFile (file);
|
zip = new ZipFile (file);
|
||||||
|
updatables = new HashSet ();
|
||||||
for (Enumeration en = zip.entries (); en.hasMoreElements (); ) {
|
for (Enumeration en = zip.entries (); en.hasMoreElements (); ) {
|
||||||
ZipEntry entry = (ZipEntry) en.nextElement ();
|
ZipEntry entry = (ZipEntry) en.nextElement ();
|
||||||
String ename = entry.getName ();
|
String ename = entry.getName ();
|
||||||
|
@ -74,6 +76,7 @@ public class ZippedAppFile implements Updatable {
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
ActionFile act = new ActionFile (content, name, proto);
|
ActionFile act = new ActionFile (content, name, proto);
|
||||||
proto.actions.put (name, act);
|
proto.actions.put (name, act);
|
||||||
|
updatables.add (act);
|
||||||
// mark prototype as updated
|
// mark prototype as updated
|
||||||
proto.markUpdated ();
|
proto.markUpdated ();
|
||||||
}
|
}
|
||||||
|
@ -83,6 +86,7 @@ public class ZippedAppFile implements Updatable {
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
Template tmp = new Template (content, name, proto);
|
Template tmp = new Template (content, name, proto);
|
||||||
proto.templates.put (name, tmp);
|
proto.templates.put (name, tmp);
|
||||||
|
updatables.add (tmp);
|
||||||
// mark prototype as updated
|
// mark prototype as updated
|
||||||
proto.markUpdated ();
|
proto.markUpdated ();
|
||||||
}
|
}
|
||||||
|
@ -92,6 +96,7 @@ public class ZippedAppFile implements Updatable {
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
SkinFile skin = new SkinFile (content, name, proto);
|
SkinFile skin = new SkinFile (content, name, proto);
|
||||||
proto.skins.put (name, skin);
|
proto.skins.put (name, skin);
|
||||||
|
updatables.add (skin);
|
||||||
}
|
}
|
||||||
else if (fname.endsWith (".js")) {
|
else if (fname.endsWith (".js")) {
|
||||||
String name = fname.substring (0, fname.lastIndexOf ("."));
|
String name = fname.substring (0, fname.lastIndexOf ("."));
|
||||||
|
@ -99,35 +104,20 @@ public class ZippedAppFile implements Updatable {
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
FunctionFile ff = new FunctionFile (content, name, proto);
|
FunctionFile ff = new FunctionFile (content, name, proto);
|
||||||
proto.functions.put (name, ff);
|
proto.functions.put (name, ff);
|
||||||
|
updatables.add (ff);
|
||||||
// mark prototype as updated
|
// mark prototype as updated
|
||||||
proto.markUpdated ();
|
proto.markUpdated ();
|
||||||
}
|
}
|
||||||
else if ("type.properties".equalsIgnoreCase (fname)) {
|
else if ("type.properties".equalsIgnoreCase (fname)) {
|
||||||
String name = fname.substring (0, fname.lastIndexOf ("."));
|
String name = fname.substring (0, fname.lastIndexOf ("."));
|
||||||
DbMapping dbmap = proto.getDbMapping ();
|
DbMapping dbmap = proto.getDbMapping ();
|
||||||
if (dbmap == null) {
|
SystemProperties props = dbmap.getProperties ();
|
||||||
SystemProperties props = new SystemProperties (zip.getInputStream (entry));
|
props.addProps (file.getName(), 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));
|
|
||||||
}
|
|
||||||
// mark prototype as updated
|
// mark prototype as updated
|
||||||
proto.markUpdated ();
|
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) {
|
} catch (Throwable x) {
|
||||||
System.err.println ("Error updating ZipFile: "+x);
|
System.err.println ("Error updating ZipFile: "+x);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -139,8 +129,12 @@ public class ZippedAppFile implements Updatable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove () {
|
public void remove () {
|
||||||
app.typemgr.zipfiles.remove (file.getName());
|
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);
|
// System.err.println ("REMOVING ZIP FILE "+this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue