01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.util;
18:
19: import java.io.Serializable;
20:
21: import org.apache.pluto.om.common.ObjectID;
22: import org.apache.pluto.om.portlet.PortletDefinition;
23:
24: /**
25: *
26: * JetspeedObjectID
27: ** Wraps around the internal Object IDs. By holding both
28: ** the string and the integer version of an Object ID this class
29: ** helps speed up the internal processing.
30: *
31: * @version $Id: JetspeedObjectID.java 516448 2007-03-09 16:25:47Z ate $
32: *
33: */
34: public class JetspeedObjectID implements ObjectID, Serializable {
35: private String stringOID = null;
36:
37: public JetspeedObjectID(String stringOID) {
38: this .stringOID = stringOID;
39: if (stringOID == null) {
40: // really cannot have a null here
41: throw new NullPointerException();
42: }
43: }
44:
45: public boolean equals(Object object) {
46: if (object instanceof JetspeedObjectID) {
47: return ((JetspeedObjectID) object).stringOID
48: .equals(stringOID);
49: } else if (object instanceof String) {
50: return ((String) object).equals(stringOID);
51: }
52: return false;
53: }
54:
55: public int hashCode() {
56: return stringOID.hashCode();
57: }
58:
59: public String toString() {
60: return (stringOID);
61: }
62:
63: static public JetspeedObjectID createFromString(String idStr) {
64: return new JetspeedObjectID(idStr);
65: }
66:
67: /**
68: * @param portletDefinition
69: * @param instanceName
70: * @return
71: */
72: public static JetspeedObjectID createPortletEntityId(
73: PortletDefinition portletDefinition, String instanceName) {
74: return createFromString(portletDefinition.getName() + ":"
75: + portletDefinition.getId().toString() + ":"
76: + instanceName);
77: }
78: }
|