KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > notification > SubjectCarrier


1 /* ************************************************************************** *
2  * Copyright (C) 2004 NightLabs GmbH, Marco Schulze *
3  * All rights reserved. *
4  * http://www.NightLabs.de *
5  * *
6  * This program and the accompanying materials are free software; you can re- *
7  * distribute it and/or modify it under the terms of the GNU General Public *
8  * License as published by the Free Software Foundation; either ver 2 of the *
9  * License, or any later version. *
10  * *
11  * This module is distributed in the hope that it will be useful, but WITHOUT *
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT- *
13  * NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more *
14  * details. *
15  * *
16  * You should have received a copy of the GNU General Public License along *
17  * with this module; if not, write to the Free Software Foundation, Inc.: *
18  * 59 Temple Place, Suite 330 *
19  * Boston MA 02111-1307 *
20  * USA *
21  * *
22  * Or get it online: *
23  * http://www.opensource.org/licenses/gpl-license.php *
24  * *
25  * In case, you want to use this module or parts of it in a proprietary pro- *
26  * ject, you can purchase it under the NightLabs Commercial License. Please *
27  * contact NightLabs GmbH under info AT nightlabs DOT com for more infos or *
28  * visit http://www.NightLabs.com *
29  * ************************************************************************** */

30
31 /*
32  * Created on May 7, 2005
33  */

34 package com.nightlabs.notification;
35
36 import java.util.HashSet JavaDoc;
37 import java.util.Set JavaDoc;
38
39 /**
40  * @author Marco Schulze - marco at nightlabs dot de
41  */

42 public class SubjectCarrier
43 // implements Cloneable
44
{
45     private Object JavaDoc subject;
46     private Set JavaDoc subjectClasses = new HashSet JavaDoc();
47     private boolean inheritanceIgnored;
48     private boolean interfacesIgnored;
49     private boolean breakOnFirstFound = false;
50     
51     public SubjectCarrier(Object JavaDoc subject)
52     {
53         this(subject, false, false);
54     }
55     
56     public SubjectCarrier(Object JavaDoc subject, boolean inheritanceIgnored)
57     {
58         this(subject, inheritanceIgnored, false);
59     }
60
61     public SubjectCarrier(Object JavaDoc subject, boolean inheritanceIgnored, boolean interfacesIgnored)
62     {
63         if (subject == null)
64             throw new NullPointerException JavaDoc("Cannot use subject=null without specifying a class!");
65
66         this.subject = subject;
67         subjectClasses.add(subject.getClass());
68         this.inheritanceIgnored = inheritanceIgnored;
69         this.interfacesIgnored = interfacesIgnored;
70     }
71
72     public SubjectCarrier(Class JavaDoc subjectClass)
73     {
74         this(subjectClass, false, false);
75     }
76     
77     public SubjectCarrier(Class JavaDoc subjectClass, boolean inheritanceIgnored) {
78         this(subjectClass, inheritanceIgnored, false);
79     }
80
81     public SubjectCarrier(Class JavaDoc subjectClass, boolean inheritanceIgnored, boolean interfacesIgnored)
82     {
83         if (subjectClass == null)
84             throw new NullPointerException JavaDoc("Parameter subjectClass must not be null!");
85
86         subject = null;
87         subjectClasses.add(subjectClass);
88         this.inheritanceIgnored = inheritanceIgnored;
89         this.interfacesIgnored = interfacesIgnored;
90     }
91
92     /**
93      * @param subject May be <tt>null</tt> if <tt>subjectClass</tt> isn't.
94      * @param subjectClass If <tt>subject</tt> is <tt>null</tt>, this must be specified,
95      * otherwise <tt>subjectClass</tt> may be <tt>null</tt>. If this <tt>Class</tt>
96      * differs from the type of <tt>subject</tt>, it is added to the <tt>Set</tt> of
97      * subject classes.
98      */

99     public SubjectCarrier(Object JavaDoc subject, Class JavaDoc subjectClass)
100     {
101         this.subject = subject;
102
103         if (subject != null)
104             subjectClasses.add(subject.getClass());
105     }
106
107     /**
108      * @return Returns the subject.
109      */

110     public Object JavaDoc getSubject()
111     {
112         return subject;
113     }
114     /**
115      * @return Returns the subjectClasses.
116      */

117     public Set JavaDoc getSubjectClasses()
118     {
119         return subjectClasses;
120     }
121
122 // /**
123
// * This method does NOT clone the subject - hence the subject will be the same
124
// * for the new SubjectCarrier.
125
// *
126
// * @see java.lang.Object#clone()
127
// */
128
// public Object clone()
129
// {
130
// SubjectCarrier n = new SubjectCarrier(subject);
131
// n.subjectClasses.addAll(subjectClasses);
132
// return n;
133
// }
134

135     /**
136      * @return Returns the inheritanceIgnored.
137      */

138     public boolean isInheritanceIgnored()
139     {
140         return inheritanceIgnored;
141     }
142     /**
143      * @param inheritanceIgnored The inheritanceIgnored to set.
144      */

145     public void setInheritanceIgnored(boolean inheritanceIgnored)
146     {
147         this.inheritanceIgnored = inheritanceIgnored;
148     }
149     
150     /**
151      * @return Returns the interfacesIgnored.
152      */

153     public boolean isInterfacesIgnored() {
154         return interfacesIgnored;
155     }
156     
157     /**
158      * @param interfacesIgnored The interfacesIgnored to set.
159      */

160     public void setInterfacesIgnored(boolean interfacesIgnored) {
161         this.interfacesIgnored = interfacesIgnored;
162     }
163     
164     public boolean isBreakOnFirstFound() {
165         return breakOnFirstFound;
166     }
167     
168     public void setBreakOnFirstFound(boolean breakOnFirstFound) {
169         this.breakOnFirstFound = breakOnFirstFound;
170     }
171 }
172
Popular Tags