public void updatePrototype (Prototype proto) {  if (proto == null) return; if (System.currentTimeMillis() - proto.getLastCheck() < 1000) return;  synchronized (proto) { if (System.currentTimeMillis() - proto.getLastCheck() < 1000) return;  File dir = new File (appDir, proto.getName()); boolean needsUpdate = false; HashSet updatables = null;    for (Iterator i = proto.updatables.values().iterator(); i.hasNext(); ) { Updatable upd = (Updatable) i.next(); if (upd.needsUpdate ()) { if (updatables == null) updatables = new HashSet (); needsUpdate = true; updatables.add (upd); } }     long lastcheck = proto.getLastCheck (); proto.markChecked ();   if (lastcheck < dir.lastModified ()) { String[] list = dir.list(); for (int i=0; i<list.length; i++) { String fn = list[i]; if (!proto.updatables.containsKey (fn)) { if (fn.endsWith (templateExtension) || fn.endsWith (scriptExtension) || fn.endsWith (actionExtension) || fn.endsWith (skinExtension) || "type.properties".equalsIgnoreCase (fn)) { needsUpdate = true;  } } } }   if (!needsUpdate) return;     String[] list = dir.list (); for (int i=0; i<list.length; i++) { String fn = list[i]; int dot = fn.indexOf (".");  if (dot < 0) continue;  if (proto.updatables.containsKey (fn) || !(fn.endsWith (templateExtension) || fn.endsWith (scriptExtension) || fn.endsWith (actionExtension) || fn.endsWith (skinExtension) || "type.properties".equalsIgnoreCase (fn))) { continue; }  String tmpname = list[i].substring(0, dot); File tmpfile = new File (dir, list[i]);  if (list[i].endsWith (templateExtension)) { try { Template t = new Template (tmpfile, tmpname, proto); proto.updatables.put (list[i], t); proto.templates.put (tmpname, t); } catch (Throwable x) { app.logEvent ("Error updating prototype: "+x); }  } else if (list[i].endsWith (scriptExtension)) { try { FunctionFile ff = new FunctionFile (tmpfile, tmpname, proto); proto.updatables.put (list[i], ff); proto.functions.put (tmpname, ff); } catch (Throwable x) { app.logEvent ("Error updating prototype: "+x); }  }  else if (list[i].endsWith (actionExtension)) { try { ActionFile af = new ActionFile (tmpfile, tmpname, proto); proto.updatables.put (list[i], af); proto.actions.put (tmpname, af); } catch (Throwable x) { app.logEvent ("Error updating prototype: "+x); }  }  else if (list[i].endsWith (skinExtension)) { SkinFile sf = new SkinFile (tmpfile, tmpname, proto); proto.updatables.put (list[i], sf); proto.skins.put (tmpname, sf); } }   if (updatables != null) { for (Iterator i = updatables.iterator(); i.hasNext(); ) { Updatable upd = (Updatable) i.next();  if (upd.needsUpdate ()) { if (upd instanceof DbMapping) rewire = true; try { upd.update (); } catch (Exception x) { if (upd instanceof DbMapping) app.logEvent ("Error updating db mapping for type "+proto.getName()+": "+x); else app.logEvent ("Error updating "+upd+" of prototye type "+proto.getName()+": "+x); } } } } proto.markUpdated();  }
public void updatePrototype (String name) {  Prototype proto = getPrototype (name); updatePrototype (proto);
    public void updatePrototype (Prototype proto) {        if (proto == null)            return;        if (System.currentTimeMillis() - proto.getLastCheck() < 1000)            return;        synchronized (proto) {        if (System.currentTimeMillis() - proto.getLastCheck() < 1000)            return;        File dir = new File (appDir, proto.getName());        boolean needsUpdate = false;        HashSet updatables = null;        // our plan is to do as little as possible, so first check if        // anything the prototype knows about has changed on disk        for (Iterator i = proto.updatables.values().iterator(); i.hasNext(); ) {            Updatable upd = (Updatable) i.next();            if (upd.needsUpdate ()) {                if (updatables == null)                    updatables = new HashSet ();                needsUpdate = true;                updatables.add (upd);            }        }        // fetch previous last-check timestamp and update it on prototype        // we do this here for the (not very likely but possible) case         // where files are created in the exact moment we are doing this check.        long lastcheck = proto.getLastCheck ();        proto.markChecked ();        // next we check if files have been created since last update        if (lastcheck < dir.lastModified ()) {            String[] list = dir.list();            for (int i=0; i<list.length; i++) {                String fn = list[i];                if (!proto.updatables.containsKey (fn)) {                    if (fn.endsWith (templateExtension) || fn.endsWith (scriptExtension) ||	    	fn.endsWith (actionExtension) || fn.endsWith (skinExtension) ||	    	"type.properties".equalsIgnoreCase (fn)) {                        needsUpdate = true;                        // updatables.add ("[new:"+proto.getName()+"/"+fn+"]");                    }                }            }        }        // if nothing needs to be updated, return now        if (!needsUpdate)            return;        // app.logEvent ("TypeManager: Updating prototypes for "+app.getName()+": "+updatables);        // first go through new files and create new items        String[] list = dir.list ();        for (int i=0; i<list.length; i++) {            String fn = list[i];            int dot = fn.indexOf (".");            if (dot < 0)                continue;            if (proto.updatables.containsKey (fn) || !(fn.endsWith (templateExtension) || fn.endsWith (scriptExtension) ||            fn.endsWith (actionExtension) || fn.endsWith (skinExtension) || "type.properties".equalsIgnoreCase (fn))) {                continue;            }            String tmpname = list[i].substring(0, dot);            File tmpfile = new File (dir, list[i]);            if (list[i].endsWith (templateExtension)) {                try {                    Template t = new Template (tmpfile, tmpname, proto);                    proto.updatables.put (list[i], t);                    proto.templates.put (tmpname, t);                } catch (Throwable x) {                    app.logEvent ("Error updating prototype: "+x);                }            } else if (list[i].endsWith (scriptExtension)) {                try {                    FunctionFile ff = new FunctionFile (tmpfile, tmpname, proto);                    proto.updatables.put (list[i], ff);                    proto.functions.put (tmpname, ff);                } catch (Throwable x) {                    app.logEvent ("Error updating prototype: "+x);                }            }  else if (list[i].endsWith (actionExtension)) {                try {                    ActionFile af = new ActionFile (tmpfile, tmpname, proto);                    proto.updatables.put (list[i], af);                    proto.actions.put (tmpname, af);                } catch (Throwable x) {                    app.logEvent ("Error updating prototype: "+x);                }            }  else if (list[i].endsWith (skinExtension)) {                SkinFile sf = new SkinFile (tmpfile, tmpname, proto);                proto.updatables.put (list[i], sf);                proto.skins.put (tmpname, sf);            }        }        // next go through existing updatables        if (updatables != null) {            for (Iterator i = updatables.iterator(); i.hasNext(); ) {                Updatable upd = (Updatable) i.next();                if (upd.needsUpdate ()) {                    if (upd instanceof DbMapping)                        rewire = true;                    try {                        upd.update ();                    } catch (Exception x) {                         if (upd instanceof DbMapping)                            app.logEvent ("Error updating db mapping for type "+proto.getName()+": "+x);                         else                            app.logEvent ("Error updating "+upd+" of prototye type "+proto.getName()+": "+x);                    }                }            }        }        proto.markUpdated();        } // end of synchronized (proto)        // app.scriptingEngine.updatePrototype (proto);    }