From 4957ef1c381a95011141869186006d958a991ee5 Mon Sep 17 00:00:00 2001
From: Martin Oberhuber < martin.oberhuber@windriver.com>
Date: Fri, 25 Apr 2008 16:33:14 +0000
Subject: [PATCH] Add RemoteObjectId
---
.../internal/core/model/RemoteObjectId.java | 118 ++++++++++++++++++
1 file changed, 118 insertions(+)
create mode 100644 rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/RemoteObjectId.java
diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/RemoteObjectId.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/RemoteObjectId.java
new file mode 100644
index 00000000000..d2bdc553c3d
--- /dev/null
+++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/model/RemoteObjectId.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. 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:
+ * Martin Oberhuber (Wind River) - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.rse.internal.core.model;
+
+import org.eclipse.rse.core.subsystems.IRemoteObjectIdentifier;
+import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.core.subsystems.ISystemDragDropAdapter;
+
+/**
+ * A RemoteObjectId uniquely identifies an object in the RSE Tree, and is valid
+ * as long as its parent subsystem exists.
+ *
+ * It holds a Subsystem instance, and an absolute name. This class is meant as a
+ * short-lived object for using in local comparisons only. Since it is only
+ * valid as long as its parent subsystem exists, RemoteObjectId's cannot be
+ * usefully persisted.
+ *
+ * This class is immutable and therefore thread-safe.
+ *
+ * TODO It is unfortunate that we need to access an ISystemDragDropAdapter just
+ * to get the ISubSystem. A lower-level object identifier should be available,
+ * but making that happen would break almost all clients since their adapter
+ * factories are not prepared for it.
+ *
+ * TODO This class is currently nowhere used and is therefore dead code. But it
+ * is kept here in order to be convey the original idea and have it available
+ * when needed.
+ *
+ * @since org.eclipse.rse.core 3.0
+ */
+public final class RemoteObjectId {
+ // Subsystem instance, may be null
+ private final ISubSystem fSubSystem;
+ // Absolute name, must not be null
+ private final String fAbsoluteName;
+
+ /**
+ * Construct a RemoteObjectId.
+ *
+ * @param ss subsystem instance. May be null
if unknown.
+ * @param absoluteName absolute name. Must not be null
.
+ */
+ private RemoteObjectId(ISubSystem ss, String absoluteName) {
+ assert absoluteName != null;
+ fSubSystem = ss;
+ fAbsoluteName = absoluteName;
+ }
+
+ /**
+ * Create an RemoteObjectId for any kind of Object. Tries to adapt the given
+ * object to an RSE {@link ISystemDragDropAdapter} or
+ * {@link IRemoteObjectIdentifier}, in order to obtain an absolute name
+ * and subsystem instance.
+ *
+ * @param element an element that needs to be adaptable such that an
+ * absolute name can be obtained.
+ * @return an RemoteObjectId for the given element, or null
if
+ * the given element is not adaptable to the necessary RSE
+ * adapter type, or no absolute name can be obtained.
+ */
+ public static RemoteObjectId create(Object element) {
+ ISystemDragDropAdapter dda = SystemRegistry.getSystemDragDropAdapter(element);
+ if (dda != null) {
+ String absoluteName = dda.getAbsoluteName(element);
+ if (absoluteName != null) {
+ return new RemoteObjectId(dda.getSubSystem(element), absoluteName);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the absolute name of this object id.
+ *
+ * @return the absolute name
+ */
+ public final String getAbsoluteName() {
+ return fAbsoluteName;
+ }
+
+ /**
+ * Return the subsystem instance of this object id.
+ *
+ * @return the subsystem instance. May be null
if the
+ * subsystem instance could not be determined.
+ */
+ public final ISubSystem getSubSystem() {
+ return fSubSystem;
+ }
+
+ public final boolean equals(Object o) {
+ try {
+ // We're optimistic and think nobody will ever call
+ // equals() on us with any other kind of Object
+ RemoteObjectId other = (RemoteObjectId) o;
+ return (fSubSystem == other.fSubSystem) && (fAbsoluteName.equals(other.fAbsoluteName));
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public final int hashCode() {
+ int hashCode = fAbsoluteName.hashCode();
+ if (fSubSystem != null) {
+ hashCode = hashCode * 31 + fSubSystem.hashCode();
+ }
+ return hashCode;
+ }
+}
\ No newline at end of file