Table retTable = new Table(); PushbackInputStream pbStream = null; boolean isSerialized = false; BufferedInputStream bis = (pbStream != null) ? new BufferedInputStream(pbStream) : new BufferedInputStream(is); retTable.readFromXML(bis, false); return new Table();
/** Load attributes from cache or * from disk. * @param name of folder to load data from */ private Table loadTable(String name) { //throws IOException { Reference r = (Reference) getCache().get(name); if (r != null) { Table m = (Table) r.get(); if (m != null) { return m; } } // have to load new table Table t = load(name); t.attach(name, this); getCache().put(name, new SoftReference(t)); return t; }
Object prev = t.getAttr(arr[1], attrName); t.setAttr (arr[1], attrName, null); // clear the attribute }else { if ((objType = XMLMapAttr.Attr.distinguishObject (value)) == XMLMapAttr.Attr.isValid("SERIALVALUE") ) { // NOI18N t.setAttr (arr[1], attrName, value);//change value instead of marshall t.setAttr (arr[1], attrName, XMLMapAttr.createAttribute (objType,value.toString()) );
Object prev = t.getAttr(arr[1], attrName); t.setAttr (arr[1], attrName, null); // clear the attribute }else { if ((objType = XMLMapAttr.Attr.distinguishObject (value)) == XMLMapAttr.Attr.isValid("SERIALVALUE") ) { // NOI18N t.setAttr (arr[1], attrName, value);//change value instead of marshall t.setAttr (arr[1], attrName, XMLMapAttr.createAttribute (objType,value.toString()) );
Table retTable = new Table (); PushbackInputStream pbStream = null; boolean isSerialized = false; retTable.readFromXML(bis, false); return retTable; return new Table ();
Table retTable = new Table (); PushbackInputStream pbStream = null; boolean isSerialized = false; retTable.readFromXML(bis, false); return retTable; return new Table ();
XMLMapAttr m = (XMLMapAttr)get (fileName); if (m != null) { Object o = null;
XMLMapAttr m = (XMLMapAttr)get (fileName); if (m != null) { Object o = null;
/** Writes external. * @param oo * @throws IOException */ public void writeExternal (ObjectOutput oo) throws IOException { // list of names Iterator it = keySet ().iterator (); while (it.hasNext ()) { String file = (String)it.next (); Map attr = (Map)get (file); if (attr != null && !attr.isEmpty ()) { oo.writeObject (file); Iterator entries = attr.entrySet ().iterator (); while (entries.hasNext ()) { Map.Entry entry = (Map.Entry)entries.next (); String key = (String)entry.getKey (); Object value = entry.getValue (); if (key != null && value != null) { oo.writeObject (key); oo.writeObject (value); } } oo.writeObject (null); } } oo.writeObject (null); }
/** Loads the table. Does no initialization. */ private Table load (String name) { String acceptNames[] = {(name.length()==0 ? "": (name + '/')) + getFileName(),// NOI18N (name.length()==0 ? "": (name + '/')) + ATTR_NAME_EXT}; // NOI18N for (int i = 0; i < acceptNames.length;i++) { if (info.size (acceptNames[i]) > 0L) { try { InputStream fis = info.inputStream (acceptNames[i]); try { return loadTable (fis,acceptNames[i]); } finally { try { fis.close (); } catch (IOException e) { // ignore--who cares? } } } catch (FileNotFoundException ex) { ExternalUtil.exception(ex); } } } return new Table (); }
public synchronized void renameAttributes (String oldName, String newName) { try { String[] arr = new String[2]; split (oldName, arr); Table t = loadTable (arr[0]); Map v = (Map) t.remove (arr[1]); // System.out.println ("ARg[0] = " + arr[0] + " arr[1] = " + arr[1] + " value: " + v); // NOI18N if (v == null) { // no attrs no change return; } split (newName, arr); // Remove transient attributes: Iterator it = v.entrySet ().iterator (); while (it.hasNext ()) { Map.Entry pair = (Map.Entry) it.next (); if (FileUtil.transientAttributes.contains (pair.getKey ())) it.remove (); } t.put (arr[1], v); // System.out.println ("xyz[0] = " + arr[0] + " xyz[1] = " + arr[1] + " value: " + v); // NOI18N saveTable (arr[0], t); } catch (IOException e) { ExternalUtil.exception (e); } }
public synchronized void renameAttributes (String oldName, String newName) { try { String[] arr = new String[2]; split (oldName, arr); Table t = loadTable (arr[0]); Map v = (Map) t.remove (arr[1]); // System.out.println ("ARg[0] = " + arr[0] + " arr[1] = " + arr[1] + " value: " + v); // NOI18N if (v == null) { // no attrs no change return; } split (newName, arr); // Remove transient attributes: Iterator it = v.entrySet ().iterator (); while (it.hasNext ()) { Map.Entry pair = (Map.Entry) it.next (); if (FileUtil.transientAttributes.contains (pair.getKey ())) it.remove (); } t.put (arr[1], v); // System.out.println ("xyz[0] = " + arr[0] + " xyz[1] = " + arr[1] + " value: " + v); // NOI18N saveTable (arr[0], t); } catch (IOException e) { ExternalUtil.exception (e); } }
/** Writes external. * @param oo * @throws IOException */ public void writeExternal (ObjectOutput oo) throws IOException { // list of names Iterator it = keySet ().iterator (); while (it.hasNext ()) { String file = (String)it.next (); Map attr = (Map)get (file); if (attr != null && !attr.isEmpty ()) { oo.writeObject (file); Iterator entries = attr.entrySet ().iterator (); while (entries.hasNext ()) { Map.Entry entry = (Map.Entry)entries.next (); String key = (String)entry.getKey (); Object value = entry.getValue (); if (key != null && value != null) { oo.writeObject (key); oo.writeObject (value); } } oo.writeObject (null); } } oo.writeObject (null); }
/** Loads the table. Does no initialization. */ private Table load (String name) { String acceptNames[] = {(name.length()==0 ? "": (name + '/')) + getFileName(),// NOI18N (name.length()==0 ? "": (name + '/')) + ATTR_NAME_EXT}; // NOI18N for (int i = 0; i < acceptNames.length;i++) { if (info.size (acceptNames[i]) > 0L) { try { InputStream fis = info.inputStream (acceptNames[i]); try { return loadTable (fis,acceptNames[i]); } finally { try { fis.close (); } catch (IOException e) { // ignore--who cares? } } } catch (FileNotFoundException ex) { ExternalUtil.exception(ex); } } } return new Table (); }
public Object readAttribute(String name, String attrName) { Table t; String[] arr = new String[2]; split (name, arr); /** At the momement substitutes lack of API */ if (attrName.equals (READONLY_ATTRIBUTES)) return info.readOnly(arr[0]) ? Boolean.TRUE : Boolean.FALSE; synchronized (this) { // synchronized so only one table for each folder // can exist t = loadTable (arr[0]); } // JST: // had to split the code to do getAttr out of synchronized block // because the attribute can be serialized FileObject and // so the code returns back to FileSystem (that is usually synchronized) // // this leads to deadlocks between FS & DefaultAttributes implementation // // I do not know if the table should not be somehow synchronized, // but it seems ok. return t.getAttr (arr[1], attrName); }
/** * Sets an attribute to the table. * New added - for Sandwich project (XML format instead of serialization) . * @param fileName - name of file * @param attrName - name of attribute * @param obj - attribute */ final void setAttr (String fileName, String attrName, Object obj) { XMLMapAttr m = (XMLMapAttr)get (fileName); if (m == null) { m = new XMLMapAttr();//HashMap (7);//XMLMapAttr(); put (fileName, m); } m.put (attrName, obj, false); if (obj == null && m.size() == 1) { remove(fileName); } // increments the version version++; }
public Object readAttribute(String name, String attrName) { Table t; String[] arr = new String[2]; split (name, arr); /** At the momement substitutes lack of API */ if (attrName.equals (READONLY_ATTRIBUTES)) return info.readOnly(arr[0]) ? Boolean.TRUE : Boolean.FALSE; synchronized (this) { // synchronized so only one table for each folder // can exist t = loadTable (arr[0]); } // JST: // had to split the code to do getAttr out of synchronized block // because the attribute can be serialized FileObject and // so the code returns back to FileSystem (that is usually synchronized) // // this leads to deadlocks between FS & DefaultAttributes implementation // // I do not know if the table should not be somehow synchronized, // but it seems ok. return t.getAttr (arr[1], attrName); }