001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: FileNodeFS.java$
021: * $FileID: 4432$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 4/23/03 5:17 PM$
026: * $Comment: $
027: *
028: * $KeyWordsOff: $
029: */
030:
031: package org.sourcejammer.project.model.filesys;
032:
033: import org.sourcejammer.project.controller.FileNode;
034: import org.sourcejammer.project.controller.VersionNode;
035: import org.sourcejammer.project.NodeList;
036: import org.sourcejammer.project.controller.NoSuchVersionException;
037: import org.sourcejammer.project.NodeDoesNotExistException;
038: import org.sourcejammer.util.ConfigurationException;
039: import org.sourcejammer.util.ProcessTimer;
040:
041: import java.util.Date;
042: import java.io.IOException;
043: import org.sourcejammer.project.ArchiveInfoFlex;
044: import org.sourcejammer.project.model.FileAccessException;
045: import org.w3c.dom.Document;
046: import org.sourcejammer.util.AppConfig;
047: import org.sourcejammer.project.NodeIterator;
048: import org.sourcejammer.server.security.SecurityException;
049: import org.sourcejammer.project.controller.ProjectNode;
050: import org.sourcejammer.project.NodeExistsException;
051: import org.sourcejammer.project.controller.ControllerNode;
052:
053: /**
054: * Title: SourceJammer v 0.1.0
055: * Description:
056: * Copyright: Copyright (c) 2001
057: * Company:
058: * @author Robert MacGrogan
059: * @version 1.0
060: */
061:
062: public class FileNodeFS extends FileNode implements NodeFS {
063:
064: private String msFileName;
065: private long mlFileSysKey = -1;
066: private boolean mbReadOnly = false;
067:
068: public FileNodeFS() {
069: super ();
070: }
071:
072: public void setReadOnly() {
073: mbReadOnly = true;
074: }
075:
076: public boolean isReadOnly() {
077: return mbReadOnly;
078: }
079:
080: /**
081: * Override the super class method to check if node is read-only. If so,
082: * SecurityException is thrown.
083: */
084: public synchronized void lock(long key) throws SecurityException {
085: if (mbReadOnly) {
086: throw new SecurityException(
087: "This node is read-only and cannot be locked.");
088: }
089: super .lock(key);
090: }
091:
092: /**
093: * Sets the name to the file used by filesys implementation to
094: * store info on this Node.
095: */
096: public void setFileName(String s, long key) {
097: checkKey(key);
098: msFileName = s;
099: }
100:
101: /**
102: * Gets the name of the file used by the filesys implementation to
103: * store info on this Node.
104: */
105: public String getFileName() {
106: return msFileName;
107: }
108:
109: /**
110: * Creates and stores the XML file for this Node.
111: */
112: public void store(long key, ArchiveInfoFlex info)
113: throws FileAccessException {
114: checkKey(key);
115: //System.out.println("file - store");
116: ArchiveInfoFlexFS oInfo = (ArchiveInfoFlexFS) info;
117: //System.out.println("file - got archive info");
118: Document this Doc = XMLUtilFS.fileNodeToXML(this );
119: //System.out.println("file - got doc");
120: String sSwitch = java.io.File.separator;
121: String sFullPath = oInfo.getPathToArchiveRoot() + sSwitch
122: + Util.Directories.FILE + sSwitch + msFileName;
123: //System.out.println("file - got path");
124: //ProcessTimer.getDefaultInstance().beginProcess("Update File View: " + getUniqueID());
125: updateLightweightViewString();
126: //ProcessTimer.getDefaultInstance().endProcess("Update File View: " + getUniqueID());
127: try {
128: //System.out.println("file - try to write file");
129: Util.writeXMLDocToFileSys(this Doc, sFullPath);
130: //System.out.println("file - file written successfully");
131: } catch (IOException ex) {
132: throw new FileAccessException(
133: "Could not save file information.", ex);
134: }
135: }
136:
137: /*
138: * Refresh this node and all children from model storage.
139: */
140: /*
141: public void refresh(long key, ArchiveInfo info) throws FileAccessException {
142: checkKey(key);
143: try {
144: ArchiveInfoFS oInfo = (ArchiveInfoFS)info;
145: Util.readFileNodeFromFileSys(oInfo.getPathToArchiveRoot(), msFileName, key, this);
146: }
147: catch (IOException ex){
148: throw new FileAccessException("Could not access file info on filesystem.", ex);
149: }
150: catch (org.xml.sax.SAXException ex){
151: throw new FileAccessException("Unable to parse file node xml.", ex);
152: }
153: catch (org.sourcejammer.xml.XMLNodeDoesNotExistException ex){
154: throw new FileAccessException("Unable to parse file node xml.", ex);
155: }
156: }
157: */
158:
159: public void setFileSysKey(long l) {
160: mlFileSysKey = l;
161: }
162:
163: public long getFileSysKey() {
164: return mlFileSysKey;
165: }
166:
167: }
|