001: /* Copyright 2001, 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.groups;
007:
008: import org.jasig.portal.EntityIdentifier;
009:
010: /**
011: * Reference implementation for <code>IEntity</code>.
012: * @author Dan Ellentuck
013: * @version $Revision: 34758 $
014: */
015: public class EntityImpl extends GroupMemberImpl implements IEntity {
016: protected EntityIdentifier entityIdentifier;
017:
018: /**
019: * EntityImpl constructor
020: */
021: public EntityImpl(String newEntityKey, Class newEntityType)
022: throws GroupsException {
023: this (new EntityIdentifier(newEntityKey, newEntityType));
024: }
025:
026: /**
027: * EntityImpl constructor
028: */
029: public EntityImpl(EntityIdentifier ei) throws GroupsException {
030: super (ei);
031: Integer id = org.jasig.portal.EntityTypes.getEntityTypeID(ei
032: .getType());
033: String key = id + "." + ei.getKey();
034: entityIdentifier = new EntityIdentifier(key,
035: org.jasig.portal.EntityTypes.LEAF_ENTITY_TYPE);
036: }
037:
038: /**
039: * @param obj the Object to compare with
040: * @return true if these Objects are equal; false otherwise.
041: * @see java.util.Hashtable
042: */
043: public boolean equals(Object obj) {
044: if (obj == null)
045: return false;
046: if (obj == this )
047: return true;
048: if (!(obj instanceof EntityImpl))
049: return false;
050:
051: return this .getEntityIdentifier().equals(
052: ((IEntity) obj).getEntityIdentifier());
053: }
054:
055: /**
056: * @return org.jasig.portal.EntityIdentifier
057: */
058: public EntityIdentifier getEntityIdentifier() {
059: return entityIdentifier;
060: }
061:
062: /**
063: * Returns the type of the underyling entity.
064: * @return java.lang.Class
065: */
066: public Class getEntityType() {
067: return getUnderlyingEntityIdentifier().getType();
068: }
069:
070: /**
071: * Returns the key of the underlying entity.
072: * @return java.lang.String
073: */
074: public java.lang.String getKey() {
075: return getUnderlyingEntityIdentifier().getKey();
076: }
077:
078: /**
079: * Returns the type of the underyling entity.
080: * @return java.lang.Class
081: */
082: public Class getLeafType() {
083: return getEntityType();
084: }
085:
086: /**
087: * Returns this object's type, as opposed to the type of its
088: * underlying entity.
089: *
090: * @return java.lang.Class
091: */
092: public Class getType() {
093: return getEntityType();
094: }
095:
096: /**
097: * @return boolean
098: */
099: public boolean isEntity() {
100: return true;
101: }
102:
103: /**
104: * Returns a String that represents the value of this object.
105: * @return a string representation of the receiver
106: */
107: public String toString() {
108: String clsName = getEntityType().getName();
109: return "EntityImpl (" + clsName + ") " + getKey();
110: }
111: }
|