]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceInput.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / ResourceInput.java
index 20399c6f3587f38efcb8cc51cb1dd31767eb9019..3578456d10e3648e6a71577d6765dc78d244f69a 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.ui.workbench;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.common.request.Queries;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-\r
-/**\r
- * A wrapper class for parsing and generating the information given to Simantics\r
- * views as a parameter through view secondary ID's.\r
- * \r
- * <p>\r
- * To parse the input data (given in the secondary ID) just invoke:<br>\r
- * <code>new ResourceInput(secondaryIdString)</code>\r
- * </p>\r
- * \r
- * <p>\r
- * To generate a secondary ID string based an input resource ID, invoke:<br>\r
- * <code>new ResourceInput(inputResourceId).marshall()</code>\r
- * </p>\r
- * \r
- * @author Tuukka Lehtonen\r
- * \r
- * @see ResourceViewPartUtils\r
- */\r
-public class ResourceInput {\r
-\r
-    private static final String SUFFIX_SEPARATOR = "@";\r
-\r
-    private static final String EMPTY_SUFFIX = "";\r
-\r
-    private final String        inputResourceId;\r
-\r
-    private final String        suffix;\r
-\r
-    /**\r
-     * Construct a new input based on ID's.\r
-     * Use this to serialize ID data into an input string.\r
-     * \r
-     * @param randomAccessResourceId\r
-     */\r
-    public ResourceInput(String randomAccessResourceId) {\r
-        this.inputResourceId = randomAccessResourceId;\r
-        this.suffix = EMPTY_SUFFIX;\r
-    }\r
-\r
-    /**\r
-     * Construct a new input based on ID's. Use this to serialize ID data into\r
-     * an input string.\r
-     * \r
-     * @param randomAccessResourceId\r
-     * @param uniqueSuffix a unique suffix to add to the secondary ID or\r
-     *        <code>null</code> to ignore the unique suffix\r
-     */\r
-    public ResourceInput(String randomAccessResourceId, String uniqueSuffix) {\r
-        this.inputResourceId = randomAccessResourceId;\r
-        this.suffix = (uniqueSuffix == null) ? EMPTY_SUFFIX : uniqueSuffix;\r
-    }\r
-\r
-    /**\r
-     * Returns a new ResourceInput instance with the specified ID as\r
-     * input. This method exists in order to make sure that the client can get a\r
-     * clone of the original ResourceInput in every way except for the\r
-     * input ID in a unified fashion.\r
-     * \r
-     * @param newInputResourceId the new input resource ID\r
-     * @return new ResourceInput instance with the specified input resource ID\r
-     */\r
-    public ResourceInput changeInput(String newRandomAccessResourceId) {\r
-        if (suffix == EMPTY_SUFFIX)\r
-            return new ResourceInput(newRandomAccessResourceId);\r
-        return new ResourceInput(newRandomAccessResourceId, suffix);\r
-    }\r
-\r
-    public String getInputResourceId() {\r
-        return inputResourceId;\r
-    }\r
-\r
-    public String getSuffix() {\r
-        return suffix;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return marshall();\r
-    }\r
-\r
-    /**\r
-     * @param session the Session to use for initiating the\r
-     *        transaction for retrieving the input Resource.\r
-     * @return <code>null</code> if the random access reference of this\r
-     *         ResourceInput is invalid.\r
-     */\r
-    public Resource toResource(Session session) throws DatabaseException {\r
-        return session.syncRequest(Queries.resource(inputResourceId));\r
-    }\r
-\r
-    /**\r
-     * @param input Input format:\r
-     *        <code>client-id#input-resource-id[#unique-suffix]</code>\r
-     * @throws IllegalArgumentException if input is invalid\r
-     */\r
-    public String marshall() {\r
-        return String.format("%s@%s", inputResourceId, suffix);\r
-    }\r
-\r
-    /**\r
-     * @param a previously marshalled ResourceInput using\r
-     *        {@link #marshall()}\r
-     * @throws IllegalArgumentException if input is invalid\r
-     */\r
-    public static ResourceInput unmarshall(String input) throws IllegalArgumentException {\r
-        if (input == null)\r
-            throw new IllegalArgumentException("null input");\r
-        String[] parts = input.split(SUFFIX_SEPARATOR);\r
-        if (parts.length < 1)\r
-            throw new IllegalArgumentException("invalid input: " + input);\r
-\r
-        // Get input resource random access id\r
-        String id = parts[0];\r
-\r
-        // Get arbitrary suffix\r
-        String suffix = EMPTY_SUFFIX;\r
-        if (parts.length > 1) {\r
-            suffix = input.substring(id.length() + 1);\r
-        }\r
-        return new ResourceInput(id, suffix);\r
-    }\r
-\r
-    public static Resource unmarshallToResource(String input, Session session) throws DatabaseException {\r
-        ResourceInput in = unmarshall(input);\r
-        return in.toResource(session);\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + ((inputResourceId == null) ? 0 : inputResourceId.hashCode());\r
-        result = prime * result + ((suffix == null) ? 0 : suffix.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        final ResourceInput other = (ResourceInput) obj;\r
-        if (inputResourceId == null) {\r
-            if (other.inputResourceId != null)\r
-                return false;\r
-        } else if (!inputResourceId.equals(other.inputResourceId))\r
-            return false;\r
-        if (suffix == null) {\r
-            if (other.suffix != null)\r
-                return false;\r
-        } else if (!suffix.equals(other.suffix))\r
-            return false;\r
-        return true;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.ui.workbench;
+
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.common.request.Queries;
+import org.simantics.db.exception.DatabaseException;
+
+
+/**
+ * A wrapper class for parsing and generating the information given to Simantics
+ * views as a parameter through view secondary ID's.
+ * 
+ * <p>
+ * To parse the input data (given in the secondary ID) just invoke:<br>
+ * <code>new ResourceInput(secondaryIdString)</code>
+ * </p>
+ * 
+ * <p>
+ * To generate a secondary ID string based an input resource ID, invoke:<br>
+ * <code>new ResourceInput(inputResourceId).marshall()</code>
+ * </p>
+ * 
+ * @author Tuukka Lehtonen
+ * 
+ * @see ResourceViewPartUtils
+ */
+public class ResourceInput {
+
+    private static final String SUFFIX_SEPARATOR = "@";
+
+    private static final String EMPTY_SUFFIX = "";
+
+    private final String        inputResourceId;
+
+    private final String        suffix;
+
+    /**
+     * Construct a new input based on ID's.
+     * Use this to serialize ID data into an input string.
+     * 
+     * @param randomAccessResourceId
+     */
+    public ResourceInput(String randomAccessResourceId) {
+        this.inputResourceId = randomAccessResourceId;
+        this.suffix = EMPTY_SUFFIX;
+    }
+
+    /**
+     * Construct a new input based on ID's. Use this to serialize ID data into
+     * an input string.
+     * 
+     * @param randomAccessResourceId
+     * @param uniqueSuffix a unique suffix to add to the secondary ID or
+     *        <code>null</code> to ignore the unique suffix
+     */
+    public ResourceInput(String randomAccessResourceId, String uniqueSuffix) {
+        this.inputResourceId = randomAccessResourceId;
+        this.suffix = (uniqueSuffix == null) ? EMPTY_SUFFIX : uniqueSuffix;
+    }
+
+    /**
+     * Returns a new ResourceInput instance with the specified ID as
+     * input. This method exists in order to make sure that the client can get a
+     * clone of the original ResourceInput in every way except for the
+     * input ID in a unified fashion.
+     * 
+     * @param newInputResourceId the new input resource ID
+     * @return new ResourceInput instance with the specified input resource ID
+     */
+    public ResourceInput changeInput(String newRandomAccessResourceId) {
+        if (suffix == EMPTY_SUFFIX)
+            return new ResourceInput(newRandomAccessResourceId);
+        return new ResourceInput(newRandomAccessResourceId, suffix);
+    }
+
+    public String getInputResourceId() {
+        return inputResourceId;
+    }
+
+    public String getSuffix() {
+        return suffix;
+    }
+
+    @Override
+    public String toString() {
+        return marshall();
+    }
+
+    /**
+     * @param session the Session to use for initiating the
+     *        transaction for retrieving the input Resource.
+     * @return <code>null</code> if the random access reference of this
+     *         ResourceInput is invalid.
+     */
+    public Resource toResource(Session session) throws DatabaseException {
+        return session.syncRequest(Queries.resource(inputResourceId));
+    }
+
+    /**
+     * @param input Input format:
+     *        <code>client-id#input-resource-id[#unique-suffix]</code>
+     * @throws IllegalArgumentException if input is invalid
+     */
+    public String marshall() {
+        return String.format("%s@%s", inputResourceId, suffix);
+    }
+
+    /**
+     * @param a previously marshalled ResourceInput using
+     *        {@link #marshall()}
+     * @throws IllegalArgumentException if input is invalid
+     */
+    public static ResourceInput unmarshall(String input) throws IllegalArgumentException {
+        if (input == null)
+            throw new IllegalArgumentException("null input");
+        String[] parts = input.split(SUFFIX_SEPARATOR);
+        if (parts.length < 1)
+            throw new IllegalArgumentException("invalid input: " + input);
+
+        // Get input resource random access id
+        String id = parts[0];
+
+        // Get arbitrary suffix
+        String suffix = EMPTY_SUFFIX;
+        if (parts.length > 1) {
+            suffix = input.substring(id.length() + 1);
+        }
+        return new ResourceInput(id, suffix);
+    }
+
+    public static Resource unmarshallToResource(String input, Session session) throws DatabaseException {
+        ResourceInput in = unmarshall(input);
+        return in.toResource(session);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((inputResourceId == null) ? 0 : inputResourceId.hashCode());
+        result = prime * result + ((suffix == null) ? 0 : suffix.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final ResourceInput other = (ResourceInput) obj;
+        if (inputResourceId == null) {
+            if (other.inputResourceId != null)
+                return false;
+        } else if (!inputResourceId.equals(other.inputResourceId))
+            return false;
+        if (suffix == null) {
+            if (other.suffix != null)
+                return false;
+        } else if (!suffix.equals(other.suffix))
+            return false;
+        return true;
+    }
+
+}