001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: *
013: * @ Author Francis Sujai
014: */package com.sun.portal.proxylet.admin;
015:
016: // JDK classes
017:
018: import com.iplanet.am.console.base.model.AMModelBase;
019: import com.iplanet.am.util.Debug;
020: import com.iplanet.am.util.Locale;
021: import com.iplanet.jato.ModelManager;
022: import com.iplanet.jato.ModelTypeMap;
023: import com.iplanet.jato.RequestContext;
024: import com.iplanet.sso.SSOException;
025: import com.iplanet.sso.SSOToken;
026: import com.iplanet.sso.SSOTokenManager;
027:
028: import java.util.MissingResourceException;
029: import java.util.ResourceBundle;
030:
031: //import com.iplanet.am.console.base.model.AMAdminLog;
032:
033: public class ProxyletAdminModelManager extends ModelManager {
034:
035: public static final String SRAP_PROXYLET_MODEL_MGR_KEY = "srapProxyletModelMgrKey";
036:
037: private static final String TOKEN_DELIMITER = "|";
038:
039: protected SSOToken token = null;
040: protected String rbName = "srapproxyletadminmsgs";
041: protected ResourceBundle bundle = null;
042: protected java.util.Locale locale = null;
043: private static Debug debug = AMModelBase.debug;
044:
045: static {
046: if (AMModelBase.debug == null) {
047: debug = AMModelBase.debug = com.iplanet.am.util.Debug
048: .getInstance("amConsole");
049: }
050:
051: }
052:
053: public ProxyletAdminModelManager(RequestContext requestContext,
054: ModelTypeMap typeMap) {
055: super (requestContext, typeMap);
056: initSSOToken(requestContext);
057: initRB();
058: }
059:
060: /**
061: * Initializes the SSO token for use in this request. The SSO token
062: * can then be used as a store for session info across requests.
063: * @param requestContext is the JATO request context.
064: */
065: void initSSOToken(RequestContext requestContext) {
066: try {
067: SSOTokenManager manager = SSOTokenManager.getInstance();
068: token = manager.createSSOToken(requestContext.getRequest());
069: manager.getInstance().validateToken(token);
070: } catch (Exception e) {
071: token = null;
072: }
073: }
074:
075: /**
076: * Initializes the resuource bundle using the locale from the
077: * SSO token.
078: */
079: void initRB() {
080: if (token != null) {
081: try {
082: String lstr = token.getProperty("Locale");
083: locale = Locale.getLocale(lstr);
084: } catch (SSOException ssoe) {
085: locale = java.util.Locale.getDefault();
086: }
087: } else {
088: locale = java.util.Locale.getDefault();
089: }
090: try {
091: bundle = ResourceBundle.getBundle(rbName, locale);
092: } catch (MissingResourceException mre) {
093: }
094: }
095:
096: public static boolean warningEnabled() {
097: return debug.warningEnabled();
098: }
099:
100: public static boolean messageEnabled() {
101: return debug.messageEnabled();
102: }
103:
104: public static void debugWarning(String message) {
105: if (debug.warningEnabled())
106: debug.warning(message);
107: }
108:
109: public static void debugWarning(String message, Throwable t) {
110: if (debug.warningEnabled())
111: debug.warning(message, t);
112: }
113:
114: public static void debugMessage(String message) {
115: if (debug.messageEnabled())
116: debug.message(message);
117: }
118:
119: public static void debugMessage(String message, Throwable t) {
120: if (debug.messageEnabled())
121: debug.message(message, t);
122: }
123:
124: public static void debugError(String message) {
125: debug.error(message);
126: }
127:
128: public static void debugError(String message, Throwable t) {
129: debug.error(message, t);
130: }
131:
132: /**
133: * Returns the localized resource string for the corresponding
134: * resource key.
135: */
136: public String getString(String key) {
137: String result = null;
138: try {
139: if (bundle != null) {
140: result = bundle.getString(key);
141: }
142: } catch (MissingResourceException mre) {
143: }
144: return (result == null ? key : result);
145: }
146:
147: public ResourceBundle getAdminMsgsRB() {
148: return bundle;
149: }
150:
151: }
|