diff --git a/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java b/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java index b3990eb92e6f87470f3a4d7decf4a45ffa228aca..fba83e40ebd9c4d3d87817773af9ba14ae281ccd 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java +++ b/bindings/java/src/org/sleuthkit/datamodel/BlackboardArtifact.java @@ -900,6 +900,21 @@ public String toString() { return "BlackboardArtifact{" + "artifactID=" + artifactId + ", objID=" + getObjectID() + ", artifactObjID=" + artifactObjId + ", artifactTypeID=" + artifactTypeId + ", artifactTypeName=" + artifactTypeName + ", displayName=" + displayName + ", Case=" + getSleuthkitCase() + '}'; //NON-NLS } + /** + * Accepts a visitor SleuthkitItemVisitor that will perform an operation on + * this artifact type and return some object as the result of the operation. + * + * @param visitor The visitor, where the type parameter of the visitor is + * the type of the object that will be returned as the result + * of the visit operation. + * + * @return An object of type T. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Get the (reported) size of the content object. Artifact content is a * string dump of all its attributes. @@ -1579,7 +1594,7 @@ public int hashCode() { * http://sleuthkit.org/sleuthkit/docs/jni-docs/latest/artifact_catalog_page.html * for details on the standard attributes for each artifact type. */ - public enum ARTIFACT_TYPE { + public enum ARTIFACT_TYPE implements SleuthkitVisitableItem { /** * A generic information artifact. @@ -2101,6 +2116,23 @@ static public ARTIFACT_TYPE fromID(int id) { public String getDisplayName() { return displayName; } + + /** + * Accepts a visitor SleuthkitItemVisitor that will perform an operation + * on this artifact type and return some object as the result of the + * operation. + * + * @param visitor The visitor, where the type parameter of the visitor + * is the type of the object that will be returned as the + * result of the visit operation. + * + * @return An object of type T. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + } /** diff --git a/bindings/java/src/org/sleuthkit/datamodel/Content.java b/bindings/java/src/org/sleuthkit/datamodel/Content.java index a8779ad1e6cd6f8abb451e840e316f54c2fa0a6e..5993ac460165046abba1e0ec0cf1603f181e397a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Content.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Content.java @@ -30,7 +30,7 @@ * interface defines the basic methods for reading the content associated with * this object, the parent and children, and adding artifacts. */ -public interface Content { +public interface Content extends SleuthkitVisitableItem { /** * Reads data that this content object is associated with (file contents, diff --git a/bindings/java/src/org/sleuthkit/datamodel/ContentVisitor.java b/bindings/java/src/org/sleuthkit/datamodel/ContentVisitor.java index 875f9bad1345c4f950b256fee791e071e9f295d3..7d922b9f126955745f0717dcdfcaccbde3728d71 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/ContentVisitor.java +++ b/bindings/java/src/org/sleuthkit/datamodel/ContentVisitor.java @@ -66,7 +66,7 @@ public interface ContentVisitor<T> { * @return result of the visit */ T visit(Image i); - + /** * Act on (visit) a Pool content object * @@ -74,7 +74,7 @@ public interface ContentVisitor<T> { * * @return result of the visit */ - T visit(Pool p); + T visit(Pool p); /** * Act on (visit) a Volume content object @@ -111,7 +111,7 @@ public interface ContentVisitor<T> { * @return result of the visit */ T visit(VirtualDirectory vd); - + /** * Act on (visit) a LocalDirectory content object * @@ -119,7 +119,7 @@ public interface ContentVisitor<T> { * * @return result of the visit */ - T visit(LocalDirectory ld); + T visit(LocalDirectory ld); /** * Act on (visit) a DerivedFile content object @@ -138,7 +138,7 @@ public interface ContentVisitor<T> { * @return result of the visit */ T visit(LocalFile df); - + /** * Act on (visit) a SlackFile content object * @@ -146,7 +146,7 @@ public interface ContentVisitor<T> { * * @return result of the visit */ - T visit(SlackFile sf); + T visit(SlackFile sf); /** * Act on (visit) a blackboard artifact object @@ -155,17 +155,8 @@ public interface ContentVisitor<T> { * * @return result of the visit */ - T visit(BlackboardArtifact ba); - - /** - * Act on (visit) a local files data source object - * - * @param ds The local files data source object - * - * @return result of the visit - */ - T visit(LocalFilesDataSource lfds); - + T visit(BlackboardArtifact ba); + /** * Act on (visit) a Report object * @@ -174,7 +165,7 @@ public interface ContentVisitor<T> { * @return result of the visit */ T visit(Report r); - + /** * Act on (visit) a OsAccount object * @@ -183,7 +174,7 @@ public interface ContentVisitor<T> { * @return result of the visit */ T visit(OsAccount act); - + /** * Act on (visit) an UnsupportedContent object * @@ -231,7 +222,7 @@ public T visit(Image i) { public T visit(Volume v) { return defaultVisit(v); } - + @Override public T visit(Pool p) { return defaultVisit(p); @@ -251,7 +242,7 @@ public T visit(LayoutFile lf) { public T visit(VirtualDirectory ld) { return defaultVisit(ld); } - + @Override public T visit(LocalDirectory ld) { return defaultVisit(ld); @@ -266,32 +257,27 @@ public T visit(DerivedFile df) { public T visit(LocalFile lf) { return defaultVisit(lf); } - + @Override public T visit(SlackFile sf) { return defaultVisit(sf); } - + @Override public T visit(BlackboardArtifact ba) { return defaultVisit(ba); } - @Override - public T visit(LocalFilesDataSource lfds) { - return defaultVisit(lfds); - } - @Override public T visit(Report r) { return defaultVisit(r); } - + @Override public T visit(OsAccount act) { return defaultVisit(act); } - + @Override public T visit(UnsupportedContent uc) { return defaultVisit(uc); diff --git a/bindings/java/src/org/sleuthkit/datamodel/DerivedFile.java b/bindings/java/src/org/sleuthkit/datamodel/DerivedFile.java index c06dab73054d4c161d5816d1f692d30e3675ab5e..274100654d9bd2a3787e447f96822a6def9f8172 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/DerivedFile.java +++ b/bindings/java/src/org/sleuthkit/datamodel/DerivedFile.java @@ -150,6 +150,19 @@ public synchronized DerivedMethod getDerivedMethod() throws TskCoreException { return derivedMethod; } + /** + * Accepts a content visitor (Visitor design pattern). + * + * @param visitor A ContentVisitor supplying an algorithm to run using this + * derived file as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + /** * Accepts a Sleuthkit item visitor (Visitor design pattern). * diff --git a/bindings/java/src/org/sleuthkit/datamodel/Directory.java b/bindings/java/src/org/sleuthkit/datamodel/Directory.java index ffebd6b2ce59d7859936b889f6bad51f45d016bb..f0d376b381093971ca36fde7624365117502bda0 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Directory.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Directory.java @@ -94,6 +94,19 @@ public class Directory extends FsContent { super(db, objId, dataSourceObjectId, fsObjId, attrType, attrId, name, TskData.TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, sha256Hash, knownState, parentPath, null, null, ownerUid, osAccountObjId, Collections.emptyList()); } + /** + * Accepts a content visitor (Visitor design pattern). + * + * @param visitor A ContentVisitor supplying an algorithm to run using this + * directory as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + /** * Accepts a Sleuthkit item visitor (Visitor design pattern). * diff --git a/bindings/java/src/org/sleuthkit/datamodel/File.java b/bindings/java/src/org/sleuthkit/datamodel/File.java index f3da36861ea3eaf75bfced09b56fb68d50238d4c..659ed70acdee84c323b760f6a1a7f7915be6196b 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/File.java +++ b/bindings/java/src/org/sleuthkit/datamodel/File.java @@ -102,6 +102,19 @@ public class File extends FsContent { super(db, objId, dataSourceObjectId, fsObjId, attrType, attrId, name, TskData.TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, sha256Hash, knownState, parentPath, mimeType, extension, ownerUid, osAccountObjId, fileAttributes); } + /** + * Accepts a content visitor (Visitor design pattern). + * + * @param visitor A ContentVisitor supplying an algorithm to run using this + * file as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Accepts a Sleuthkit item visitor (Visitor design pattern). * diff --git a/bindings/java/src/org/sleuthkit/datamodel/FileSystem.java b/bindings/java/src/org/sleuthkit/datamodel/FileSystem.java index 25ce946a4ae0ccacd1a0a4703b98115beadcddac..d20f8b7df1b3dc5c8a62bef7677201a5badfca50 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/FileSystem.java +++ b/bindings/java/src/org/sleuthkit/datamodel/FileSystem.java @@ -207,6 +207,11 @@ public void finalize() throws Throwable { } } + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + @Override public <T> T accept(ContentVisitor<T> v) { return v.visit(this); diff --git a/bindings/java/src/org/sleuthkit/datamodel/HostAddress.java b/bindings/java/src/org/sleuthkit/datamodel/HostAddress.java index 191c759dec969d1b20ebac8b6b5a774471e77a01..4b545baee03e78c3acffffa4bc79432bcdafb160 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/HostAddress.java +++ b/bindings/java/src/org/sleuthkit/datamodel/HostAddress.java @@ -128,6 +128,12 @@ public <T> T accept(ContentVisitor<T> v) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + // TODO + throw new UnsupportedOperationException("Not supported yet."); + } + /** * A host may have different types of addresses at a given point in time. */ diff --git a/bindings/java/src/org/sleuthkit/datamodel/Image.java b/bindings/java/src/org/sleuthkit/datamodel/Image.java index 670449a00b34979270bc8f34b58b25782b395b04..7e2d793a29e1749b0d4b4aa192334d73fa4def6b 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Image.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Image.java @@ -275,6 +275,11 @@ public String getTimeZone() { return timezone; } + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + @Override public <T> T accept(ContentVisitor<T> v) { return v.visit(this); diff --git a/bindings/java/src/org/sleuthkit/datamodel/LayoutFile.java b/bindings/java/src/org/sleuthkit/datamodel/LayoutFile.java index 39a4709c42457df76017af04db46ccea745c5256..311dc8318c13ede3efd642e1a5ba462b760a35f1 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/LayoutFile.java +++ b/bindings/java/src/org/sleuthkit/datamodel/LayoutFile.java @@ -230,6 +230,19 @@ public <T> T accept(ContentVisitor<T> visitor) { return visitor.visit(this); } + /** + * Accepts a Sleuthkit item visitor (Visitor design pattern). + * + * @param visitor A SleuthkitItemVisitor supplying an algorithm to run using + * this file as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Provides a string representation of this file. * diff --git a/bindings/java/src/org/sleuthkit/datamodel/LocalDirectory.java b/bindings/java/src/org/sleuthkit/datamodel/LocalDirectory.java index 1183899ead5d5c68e832dd2fc54a54f53277052e..2b90de8309f22a8eb2bb955eed25fcad127cdb94 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/LocalDirectory.java +++ b/bindings/java/src/org/sleuthkit/datamodel/LocalDirectory.java @@ -109,6 +109,19 @@ public <T> T accept(ContentVisitor<T> visitor) { return visitor.visit(this); } + /** + * Accepts a Sleuthkit item visitor (Visitor design pattern). + * + * @param visitor A SleuthkitItemVisitor supplying an algorithm to run using + * this local directory as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Provides a string representation of this local directory. * diff --git a/bindings/java/src/org/sleuthkit/datamodel/LocalFile.java b/bindings/java/src/org/sleuthkit/datamodel/LocalFile.java index 405e2e19959e0acd2c43b15e2eff8a34779f37d7..1e5dcf6bfebe504e85e335473b01821de1e1c99d 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/LocalFile.java +++ b/bindings/java/src/org/sleuthkit/datamodel/LocalFile.java @@ -146,6 +146,20 @@ public <T> T accept(ContentVisitor<T> visitor) { return visitor.visit(this); } + /** + * Accepts a Sleuthkit item visitor (Visitor design pattern). + * + * @param <T> The type returned by the visitor. + * @param visitor A SleuthkitItemVisitor supplying an algorithm to run using + * this local file as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Provides a string representation of this local file. * diff --git a/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java b/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java index 96a99de8d63c403cc464c95d4bde2c4f92c82c35..871d292c908370887f1e28fd124a4beebfc03b9a 100755 --- a/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java +++ b/bindings/java/src/org/sleuthkit/datamodel/LocalFilesDataSource.java @@ -333,6 +333,20 @@ public <T> T accept(ContentVisitor<T> visitor) { return visitor.visit(this); } + /** + * Accepts a Sleuthkit item visitor (Visitor design pattern). + * + * @param <T> The type returned by the visitor. + * @param visitor A SleuthkitItemVisitor supplying an algorithm to run using + * this virtual directory as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Constructs a local/logical files and/or directories data source. * diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java index feb54bfc48ae340f088e78bd70f665325531db41..d78434f4c3e7efcc660b4b4df9ca32d33b6c770a 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java +++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccount.java @@ -399,6 +399,11 @@ public <T> T accept(ContentVisitor<T> v) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + /** * Abstracts attributes of an OS account. An attribute may be specific to a * host, or applicable across all hosts. diff --git a/bindings/java/src/org/sleuthkit/datamodel/Pool.java b/bindings/java/src/org/sleuthkit/datamodel/Pool.java index 436d58a215db637f435a5aaf0e04271a5a54d8e4..2a6e712e73b78ab596db12640e3b52d01e6f2c2e 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Pool.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Pool.java @@ -133,6 +133,11 @@ protected void finalize() throws Throwable { } } + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + @Override public <T> T accept(ContentVisitor<T> v) { return v.visit(this); diff --git a/bindings/java/src/org/sleuthkit/datamodel/Report.java b/bindings/java/src/org/sleuthkit/datamodel/Report.java index 089363d4acfac0999b1cc9cc1ca0b3a20d28c4e6..3b6928cfa7a6f8338fceca799502a1d28efce196 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Report.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Report.java @@ -403,4 +403,9 @@ public long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type) throws TskC public long getAllArtifactsCount() throws TskCoreException { return db.getBlackboardArtifactsCount(objectId); } + + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } } diff --git a/bindings/java/src/org/sleuthkit/datamodel/SlackFile.java b/bindings/java/src/org/sleuthkit/datamodel/SlackFile.java index e0350d5a91f17856519c4b76134f6d61cd67d327..8cf9407e5c3209787c76fbf27684b59824041c33 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/SlackFile.java +++ b/bindings/java/src/org/sleuthkit/datamodel/SlackFile.java @@ -124,6 +124,19 @@ protected int readInt(byte[] buf, long offset, long len) throws TskCoreException return SleuthkitJNI.readFileSlack(fileHandle, buf, offset, len); } + /** + * Accepts a content visitor (Visitor design pattern). + * + * @param v A ContentVisitor supplying an algorithm to run using this file + * as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + /** * Accepts a Sleuthkit item visitor (Visitor design pattern). * diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitItemVisitor.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitItemVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..5e90113f99b0647e451fb2d5cef4c80cca79a0b2 --- /dev/null +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitItemVisitor.java @@ -0,0 +1,316 @@ +/* + * Sleuth Kit Data Model + * + * Copyright 2011-2021 Basis Technology Corp. + * Contact: carrier <at> sleuthkit <dot> org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.datamodel; + +/** + * Interface for implementing a visitor pattern on all displayable items: + * Content implementations and blackboard artifacts. + * + * Visitor implements an algorithm on the content and blackboard artifacts + * objects. The algorithm is completely decoupled from the data object. The + * visitor pattern emulates double dispatch mechanism. It allows to act + * differently depending on the instance type, without need to test what the + * actual type is. E.g. it allows for processing an object hierarchy without + * using instanceof statements. Generic type parameter T is a return type from + * the visit methods. + * + * @param <T> return type of visit methods + */ +public interface SleuthkitItemVisitor<T> { + + /** + * Act on (visit) a Directory content object + * + * @param d the directory to visit / act on + * + * @return result of the visit + */ + T visit(Directory d); + + /** + * Act on (visit) a File content object + * + * @param f the file to visit / act on + * + * @return result of the visit + */ + T visit(File f); + + /** + * Act on (visit) a FileSystem content object + * + * @param fs the filesystem to visit / act on + * + * @return result of the visit + */ + T visit(FileSystem fs); + + /** + * Act on (visit) an Image content object + * + * @param i the image to visit / act on + * + * @return result of the visit + */ + T visit(Image i); + + /** + * Act on (visit) a Volume content object + * + * @param v the volume to visit / act on + * + * @return result of the visit + */ + T visit(Volume v); + + /** + * Act on (visit) a VolumeSystem content object + * + * @param vs the volume system to visit / act on + * + * @return result of the visit + */ + T visit(VolumeSystem vs); + + /** + * Act on (visit) a Pool content object + * + * @param pool the volume system to visit / act on + * + * @return result of the visit + */ + T visit(Pool pool); + + /** + * Act on (visit) a blackboard artifact object + * + * @param ba blackboard artifact object to visit / act on + * + * @return result of the visit + */ + T visit(BlackboardArtifact ba); + + /** + * Act on (visit) a blackboard artifact type + * + * @param tw blackboard artifact type to visit / act on + * + * @return result of the visit + */ + T visit(BlackboardArtifact.ARTIFACT_TYPE tw); + + /** + * Act on (visit) a layout file content object + * + * @param lf layout file to visit / act on + * + * @return result of the visit + */ + T visit(LayoutFile lf); + + /** + * Act on (visit) a VirtualDirectory content object + * + * @param ld layout dir to visit / act on + * + * @return result of the visit + */ + T visit(VirtualDirectory ld); + + /** + * Act on (visit) a LocalDirectory content object + * + * @param ld layout dir to visit / act on + * + * @return result of the visit + */ + T visit(LocalDirectory ld); + + /** + * Act on (visit) a DerivedFile content object + * + * @param df derived file to visit / act on + * + * @return result of the visit + */ + T visit(DerivedFile df); + + /** + * Act on (visit) a LocalFile content object + * + * @param lf local file to visit / act on + * + * @return result of the visit + */ + T visit(LocalFile lf); + + /** + * Act on (visit) a SlackFile content object + * + * @param sf slack file to visit / act on + * + * @return result of the visit + */ + T visit(SlackFile sf); + + /** + * Act on (visit) a Report content object + * + * @param report report to visit / act on + * + * @return result of the visit + */ + T visit(Report report); + + /** + * Act on (visit) a OsAccount content object + * + * @param account report to visit / act on + * + * @return result of the visit + */ + T visit(OsAccount account); + + /** + * Act on (visit) an UnsupportedContent object + * + * @param unsupportedContent content to visit / act on + * + * @return result of the visit + */ + T visit(UnsupportedContent unsupportedContent); + + /** + * Act on (visit) a LocalFilesDataSource content object + * + * @param localFilesDataSource report to visit / act on + * + * @return result of the visit + */ + T visit(LocalFilesDataSource localFilesDataSource); + + /** + * The default visitor - quickest method for implementing a custom visitor. + * Every visit method delegates to the defaultVisit method, the only + * required method to be implemented. Then, implement the specific visit + * methods for the objects on which the algorithm needs to act differently. + * + * @param <T> generic type, signifies the object type to be returned from + * visit() + */ + static abstract public class Default<T> implements SleuthkitItemVisitor<T> { + + protected abstract T defaultVisit(SleuthkitVisitableItem s); + + @Override + public T visit(Directory d) { + return defaultVisit(d); + } + + @Override + public T visit(File f) { + return defaultVisit(f); + } + + @Override + public T visit(FileSystem fs) { + return defaultVisit(fs); + } + + @Override + public T visit(Image i) { + return defaultVisit(i); + } + + @Override + public T visit(Volume v) { + return defaultVisit(v); + } + + @Override + public T visit(VolumeSystem vs) { + return defaultVisit(vs); + } + + @Override + public T visit(Pool p) { + return defaultVisit(p); + } + + @Override + public T visit(BlackboardArtifact ba) { + return defaultVisit(ba); + } + + @Override + public T visit(BlackboardArtifact.ARTIFACT_TYPE tw) { + return defaultVisit(tw); + } + + @Override + public T visit(LayoutFile lf) { + return defaultVisit(lf); + } + + @Override + public T visit(VirtualDirectory vd) { + return defaultVisit(vd); + } + + @Override + public T visit(LocalDirectory ld) { + return defaultVisit(ld); + } + + @Override + public T visit(DerivedFile df) { + return defaultVisit(df); + } + + @Override + public T visit(LocalFile lf) { + return defaultVisit(lf); + } + + @Override + public T visit(SlackFile sf) { + return defaultVisit(sf); + } + + @Override + public T visit(Report report) { + return defaultVisit(report); + } + + @Override + public T visit(OsAccount account) { + return defaultVisit(account); + } + + @Override + public T visit(UnsupportedContent unsupportedContent) { + return defaultVisit(unsupportedContent); + } + + @Override + public T visit(LocalFilesDataSource localFilesDataSource) { + return defaultVisit(localFilesDataSource); + } + } +} diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitVisitableItem.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitVisitableItem.java new file mode 100644 index 0000000000000000000000000000000000000000..ed17d61d71d567db2bea40745c95888fceaf41e0 --- /dev/null +++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitVisitableItem.java @@ -0,0 +1,35 @@ +/* + * Sleuth Kit Data Model + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier <at> sleuthkit <dot> org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.datamodel; + +/** + * Interface for all visitable datatypes that can be found in the tsk database + */ +public interface SleuthkitVisitableItem { + + /** + * visitor pattern support + * + * @param v visitor + * + * @return visitor return value + */ + public <T> T accept(SleuthkitItemVisitor<T> v); + +} diff --git a/bindings/java/src/org/sleuthkit/datamodel/UnsupportedContent.java b/bindings/java/src/org/sleuthkit/datamodel/UnsupportedContent.java index 120a4988c75a89cf8d11476501c3338585c40492..d9bbca1bdd7b59ada02ad29b51d762789b4ceedd 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/UnsupportedContent.java +++ b/bindings/java/src/org/sleuthkit/datamodel/UnsupportedContent.java @@ -55,4 +55,9 @@ public long getSize() { public <T> T accept(ContentVisitor<T> v) { return v.visit(this); } + + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } } diff --git a/bindings/java/src/org/sleuthkit/datamodel/VirtualDirectory.java b/bindings/java/src/org/sleuthkit/datamodel/VirtualDirectory.java index 4c22cc7288557c4da8f49331160b02f81cb10747..7d2c4519e411cc90be76db10743113d220046501 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/VirtualDirectory.java +++ b/bindings/java/src/org/sleuthkit/datamodel/VirtualDirectory.java @@ -117,6 +117,20 @@ public <T> T accept(ContentVisitor<T> visitor) { return visitor.visit(this); } + /** + * Accepts a Sleuthkit item visitor (Visitor design pattern). + * + * @param <T> The type returned by the visitor. + * @param visitor A SleuthkitItemVisitor supplying an algorithm to run using + * this virtual directory as input. + * + * @return The output of the algorithm. + */ + @Override + public <T> T accept(SleuthkitItemVisitor<T> visitor) { + return visitor.visit(this); + } + /** * Provides a string representation of this virtual directory. * diff --git a/bindings/java/src/org/sleuthkit/datamodel/Volume.java b/bindings/java/src/org/sleuthkit/datamodel/Volume.java index 6d07dd9f433a9089c38cf280959de24ee815dd78..f63557cda0ff82367d2a5a5cc83984def62236e1 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Volume.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Volume.java @@ -255,6 +255,11 @@ public static String vsFlagToString(long vsFlag) { return result; } + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } + @Override public <T> T accept(ContentVisitor<T> v) { return v.visit(this); diff --git a/bindings/java/src/org/sleuthkit/datamodel/VolumeSystem.java b/bindings/java/src/org/sleuthkit/datamodel/VolumeSystem.java index 7b1f74d7dd606b157f6052106a65408a00804d25..e403576142eb9d389bcf627e1395b82cdf9b396f 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/VolumeSystem.java +++ b/bindings/java/src/org/sleuthkit/datamodel/VolumeSystem.java @@ -131,6 +131,11 @@ public void finalize() throws Throwable { super.finalize(); } } + + @Override + public <T> T accept(SleuthkitItemVisitor<T> v) { + return v.visit(this); + } @Override public <T> T accept(ContentVisitor<T> v) {