View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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  
18  package org.apache.jetspeed.capabilities.impl;
19  
20  import org.apache.jetspeed.capabilities.MimeType;
21  
22  /***
23   * Mimetype implementation class.
24   *
25   * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
26   * @version $Id: MimeTypeImpl.java 517719 2007-03-13 15:05:48Z ate $
27   */
28  
29  public class MimeTypeImpl implements MimeType
30  {
31      private int mimeTypeId;
32      private String name;
33  
34      /* (non-Javadoc)
35       * @see org.apache.jetspeed.om.registry.MimeType#setMimetypeId(int)
36       */
37      public void setMimetypeId(int id)
38      {
39          this.mimeTypeId = id;
40      }
41  
42      /* (non-Javadoc)
43       * @see org.apache.jetspeed.om.registry.MimeType#getMimetypeId()
44       */
45      public int getMimetypeId()
46      {
47          return this.mimeTypeId;
48      }
49  
50      /* (non-Javadoc)
51       * @see org.apache.jetspeed.om.registry.MimeType#setName(java.lang.String)
52       */
53      public void setName(String name)
54      {
55          this.name = name;
56      }
57  
58      /* (non-Javadoc)
59       * @see org.apache.jetspeed.om.registry.MimeType#getName()
60       */
61      public String getName()
62      {
63          return this.name;
64      }
65  
66      /***
67       * Implements the hashCode calculation so two different objects with the content return the same hashcode....
68       */
69      public int hashCode()
70      {
71      	return name.hashCode();
72      }
73      /***
74       * Implements the equals operation so that 2 elements are equal if
75       * all their member values are equal.
76       *
77       *      
78       * @param object to compare this one with
79       * @return true if both objects represent the same (logical) content
80       */
81      public boolean equals(Object object)
82      {
83      	if (!(object instanceof MimeType))
84      	{
85      		return false;
86      	}
87      	if (this == object)
88      		return true;
89  // Don't check the ID - id is only set through OJB so this would not recognize equality correctly 
90  /*    	if (mimeTypeId != ((MimeType)object).getMimetypeId())
91      		return false;
92  */
93      	String oName = ((MimeType)object).getName();
94      	if (
95      			(oName == null) && (name == null)
96      			||
97      			(oName == name)
98      			||
99      			((oName != null) && (oName.equals(name)))
100     		)
101     		return true;
102     	return false;	
103     }
104 
105 }