001: package com.sun.portal.community.admin.mbeans.tasks;
002:
003: import java.lang.*;
004: import java.util.*;
005: import java.util.logging.*;
006:
007: import javax.management.*;
008: import javax.management.remote.JMXConnector;
009:
010: import com.sun.portal.admin.server.PASModule;
011:
012: import com.sun.portal.admin.common.AttributeInfo;
013: import com.sun.portal.admin.common.AttrOptionConstants;
014: import com.sun.portal.admin.common.PSMBeanException;
015: import com.sun.portal.admin.common.util.AdminClientUtil;
016: import com.sun.portal.fabric.common.GenericDSAMEAttributeHandler;
017: import com.sun.portal.log.common.PortalLogger;
018:
019: public class CommunitiesGetSetAttributeHandler extends
020: GenericDSAMEAttributeHandler {
021:
022: private static final String WEBSERVICESURL = "WebServicesURL";
023: private String portalId = null;
024:
025: public void init(String component, String domainId, String portalId)
026: throws PSMBeanException {
027: super .init(component, domainId, portalId);
028:
029: this .portalId = portalId;
030: }
031:
032: public String getComponentName(String userFriendlyName) {
033: return "Communities";
034: }
035:
036: public String getAttributeName(String userFriendlyName) {
037: return userFriendlyName;
038: }
039:
040: public void validate(List values, Map optionsMap) {
041: }
042:
043: public void setAttribute(List values, Map optionsMap)
044: throws PSMBeanException {
045: String name = (String) optionsMap
046: .get(AttrOptionConstants.OPT_ATTR_NAME);
047: String value = (String) values.get(0);
048: if (name.equals(WEBSERVICESURL)) {
049: setCommunityManagerWSURL(value);
050: }
051: }
052:
053: public void setAttributes(Map nameValues, Map optionsMap)
054: throws PSMBeanException {
055: Set names = (Set) optionsMap
056: .get(AttrOptionConstants.OPT_ATTR_NAMES);
057: Iterator i = names.iterator();
058: while (i.hasNext()) {
059: String name = (String) i.next();
060: List values = (List) nameValues.get(name);
061: String value = (String) values.get(0);
062: if (name.equals(WEBSERVICESURL)) {
063: setCommunityManagerWSURL(value);
064: }
065: }
066: }
067:
068: public List getAttribute(Map optionsMap) throws PSMBeanException {
069: List l = new ArrayList();
070:
071: String name = (String) optionsMap
072: .get(AttrOptionConstants.OPT_ATTR_NAME);
073: if (name.equals(WEBSERVICESURL)) {
074: l.add(getCommunityManagerWSURL());
075: }
076:
077: return l;
078: }
079:
080: public Map getAttributes(Map optionsMap) throws PSMBeanException {
081: Map m = new HashMap();
082:
083: Set names = (Set) optionsMap
084: .get(AttrOptionConstants.OPT_ATTR_NAMES);
085: Iterator i = names.iterator();
086: while (i.hasNext()) {
087: String name = (String) i.next();
088: if (name.equals(WEBSERVICESURL)) {
089: List l = new ArrayList();
090: l.add(getCommunityManagerWSURL());
091: m.put(name, l);
092: }
093: }
094:
095: return m;
096: }
097:
098: public Map listAttributes(Map optionsMap) throws PSMBeanException {
099: Map attributeMap = new HashMap();
100: attributeMap.put(WEBSERVICESURL, getAttributeInfoList(
101: AttributeInfo.SINGLE_STRING,
102: "psadmin.list.communty.webservicesurl.desc",
103: AttributeInfo.READ_WRITE, null));
104: return attributeMap;
105: }
106:
107: private List getAttributeInfoList(int attributeType, String desc,
108: int privilege, String exampleKey) {
109: List infoList = new ArrayList();
110: infoList.add(new Integer(attributeType));
111: infoList.add(desc);
112: infoList.add(new Integer(privilege));
113: infoList.add(exampleKey);
114: return infoList;
115: }
116:
117: private String getCommunityManagerWSURL() throws PSMBeanException {
118: try {
119: LinkedList path = new LinkedList();
120: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
121: path.addFirst(portalId);
122: path.addFirst("CommunityManager");
123: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
124: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
125: Object[] params = {};
126: String[] signatures = {};
127: return (String) PASModule.getMBeanServer()
128: .invoke(on, "retrieveCommunityManagerWSURL",
129: params, signatures);
130: } catch (Exception e) {
131: throw new PSMBeanException("error.psadmin.get.failed", e
132: .getMessage(), e);
133: }
134: }
135:
136: private void setCommunityManagerWSURL(String url)
137: throws PSMBeanException {
138: try {
139: LinkedList path = new LinkedList();
140: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
141: path.addFirst(portalId);
142: path.addFirst("CommunityManager");
143: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
144: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
145: Object[] params = { url };
146: String[] signatures = { "java.lang.String" };
147: PASModule.getMBeanServer().invoke(on,
148: "modifyCommunityManagerWSURL", params, signatures);
149: } catch (Exception e) {
150: throw new PSMBeanException("error.psadmin.set.failed", e
151: .getMessage(), e);
152: }
153: }
154:
155: }
|