Refine search
/** Restore entries from the list. If Entry.getFile () has changed from * time when backup list was created, original file is restored and * Entry is re-assigned to it. * @param backup list obtained from {@link #saveEntries ()} function */ final void restoreEntries(List backup) { Iterator it = backup.iterator (); while (it.hasNext ()) { Pair p = (Pair)it.next (); if (p.entry.getFile ().equals (p.file)) continue; if (p.file.isValid()) { p.entry.changeFile (p.file); } else { // copy back try { if (p.entry.getFile ().isData ()) p.entry.changeFile (p.entry.getFile ().copy (p.file.getParent (), p.file.getName (), p.file.getExt ())); else { FileObject fo = p.file.getParent ().createFolder (p.file.getName ()); FileUtil.copyAttributes (p.entry.getFile (), fo); p.entry.changeFile (fo); } } catch (IOException e) { // should not occure } } } }
public void run() throws java.io.IOException { FileLock lck; FileObject data; if (holder != null) { data = holder.getPrimaryEntry().getFile(); lck = holder.getPrimaryEntry().takeLock(); } else { FileObject folder = f.getPrimaryFile(); String fn = FileUtil.findFreeFileName(folder, name, "xml"); data = folder.createData(fn, "xml"); lck = data.lock(); } try { OutputStream ostm = data.getOutputStream(lck); PrintWriter writer = new PrintWriter( new OutputStreamWriter(ostm, "UTF8")); write(writer); writer.flush(); writer.close(); ostm.close(); } finally { lck.releaseLock(); } if (holder == null) { holder = (MultiDataObject)DataObject.find(data); } }
/** 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); } }
/** Get the list of all registered types in every (persistent * or not persistent) connections. * * @return the list of ConnectionCookie.Type objects */ public List getRegisteredTypes() { LinkedList typesList = new LinkedList(); LinkedList list = listeners; for (int i = 0; i <= 1; i++) { if (i == 1) list = (LinkedList)entry.getFile ().getAttribute (EA_LISTENERS); if (list == null) continue; Iterator it = list.iterator (); while (it.hasNext ()) { typesList.add(((Pair)it.next()).getType()); } } return typesList; }
public GridDataObject(FileObject pf, MultiFileLoader loader, List<FileObject> secondary) throws DataObjectExistsException, IOException, ParserConfigurationException, SAXException { super(pf, loader); registerEditor(MIME_TYPE, true); this.pf = pf; setSecondaryFiles(secondary); GridReader reader = new GridReader(); Pattern taskDataPattern = Pattern.compile(GridFileLoader.TASKDATA_PATTERN); for (Entry entry : secondaryEntries()) { FileObject child = entry.getFile(); if (taskDataPattern.matcher(child.getNameExt()).find()) { IsobusDataObject isobusDataObject = (IsobusDataObject) DataObject.find(child); for (IsobusTask task : isobusDataObject.getIsobusTaskData().getTSK()) { if (task.getGRD() != null && task.getGRD().getFilename() != null && task.getGRD().getFilename().toLowerCase().equals(pf.getName().toLowerCase())) { grid = task.getGRD(); treatmentZones = reader.getTreatMentZones(pf, task.getTZN()); } } } } }
list = (LinkedList)entry.getFile ().getAttribute (EA_LISTENERS); } else { list = listeners; entry.getFile ().setAttribute (EA_LISTENERS, list);
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; }
public void setCMakeCommand(String make) { try { getEntry().getFile().setAttribute(PROP_CMAKE_COMMAND, make); } catch (IOException ex) { if (Boolean.getBoolean("netbeans.debug.exceptions")) { // NOI18N ex.printStackTrace(); } } }
protected FileObject handleMove (DataFolder df) throws IOException { FileObject originalFolder = getPrimaryFile (); FileLock lock = originalFolder.lock(); List backup = saveEntries(); originalFolder.delete (lock); } catch (IOException e) { Throwable t = ErrorManager.getDefault ().annotate (e, DataObject.getString ("EXC_folder_delete_failed")); // NOI18N newFile = getPrimaryEntry ().getFile ();
if (isSerialized ()) { // NOI18N InputStream is = instanceOrigin ().getInputStream (); try { clazz = readClass (is); (ex, ErrorManager.UNKNOWN, "From file: " + entry.getFile(), null, null, null); // NOI18N clazzException = ex; throw ex; } catch (ClassNotFoundException ex) { ErrorManager.getDefault().annotate (ex, ErrorManager.UNKNOWN, "From file: " + entry.getFile(), null, null, null); // NOI18N clazzException = ex; throw ex; } catch (RuntimeException re) { clazzException = new ClassNotFoundException("From file: " + entry.getFile() + " due to: " + re.toString()); // NOI18N ErrorManager.getDefault ().annotate (clazzException, re); throw (ClassNotFoundException) clazzException; } catch (LinkageError le) { clazzException = new ClassNotFoundException("From file: " + entry.getFile() + " due to: " + le.toString()); // NOI18N ErrorManager.getDefault ().annotate (clazzException, le); throw (ClassNotFoundException) clazzException;
/** Try to lock this file entry. * @return the lock if the operation was successful; otherwise <code>null</code> * @throws IOException if the lock could not be taken */ public FileLock takeLock() throws IOException { FileLock l = lock == null ? null : (FileLock)lock.get (); if (l == null || !l.isValid ()){ l = getFile ().lock (); lock = new WeakReference (l); } return l; }
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); }
@Override public List<URL> getResourceFiles(FileObject srcFile) { PropertiesDataObject dobj = ResourceUtils.getPropertiesDataObject(srcFile); if (dobj != null) { try { List<URL> list = new ArrayList<URL>(); list.add(dobj.getPrimaryEntry().getFile().getURL()); for (MultiDataObject.Entry e : dobj.secondaryEntries()) { list.add(e.getFile().getURL()); } return list; } catch (IOException ex) { Logger.getLogger(ResourceServiceImpl.class.getName()).log(Level.INFO, null, ex); // NOI18N } } return Collections.emptyList(); } }
/** 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 (); }
/** Lock the file to edit. * Should be taken from the file entry if possible, helpful during * e.g. deletion of the file. * @return a lock on the primary file normally * @throws IOException if the lock could not be taken */ protected FileLock takeLock() throws java.io.IOException { return ((JSFConfigDataObject) getDataObject()).getPrimaryEntry().takeLock(); }
/** Lock the file to edit. * Should be taken from the file entry if possible, helpful during * e.g. deletion of the file. * @return a lock on the primary file normally * @throws IOException if the lock could not be taken */ protected FileLock takeLock () throws java.io.IOException { return ((TLDDataObject) getDataObject ()).getPrimaryEntry ().takeLock (); }
Pair(MultiDataObject.Entry e) { entry = e; file = e.getFile (); } }
/** 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; }
/** Returns the origin of the instance. * @return the origin */ public FileObject instanceOrigin () { // return getEntry ().getFile (); return entry.getFile (); }
/** Remove a secondary entry from the list. * @param fe the entry to remove */ protected final void removeSecondaryEntry (Entry fe) { synchronized (getSecondary()) { getSecondary().remove (fe.getFile ()); } firePropertyChangeLater (PROP_FILES, null, null); if (fe.isImportant ()) { checkConsistency(this); } }