001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.jbi.jsf.handlers;
038:
039: import com.sun.enterprise.tools.admingui.util.GuiUtil;
040: import com.sun.jbi.jsf.bean.AlertBean;
041: import com.sun.jbi.jsf.util.AlertUtilities;
042: import com.sun.jbi.jsf.util.BeanUtilities;
043: import com.sun.jbi.jsf.util.ClusterUtilities;
044: import com.sun.jbi.jsf.util.I18nUtilities;
045: import com.sun.jbi.jsf.util.JBILogger;
046: import com.sun.jsftemplating.annotation.Handler;
047: import com.sun.jsftemplating.annotation.HandlerInput;
048: import com.sun.jsftemplating.annotation.HandlerOutput;
049: import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
050: import java.util.logging.Logger;
051:
052: /**
053: * Provides jsftemplating handlers for showing/discarding Alerts
054: */
055: public class AlertHandlers {
056: //Get Logger to log fine mesages for debugging
057: private static Logger sLog = JBILogger.getInstance();
058:
059: /**
060: * <p> Decreases the number of alerts to be displayed if an alert is to be displayed
061: * <p> Input value: "isAlertNeeded" -- Type: <code> Boolean</code></p>
062: * @param handlerCtx <code>HandlerContext</code> provides inputs and outputs.
063: */
064: @Handler(id="jbiDecrementAlertCountIfNeeded",input={@HandlerInput(name="isAlertNeeded",type=Boolean.class,required=true)})
065: public static void jbiDecrementAlertCountIfNeeded(
066: HandlerContext handlerCtx) {
067: jbiDecrementAlertCountIfNeededImpl(handlerCtx);
068: }
069:
070: /**
071: * invoked by JBIHookHandlers.jbiDecrementAlertCountIfNeeded and
072: * AlertHandlers.jbiDecrementAlertCountIfNeeded
073: */
074: public static void jbiDecrementAlertCountIfNeededImpl(
075: HandlerContext handlerCtx) {
076: Boolean isAlertNeeded = (Boolean) handlerCtx
077: .getInputValue("isAlertNeeded");
078:
079: AlertBean alertBean = BeanUtilities.getAlertBean();
080: int alertCount = alertBean.getAlertCount();
081:
082: if ((null != isAlertNeeded) && (isAlertNeeded)) {
083: --alertCount;
084: alertBean.setAlertCount(alertCount);
085: }
086:
087: sLog
088: .fine("AlertHandlers.jbiDecrementAlertCountIfNeededImpl(...), "
089: + " isAlertNeeded="
090: + isAlertNeeded
091: + ", alertBean.getAlertCount()=" + alertCount);
092:
093: }
094:
095: /**
096: * <p> Sets a Defaults or Target Loaded alert
097: * <p> Input value: "defaultsOrTarget" -- Type: <code> java.lang.String</code>
098: * <p> Input value: "clusterOrPe" -- Type: <code> java.lang.String</code>
099: * <p> Input value: "target" -- Type: <code> java.lang.String</code>
100: * @param handlerCtx <code>HandlerContext</code> provides inputs and outputs.
101: */
102: @Handler(id="jbiSetDefaultsOrTargetLoadedAlert",input={@HandlerInput(name="defaultsOrTarget",type=String.class,required=true),@HandlerInput(name="clusterOrPe",type=String.class,required=true),@HandlerInput(name="target",type=String.class,required=true)})
103: public static void jbiSetDefaultsOrTargetLoadedAlert(
104: HandlerContext handlerCtx) {
105: String defaultsOrTarget = (String) handlerCtx
106: .getInputValue("defaultsOrTarget");
107: String clusterOrPe = (String) handlerCtx
108: .getInputValue("clusterOrPe");
109: String target = (String) handlerCtx.getInputValue("target");
110:
111: sLog
112: .fine("AlertHandlers.jbiSetDefaultsOrTargetLoadedAlert(), defaultsOrTarget ="
113: + defaultsOrTarget
114: + ", clusterOrPe="
115: + clusterOrPe + ", target=" + target);
116:
117: AlertBean alertBean = BeanUtilities.getAlertBean();
118:
119: Object[] args = { target };
120:
121: String alertType = "info";
122: String alertSummary = GuiUtil.getMessage(I18nUtilities
123: .getResourceString("jbi.root.configuration."
124: + defaultsOrTarget + "." + clusterOrPe
125: + ".loaded.summary.message"), args);
126: String alertDetail = I18nUtilities
127: .getResourceString("jbi.root.configuration."
128: + defaultsOrTarget + "." + clusterOrPe
129: + ".loaded.detail.message");
130:
131: alertBean.setAlertType(alertType);
132: alertBean.setAlertSummary(alertSummary);
133: alertBean.setAlertDetail(alertDetail);
134:
135: sLog
136: .fine("AlertHandlers.jbiSetDefaultsOrTargetLoadedAlert(), alertType="
137: + alertType
138: + ", alertSummary="
139: + alertSummary
140: + ", alertDetail=" + alertDetail);
141: }
142:
143: /**
144: * <p> Increases the number of alerts to be displayed if an alert is to be displayed
145: * <p> Input value: "isAlertNeeded" -- Type: <code> Boolean</code></p>
146: * @param handlerCtx <code>HandlerContext</code> provides inputs and outputs.
147: */
148: @Handler(id="jbiIncrementAlertCountIfNeeded",input={@HandlerInput(name="isAlertNeeded",type=Boolean.class,required=true)})
149: public static void jbiIncrementAlertCountIfNeeded(
150: HandlerContext handlerCtx) {
151: Boolean isAlertNeeded = (Boolean) handlerCtx
152: .getInputValue("isAlertNeeded");
153:
154: AlertBean alertBean = BeanUtilities.getAlertBean();
155: int alertCount = alertBean.getAlertCount();
156:
157: if ((null != isAlertNeeded) && (isAlertNeeded)) {
158: ++alertCount;
159: alertBean.setAlertCount(alertCount);
160: }
161:
162: sLog.fine("AlertHandlers.jbiIncrementAlertCountIfNeeded(...), "
163: + " isAlertNeeded=" + isAlertNeeded
164: + ", alertBean.getAlertCount()=" + alertCount);
165:
166: }
167:
168: /**
169: * <p> Returns true if an alert still needs to be displayed
170: * <p> Output value: "isAlertNeeded" -- Type: <code> Boolean</code></p>
171: * @param handlerCtx <code>HandlerContext</code> provides inputs and outputs.
172: */
173: @Handler(id="jbiIsAlertNeeded",output={@HandlerOutput(name="isAlertNeeded",type=Boolean.class)})
174: public static void jbiIsAlertNeeded(HandlerContext handlerCtx) {
175: jbiIsAlertNeededImpl(handlerCtx);
176: }
177:
178: /**
179: * called by JBIHookHandler.jbiIsAlertNeeded
180: * and AlertHandlers.jbiIsAlertNeeded
181: */
182: public static void jbiIsAlertNeededImpl(HandlerContext handlerCtx) {
183: AlertBean alertBean = BeanUtilities.getAlertBean();
184:
185: int alertCount = alertBean.getAlertCount();
186:
187: boolean isAlertNeeded = (0 < alertCount);
188:
189: handlerCtx.setOutputValue("isAlertNeeded", isAlertNeeded);
190:
191: sLog.fine("AlertHandlers.jbiIsAlertNeededImpl(...), "
192: + " isAlertNeeded=" + isAlertNeeded
193: + ", alertBean.getAlertCount()=" + alertCount);
194:
195: }
196:
197: }
|