001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.users;
020:
021: import java.util.*;
022:
023: import org.openharmonise.commons.dsi.*;
024: import org.openharmonise.commons.dsi.dml.*;
025: import org.openharmonise.rm.dsi.*;
026: import org.openharmonise.rm.publishing.*;
027: import org.openharmonise.rm.resources.*;
028: import org.openharmonise.rm.resources.lifecycle.*;
029:
030: /**
031: * This class provides the functionality to manage groups of
032: * <code>User</code> objects.
033: *
034: * @author Michael Bell
035: * @version $Revision: 1.2 $
036: *
037: */
038: public class UserGroup extends AbstractParentObject implements
039: DataStoreObject, Publishable, Editable, Cloneable, Comparable {
040:
041: //DB constants
042: private static final String TBL_USERGROUP = "users_group";
043:
044: //XML constants
045: public static final String TAG_USERGROUP = "UserGroup";
046:
047: // member variables
048: private static List CHILD_CLASS_NAMES = null;
049:
050: static {
051: DatabaseInfo.getInstance().registerTableName(
052: UserGroup.class.getName(), TBL_USERGROUP);
053:
054: try {
055: CHILD_CLASS_NAMES = new Vector();
056: CHILD_CLASS_NAMES.add(User.class.getName());
057: CHILD_CLASS_NAMES.add(UserGroup.class.getName());
058:
059: } catch (Exception e) {
060: throw new RuntimeException(e.getMessage());
061: }
062: }
063:
064: /**
065: * Basic empty constructor.
066: *
067: */
068: public UserGroup() {
069: super ();
070:
071: }
072:
073: /**
074: * Constructs an object with an interface to the DB.
075: *
076: * @param dbinterf
077: */
078: public UserGroup(AbstractDataStoreInterface dbinterf) {
079: super (dbinterf);
080: }
081:
082: /**
083: * Constructs a historical object with an interface to the DB.
084: *
085: * @param dbinterf
086: * @param bHist
087: */
088: public UserGroup(AbstractDataStoreInterface dbinterf, boolean bHist) {
089: super (dbinterf);
090: }
091:
092: /**
093: * Standard constructor for an object with a known id.
094: *
095: * @param dbinterf
096: * @param nId
097: */
098: public UserGroup(AbstractDataStoreInterface dbinterf, int nId) {
099: super (dbinterf, nId);
100:
101: }
102:
103: /**
104: * Standard constructor for a historical object with a known id.
105: *
106: * @param dbinterf
107: * @param nId
108: * @param bHist
109: */
110: public UserGroup(AbstractDataStoreInterface dbinterf, int nId,
111: int nKey, boolean bHist) throws Exception {
112: super (dbinterf, nId, nKey, bHist);
113:
114: }
115:
116: /* (non-Javadoc)
117: * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
118: */
119: public JoinConditions getInstanceJoinConditions(String sObjectTag,
120: boolean bIsOuter) throws DataStoreException {
121: JoinConditions joinConditions = new JoinConditions();
122: DatabaseInfo dbInfo = DatabaseInfo.getInstance();
123: String sChildTableName = null;
124:
125: if (sObjectTag.equals("User") == true) {
126: sChildTableName = dbInfo.getTableName(User.class.getName());
127: } else if (sObjectTag.equals("UserGroup") == true) {
128: sChildTableName = dbInfo.getTableName(UserGroup.class
129: .getName());
130: } else {
131: throw new DataStoreException("Invalid child object");
132: }
133:
134: // get the child and parent keys from the join table
135: ColumnRef childKeyCol = getGroupChildJoinColumnRef(
136: sChildTableName, CLMN_CHILD_KEY);
137: ColumnRef parentKeyCol = getGroupChildJoinColumnRef(
138: sChildTableName, CLMN_PARENT_KEY);
139:
140: joinConditions.addCondition(getInstanceColumnRef(
141: AbstractObject.ATTRIB_KEY, false), parentKeyCol);
142: joinConditions.addCondition(User.getColumnRef(User.class
143: .getName(), AbstractObject.ATTRIB_KEY, false),
144: childKeyCol);
145:
146: return joinConditions;
147: }
148:
149: /* (non-Javadoc)
150: * @see java.lang.Object#toString()
151: */
152: public String toString() {
153: String output = "";
154:
155: try {
156: output = output + super .toString();
157:
158: output = output + " UserGroup id:"
159: + Integer.toString(m_nId) + " title:"
160: + this .m_sName + " summary:" + this .m_sSummary;
161:
162: } catch (Exception e) {
163: throw new RuntimeException("UserGroup toString exploded!");
164: }
165:
166: return output;
167: }
168:
169: /* (non-Javadoc)
170: * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
171: */
172: public String getParentObjectClassName() {
173: return UserGroup.class.getName();
174: }
175:
176: /* (non-Javadoc)
177: * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
178: */
179: public String getDBTableName() {
180: return TBL_USERGROUP;
181: }
182:
183: /* (non-Javadoc)
184: * @see org.openharmonise.rm.publishing.Publishable#getTagName()
185: */
186: public String getTagName() {
187: return TAG_USERGROUP;
188: }
189:
190: /*----------------------------------------------------------------------------
191: Protected methods
192: -----------------------------------------------------------------------------*/
193:
194: /* (non-Javadoc)
195: * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
196: */
197: public List getChildClassNames() {
198: return CHILD_CLASS_NAMES;
199: }
200: }
|