public String instanceName () { // try the life object if any FileObject fo = entry ().getFile (); if (fo.lastModified ().getTime () <= saveTime) { Object o = bean.get (); if (o != null) { return o.getClass().getName(); } } if (!fo.hasExt (INSTANCE)) { return super.instanceName (); } return getClassName(fo); }
public Object instanceCreate () throws IOException, ClassNotFoundException { FileObject fo = entry ().getFile (); Object o; if (fo.lastModified ().getTime () <= saveTime) { o = bean.get (); } else { o = null; } if (o != null) { return o; } saveTime = fo.lastModified ().getTime (); if (saveTime < System.currentTimeMillis ()) { saveTime = System.currentTimeMillis (); } if (fo.hasExt (INSTANCE)) { // try to ask for instance creation attribute o = fo.getAttribute (EA_INSTANCE_CREATE); } if (o == null) { // try super method o = super.instanceCreate (); } // remember the created value bean = new java.lang.ref.SoftReference (o); return o; }
/** Uses the cache to answer this question without loading the class itself, if the * cache exists. */ public boolean instanceOf (Class type) { // try the life object if any FileObject fo = entry ().getFile (); if (fo.lastModified ().getTime () <= saveTime) { Object o = bean.get (); if (o != null) { return type.isInstance (o); } } // else do checking of classes // null means no cache exists Boolean res = inListOfClasses (type, entry ().getFile ()); if (res == null) { // uses instanceClass and then assignableFrom return super.instanceOf (type); } return res.booleanValue (); }
/** Saves the bean to disk. */ private void runImpl () { Object bean = this.bean.get (); if (bean == null) { // nothing to save return; } try { FileLock lock = dobj.doFileLock(); if (lock == null) return; ObjectOutputStream oos = new ObjectOutputStream ( entry ().getFile ().getOutputStream (lock) ); try { oos.writeObject (bean); // avoid bean reloading saveTime = entry ().getFile ().lastModified ().getTime (); } finally { oos.close (); } } catch (IOException ex) { err.annotate (ex, NbBundle.getMessage ( InstanceDataObject.class, "EXC_CannotSaveBean", // NOI18N instanceName (), entry ().getFile ().getPath() )); err.notify (ex); } }
/** Uses cache to remember list of classes to them this object is * assignable. */ public Class instanceClass() throws IOException, ClassNotFoundException { Class type = super.instanceClass (customClassLoader); updateListOfClasses (type, entry ().getFile ()); return type; }