001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-hbm/src/java/org/sakaiproject/component/app/messageforums/dao/hibernate/PrivateTopicImpl.java $
003: * $Id: PrivateTopicImpl.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.app.messageforums.dao.hibernate;
021:
022: import java.util.Arrays;
023: import java.util.Comparator;
024: import java.util.Date;
025: import java.util.List;
026: import java.util.Set;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.api.app.messageforums.PrivateTopic;
031: import org.sakaiproject.api.app.messageforums.Topic;
032:
033: public class PrivateTopicImpl extends TopicImpl implements PrivateTopic {
034:
035: private static final Log LOG = LogFactory
036: .getLog(PrivateTopicImpl.class);
037:
038: private String userId;
039: private String contextId;
040: private PrivateTopic parentTopic;
041: private Set childrenFoldersSet;// = new HashSet();
042:
043: //private int ptindex;
044:
045: public static Comparator TITLE_COMPARATOR;
046:
047: private static final List lookupOrderList = Arrays
048: .asList(new String[] { "Received", "Sent", "Deleted",
049: "Drafts" });
050:
051: static {
052: TITLE_COMPARATOR = new Comparator() {
053: private String title1, title2;
054: private Integer index1, index2;
055:
056: public int compare(Object topic, Object otherTopic) {
057: if (topic != null && otherTopic != null
058: && topic instanceof Topic
059: && otherTopic instanceof Topic) {
060: // title1 = ((Topic) topic).getTitle();
061: // title2 = ((Topic) otherTopic).getTitle();
062: //
063: // index1 = new Integer(lookupOrderList.indexOf(title1));
064: // index2 = new Integer(lookupOrderList.indexOf(title2));
065: //
066: // /** expecting elements to exist in lookupOrderedList */
067: // return index1.compareTo(index2);
068: if (lookupOrderList.indexOf(((Topic) topic)
069: .getTitle()) >= 0
070: && lookupOrderList
071: .indexOf(((Topic) otherTopic)
072: .getTitle()) < 0) {
073: return -1;
074: }
075: if (lookupOrderList.indexOf(((Topic) topic)
076: .getTitle()) < 0
077: && lookupOrderList
078: .indexOf(((Topic) otherTopic)
079: .getTitle()) >= 0) {
080: return 1;
081: }
082: Date date1 = ((Topic) topic).getCreated();
083: Date date2 = ((Topic) otherTopic).getCreated();
084: return date1.compareTo(date2);
085: }
086: return -1;
087: }
088: };
089: }
090:
091: public String getUserId() {
092: return userId;
093: }
094:
095: public void setUserId(String userId) {
096: this .userId = userId;
097: }
098:
099: public String getContextId() {
100: return contextId;
101: }
102:
103: public void setContextId(String contextId) {
104: this .contextId = contextId;
105: }
106:
107: public PrivateTopic getParentTopic() {
108: return parentTopic;
109: }
110:
111: public void setParentTopic(PrivateTopic parentTopic) {
112: this .parentTopic = parentTopic;
113: }
114:
115: public Set getChildrenFoldersSet() {
116: return childrenFoldersSet;
117: }
118:
119: public void setChildrenFoldersSet(Set childrenFoldersSet) {
120: this .childrenFoldersSet = childrenFoldersSet;
121: }
122:
123: public List getChildrenFolders() {
124: return Util.setToList(childrenFoldersSet);
125: }
126:
127: public void setChildrenFolders(List childrenFolders) {
128: this .childrenFoldersSet = Util.listToSet(childrenFolders);
129: }
130:
131: //
132: // public int getPtindex() {
133: // try {
134: // return getParentTopic().getChildrenFolders().indexOf(this);
135: // } catch (Exception e) {
136: // return ptindex;
137: // }
138: // }
139: //
140: // public void setPtindex(int ptindex) {
141: // this.ptindex = ptindex;
142: // }
143:
144: ////////////////////////////////////////////////////////////////////////
145: // helper methods for collections
146: ////////////////////////////////////////////////////////////////////////
147:
148: public void addChildFolder(PrivateTopic folder) {
149: if (LOG.isDebugEnabled()) {
150: LOG.debug("addChildFolder(folder " + folder + ")");
151: }
152:
153: if (folder == null) {
154: throw new IllegalArgumentException("folder == null");
155: }
156:
157: folder.setParentTopic(this );
158: childrenFoldersSet.add(folder);
159: }
160:
161: public void removeChildFolder(PrivateTopic folder) {
162: if (LOG.isDebugEnabled()) {
163: LOG.debug("removeChildFolder(folder " + folder + ")");
164: }
165:
166: if (folder == null) {
167: throw new IllegalArgumentException(
168: "Illegal folder argument passed!");
169: }
170:
171: folder.setParentTopic(null);
172: childrenFoldersSet.remove(folder);
173: }
174: }
|