001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.hibernate.model;
023:
024: import java.io.Serializable;
025: import java.util.ArrayList;
026: import java.util.Calendar;
027: import java.util.List;
028:
029: /**
030: * @author Gavin King
031: */
032: public class Role implements Serializable {
033: static final long serialVersionUID = 3981536407512229410L;
034: private Long id;
035: private String name;
036: private String description;
037: private Calendar timeOfCreation;
038: private List users = new ArrayList();
039:
040: public String getDescription() {
041: return description;
042: }
043:
044: public void setDescription(String description) {
045: this .description = description;
046: }
047:
048: public Long getId() {
049: return id;
050: }
051:
052: private void setId(Long id) {
053: this .id = id;
054: }
055:
056: public String getName() {
057: return name;
058: }
059:
060: public void setName(String name) {
061: this .name = name;
062: }
063:
064: public List getUsers() {
065: return users;
066: }
067:
068: private void setUsers(List users) {
069: this .users = users;
070: }
071:
072: public void addUser(User user) {
073: users.add(user);
074: user.getRoles().add(this );
075: }
076:
077: public Calendar getTimeOfCreation() {
078: return timeOfCreation;
079: }
080:
081: public void setTimeOfCreation(Calendar timeOfCreation) {
082: this .timeOfCreation = timeOfCreation;
083: }
084:
085: //it is best to implement equals()/hashCode()
086: //to compare a "business key" (in this case
087: //the unique name of the Role) rather than
088: //the surrogate id
089:
090: public boolean equals(Object other) {
091: if (other == null)
092: return false;
093: if (!(other instanceof Role))
094: return false;
095: return ((Role) other).getName().equals(name);
096: }
097:
098: public int hashCode() {
099: return name.hashCode();
100: }
101:
102: }
|