001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: BeanDeclaration.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: public class BeanDeclaration {
011: private String mClassname = null;
012: private Class mClass = null;
013: private String mPrefix = null;
014: private String mGroupName = null;
015:
016: BeanDeclaration(String classname, String prefix, String groupName) {
017: assert classname != null;
018: assert classname.length() > 0;
019: assert null == prefix || prefix.length() > 0;
020:
021: if (prefix != null && 0 == prefix.length())
022: prefix = null;
023: if (groupName != null && 0 == groupName.length())
024: groupName = null;
025:
026: mClassname = classname;
027: mPrefix = prefix;
028: mGroupName = groupName;
029: }
030:
031: BeanDeclaration(Class klass, String prefix, String groupName) {
032: this (klass.getName(), prefix, groupName);
033:
034: assert klass != null;
035:
036: mClass = klass;
037: }
038:
039: public Class getBeanClass() throws ClassNotFoundException {
040: if (null == mClass) {
041: mClass = Class.forName(mClassname);
042: }
043:
044: return mClass;
045: }
046:
047: public String getClassname() {
048: return mClassname;
049: }
050:
051: public String getPrefix() {
052: return mPrefix;
053: }
054:
055: public String getGroupName() {
056: return mGroupName;
057: }
058:
059: public int hashCode() {
060: int classname = 1;
061: int prefix = 1;
062: int groupname = 1;
063:
064: if (mClassname != null) {
065: classname = mClassname.hashCode();
066: }
067: if (mPrefix != null) {
068: prefix = mPrefix.hashCode();
069: }
070: if (mGroupName != null) {
071: groupname = mGroupName.hashCode();
072: }
073:
074: return classname * prefix * groupname;
075: }
076:
077: public boolean equals(Object other) {
078: if (this == other) {
079: return true;
080: }
081:
082: if (null == other) {
083: return false;
084: }
085:
086: if (!(other instanceof BeanDeclaration)) {
087: return false;
088: }
089:
090: BeanDeclaration other_bean = (BeanDeclaration) other;
091: if (!other_bean.getClassname().equals(getClassname())) {
092: return false;
093: }
094: if (other_bean.getPrefix() != null || getPrefix() != null) {
095: if (null == other_bean.getPrefix() && getPrefix() != null) {
096: return false;
097: }
098: if (other_bean.getPrefix() != null && null == getPrefix()) {
099: return false;
100: }
101: if (!other_bean.getPrefix().equals(getPrefix())) {
102: return false;
103: }
104: }
105: if (other_bean.getGroupName() != null || getGroupName() != null) {
106: if (null == other_bean.getGroupName()
107: && getGroupName() != null) {
108: return false;
109: }
110: if (other_bean.getGroupName() != null
111: && null == getGroupName()) {
112: return false;
113: }
114: if (!other_bean.getGroupName().equals(getGroupName())) {
115: return false;
116: }
117: }
118:
119: return true;
120: }
121: }
|