001: /*
002: * Created on Apr 6, 2005
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package com.sun.portal.sra.admin.attribute.handlers;
008:
009: import java.util.Collections;
010: import java.util.List;
011: import java.util.Map;
012: import java.util.Set;
013: import java.util.logging.Logger;
014:
015: import com.sun.portal.admin.common.AttrOptionConstants;
016: import com.sun.portal.admin.common.PSMBeanException;
017: import com.sun.portal.admin.server.AdminServerUtil;
018: import com.sun.portal.fabric.common.AttributeHandler;
019: import com.sun.portal.fabric.common.AttributeOperations;
020: import com.sun.portal.log.common.PortalLogger;
021:
022: /**
023: * @author ss150821
024: *
025: */
026: public class GatewayAttributeHandler implements AttributeHandler {
027:
028: private static String _compName = null;
029:
030: private static String _domainId = null;
031:
032: private static String _portalId = null;
033:
034: protected AttributeOperations _attrOps = null;
035:
036: private static Logger logger = PortalLogger
037: .getLogger(GatewayAttributeHandler.class);
038:
039: private static String loggerName = "debug.com.sun.portal.admin.mbeans";
040:
041: private static final String ATTRIBUTE_PREFIX = "sunPortalGateway";
042:
043: public void init(String component, String domainId, String portalId)
044: throws PSMBeanException {
045: _compName = component;
046: _domainId = domainId;
047: _portalId = portalId;
048:
049: try {
050: _attrOps = new GatewayAttributeOperations(AdminServerUtil
051: .getSSOToken());
052: } catch (Exception e) {
053: throw new PSMBeanException(
054: "error.psadmin.handler.init.failed",
055: e.getMessage(), e);
056: }
057: }
058:
059: public void validate(List values, Map optionsMap)
060: throws PSMBeanException {
061: return;
062: }
063:
064: public String getAttributeName(String userFriendlyName) {
065: if (userFriendlyName.toLowerCase().startsWith(
066: ATTRIBUTE_PREFIX.toLowerCase()))
067: return userFriendlyName;
068: else
069: return ATTRIBUTE_PREFIX + userFriendlyName;
070: }
071:
072: public String getComponentName(String userFriendlyName) {
073: return userFriendlyName;
074: }
075:
076: private void replaceUserFriendlyAttributeNameWithActual(
077: Map optionsMap) {
078: String passedInAttribName = (String) optionsMap
079: .get(AttrOptionConstants.OPT_ATTR_NAME);
080: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME,
081: getAttributeName(passedInAttribName));
082: }
083:
084: public List getAttribute(Map optionsMap) throws PSMBeanException {
085: replaceUserFriendlyAttributeNameWithActual(optionsMap);
086: String component = (String) optionsMap
087: .get(AttrOptionConstants.OPT_COMPONENT);
088: String attribute = (String) optionsMap
089: .get(AttrOptionConstants.OPT_ATTR_NAME);
090:
091: try {
092: logger.info("PSSR_CSPS_ADM_ATTRIB_HNDLRS000");
093: return _attrOps.getAttribute(component, attribute,
094: optionsMap);
095: } catch (Exception e) {
096: logger.info("PSSR_CSPS_ADM_ATTRIB_HNDLRS001");
097: throw new PSMBeanException("error.psadmin.get.failed", e
098: .getMessage(), e);
099: }
100: }
101:
102: public void setAttribute(List values, Map optionsMap)
103: throws PSMBeanException {
104: replaceUserFriendlyAttributeNameWithActual(optionsMap);
105: String component = (String) optionsMap
106: .get(AttrOptionConstants.OPT_COMPONENT);
107: String attribute = (String) optionsMap
108: .get(AttrOptionConstants.OPT_ATTR_NAME);
109: try {
110: _attrOps.setAttribute(component, attribute, values,
111: optionsMap);
112: } catch (Exception e) {
113: logger.info("PSSR_CSPS_ADM_ATTRIB_HNDLRS002");
114: throw new PSMBeanException("error.psadmin.set.failed", e
115: .getMessage(), e);
116: }
117: }
118:
119: public Map listAttributes(Map optionsMap) throws PSMBeanException {
120: String component = (String) optionsMap
121: .get(AttrOptionConstants.OPT_COMPONENT);
122: Map values = _attrOps.listAttributes(component, optionsMap);
123: return values == null ? Collections.EMPTY_MAP : values;
124: }
125:
126: public void setAttributes(Map nameValues, Map optionsMap)
127: throws PSMBeanException {
128: String component = (String) optionsMap
129: .get(AttrOptionConstants.OPT_COMPONENT);
130:
131: try {
132: _attrOps.setAttributes(component, nameValues, optionsMap);
133: } catch (Exception e) {
134: logger.info("PSSR_CSPS_ADM_ATTRIB_HNDLRS002");
135: throw new PSMBeanException("error.psadmin.set.failed", e
136: .getMessage(), e);
137: }
138: }
139:
140: public Map getAttributes(Map optionsMap) throws PSMBeanException {
141: String component = (String) optionsMap
142: .get(AttrOptionConstants.OPT_COMPONENT);
143: Set attributes = (Set) optionsMap
144: .get(AttrOptionConstants.OPT_ATTR_NAMES);
145:
146: try {
147: logger.info("PSSR_CSPS_ADM_ATTRIB_HNDLRS000");
148: return _attrOps.getAttributes(component, attributes,
149: optionsMap);
150: } catch (Exception e) {
151: logger.info("PSSR_CSPS_ADM_ATTRIB_HNDLRS001");
152: throw new PSMBeanException("error.psadmin.get.failed", e
153: .getMessage(), e);
154: }
155: }
156:
157: }
|