001: /* Copyright 2005 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.services.stats;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.jasig.portal.ChannelDefinition;
011: import org.jasig.portal.UserProfile;
012: import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
013: import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
014: import org.jasig.portal.security.IPerson;
015:
016: /**
017: * Stats recorder implementation which conditionally propogates IStatsRecorder
018: * events to a target IStatsRecorder.
019: *
020: * This class just applies configured rules about which events to propogate. It
021: * requires that a target IStatsRecorder instance be injected via the
022: * setTargetStatsRecorder() setter method.
023: *
024: * @version $Revision: 36282 $ $Date: 2005-10-31 10:50:39 -0700 (Mon, 31 Oct 2005) $
025: * @since uPortal 2.5.1
026: */
027: public final class ConditionalStatsRecorder implements IStatsRecorder {
028:
029: private final Log log = LogFactory.getLog(getClass());
030:
031: /**
032: * IStatsRecorder to which we will conditionally propogate IStatsRecorder
033: * method calls.
034: */
035: private IStatsRecorder targetStatsRecorder;
036:
037: /**
038: * Bundle of boolean flags indicating whether we should propogate each
039: * IStatsRecorder method.
040: */
041: private IStatsRecorderFlags flags = new StatsRecorderFlagsImpl();
042:
043: /**
044: * Returns the IStatsRecorder to which we will or will not propogate IStatsRecorder
045: * method calls depending upon our configuration.
046: * @return Returns the targetStatsRecorder.
047: */
048: public IStatsRecorder getTargetStatsRecorder() {
049: return this .targetStatsRecorder;
050: }
051:
052: /**
053: * Set the IStatsRecorder to which we will (or will not) propogate IStatsRecorder
054: * method calls depending upon our configuration.
055: * @param targetStatsRecorder The targetStatsRecorder to set.
056: */
057: public void setTargetStatsRecorder(
058: IStatsRecorder targetStatsRecorder) {
059:
060: if (targetStatsRecorder == null) {
061: throw new IllegalArgumentException(
062: "Cannot set targetStatsRecorder to null");
063: }
064:
065: this .targetStatsRecorder = targetStatsRecorder;
066: }
067:
068: /**
069: * Get the StatsRecorderFlags instance defining which IStatsRecorder method
070: * calls we should propogate and which we should not.
071: * @return flags indicating which methods we should propogate and which we should not.
072: */
073: public IStatsRecorderFlags getFlags() {
074: return this .flags;
075: }
076:
077: /**
078: * Set the boolean flags indicating which IStatsRecorder method calls we
079: * should propogate and which we should not.
080: * @param flags The flags to set.
081: */
082: public void setFlags(IStatsRecorderFlags flags) {
083:
084: if (flags == null) {
085: throw new IllegalArgumentException(
086: "Cannot set flags to null.");
087: }
088:
089: this .flags = flags;
090: }
091:
092: public void recordLogin(IPerson person) {
093: if (this .flags.isRecordLogin()) {
094:
095: if (this .targetStatsRecorder == null) {
096: log
097: .error("targetStatsRecorder of ConditionalStatsRecorder was illegally null");
098: } else {
099: this .targetStatsRecorder.recordLogin(person);
100: }
101: }
102: }
103:
104: public void recordLogout(IPerson person) {
105: if (this .flags.isRecordLogout()) {
106:
107: if (this .targetStatsRecorder == null) {
108: log
109: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
110: } else {
111: this .targetStatsRecorder.recordLogout(person);
112: }
113:
114: }
115: }
116:
117: public void recordSessionCreated(IPerson person) {
118:
119: if (this .flags.isRecordSessionCreated()) {
120:
121: if (this .targetStatsRecorder == null) {
122: log
123: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
124: } else {
125: this .targetStatsRecorder.recordSessionCreated(person);
126: }
127:
128: }
129: }
130:
131: public void recordSessionDestroyed(IPerson person) {
132: if (this .flags.isRecordSessionDestroyed()) {
133: if (this .targetStatsRecorder == null) {
134: log
135: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
136: } else {
137: this .targetStatsRecorder.recordSessionDestroyed(person);
138: }
139: }
140: }
141:
142: public void recordChannelDefinitionPublished(IPerson person,
143: ChannelDefinition channelDef) {
144: if (this .flags.isRecordChannelDefinitionPublished()) {
145: if (this .targetStatsRecorder == null) {
146: log
147: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
148: } else {
149: this .targetStatsRecorder
150: .recordChannelDefinitionPublished(person,
151: channelDef);
152: }
153: }
154: }
155:
156: public void recordChannelDefinitionModified(IPerson person,
157: ChannelDefinition channelDef) {
158: if (this .flags.isRecordChannelDefinitionModified()) {
159: if (this .targetStatsRecorder == null) {
160: log
161: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
162: } else {
163: this .targetStatsRecorder
164: .recordChannelDefinitionModified(person,
165: channelDef);
166: }
167: }
168: }
169:
170: public void recordChannelDefinitionRemoved(IPerson person,
171: ChannelDefinition channelDef) {
172: if (this .flags.isRecordChannelDefinitionRemoved()) {
173: if (this .targetStatsRecorder == null) {
174: log
175: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
176: } else {
177: this .targetStatsRecorder
178: .recordChannelDefinitionRemoved(person,
179: channelDef);
180: }
181: }
182: }
183:
184: public void recordChannelAddedToLayout(IPerson person,
185: UserProfile profile,
186: IUserLayoutChannelDescription channelDesc) {
187: if (this .flags.isRecordChannelAddedToLayout()) {
188: if (this .targetStatsRecorder == null) {
189: log
190: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
191: } else {
192: this .targetStatsRecorder.recordChannelAddedToLayout(
193: person, profile, channelDesc);
194: }
195: }
196: }
197:
198: public void recordChannelUpdatedInLayout(IPerson person,
199: UserProfile profile,
200: IUserLayoutChannelDescription channelDesc) {
201: if (this .flags.isRecordChannelUpdatedInLayout()) {
202: if (this .targetStatsRecorder == null) {
203: log
204: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
205: } else {
206: this .targetStatsRecorder.recordChannelUpdatedInLayout(
207: person, profile, channelDesc);
208: }
209: }
210: }
211:
212: public void recordChannelMovedInLayout(IPerson person,
213: UserProfile profile,
214: IUserLayoutChannelDescription channelDesc) {
215: if (this .flags.isRecordChannelMovedInLayout()) {
216: if (this .targetStatsRecorder == null) {
217: log
218: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
219: } else {
220: this .targetStatsRecorder.recordChannelMovedInLayout(
221: person, profile, channelDesc);
222: }
223: }
224: }
225:
226: public void recordChannelRemovedFromLayout(IPerson person,
227: UserProfile profile,
228: IUserLayoutChannelDescription channelDesc) {
229: if (this .flags.isRecordChannelRemovedFromLayout()) {
230: if (this .targetStatsRecorder == null) {
231: log
232: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
233: } else {
234: this .targetStatsRecorder
235: .recordChannelRemovedFromLayout(person,
236: profile, channelDesc);
237: }
238: }
239: }
240:
241: public void recordFolderAddedToLayout(IPerson person,
242: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
243: if (this .flags.isRecordFolderAddedToLayout()) {
244: if (this .targetStatsRecorder == null) {
245: log
246: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
247: } else {
248: this .targetStatsRecorder.recordFolderAddedToLayout(
249: person, profile, folderDesc);
250: }
251: }
252: }
253:
254: public void recordFolderUpdatedInLayout(IPerson person,
255: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
256: if (this .flags.isRecordFolderUpdatedInLayout()) {
257: if (this .targetStatsRecorder == null) {
258: log
259: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
260: } else {
261: this .targetStatsRecorder.recordFolderUpdatedInLayout(
262: person, profile, folderDesc);
263: }
264: }
265: }
266:
267: public void recordFolderMovedInLayout(IPerson person,
268: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
269: if (this .flags.isRecordFolderMovedInLayout()) {
270: if (this .targetStatsRecorder == null) {
271: log
272: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
273: } else {
274: this .targetStatsRecorder.recordFolderMovedInLayout(
275: person, profile, folderDesc);
276: }
277: }
278: }
279:
280: public void recordFolderRemovedFromLayout(IPerson person,
281: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
282: if (this .flags.isRecordFolderRemovedFromLayout()) {
283: if (this .targetStatsRecorder == null) {
284: log
285: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
286: } else {
287: this .targetStatsRecorder.recordFolderRemovedFromLayout(
288: person, profile, folderDesc);
289: }
290: }
291: }
292:
293: public void recordChannelInstantiated(IPerson person,
294: UserProfile profile,
295: IUserLayoutChannelDescription channelDesc) {
296: if (this .flags.isRecordChannelInstantiated()) {
297: if (this .targetStatsRecorder == null) {
298: log
299: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
300: } else {
301: this .targetStatsRecorder.recordChannelInstantiated(
302: person, profile, channelDesc);
303: }
304: }
305: }
306:
307: public void recordChannelRendered(IPerson person,
308: UserProfile profile,
309: IUserLayoutChannelDescription channelDesc) {
310: if (this .flags.isRecordChannelRendered()) {
311: if (this .targetStatsRecorder == null) {
312: log
313: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
314: } else {
315: this .targetStatsRecorder.recordChannelRendered(person,
316: profile, channelDesc);
317: }
318: }
319: }
320:
321: public void recordChannelTargeted(IPerson person,
322: UserProfile profile,
323: IUserLayoutChannelDescription channelDesc) {
324: if (this .flags.isRecordChannelTargeted()) {
325: if (this .targetStatsRecorder == null) {
326: log
327: .error("targetStatsRecorder of ConditionalStatsRecorder illegally null");
328: } else {
329: this.targetStatsRecorder.recordChannelTargeted(person,
330: profile, channelDesc);
331: }
332: }
333: }
334:
335: }
|