001: /**
002: * $Id: PortalBaseBean.java,v 1.5 2006/06/15 22:34:46 cathywu Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.common;
014:
015: import java.util.LinkedList;
016: import java.util.Set;
017: import java.util.logging.Level;
018:
019: import java.io.IOException;
020: import java.net.InetAddress;
021: import java.net.UnknownHostException;
022:
023: import javax.faces.el.VariableResolver;
024: import javax.faces.context.FacesContext;
025:
026: import javax.management.ObjectName;
027:
028: import com.sun.portal.admin.common.util.AdminClientUtil;
029: import com.sun.portal.admin.common.util.AdminUtil;
030:
031: /**
032: * This bean implements functionality that is common to all JSF beans that are
033: * related to a portal. Any reusable piece of code that is related to portals
034: * or portal related beans should be in this bean.
035: *
036: * @author Raju Uppalapati
037: */
038: public class PortalBaseBean extends PSBaseBean {
039:
040: /**
041: * request attr names (should be moved to a new file like RequestAttributeNames?)
042: */
043: public static final String ATTR_SELECTED_CHANNEL_NAME = "selected.channel.name";
044: public static final String ATTR_NESTED_PROPERTY_NAME = "nested.property.name";
045:
046: /**
047: * Default Charset
048: */
049: public static final String DEFAULT_CHARSET = "UTF-8";
050:
051: /**
052: * Constructor for this bean
053: */
054: public PortalBaseBean() {
055: }
056:
057: /**
058: * Gets the portal that is currently being navigated by the user
059: * @return The portal Id as a String
060: */
061: public String getPortalId() {
062: return (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
063: }
064:
065: /**
066: * Gets the instance object names for a given portal id
067: * @return <code>Set</code> of instance object names
068: */
069: public Set getInstanceObjectNames(String portalId)
070: throws IOException, Exception {
071: ObjectName instancePat = AdminClientUtil
072: .getPortalServerInstancesPattern(
073: AdminClientUtil.DEFAULT_DOMAIN, portalId);
074: Set objNames = getMBeanServerConnection().queryNames(
075: instancePat,
076: AdminUtil.getPortalServerInstancesPattern(
077: AdminUtil.DEFAULT_DOMAIN, portalId));
078: return objNames;
079: }
080:
081: /**
082: * Checks if the console is connecting a remote PAS from
083: * the console machine.
084: *
085: * This method does not throw exception in case of error, it will
086: * return false and assume the cacao server is running on the
087: * psconsole machine.
088: */
089: public boolean isLocal() {
090: String isLocalStr = (String) getSessionAttribute(ATTR_ISLOCAL);
091: if (isLocalStr != null) {
092: return Boolean.valueOf(isLocalStr).booleanValue();
093: }
094:
095: boolean isLocal = true;
096: FacesContext context = FacesContext.getCurrentInstance();
097: VariableResolver vr = context.getApplication()
098: .getVariableResolver();
099: String pasHost = null; //Portal Server machine running cacao
100:
101: Object loginObj = (Object) vr.resolveVariable(context,
102: "LoginBean");
103: if ((loginObj != null) && (loginObj instanceof LoginBean)) {
104: LoginBean loginBean = (LoginBean) loginObj;
105: pasHost = loginBean.getPasHost();
106: }
107:
108: log(Level.INFO, "PortalBaseBean.isLocal(), pashost: " + pasHost);
109:
110: try {
111: if (pasHost != null && pasHost.length() > 0) {
112: isLocal = AdminUtil.isLocal(pasHost);
113: setSessionAttribute(ATTR_ISLOCAL, Boolean
114: .toString(isLocal));
115: }
116: } catch (UnknownHostException ue) {
117: //do nothing
118: }
119:
120: return isLocal;
121: }
122:
123: }
|