diff --git a/bds/source/java/ch/systemsx/cisd/bds/.gitignore b/bds/source/java/ch/systemsx/cisd/bds/.gitignore deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructure.java b/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructure.java new file mode 100644 index 0000000000000000000000000000000000000000..b06ae5a928feead895c22e923daff7b7cbc59077 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructure.java @@ -0,0 +1,39 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * + * + * @author Franz-Josef Elmer + */ +public abstract class AbstractDataStructure implements IDataStructure +{ + private final String name; + + public AbstractDataStructure(String name) + { + assert name != null && name.length() > 0: "Unspecified name"; + this.name = name; + } + + public String getName() + { + return name; + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructureFactory.java b/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructureFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..bc9f10dfbf2d954041be7f8ab047fcb6dde2ca16 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructureFactory.java @@ -0,0 +1,36 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +import java.io.File; + +/** + * + * + * @author Franz-Josef Elmer + */ +public abstract class AbstractDataStructureFactory implements IDataStructureFactory +{ + protected final File baseDir; + + public AbstractDataStructureFactory(File baseDir) + { + assert baseDir != null : "Unspecified base directory."; + assert baseDir.isDirectory() : "Is not a directory : " + baseDir.getAbsolutePath(); + this.baseDir = baseDir; + } +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructureV1_0.java b/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructureV1_0.java new file mode 100644 index 0000000000000000000000000000000000000000..8d46c817464f3ba4b2b52ece26dbd926d7946a91 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/AbstractDataStructureV1_0.java @@ -0,0 +1,64 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * + * + * @author Franz-Josef Elmer + */ +public abstract class AbstractDataStructureV1_0 extends AbstractDataStructure implements IDataStructureV1_0 +{ + private static final Version VERSION = new Version(1, 0); + + + private ExperimentIdentifier experimentIdentifier; + + private ProcessingType processingType; + + public AbstractDataStructureV1_0(String name) + { + super(name); + } + + public Version getVersion() + { + return VERSION; + } + + public ExperimentIdentifier getExperimentIdentifier() + { + return experimentIdentifier; + } + + public void setExperimentIdentifier(ExperimentIdentifier id) + { + experimentIdentifier = id; + } + + public ProcessingType getProcessingType() + { + return processingType; + } + + public void setProcessingType(ProcessingType type) + { + processingType = type; + } + + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/Container.java b/bds/source/java/ch/systemsx/cisd/bds/Container.java new file mode 100644 index 0000000000000000000000000000000000000000..950e02163938478222e8447a6dd6d646dd3d126e --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/Container.java @@ -0,0 +1,62 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +import java.io.File; + +import ch.systemsx.cisd.bds.fs.FileDataStructureFactory; +import ch.systemsx.cisd.bds.hdf5.HDF5DataStructureFactory; +import ch.systemsx.cisd.common.exceptions.UserFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class Container +{ + private final File baseDir; + + public Container(File baseDir) + { + assert baseDir != null : "Unspecified base directory."; + assert baseDir.isDirectory() : "Is not a directory : " + baseDir.getAbsolutePath(); + this.baseDir = baseDir; + } + + public IDataStructure load(String name) + { + File file = new File(baseDir, name); + if (file.exists() == false) + { + throw new UserFailureException("No container name '" + name + "' exists in " + baseDir.getAbsolutePath()); + } + IDataStructureFactory dataStructureFactory; + if (file.isDirectory()) + { + dataStructureFactory = new FileDataStructureFactory(baseDir); + } else if (new File(baseDir, name + ".hdf5").exists()) + { + dataStructureFactory = new HDF5DataStructureFactory(baseDir); + } else + { + throw new UserFailureException("Couldn't found appropriate container named '" + name + "' in " + + baseDir.getAbsolutePath()); + } + return dataStructureFactory.createDataStructure(name, null); + } +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/ExperimentIdentifier.java b/bds/source/java/ch/systemsx/cisd/bds/ExperimentIdentifier.java new file mode 100644 index 0000000000000000000000000000000000000000..2020b0cb4687fd5ffcd8ca82f269f6a9b69bf5b9 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/ExperimentIdentifier.java @@ -0,0 +1,101 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Identifier of the experiment which corresponds to the data. This is an immutable but extendable value object class. + * An instance of this class allows unique identification in the database. + * + * @author Franz-Josef Elmer + */ +public class ExperimentIdentifier +{ + private final String groupCode; + private final String projectCode; + private final String experimentCode; + + /** + * Creates an instance for the specified codes of group, project, and experiment. + * + * @param groupCode A non-empty string of the group code. + * @param projectCode A non-empty string of the project code. + * @param experimentCode A non-empty string of the experiment code. + */ + public ExperimentIdentifier(String groupCode, String projectCode, String experimentCode) + { + assert groupCode != null && groupCode.length() > 0 : "Undefined group code"; + this.groupCode = groupCode; + assert projectCode != null && projectCode.length() > 0 : "Undefined project code"; + this.projectCode = projectCode; + assert experimentCode != null && experimentCode.length() > 0 : "Undefined experiment code"; + this.experimentCode = experimentCode; + } + + /** + * Returns the group code; + */ + public final String getGroupCode() + { + return groupCode; + } + + /** + * Returns the project code; + */ + public final String getProjectCode() + { + return projectCode; + } + + /** + * Returns the experiment code; + */ + public final String getExperimentCode() + { + return experimentCode; + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + if (obj instanceof ExperimentIdentifier == false) + { + return false; + } + ExperimentIdentifier id = (ExperimentIdentifier) obj; + return id.groupCode.equals(groupCode) && id.projectCode.equals(projectCode) + && id.experimentCode.equals(experimentCode); + } + + @Override + public int hashCode() + { + return (groupCode.hashCode() * 37 + projectCode.hashCode()) * 37 + experimentCode.hashCode(); + } + + @Override + public String toString() + { + return "[group:" + groupCode + ",project:" + projectCode + ",experiment" + experimentCode; + } + + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IDataStructure.java b/bds/source/java/ch/systemsx/cisd/bds/IDataStructure.java new file mode 100644 index 0000000000000000000000000000000000000000..e8c6b1bc5260518b31a43ac861cc7df3c55e5b5a --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IDataStructure.java @@ -0,0 +1,39 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; + +/** + * Common interface of all versions of data structures. + * + * @author Franz-Josef Elmer + */ +public interface IDataStructure extends IHasVersion +{ + /** + * Returns the name of this data structure. + */ + public String getName(); + + /** + * Save the current structure. + * + * @throws EnvironmentFailureException if it couldn't saved. + */ + public void save() throws EnvironmentFailureException; +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IDataStructureFactory.java b/bds/source/java/ch/systemsx/cisd/bds/IDataStructureFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..9ba3ce97725876025d62f1c5310115d06342b576 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IDataStructureFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; + +/** + * Factory of {@link IDataStructure}. + * + * @author Franz-Josef Elmer + */ +public interface IDataStructureFactory +{ + /** + * Returns the subinterface of {@link IDataStructure} for the specified version. + * + * @throws UserFailureException if this factory can not create a data structure for the specified version. + */ + public Class<? extends IDataStructure> getDataStructureInterfaceFor(Version version) throws UserFailureException; + + /** + * Creates a new data structure of specified name and version. The return object implements the interface + * returned by {@link #getDataStructureInterfaceFor(Version)} for the same value of <code>version</code>. + * + * @throws UserFailureException if this factory can not create a data structure for the specified version. + */ + public IDataStructure createDataStructure(String name, Version version) throws UserFailureException; +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IDataStructureV1_0.java b/bds/source/java/ch/systemsx/cisd/bds/IDataStructureV1_0.java new file mode 100644 index 0000000000000000000000000000000000000000..82219390b36901eda5cbed101254083b8bcb162c --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IDataStructureV1_0.java @@ -0,0 +1,37 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Data structure interface for Version 1.0. + * + * @author Franz-Josef Elmer + */ +public interface IDataStructureV1_0 extends IDataStructure +{ + public IDirectory getOriginalData(); + + public IFormatedData getFormatedData(); + + public ExperimentIdentifier getExperimentIdentifier(); + + public void setExperimentIdentifier(ExperimentIdentifier id); + + public ProcessingType getProcessingType(); + + public void setProcessingType(ProcessingType type); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IDirectory.java b/bds/source/java/ch/systemsx/cisd/bds/IDirectory.java new file mode 100644 index 0000000000000000000000000000000000000000..0b515a5c112ab320d7b9a8368c1e3e48be549710 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IDirectory.java @@ -0,0 +1,35 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +import java.io.File; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface IDirectory extends INode, Iterable<INode> +{ + public void appendNode(INode node); + + public void appendRealFile(File file); + + public void appendKeyValuePair(String key, String value); + + public void appendLink(String name, INode node); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IFile.java b/bds/source/java/ch/systemsx/cisd/bds/IFile.java new file mode 100644 index 0000000000000000000000000000000000000000..1eae746f513a7eb2ffd17adf31a33f25777c0cc8 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IFile.java @@ -0,0 +1,30 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Role of a file with a value (content) of type <code>T</code>. + * + * @author Franz-Josef Elmer + */ +public interface IFile<T> extends INode +{ + /** + * Returns the value (or content) of this file node. + */ + public T getValue(); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IFormat.java b/bds/source/java/ch/systemsx/cisd/bds/IFormat.java new file mode 100644 index 0000000000000000000000000000000000000000..27ecf2dc5d65e1c701ad36c63b6367c534a44413 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IFormat.java @@ -0,0 +1,30 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Format interface. + * + * @author Franz-Josef Elmer + */ +public interface IFormat extends IHasVersion +{ + /** + * Returns the code of this format. + */ + public String getCode(); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IFormatedData.java b/bds/source/java/ch/systemsx/cisd/bds/IFormatedData.java new file mode 100644 index 0000000000000000000000000000000000000000..30a933a6091b532e299bdfb6142f14bd381d5fdf --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IFormatedData.java @@ -0,0 +1,27 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface IFormatedData +{ + public IFormat getFormat(); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IFormatedDataFactory.java b/bds/source/java/ch/systemsx/cisd/bds/IFormatedDataFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..2de4b2fe467b94000809c077b08c7c7a9b58198c --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IFormatedDataFactory.java @@ -0,0 +1,32 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface IFormatedDataFactory +{ + public Class<? extends IFormatedData> getFormatedDataInterfaceFor(IFormat format) throws UserFailureException; + + public IFormatedData createFormatedData(IFormat format) throws UserFailureException; + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/IHasVersion.java b/bds/source/java/ch/systemsx/cisd/bds/IHasVersion.java new file mode 100644 index 0000000000000000000000000000000000000000..de26651829733d3e3802ca5be56f8819ebbc424c --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/IHasVersion.java @@ -0,0 +1,30 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Role to be having a {@link Version}. + * + * @author Franz-Josef Elmer + */ +public interface IHasVersion +{ + /** + * Returns the version. + */ + public Version getVersion(); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/ILink.java b/bds/source/java/ch/systemsx/cisd/bds/ILink.java new file mode 100644 index 0000000000000000000000000000000000000000..84c8324e11a2ee879362ca0cfc70647795b3e7e9 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/ILink.java @@ -0,0 +1,27 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface ILink extends INode +{ + public INode getReference(); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/INode.java b/bds/source/java/ch/systemsx/cisd/bds/INode.java new file mode 100644 index 0000000000000000000000000000000000000000..47d50b1354ba413cf7cada1d64404e83dd9a071f --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/INode.java @@ -0,0 +1,35 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Role of a node in the data structure. + * + * @author Franz-Josef Elmer + */ +public interface INode +{ + /** + * Returns the name of this node. + */ + public String getName(); + + /** + * Returns the parent directory of this node or <code>null</code> if it is the root node. + */ + public IDirectory tryToGetParent(); +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/ProcessingType.java b/bds/source/java/ch/systemsx/cisd/bds/ProcessingType.java new file mode 100644 index 0000000000000000000000000000000000000000..d4031ad8a376164a9a8c790064398bb3ed818193 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/ProcessingType.java @@ -0,0 +1,39 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + + +/** + * Enumeration of processing types. + * + * @author Franz-Josef Elmer + */ +public enum ProcessingType +{ + OTHER, RAW_DATA, COMPUTED_DATA; + + /** + * Resolves the specified string representation of a processing type. + * + * @return {@link #OTHER} if <code>processingTypeString</code> is unknown. + */ + public static ProcessingType resolve(String processingTypeString) + { + ProcessingType type = valueOf(processingTypeString); + return type == null ? OTHER : type; + } +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/Version.java b/bds/source/java/ch/systemsx/cisd/bds/Version.java new file mode 100644 index 0000000000000000000000000000000000000000..8dbdc15d640dfc887c10dd894294cf87bfc78452 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/Version.java @@ -0,0 +1,88 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds; + +/** + * Immutable value object for the version of something. + * + * @author Franz-Josef Elmer + */ +public final class Version +{ + private final int major; + private final int minor; + + /** + * Creates a new instance for the specified major and minor number. + * + * @param major A positive number. + * @param minor A non-negative number. + */ + public Version(int major, int minor) + { + assert major > 0 : "invalid major version number: " + major; + this.major = major; + assert minor >= 0 : "invalid minor version number: " + minor; + this.minor = minor; + } + + /** + * Returns major version number. + */ + public final int getMajor() + { + return major; + } + + /** + * Returns minor version number. + */ + public final int getMinor() + { + return minor; + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + if (obj instanceof Version == false) + { + return false; + } + Version version = (Version) obj; + return version.major == major && version.minor == minor; + } + + @Override + public int hashCode() + { + return major * 1000 + minor; + } + + @Override + public String toString() + { + return "V" + major + "." + minor; + } + + + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/AbstractNode.java b/bds/source/java/ch/systemsx/cisd/bds/fs/AbstractNode.java new file mode 100644 index 0000000000000000000000000000000000000000..befbaa1da9af312a99f584eda60ba33d391129b0 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/AbstractNode.java @@ -0,0 +1,50 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import java.io.File; + +import ch.systemsx.cisd.bds.IDirectory; +import ch.systemsx.cisd.bds.INode; + +/** + * + * + * @author Franz-Josef Elmer + */ +abstract class AbstractNode implements INode +{ + protected final File fileNode; + + AbstractNode(File file) + { + assert file != null : "Unspecified file"; + this.fileNode = file; + } + + public String getName() + { + return fileNode.getName(); + } + + public IDirectory tryToGetParent() + { + File dir = fileNode.getParentFile(); + return dir == null ? null : new Directory(dir); + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/DataStructureV1_0.java b/bds/source/java/ch/systemsx/cisd/bds/fs/DataStructureV1_0.java new file mode 100644 index 0000000000000000000000000000000000000000..9cdbc3e726deabe8e078e7be662429614505fbbf --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/DataStructureV1_0.java @@ -0,0 +1,62 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import java.io.File; + +import ch.systemsx.cisd.bds.AbstractDataStructureV1_0; +import ch.systemsx.cisd.bds.IDirectory; +import ch.systemsx.cisd.bds.IFormatedData; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +class DataStructureV1_0 extends AbstractDataStructureV1_0 +{ + private final File baseDir; + + public DataStructureV1_0(String name, File baseDir) + { + super(name); + assert baseDir != null : "Unspecified base directory."; + assert baseDir.isDirectory() : "Is not a directory: " + baseDir.getAbsolutePath(); + this.baseDir = baseDir; + } + + public IFormatedData getFormatedData() + { + // TODO Auto-generated method stub + return null; + } + + public IDirectory getOriginalData() + { + // TODO Auto-generated method stub + return null; + } + + public void save() throws EnvironmentFailureException + { + // TODO Auto-generated method stub + System.out.println(baseDir); + + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/Directory.java b/bds/source/java/ch/systemsx/cisd/bds/fs/Directory.java new file mode 100644 index 0000000000000000000000000000000000000000..56b3061f3549f20061e1984afaec01ab7c4354e3 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/Directory.java @@ -0,0 +1,84 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; + +import ch.systemsx.cisd.bds.IDirectory; +import ch.systemsx.cisd.bds.INode; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +class Directory extends AbstractNode implements IDirectory +{ + public Directory(File directory) + { + super(directory); + assert directory.isDirectory() : "Not a directory: " + directory.getAbsolutePath(); + } + + public void appendKeyValuePair(String key, String value) + { + File file = new File(fileNode, key); + try + { + FileWriter fileWriter = new FileWriter(file); + fileWriter.write(value); + fileWriter.close(); + } catch (IOException ex) + { + file.delete(); + throw new EnvironmentFailureException("Can not create " + file.getAbsolutePath() + ": " + ex); + } + } + + public void appendNode(INode node) + { + // TODO Auto-generated method stub + + } + + public void appendRealFile(File file) + { + File newFile = new File(fileNode, file.getName()); + if (file.renameTo(newFile) == false) + { + throw new EnvironmentFailureException("Couldn't move file " + file.getAbsolutePath() + " to " + + fileNode.getAbsolutePath()); + } + } + + public void appendLink(String name, INode node) + { + // TODO Auto-generated method stub + + } + + public Iterator<INode> iterator() + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/FileDataStructureFactory.java b/bds/source/java/ch/systemsx/cisd/bds/fs/FileDataStructureFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..8d04d284e3a1290870a15bf5c6e96f51411eab66 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/FileDataStructureFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import java.io.File; + +import ch.systemsx.cisd.bds.AbstractDataStructureFactory; +import ch.systemsx.cisd.bds.IDataStructure; +import ch.systemsx.cisd.bds.Version; +import ch.systemsx.cisd.common.exceptions.UserFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class FileDataStructureFactory extends AbstractDataStructureFactory +{ + + public FileDataStructureFactory(File baseDir) + { + super(baseDir); + } + + public Class<? extends IDataStructure> getDataStructureInterfaceFor(Version version) throws UserFailureException + { + // TODO Auto-generated method stub + return null; + } + + public IDataStructure createDataStructure(String name, Version version) throws UserFailureException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/Link.java b/bds/source/java/ch/systemsx/cisd/bds/fs/Link.java new file mode 100644 index 0000000000000000000000000000000000000000..a1ddf4a6425f82897baeab62dc8c2bf98f4f1380 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/Link.java @@ -0,0 +1,61 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import ch.systemsx.cisd.bds.IDirectory; +import ch.systemsx.cisd.bds.ILink; +import ch.systemsx.cisd.bds.INode; + +/** + * + * + * @author Franz-Josef Elmer + */ +class Link implements ILink +{ + + private final String name; + private IDirectory parent; + private final INode reference; + + Link(String name, INode reference) + { + this.name = name; + this.reference = reference; + } + + public String getName() + { + return name; + } + + void setParent(IDirectory parentOrNull) + { + parent = parentOrNull; + } + + public IDirectory tryToGetParent() + { + return parent; + } + + public INode getReference() + { + return reference; + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/NodeFactory.java b/bds/source/java/ch/systemsx/cisd/bds/fs/NodeFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..b23c7aa6b4a3c1767e7d8e4b4dbaeacb26198dbf --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/NodeFactory.java @@ -0,0 +1,53 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import java.io.File; +import java.io.IOException; + +import ch.systemsx.cisd.bds.INode; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +class NodeFactory +{ + static INode createNode(File file) + { + assert file != null : "Unspecified node"; + String absolutePath = file.getAbsolutePath(); + try + { + String canonicalPath = file.getCanonicalPath(); + if (absolutePath.equals(canonicalPath) == false) + { + return new Link(file.getName(), createNode(new File(canonicalPath))); + } + if (file.isDirectory()) + { + return new Directory(file); + } + return new StringFile(file); + } catch (IOException ex) + { + throw new EnvironmentFailureException("Couldn't get canonical path of file " + absolutePath); + } + } +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/fs/StringFile.java b/bds/source/java/ch/systemsx/cisd/bds/fs/StringFile.java new file mode 100644 index 0000000000000000000000000000000000000000..5e651af966d9281ba163618f0e57f7945496c9f1 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/fs/StringFile.java @@ -0,0 +1,42 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.fs; + +import java.io.File; + +import ch.systemsx.cisd.bds.IFile; +import ch.systemsx.cisd.common.utilities.FileUtilities; + +/** + * + * + * @author Franz-Josef Elmer + */ +class StringFile extends AbstractNode implements IFile<String> +{ + StringFile(File file) + { + super(file); + assert file.isFile() : "Not a file " + file.getAbsolutePath(); + } + + public String getValue() + { + return FileUtilities.loadToString(fileNode); + } + +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/hdf5/HDF5DataStructureFactory.java b/bds/source/java/ch/systemsx/cisd/bds/hdf5/HDF5DataStructureFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..76ef69f26107ab41cc436befdd111402ad1f087a --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/hdf5/HDF5DataStructureFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.bds.hdf5; + +import java.io.File; + +import ch.systemsx.cisd.bds.AbstractDataStructureFactory; +import ch.systemsx.cisd.bds.IDataStructure; +import ch.systemsx.cisd.bds.Version; +import ch.systemsx.cisd.common.exceptions.UserFailureException; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class HDF5DataStructureFactory extends AbstractDataStructureFactory +{ + public HDF5DataStructureFactory(File baseDir) + { + super(baseDir); + } + + public IDataStructure createDataStructure(String name, Version version) throws UserFailureException + { + // TODO Auto-generated method stub + return null; + } + + public Class<? extends IDataStructure> getDataStructureInterfaceFor(Version version) throws UserFailureException + { + // TODO Auto-generated method stub + return null; + } + +}