Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java')
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java170
1 files changed, 170 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java
new file mode 100644
index 0000000000..477f4c81c0
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferElement.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.transfer;
+
+import org.eclipse.emf.common.util.URI;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Eike Stepper
+ * @since 4.2
+ */
+public abstract class CDOTransferElement
+{
+ public static final CDOTransferElement[] NO_CHILDREN = {};
+
+ private final CDOTransferSystem system;
+
+ protected CDOTransferElement(CDOTransferSystem system)
+ {
+ this.system = system;
+ }
+
+ public final CDOTransferSystem getSystem()
+ {
+ return system;
+ }
+
+ public abstract Object getNativeObject();
+
+ public abstract boolean isDirectory();
+
+ public abstract IPath getPath();
+
+ public final String getName()
+ {
+ return getPath().lastSegment();
+ }
+
+ public final URI getURI()
+ {
+ IPath path = getPath();
+ return system.getURI(path);
+ }
+
+ public final boolean isRoot()
+ {
+ return getParent() == null;
+ }
+
+ public final CDOTransferElement getParent()
+ {
+ IPath path = getPath();
+ if (path.isRoot())
+ {
+ return null;
+ }
+
+ return system.getElement(path.removeLastSegments(1));
+ }
+
+ public final CDOTransferElement[] getChildren() throws IOException
+ {
+ if (isDirectory())
+ {
+ return doGetChildren();
+ }
+
+ return NO_CHILDREN;
+ }
+
+ public final CDOTransferElement getChild(IPath path) throws IOException
+ {
+ IPath childPath = getPath().append(path.makeRelative());
+ return system.getElement(childPath);
+ }
+
+ public final CDOTransferElement getChild(String path) throws IOException
+ {
+ return getChild(new Path(path));
+ }
+
+ public final InputStream openInputStream() throws IOException
+ {
+ checkNotDirectory();
+ return doOpenInputStream();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ String path = getPath().toString();
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (system == null ? 0 : system.hashCode());
+ result = prime * result + (path == null ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj == null)
+ {
+ return false;
+ }
+
+ if (!(obj instanceof CDOTransferElement))
+ {
+ return false;
+ }
+
+ CDOTransferElement other = (CDOTransferElement)obj;
+ if (system != other.system)
+ {
+ return false;
+ }
+
+ String path = getPath().toString();
+ String otherPath = other.getPath().toString();
+ if (path == null)
+ {
+ if (otherPath != null)
+ {
+ return false;
+ }
+ }
+ else if (!path.equals(otherPath))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getPath().toString();
+ }
+
+ protected abstract CDOTransferElement[] doGetChildren() throws IOException;
+
+ protected abstract InputStream doOpenInputStream() throws IOException;
+
+ private void checkNotDirectory() throws IOException
+ {
+ if (isDirectory())
+ {
+ throw new IOException("Not supported for directories");
+ }
+ }
+}

Back to the top