001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.notification;
019:
020: import java.util.Arrays;
021: import java.util.Date;
022:
023: import org.apache.lenya.ac.Identifiable;
024:
025: /**
026: * A notification message.
027: */
028: public class Message {
029:
030: private String subject;
031: private String[] subjectParams;
032: private String body;
033: private String[] bodyParams;
034: private Identifiable sender;
035: private Identifiable[] recipients;
036: private Date time;
037:
038: /**
039: * Ctor.
040: * @param subject The subject.
041: * @param subjectParams The subject parameters.
042: * @param body The body.
043: * @param bodyParams The body parameters.
044: * @param sender The sender.
045: * @param recipients The recipients.
046: */
047: public Message(String subject, String[] subjectParams, String body,
048: String[] bodyParams, Identifiable sender,
049: Identifiable[] recipients) {
050: this .subject = subject;
051: this .subjectParams = subjectParams;
052: this .body = body;
053: this .bodyParams = bodyParams;
054: this .sender = sender;
055: this .recipients = recipients;
056: this .time = new Date();
057: }
058:
059: /**
060: * Determine if this message has parameters
061: * @return true if the message has parameters
062: */
063: public boolean hasBodyParameters() {
064: return bodyParams != null && bodyParams.length > 0;
065: }
066:
067: /**
068: * Retrieve the message content
069: * @return the message
070: */
071: public String getBody() {
072: return body;
073: }
074:
075: /**
076: * Retrieve the parameters for this message
077: * @return the parameters
078: */
079: public String[] getBodyParameters() {
080: return bodyParams;
081: }
082:
083: /**
084: * Determine if this message has parameters
085: * @return true if the message has parameters
086: */
087: public boolean hasSubjectParameters() {
088: return subjectParams != null && subjectParams.length > 0;
089: }
090:
091: /**
092: * Retrieve the message subject
093: * @return the subject
094: */
095: public String getSubject() {
096: return subject;
097: }
098:
099: /**
100: * Retrieve the parameters for this message
101: * @return the parameters
102: */
103: public String[] getSubjectParameters() {
104: return subjectParams;
105: }
106:
107: /**
108: * @return The sender.
109: */
110: public Identifiable getSender() {
111: return this .sender;
112: }
113:
114: /**
115: * @return The recipients.
116: */
117: public Identifiable[] getRecipients() {
118: // don't expose the internal array
119: return (Identifiable[]) Arrays.asList(this .recipients).toArray(
120: new Identifiable[this .recipients.length]);
121: }
122:
123: /**
124: * @return The time when the message was sent.
125: */
126: public Date getTime() {
127: return (Date) this.time.clone();
128: }
129:
130: }
|