alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.vcscore.cache;


import java.io.*;
import java.lang.ref.*;
import java.util.Set;
import java.util.HashSet;
import org.openide.filesystems.FileObject;

/**
 * Basic object that's stored in the cache. The filesystem can subclass it to create 
 * it's own interpretaion of a file in filesystem.
 * 

* All persistent information should be stored in PersistentData class. * * @author mkleint * @version */ public class CacheFile extends java.lang.Object { private PersistentData data; /** cacheID of the cache where this file belongs to */ protected String parentCache; private CacheDir parent; /** the reference object associated with this file * protected Reference reference; private Set referenceSet; */ /** Creates new CacheFile */ public CacheFile(String memberOfCache, PersistentData data) { setCacheName(memberOfCache); this.data = data; } public CacheFile(String memberOfCache, String name, PersistentData data) { this(memberOfCache, data); data.setName(name); } public final PersistentData getPersistentData() { return data; } /* protected CacheFile createFileFromData(PersistentData data) { return new CacheFile(getCacheName(), data); } */ /** set parent of this file.. in 99% cases it means it's parent directory * @param par - directory where this file resides. */ protected void setParent(CacheDir par) { parent = par; } /* returns it's parent directory.. note that most file manipulation is triggered fromthe dir object * */ public CacheDir getParent() { return parent; } /** return the file's name */ public String getName() { return data.getName(); } /** sets the file's name */ public void setName(String name) { //System.out.println(" cache file name = '"+name+"'"); data.setName(name); } /** * @return true when the file is local (not in VCS repository). */ public boolean isLocal() { return data.isLocal(); } /** returns the file's status */ public String getStatus() { return data.getStatus(); } /** sets the file's status */ public void setStatus(String status) { data.setStatus(status); } /** Returns the current revision of the file. */ public String getRevision() { return data.getRevision(); } /** Sets the current revision of the file. */ public void setRevision(String revision) { data.setRevision(revision); } /** Returns the current sticky information of the file. */ public String getSticky() { return data.getSticky(); } /** Sets the current sticky information of the file. */ public void setSticky(String sticky) { data.setSticky(sticky); } public String getDate() { return data.getDate(); } public void setDate(String date) { data.setDate(date); } public String getTime() { return data.getTime(); } public void setTime(String time) { data.setTime(time); } public String getLocker() { return data.getLocker(); } public void setLocker(String locker) { data.setLocker(locker); } public String getAttr() { return data.getAttr(); } public void setAttr(String attr) { data.setAttr(attr); } public int getSize() { return data.getSize(); } public void setSize(int size) { data.setSize(size); } public String getCacheName() { return parentCache; } public void setCacheName(String cacheName) { parentCache = cacheName; } /** file itself doesn't store the path, we need to access it's parent (directory) */ public String getAbsolutePath() { if (parent != null) { return parent.getAbsolutePath() + File.separator + data.getName(); } else return null; } /** subclasses need to implement this to provide structure and data of the line * that's written to disk cache. * *assumes that it's written into text files* * public final String writeLineToDisk() { return data.writeLineToDisk(); } */ /** * This class contains data, that are persistently stored in a disk cache. * CacheFiles are being held on WeakReferences and thus can be lost any time. * It's assured, that as soon as the CacheFile is lost from memory, the * persistent data are written to the disk so that they can be used to re-construct * the CacheFile in the future. * This class must NOT hold a strong reference to the corresponding CacheFile. */ protected abstract static class PersistentData extends Object { private boolean directory; private String name = ""; // NOI18N private String status = ""; // NOI18N private String locker = ""; // NOI18N private String revision = ""; // NOI18N private String sticky = ""; // NOI18N private String attr = ""; // NOI18N private String date = ""; // NOI18N private String time = ""; // NOI18N private int size = 0; private boolean modified = false; private boolean local = false; public PersistentData(boolean directory) { this.directory = directory; } /** * Write the data into the disk cache. * The data are written only if they are modified. */ public final void writeToDisk() throws IOException { if (isModified()) { doWriteToDisk(); setModified(false); } } /** * Subclasses need to implement this to store the data into disk cache. */ protected abstract void doWriteToDisk() throws IOException; public final boolean isDirectory() { return directory; } /** Getter for property name. * @return Value of property name. */ public final java.lang.String getName() { return name; } /** Setter for property name. * @param name New value of property name. */ public final void setName(java.lang.String name) { if (!this.name.equals(name)) { setModified(true); this.name = name; } } /** Getter for property status. * @return Value of property status. */ public final java.lang.String getStatus() { return status; } /** Setter for property status. * @param status New value of property status. */ public final void setStatus(java.lang.String status) { if (this.status == null && status != null || this.status != null && !this.status.equals(status)) { setModified(true); this.status = status; } } /** Getter for property locker. * @return Value of property locker. */ public final java.lang.String getLocker() { return locker; } /** Setter for property locker. * @param locker New value of property locker. */ public final void setLocker(java.lang.String locker) { if (this.locker == null && locker != null || this.locker != null && !this.locker.equals(locker)) { setModified(true); this.locker = locker; } } /** Getter for property revision. * @return Value of property revision. */ public final java.lang.String getRevision() { return revision; } /** Setter for property revision. * @param revision New value of property revision. */ public final void setRevision(java.lang.String revision) { if (this.revision == null && revision != null || this.revision != null && !this.revision.equals(revision)) { setModified(true); this.revision = revision; } } /** Getter for property sticky. * @return Value of property sticky. */ public final java.lang.String getSticky() { return sticky; } /** Setter for property sticky. * @param sticky New value of property sticky. */ public final void setSticky(java.lang.String sticky) { if (this.sticky == null && sticky != null || this.sticky != null && !this.sticky.equals(sticky)) { setModified(true); this.sticky = sticky; } } /** Getter for property attr. * @return Value of property attr. */ public final java.lang.String getAttr() { return attr; } /** Setter for property attr. * @param attr New value of property attr. */ public final void setAttr(java.lang.String attr) { if (this.attr == null && attr != null || this.attr != null && !this.attr.equals(attr)) { setModified(true); this.attr = attr; } } /** Getter for property date. * @return Value of property date. */ public final java.lang.String getDate() { return date; } /** Setter for property date. * @param date New value of property date. */ public final void setDate(java.lang.String date) { if (this.date == null && date != null || this.date != null && !this.date.equals(date)) { setModified(true); this.date = date; } } /** Getter for property time. * @return Value of property time. */ public final java.lang.String getTime() { return time; } /** Setter for property time. * @param time New value of property time. */ public final void setTime(java.lang.String time) { if (this.time == null && time != null || this.time != null && !this.time.equals(time)) { setModified(true); this.time = time; } } /** Getter for property size. * @return Value of property size. */ public final int getSize() { return size; } /** Setter for property size. * @param size New value of property size. */ public final void setSize(int size) { if (this.size != size) { setModified(true); this.size = size; } } /** Getter for property modified. The data are to be written to disk only * if they are modified. * @return Value of property modified. */ public final boolean isModified() { return modified; } /** Setter for property modified. * @param modified New value of property modified. */ public final void setModified(boolean modified) { //System.out.println("PersistentData("+this.toString()+")\n set as "+(modified ? "MODIFIED" : "UNModified")); this.modified = modified; } public final boolean isLocal() { return local; } public final void setLocal(boolean local) { //System.out.println("DATA \""+getName()+"\" set "+(local ? "LOCAL" : "NON Local")); this.local = local; } public String toString() { return ((directory) ? "DIR[" : "FILE[") + name + ", " + ((modified) ? "MODIFIED, " : "NON-MODIFIED, ") + status + ", " + locker + ", " + revision + ", " + sticky + ", " + attr + ", " + date + ", " + time + ", " + size + "]" + ((this.isLocal()) ? " IS LOCAL." : " NON Local"); } } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.