portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r378364 - in /portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util: JetspeedLongObjectID.java JetspeedObjectID.java
Date Thu, 16 Feb 2006 20:54:35 GMT
Author: ate
Date: Thu Feb 16 12:54:33 2006
New Revision: 378364

URL: http://svn.apache.org/viewcvs?rev=378364&view=rev
Log:
Fixing incorrect usage and implementation of the Pluto ObjectID interface: 
- JetspeedObjectID now only represents Strings and no longer implements PortalObjectID
- new JetspeedLongObjectID will be used for Long based id's and implements PortalObjectID

See http://issues.apache.org/jira/browse/JS2-501

Added:
    portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedLongObjectID.java
Modified:
    portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedObjectID.java

Added: portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedLongObjectID.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedLongObjectID.java?rev=378364&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedLongObjectID.java
(added)
+++ portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedLongObjectID.java
Thu Feb 16 12:54:33 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * 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.apache.jetspeed.util;
+
+/**
+ * JetspeedLongObjectID
+ *
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public class JetspeedLongObjectID implements PortalObjectID
+{
+    private Long oid;
+    
+    public JetspeedLongObjectID(long oid)
+    {
+        this.oid = new Long(oid);
+    }
+
+    public JetspeedLongObjectID(Long oid)
+    {
+        this.oid = oid;
+    }
+
+    public long getOID()
+    {
+        return oid.longValue();
+    }
+    
+    public Long getLong()
+    {
+        return oid;
+    }
+    
+    public boolean equals(Object object)
+    {
+        if (object instanceof PortalObjectID)
+        {
+            return ((PortalObjectID)object).getOID() == oid.longValue();
+        }
+        else if (object instanceof Long)
+        {
+            return ((Long)object).longValue() == oid.longValue();
+        }
+        else if (object instanceof Integer)
+        {
+            return ((Integer)object).longValue() == oid.longValue();
+        }
+        return false;
+    }
+
+    public int hashCode()
+    {
+        return oid.hashCode();
+    }
+    
+    public String toString()
+    {
+        return oid.toString();
+    }
+}

Modified: portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedObjectID.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedObjectID.java?rev=378364&r1=378363&r2=378364&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedObjectID.java
(original)
+++ portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/util/JetspeedObjectID.java
Thu Feb 16 12:54:33 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.jetspeed.util;
 
+import java.io.Serializable;
+
+import org.apache.pluto.om.common.ObjectID;
 import org.apache.pluto.om.portlet.PortletDefinition;
 
 /**
@@ -27,49 +30,36 @@
  * @version $Id$
  *
  */
-public class JetspeedObjectID implements PortalObjectID, java.io.Serializable
+public class JetspeedObjectID implements ObjectID, Serializable
 {
     private String stringOID = null;
-    private long oid;
-
-    public JetspeedObjectID(long oid)
-    {
-        stringOID = String.valueOf(oid);
-        this.oid = oid;
-    }
 
-    public JetspeedObjectID(long oid, String stringOID)
+    public JetspeedObjectID(String stringOID)
     {
         this.stringOID = stringOID;
-        this.oid  = oid;
+        if ( stringOID == null )
+        {
+            // really cannot have a null here
+            throw new NullPointerException();
+        }
     }
 
     public boolean equals(Object object)
     {
-        boolean result = false;
-
         if (object instanceof JetspeedObjectID)
         {
-            result = (oid == ((JetspeedObjectID) object).oid);
+            return ((JetspeedObjectID)object).stringOID.equals(stringOID);
         }
         else if (object instanceof String)
         {
-            result = stringOID.equals(object);
+            return ((String)object).equals(stringOID);
         }
-        else if (object instanceof Long)
-        {
-            result = (oid == ((Long) object).longValue());
-        }                
-        else if (object instanceof Integer)
-        {
-            result = (oid == ((Integer) object).intValue());
-        }        
-        return (result);
+        return false;
     }
 
     public int hashCode()
     {
-        return (int)oid; // TODO: this could be a problem slicing a long to an int
+        return stringOID.hashCode();
     }
 
     public String toString()
@@ -77,36 +67,9 @@
         return (stringOID);
     }
 
-    public long longValue()
-    {
-        return oid;
-    }
-
-/*    
-    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
-    {
-        oid = stream.readLong();
-        stringOID = String.valueOf(oid);
-    }
-
-    private void writeObject(ObjectOutputStream stream) throws IOException
-    {
-        stream.write((int)oid);
-    }
-*/
     static public JetspeedObjectID createFromString(String idStr)
     {
-        char[] id = idStr.toCharArray();
-        long _id = 1;
-        for (int i = 0; i < id.length; i++)
-        {
-            if ((i % 2) == 0)
-                _id *= id[i];
-            else
-                _id ^= id[i];
-            _id = Math.abs(_id);
-        }
-        return new JetspeedObjectID(_id, idStr);
+        return new JetspeedObjectID(idStr);
     }
 
     /**
@@ -116,12 +79,6 @@
      */
     public static JetspeedObjectID createPortletEntityId(PortletDefinition portletDefinition,
String instanceName)
     {
-        // return createFromString(portletDefinition.getId().toString());
         return createFromString(portletDefinition.getName() + ":" + portletDefinition.getId().toString()
+ ":" + instanceName);
-    }
-    
-    public long getOID()
-    {
-        return oid;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message