KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > xml > cookies > CookieMessage


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.xml.cookies;
21
22 import org.openide.util.Lookup;
23 import org.openide.util.lookup.Lookups;
24
25 /**
26  * Extensible and immutable <code>CookieObserver</code> message.
27  * Look at particular cookie what detail subclasses it supports.
28  *
29  * @author Petr Kuzel
30  * @since 0.8
31  */

32 public final class CookieMessage {
33
34     // details
35
private final Lookup details;
36
37     // localized message
38
private final String JavaDoc message;
39
40     // message level
41
private final int level;
42
43     /**
44      * Receive a localized message not tied with the processing problems.
45      */

46     public static final int INFORMATIONAL_LEVEL = 0;
47
48     /**
49      * Receive notification of a warning.
50      */

51     public static final int WARNING_LEVEL = 1;
52
53     /**
54      * Receive notification of a recoverable error.
55      */

56     public static final int ERROR_LEVEL = 2;
57
58     /**
59      * Receive notification of a non-recoverable error.
60      */

61     public static final int FATAL_ERROR_LEVEL = 3;
62
63     /**
64      * Create new informational level message.
65      * @param message Localized message.
66      */

67     public CookieMessage(String JavaDoc message) {
68         this( message, INFORMATIONAL_LEVEL, null);
69     }
70
71     /**
72      * Create new message.
73      * @param message Localized message.
74      * @param level Message level.
75      */

76     public CookieMessage(String JavaDoc message, int level) {
77         this( message, level, null);
78     }
79
80     /**
81      * Create new informational level message with structured detail.
82      * @param message Localized message.
83      * @param detail Structured detail attached to the message.
84      */

85     public CookieMessage(String JavaDoc message, Object JavaDoc detail) {
86         this( message, INFORMATIONAL_LEVEL, detail);
87     }
88     
89     /**
90      * Create new message with structured detail.
91      * @param message Localized message.
92      * @param level Message level.
93      * @param detail Structured detail attached to the message.
94      */

95     public CookieMessage(String JavaDoc message, int level, Object JavaDoc detail) {
96         this(message, level, Lookups.singleton(detail));
97     }
98
99     /**
100      * Create new message with structured detail.
101      * @param message Localized message.
102      * @param level Message level.
103      * @param details Lookup holding structured details.
104      */

105     public CookieMessage(String JavaDoc message, int level, Lookup details) {
106         if (message == null) throw new NullPointerException JavaDoc();
107         if (level < INFORMATIONAL_LEVEL || level > FATAL_ERROR_LEVEL)
108             throw new IllegalArgumentException JavaDoc();
109
110         this.message = message;
111         this.level = level;
112         this.details = details == null ? Lookup.EMPTY : details;
113     }
114     
115     
116     /**
117      * @return Localized message.
118      */

119     public String JavaDoc getMessage() {
120         return message;
121     }
122
123     /**
124      * @return Message level.
125      */

126     public final int getLevel() {
127         return level;
128     }
129
130     /**
131      * Query for structured detail attached to the message.
132      * @param klass Requested detail subclass.
133      * @return Instance of requested structured detail or <code>null</code>.
134      */

135     public Object JavaDoc getDetail(Class JavaDoc klass) {
136         return details.lookup(klass);
137     }
138
139     /**
140      * Query for structured details attached to the message.
141      * @return Lookup of attached structured details.
142      */

143     public Lookup getDetails() {
144         return details;
145     }
146 }
147
Popular Tags