01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-api/api/src/java/org/sakaiproject/metaobj/shared/model/IdImpl.java $
03: * $Id: IdImpl.java 9469 2006-05-15 14:52:05Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.metaobj.shared.model;
21:
22: import java.io.IOException;
23: import java.io.ObjectInputStream;
24: import java.io.ObjectOutputStream;
25:
26: import org.apache.commons.logging.Log;
27: import org.apache.commons.logging.LogFactory;
28:
29: /**
30: * @author rpembry
31: */
32: public class IdImpl implements Id {
33: static final long serialVersionUID = 5143985783577804880L;
34:
35: protected final transient Log logger = LogFactory
36: .getLog(IdImpl.class);
37:
38: private String id;
39: //TODO: support Type better
40: private transient Type type;
41:
42: public IdImpl() {
43: }
44:
45: public IdImpl(String id, Type type) {
46: this .id = id;
47: this .type = type;
48: }
49:
50: /* (non-Javadoc)
51: * @see org.sakaiproject.metaobj.shared.model.Id#getType()
52: */
53: public Type getType() {
54: return type;
55: }
56:
57: private void writeObject(ObjectOutputStream out) throws IOException {
58: out.writeObject(id);
59: }
60:
61: private void readObject(ObjectInputStream in) throws IOException,
62: ClassNotFoundException {
63: id = (String) in.readObject();
64: }
65:
66: public String getValue() {
67: return id;
68: }
69:
70: public String toString() {
71: return getValue();
72: }
73:
74: public boolean equals(Object other) {
75: if (other == null || !(other instanceof IdImpl)) {
76: return false;
77: }
78: if (!(other instanceof Id)) {
79: return false;
80: }
81: return getValue().equals(((IdImpl) other).getValue());
82:
83: }
84:
85: public void setValue(String id) {
86: this .id = id;
87: }
88:
89: /* (non-Javadoc)
90: * @see java.lang.Object#hashCode()
91: */
92: public int hashCode() {
93: if (id == null) {
94: return 0;
95: }
96: return this.id.hashCode();
97: }
98: }
|