0001: /**
0002: * $Id: ProducerAttributeHandler.java,v 1.12 2006/03/13 07:30:38 mg155852 Exp $
0003: * Copyright 2005 Sun Microsystems, Inc. All
0004: * rights reserved. Use of this product is subject
0005: * to license terms. Federal Acquisitions:
0006: * Commercial Software -- Government Users
0007: * Subject to Standard License Terms and
0008: * Conditions.
0009: *
0010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011: * are trademarks or registered trademarks of Sun Microsystems,
0012: * Inc. in the United States and other countries.
0013: */package com.sun.portal.wsrp.producer.admin.mbeans;
0014:
0015: import java.util.ArrayList;
0016: import java.util.Collections;
0017: import java.util.HashMap;
0018: import java.util.HashSet;
0019: import java.util.Iterator;
0020: import java.util.List;
0021: import java.util.Map;
0022: import java.util.Hashtable;
0023: import java.util.Set;
0024: import java.util.logging.Level;
0025: import java.util.logging.Logger;
0026: import java.io.IOException;
0027:
0028: import javax.xml.namespace.QName;
0029:
0030: import com.iplanet.am.util.Locale;
0031: import com.sun.portal.admin.common.AttrOptionConstants;
0032: import com.sun.portal.admin.server.AdminServerUtil;
0033: import com.sun.portal.admin.common.PSMBeanException;
0034: import com.sun.portal.fabric.common.GenericDSAMEAttributeHandler;
0035: import com.sun.portal.log.common.PortalLogger;
0036: import com.sun.portal.wsrp.common.stubs.GetServiceDescription;
0037: import com.sun.portal.wsrp.common.stubs.LocalizedString;
0038: import com.sun.portal.wsrp.common.stubs.ModelDescription;
0039: import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
0040: import com.sun.portal.wsrp.common.stubs.Property;
0041: import com.sun.portal.wsrp.common.stubs.PropertyDescription;
0042: import com.sun.portal.wsrp.common.stubs.RegistrationData;
0043: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
0044: import com.sun.portal.wsrp.producer.Producer;
0045: import com.sun.portal.wsrp.producer.ISMultiPortalConstants;
0046: import com.sun.portal.wsrp.producer.ProducerException;
0047: import com.sun.portal.wsrp.producer.impl.ProducerImpl;
0048: import com.sun.portal.wsrp.producer.registration.RegistrationManager;
0049: import com.sun.portal.wsrp.producer.registration.RegistrationRecord;
0050: import com.sun.portal.wsrp.producer.registration.validator.RegistrationValidator;
0051: import com.sun.portal.wsrp.producer.servicedescription.ServiceDescriptionManager;
0052:
0053: import com.iplanet.sso.SSOToken;
0054:
0055: public class ProducerAttributeHandler extends
0056: GenericDSAMEAttributeHandler {
0057: public static final QName PROPERTY_TYPE = new QName("string");
0058: private String lang = null;
0059: private Logger logger = PortalLogger
0060: .getLogger(ProducerAttributeHandler.class);
0061: private ISMultiPortalConstants ismpc = null;
0062:
0063: public void init(String component, String domainId, String portalId)
0064: throws PSMBeanException {
0065:
0066: if (portalId == null) {
0067: logger.severe("PSWS_CSPWPAB0006");
0068: throw new PSMBeanException("Missing portal Id.");
0069: }
0070:
0071: super .init(component, domainId, portalId);
0072: lang = Locale.getDefaultLocale().toString().replace('_', '-');
0073: ismpc = ISMultiPortalConstants.getInstance(portalId);
0074: }
0075:
0076: public String getAttributeName(String userFriendlyName) {
0077: // TODO: shouldn't hardcode the "sunPortalWSRPProducer" string here
0078: return "sunPortalWSRPProducer" + userFriendlyName;
0079: }
0080:
0081: public String getComponentName(String userFriendlyName) {
0082: return ismpc.MP_SUN_WSRP_PRODUCER_SERVICE;
0083: }
0084:
0085: public List getAttribute(Map optionsMap) throws PSMBeanException {
0086: String name = (String) optionsMap
0087: .get(AttrOptionConstants.OPT_ATTR_NAME);
0088:
0089: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, Collections
0090: .singleton(name));
0091:
0092: return (List) getAttributes(optionsMap).get(name);
0093: }
0094:
0095: public Map getAttributes(Map optionsMap) throws PSMBeanException {
0096: // TODO: shouldn't hardcode the "registrationhandle" string here
0097: String handle = (String) optionsMap.get("registrationhandle");
0098:
0099: if (handle == null) {
0100: return getProducerAttributes(optionsMap);
0101: } else {
0102: return getCRAttributes(optionsMap, handle);
0103: }
0104: }
0105:
0106: public void setAttribute(List values, Map optionsMap)
0107: throws PSMBeanException {
0108:
0109: String name = (String) optionsMap
0110: .get(AttrOptionConstants.OPT_ATTR_NAME);
0111: setAttributes(Collections.singletonMap(name, values),
0112: optionsMap);
0113: }
0114:
0115: public void setAttributes(Map nameValues, Map optionsMap)
0116: throws PSMBeanException {
0117:
0118: // TODO: shouldn't hardcode the "registrationhandle" string here
0119: String handle = (String) optionsMap.get("registrationhandle");
0120:
0121: if (handle == null) {
0122: setProducerAttributes(nameValues, optionsMap);
0123: } else {
0124: setCRAttributes(nameValues, optionsMap, handle);
0125: }
0126: }
0127:
0128: public Map listAttributes(Map optionsMap) throws PSMBeanException {
0129: // TODO: shouldn't hardcode the "consumerregistration" string here
0130: String cr = (String) optionsMap.get("consumerregistration");
0131:
0132: if (Boolean.valueOf(cr).booleanValue()) {
0133: return ProducerAttributes.CR_MAP;
0134: } else {
0135: return ProducerAttributes.PRODUCER_MAP;
0136: }
0137: }
0138:
0139: private Map getProducerAttributes(Map optionsMap)
0140: throws PSMBeanException {
0141: Set names = (Set) optionsMap
0142: .get(AttrOptionConstants.OPT_ATTR_NAMES);
0143: Map result = new HashMap(names.size());
0144: Producer producer = null;
0145: ServiceDescriptionManager sdm = null;
0146: Set allPortlets = null;
0147: Set publishedPortlets = null;
0148:
0149: // TODO: shouldn't hardcode the "producer" string here
0150: String producerID = (String) optionsMap.get("producer");
0151:
0152: try {
0153: if (producerID != null) {
0154: producer = getProducer(producerID);
0155: sdm = producer.getServiceDescriptionManager();
0156: allPortlets = producer.getPortletChannelNames();
0157: publishedPortlets = sdm.getOfferedPortletNames();
0158: publishedPortlets.retainAll(allPortlets);
0159: }
0160:
0161: for (Iterator i = names.iterator(); i.hasNext();) {
0162: String name = (String) i.next();
0163: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME, name);
0164:
0165: if (name.equals(ProducerAttributes.ALL_DISABLED)) {
0166: optionsMap.put(AttrOptionConstants.OPT_GLOBAL,
0167: Boolean.TRUE.toString());
0168:
0169: result.put(name, super .getAttribute(optionsMap));
0170: } else if (name.equals(ProducerAttributes.ENABLED)) {
0171: if (producerID == null) {
0172: logger.severe("PSWS_CSPWPAB0007");
0173: throw new PSMBeanException(
0174: "Missing producer Id.");
0175: }
0176:
0177: result.put(name, Collections.singletonList(Boolean
0178: .toString(producer.isEnabled())));
0179: } else if (name.equals(ProducerAttributes.WSDL_URL)) {
0180: if (producerID == null) {
0181: logger.severe("PSWS_CSPWPAB0007");
0182: throw new PSMBeanException(
0183: "Missing producer Id.");
0184: }
0185:
0186: String wsdlURL = ProducerAttributeHelper
0187: .getWSDLURL(producer, domainId, portalId);
0188: result
0189: .put(name, Collections
0190: .singletonList(wsdlURL));
0191: } else if (name
0192: .equals(ProducerAttributes.REGISTRATION_REQUIRED)) {
0193: if (producerID == null) {
0194: logger.severe("PSWS_CSPWPAB0007");
0195: throw new PSMBeanException(
0196: "Missing producer Id.");
0197: }
0198:
0199: result
0200: .put(
0201: name,
0202: Collections
0203: .singletonList(Boolean
0204: .toString(producer
0205: .requiresRegistration())));
0206: } else if (name
0207: .equals(ProducerAttributes.IN_BAND_REGISTRATION_SUPPORTED)) {
0208: if (producerID == null) {
0209: logger.severe("PSWS_CSPWPAB0007");
0210: throw new PSMBeanException(
0211: "Missing producer Id.");
0212: }
0213:
0214: result.put(name, Collections.singletonList(Boolean
0215: .toString(producer
0216: .inbandRegistrationSupported())));
0217: } else if (name
0218: .equals(ProducerAttributes.REGISTRATION_VALIDATOR_CLASS_NAME)) {
0219: if (producerID == null) {
0220: logger.severe("PSWS_CSPWPAB0007");
0221: throw new PSMBeanException(
0222: "Missing producer Id.");
0223: }
0224:
0225: result.put(name, Collections.singletonList(producer
0226: .getRegistrationManager()
0227: .getRegistrationValidatorClassName()));
0228: } else if (name
0229: .equals(ProducerAttributes.PUBLISHED_PORTLETS)) {
0230: if (producerID == null) {
0231: logger.severe("PSWS_CSPWPAB0007");
0232: throw new PSMBeanException(
0233: "Missing producer Id.");
0234: }
0235:
0236: result.put(name, new ArrayList(publishedPortlets));
0237: } else if (name
0238: .equals(ProducerAttributes.UNPUBLISHED_PORTLETS)) {
0239: if (producerID == null) {
0240: logger.severe("PSWS_CSPWPAB0007");
0241: throw new PSMBeanException(
0242: "Missing producer Id.");
0243: }
0244:
0245: Set unpublishedPortlets = new HashSet(allPortlets);
0246: unpublishedPortlets.removeAll(publishedPortlets);
0247: result
0248: .put(name, new ArrayList(
0249: unpublishedPortlets));
0250: } else if (name
0251: .equals(ProducerAttributes.REGISTRATION_PROPERTY_DESCRIPTION)) {
0252: if (producerID == null) {
0253: logger.severe("PSWS_CSPWPAB0007");
0254: throw new PSMBeanException(
0255: "Missing producer Id.");
0256: }
0257:
0258: List rpds = new ArrayList();
0259: GetServiceDescription gsd = new GetServiceDescription();
0260: ServiceDescription sd = sdm
0261: .getServiceDescription(gsd);
0262: ModelDescription rpd = sd
0263: .getRegistrationPropertyDescription();
0264:
0265: if (rpd != null) {
0266: PropertyDescription[] propDesc = rpd
0267: .getPropertyDescriptions();
0268:
0269: if (propDesc != null) {
0270: for (int j = 0; j < propDesc.length; j++) {
0271: StringBuffer sb = new StringBuffer();
0272: sb.append(propDesc[j].getName());
0273: sb.append("=");
0274: LocalizedString hint = propDesc[j]
0275: .getHint();
0276:
0277: if (hint != null) {
0278: sb.append(hint.getValue());
0279: }
0280:
0281: rpds.add(sb.toString());
0282: }
0283: }
0284: }
0285:
0286: result.put(name, rpds);
0287: } else {
0288: logger.log(Level.SEVERE, "PSWS_CSPWPAB0008", name);
0289: throw new PSMBeanException(
0290: "No such producer attribute: " + name);
0291: }
0292: }
0293:
0294: return result;
0295: } catch (OperationFailedFault e) {
0296: logger.log(Level.SEVERE, "PSWS_CSPWPAB0009", e);
0297: throw new PSMBeanException("SD error", e.getMessage());
0298: } catch (ProducerException e) {
0299: logger.log(Level.SEVERE, "PSWS_CSPWPAB0010", e);
0300: throw new PSMBeanException("Producer error", e.getMessage());
0301: }
0302: }
0303:
0304: private Map getCRAttributes(Map optionsMap, String handle)
0305: throws PSMBeanException {
0306:
0307: Set names = (Set) optionsMap
0308: .get(AttrOptionConstants.OPT_ATTR_NAMES);
0309: Map result = new HashMap(names.size());
0310:
0311: // TODO: shouldn't hardcode the "producer" string here
0312: String producerID = (String) optionsMap.get("producer");
0313:
0314: if (producerID == null) {
0315: throw new PSMBeanException("Missing producer Id.");
0316: }
0317:
0318: Producer producer = getProducer(producerID);
0319:
0320: try {
0321: RegistrationManager rm = producer.getRegistrationManager();
0322: RegistrationRecord rr = rm.getRegistrationRecord(handle);
0323:
0324: for (Iterator i = names.iterator(); i.hasNext();) {
0325: String name = (String) i.next();
0326:
0327: if (name.equals(ProducerAttributes.ENABLED)) {
0328: result.put(name, Collections
0329: .singletonList(Boolean.toString(rm
0330: .getRegistrationStatus(handle))));
0331: } else if (name
0332: .equals(ProducerAttributes.CONSUMER_NAME)) {
0333: result.put(name, Collections.singletonList(rr
0334: .getConsumerName()));
0335: } else if (name
0336: .equals(ProducerAttributes.CONSUMER_AGENT)) {
0337: result.put(name, Collections.singletonList(rr
0338: .getConsumerAgent()));
0339: } else if (name
0340: .equals(ProducerAttributes.METHOD_GET_SUPPORTED)) {
0341: result.put(name, Collections.singletonList(Boolean
0342: .toString(rr.isMethodGetSupported())));
0343: } else if (name
0344: .equals(ProducerAttributes.CONSUMER_MODES)) {
0345: result
0346: .put(name, arrayToList(rr
0347: .getConsumerModes()));
0348: } else if (name
0349: .equals(ProducerAttributes.CONSUMER_WINDOW_STATES)) {
0350: result.put(name, arrayToList(rr
0351: .getConsumerWindowStates()));
0352: } else if (name
0353: .equals(ProducerAttributes.CONSUMER_USER_SCOPES)) {
0354: result.put(name, arrayToList(rr
0355: .getConsumerUserScopes()));
0356: } else if (name
0357: .equals(ProducerAttributes.CUSTOM_USER_PROFILE_DATA)) {
0358: result.put(name, arrayToList(rr
0359: .getCustomUserProfileData()));
0360: } else if (name
0361: .equals(ProducerAttributes.REGISTRATION_PROPERTIES)) {
0362: List registrationProperties = Collections.EMPTY_LIST;
0363: Property[] rps = rr.getRegistrationProperties();
0364:
0365: if (rps != null) {
0366: registrationProperties = new ArrayList(
0367: rps.length);
0368:
0369: for (int j = 0; j < rps.length; j++) {
0370: StringBuffer sb = new StringBuffer();
0371: sb.append(rps[j].getName());
0372: sb.append("=");
0373: sb.append(rps[j].getStringValue());
0374: registrationProperties.add(sb.toString());
0375: }
0376: }
0377:
0378: result.put(name, registrationProperties);
0379: } else {
0380: logger.log(Level.SEVERE, "PSWS_CSPWPAB0011", name);
0381: throw new PSMBeanException(
0382: "No such consumer registration attribute: "
0383: + name);
0384: }
0385: }
0386:
0387: return result;
0388: } catch (ProducerException e) {
0389: logger.log(Level.SEVERE, "PSWS_CSPWPAB0010", e);
0390: throw new PSMBeanException("Producer error", e.getMessage());
0391: }
0392: }
0393:
0394: private void setProducerAttributes(Map nameValues, Map optionsMap)
0395: throws PSMBeanException {
0396:
0397: boolean add = optionsMap
0398: .containsKey(AttrOptionConstants.OPT_ADD);
0399: boolean remove = optionsMap
0400: .containsKey(AttrOptionConstants.OPT_REMOVE);
0401: boolean set = !add && !remove;
0402: Producer producer = null;
0403: RegistrationManager rm = null;
0404: ServiceDescriptionManager sdm = null;
0405: Set portletsPublished = null;
0406:
0407: // TODO: shouldn't hardcode the "producer" string here
0408: String producerID = (String) optionsMap.get("producer");
0409:
0410: try {
0411: if (producerID != null) {
0412: producer = getProducer(producerID);
0413: rm = producer.getRegistrationManager();
0414: sdm = producer.getServiceDescriptionManager();
0415: portletsPublished = sdm.getOfferedPortletNames();
0416: }
0417:
0418: for (Iterator i = nameValues.entrySet().iterator(); i
0419: .hasNext();) {
0420: Map.Entry attribute = (Map.Entry) i.next();
0421: String name = (String) attribute.getKey();
0422: List values = (List) attribute.getValue();
0423:
0424: if (name.equals(ProducerAttributes.ALL_DISABLED)) {
0425: optionsMap.put(AttrOptionConstants.OPT_GLOBAL,
0426: Boolean.TRUE.toString());
0427:
0428: super .setAttribute(values, optionsMap);
0429: } else if (name.equals(ProducerAttributes.ENABLED)) {
0430: if (producerID == null) {
0431: throw new PSMBeanException(
0432: "Missing producer Id.");
0433: }
0434:
0435: checkSingleton(name, values, set);
0436: boolean enable = Boolean.valueOf(
0437: (String) values.get(0)).booleanValue();
0438:
0439: if (enable) {
0440: List portletsToBeSet = (List) nameValues
0441: .get(ProducerAttributes.PUBLISHED_PORTLETS);
0442:
0443: if (((portletsToBeSet == null) && ((portletsPublished == null) || portletsPublished
0444: .isEmpty()))
0445: || ((portletsToBeSet != null) && portletsToBeSet
0446: .isEmpty())) {
0447:
0448: logger.log(Level.SEVERE,
0449: "PSWS_CSPWPAB0012", producerID);
0450: throw new PSMBeanException(
0451: "wsrp.producer.attribute.handler.nopublishedportlets.error",
0452: "To enable this producer please publish one or more portlets first");
0453: }
0454: }
0455:
0456: producer.setIsEnabled(enable);
0457: } else if (name.equals(ProducerAttributes.WSDL_URL)) {
0458: throw new PSMBeanException(
0459: ProducerAttributes.WSDL_URL
0460: + " is a read-only attribute.");
0461: } else if (name
0462: .equals(ProducerAttributes.REGISTRATION_REQUIRED)) {
0463: if (producerID == null) {
0464: logger.severe("PSWS_CSPWPAB0007");
0465: throw new PSMBeanException(
0466: "Missing producer Id.");
0467: }
0468:
0469: checkSingleton(name, values, set);
0470: producer.setRequiresRegistration(Boolean.valueOf(
0471: (String) values.get(0)).booleanValue());
0472: } else if (name
0473: .equals(ProducerAttributes.IN_BAND_REGISTRATION_SUPPORTED)) {
0474: if (producerID == null) {
0475: logger.severe("PSWS_CSPWPAB0007");
0476: throw new PSMBeanException(
0477: "Missing producer Id.");
0478: }
0479:
0480: checkSingleton(name, values, set);
0481: producer.setInbandRegistrationSupported(Boolean
0482: .valueOf((String) values.get(0))
0483: .booleanValue());
0484: } else if (name
0485: .equals(ProducerAttributes.REGISTRATION_VALIDATOR_CLASS_NAME)) {
0486: if (producerID == null) {
0487: logger.severe("PSWS_CSPWPAB0007");
0488: throw new PSMBeanException(
0489: "Missing producer Id.");
0490: }
0491:
0492: checkSingleton(name, values, set);
0493: rm
0494: .setRegistrationValidatorClassName((String) values
0495: .get(0));
0496: } else if (name
0497: .equals(ProducerAttributes.PUBLISHED_PORTLETS)) {
0498: if (producerID == null) {
0499: logger.severe("PSWS_CSPWPAB0007");
0500: throw new PSMBeanException(
0501: "Missing producer Id.");
0502: }
0503:
0504: Set allPortlets = producer.getPortletChannelNames();
0505: Set publishedPortlets = sdm
0506: .getOfferedPortletNames();
0507: publishedPortlets.retainAll(allPortlets);
0508: Set result = filter(publishedPortlets, values,
0509: optionsMap);
0510: result.retainAll(allPortlets);
0511:
0512: if (result.isEmpty()) {
0513: List enable = (List) nameValues
0514: .get(ProducerAttributes.ENABLED);
0515:
0516: if (((enable == null) && producer.isEnabled())
0517: || ((enable != null) && Boolean
0518: .valueOf((String) enable.get(0))
0519: .booleanValue())) {
0520:
0521: logger.severe("PSWS_CSPWPAB0012");
0522: throw new PSMBeanException(
0523: "published portlets list cannot be empty.");
0524: }
0525: }
0526:
0527: sdm.setOfferedPortletNames(result);
0528: } else if (name
0529: .equals(ProducerAttributes.UNPUBLISHED_PORTLETS)) {
0530: throw new PSMBeanException(
0531: ProducerAttributes.UNPUBLISHED_PORTLETS
0532: + " is a read-only attribute.");
0533: } else if (name
0534: .equals(ProducerAttributes.REGISTRATION_PROPERTY_DESCRIPTION)) {
0535: if (producerID == null) {
0536: logger.severe("PSWS_CSPWPAB0007");
0537: throw new PSMBeanException(
0538: "Missing producer Id.");
0539: }
0540:
0541: setRegPropDesc(values, optionsMap, set, sdm);
0542: } else {
0543: logger.log(Level.SEVERE, "PSWS_CSPWPAB0008", name);
0544: throw new PSMBeanException(
0545: "No such producer attribute: " + name);
0546: }
0547: }
0548: } catch (ProducerException e) {
0549: logger.log(Level.SEVERE, "PSWS_CSPWPAB0010", e);
0550: throw new PSMBeanException("Producer error", e.getMessage());
0551: }
0552: }
0553:
0554: private void setCRAttributes(Map nameValues, Map optionsMap,
0555: String handle) throws PSMBeanException {
0556:
0557: boolean add = optionsMap
0558: .containsKey(AttrOptionConstants.OPT_ADD);
0559: boolean remove = optionsMap
0560: .containsKey(AttrOptionConstants.OPT_REMOVE);
0561: boolean set = !add && !remove;
0562:
0563: // TODO: shouldn't hardcode the "producer" string here
0564: String producerID = (String) optionsMap.get("producer");
0565:
0566: if (producerID == null) {
0567: logger.severe("PSWS_CSPWPAB0007");
0568: throw new PSMBeanException("Missing producer Id.");
0569: }
0570:
0571: Producer producer = getProducer(producerID);
0572:
0573: try {
0574: RegistrationManager rm = producer.getRegistrationManager();
0575: RegistrationRecord rr = rm.getRegistrationRecord(handle);
0576: RegistrationData rd = rr.getRegistrationData();
0577: boolean modifyRegistration = false;
0578:
0579: for (Iterator i = nameValues.entrySet().iterator(); i
0580: .hasNext();) {
0581: Map.Entry attribute = (Map.Entry) i.next();
0582: String name = (String) attribute.getKey();
0583: List values = (List) attribute.getValue();
0584:
0585: if (name.equals(ProducerAttributes.ENABLED)) {
0586: checkSingleton(name, values, set);
0587: boolean enabled = Boolean.valueOf(
0588: (String) values.get(0)).booleanValue();
0589: rr = new RegistrationRecord(handle, enabled, rd);
0590: rm.setRegistrationStatus(handle, enabled);
0591: } else if (name
0592: .equals(ProducerAttributes.CONSUMER_NAME)) {
0593: checkSingleton(name, values, set);
0594: rd.setConsumerName((String) values.get(0));
0595: modifyRegistration = true;
0596: } else if (name
0597: .equals(ProducerAttributes.CONSUMER_AGENT)) {
0598: checkSingleton(name, values, set);
0599: rd.setConsumerAgent((String) values.get(0));
0600: modifyRegistration = true;
0601: } else if (name
0602: .equals(ProducerAttributes.METHOD_GET_SUPPORTED)) {
0603: checkSingleton(name, values, set);
0604: rd.setMethodGetSupported(Boolean.valueOf(
0605: (String) values.get(0)).booleanValue());
0606: modifyRegistration = true;
0607: } else if (name
0608: .equals(ProducerAttributes.CONSUMER_MODES)) {
0609: List oldValues = arrayToList(rr.getConsumerModes());
0610: rd.setConsumerModes(filter(oldValues, values,
0611: optionsMap));
0612: modifyRegistration = true;
0613: } else if (name
0614: .equals(ProducerAttributes.CONSUMER_WINDOW_STATES)) {
0615: List oldValues = arrayToList(rr
0616: .getConsumerWindowStates());
0617: rd.setConsumerWindowStates(filter(oldValues,
0618: values, optionsMap));
0619: modifyRegistration = true;
0620: } else if (name
0621: .equals(ProducerAttributes.CONSUMER_USER_SCOPES)) {
0622: List oldValues = arrayToList(rr
0623: .getConsumerUserScopes());
0624: rd.setConsumerUserScopes(filter(oldValues, values,
0625: optionsMap));
0626: modifyRegistration = true;
0627: } else if (name
0628: .equals(ProducerAttributes.CUSTOM_USER_PROFILE_DATA)) {
0629: List oldValues = arrayToList(rr
0630: .getCustomUserProfileData());
0631: rd.setCustomUserProfileData(filter(oldValues,
0632: values, optionsMap));
0633: modifyRegistration = true;
0634: } else if (name
0635: .equals(ProducerAttributes.REGISTRATION_PROPERTIES)) {
0636: setRegProp(values, optionsMap, set, producer, rr);
0637: modifyRegistration = true;
0638: } else {
0639: logger.log(Level.SEVERE, "PSWS_CSPWPAB0011", name);
0640: throw new PSMBeanException(
0641: "No such consumer registration attribute: "
0642: + name);
0643: }
0644: }
0645:
0646: if (modifyRegistration) {
0647: validateRegistration(rd, producer);
0648: rm.modifyRegistration(rr);
0649: }
0650: } catch (ProducerException e) {
0651: logger.log(Level.SEVERE, "PSWS_CSPWPAB0010", e);
0652: throw new PSMBeanException("Producer error", e.getMessage());
0653: }
0654: }
0655:
0656: private Producer getProducer(String producerID)
0657: throws PSMBeanException {
0658: try {
0659: // TO: null HttpServletRequest and ServletContext won't work.
0660: //SSOToken ssoToken = getSSOToken();
0661: SSOToken ssoToken = AdminServerUtil.getSSOToken();
0662: String portalId = this .portalId;
0663: return new ProducerImpl(ssoToken, producerID, portalId);
0664: } catch (ProducerException e) {
0665: logger.log(Level.SEVERE, "PSWS_CSPWPAB0014", e);
0666: throw new PSMBeanException("Can't get producer.", e
0667: .getMessage());
0668: }
0669: }
0670:
0671: private List arrayToList(String[] stringArray) {
0672: if ((stringArray == null) || (stringArray.length == 0)) {
0673: return Collections.EMPTY_LIST;
0674: }
0675:
0676: List result = new ArrayList(stringArray.length);
0677:
0678: for (int i = 0; i < stringArray.length; i++) {
0679: result.add(stringArray[i]);
0680: }
0681:
0682: return result;
0683: }
0684:
0685: private void checkSingleton(String attributeName, List values,
0686: boolean set) throws PSMBeanException {
0687:
0688: if (!set) {
0689: logger.log(Level.SEVERE, "PSWS_CSPWPAB0015", attributeName);
0690: throw new PSMBeanException(attributeName
0691: + " does not allow add or remove.");
0692: }
0693:
0694: if (values.size() != 1) {
0695: logger.log(Level.SEVERE, "PSWS_CSPWPAB0016", attributeName);
0696: throw new PSMBeanException(attributeName
0697: + " requires one and only one value specified.");
0698: }
0699: }
0700:
0701: private Set filter(Set currentValues, List values, Map optionsMap)
0702: throws PSMBeanException {
0703:
0704: List addValues = (List) optionsMap
0705: .get(AttrOptionConstants.OPT_ADD);
0706: List removeValues = (List) optionsMap
0707: .get(AttrOptionConstants.OPT_REMOVE);
0708:
0709: if ((addValues == null) && (removeValues == null)) {
0710: return new HashSet(values);
0711: }
0712:
0713: if (addValues != null) {
0714: currentValues.addAll(addValues);
0715: }
0716:
0717: if (removeValues != null) {
0718: currentValues.removeAll(removeValues);
0719: }
0720:
0721: return currentValues;
0722: }
0723:
0724: private String[] filter(List currentValues, List values,
0725: Map optionsMap) throws PSMBeanException {
0726:
0727: List addValues = (List) optionsMap
0728: .get(AttrOptionConstants.OPT_ADD);
0729: List removeValues = (List) optionsMap
0730: .get(AttrOptionConstants.OPT_REMOVE);
0731:
0732: if ((addValues == null) && (removeValues == null)) {
0733: return (String[]) values.toArray(new String[0]);
0734: }
0735:
0736: Set result = new HashSet(currentValues);
0737:
0738: if (addValues != null) {
0739: result.addAll(addValues);
0740: }
0741:
0742: if (removeValues != null) {
0743: result.removeAll(removeValues);
0744: }
0745:
0746: return (String[]) result.toArray(new String[0]);
0747: }
0748:
0749: private void setRegPropDesc(List values, Map optionsMap,
0750: boolean set, ServiceDescriptionManager sdm)
0751: throws PSMBeanException {
0752:
0753: // Get current registration property descriptions list.
0754: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME,
0755: ProducerAttributes.REGISTRATION_PROPERTY_DESCRIPTION);
0756:
0757: List regPropDesc = getAttribute(optionsMap);
0758: Set names = getNamesFromRegPropDescList(regPropDesc);
0759:
0760: try {
0761: if (set && !names.isEmpty()) {
0762: // Remove all current registration property descriptions first.
0763: sdm.removeRegistrationPropertyDescriptions(names);
0764: names.clear();
0765: }
0766:
0767: List addValues = (List) optionsMap
0768: .get(AttrOptionConstants.OPT_ADD);
0769:
0770: if (addValues == null) {
0771: addValues = values;
0772: }
0773:
0774: for (int i = 0; i < addValues.size(); i++) {
0775: String name = null;
0776: String desc = null;
0777: String propDesc = (String) addValues.get(i);
0778: int index = propDesc.indexOf("=");
0779:
0780: if (index >= 0) {
0781: name = propDesc.substring(0, index).trim();
0782: desc = propDesc.substring(index + 1).trim();
0783: } else {
0784: name = propDesc.trim();
0785: desc = "";
0786: }
0787:
0788: if (name.length() == 0) {
0789: logger.severe("PSWS_CSPWPAB0017");
0790: throw new PSMBeanException("Name can't be empty.");
0791: }
0792:
0793: if (names.contains(name)) {
0794: logger.log(Level.SEVERE, "PSWS_CSPWPAB0018", name);
0795: throw new PSMBeanException("Duplicate name.");
0796: }
0797:
0798: LocalizedString label = new LocalizedString(lang, null,
0799: name);
0800: LocalizedString hint = null;
0801:
0802: if (desc.length() > 0) {
0803: hint = new LocalizedString(lang, null, desc);
0804: }
0805:
0806: PropertyDescription pd = new PropertyDescription(name,
0807: PROPERTY_TYPE, label, hint, null);
0808:
0809: sdm.addRegistrationPropertyDescription(pd);
0810: names.add(name);
0811: }
0812:
0813: List removeValues = (List) optionsMap
0814: .get(AttrOptionConstants.OPT_REMOVE);
0815:
0816: if (removeValues != null) {
0817: names = getNamesFromRegPropDescList(removeValues);
0818: sdm.removeRegistrationPropertyDescriptions(names);
0819: }
0820: } catch (ProducerException e) {
0821: logger.log(Level.SEVERE, "PSWS_CSPWPAB0019", e);
0822: throw new PSMBeanException("SDM error", e.getMessage());
0823: }
0824: }
0825:
0826: private Set getNamesFromRegPropDescList(List regPropDesc) {
0827: Set names = new HashSet();
0828:
0829: for (int i = 0; i < regPropDesc.size(); i++) {
0830: String propDesc = (String) regPropDesc.get(i);
0831: String name = propDesc.substring(0, propDesc.indexOf("="));
0832: names.add(name);
0833: }
0834:
0835: return names;
0836: }
0837:
0838: private void validateRegistration(
0839: RegistrationData registrationData, Producer producer)
0840: throws PSMBeanException {
0841:
0842: String consumerName = registrationData.getConsumerName();
0843:
0844: if ((consumerName == null)
0845: || (consumerName.trim().length() == 0)) {
0846: String key = "registration.missing.consumerName";
0847: throw new PSMBeanException(key);
0848: }
0849:
0850: registrationData.setConsumerName(consumerName.trim());
0851: String consumerAgent = registrationData.getConsumerAgent();
0852:
0853: if ((consumerAgent == null)
0854: || (consumerAgent.trim().length() == 0)) {
0855: String key = "registration.missing.consumerAgent";
0856: throw new PSMBeanException(key);
0857: }
0858:
0859: registrationData.setConsumerAgent(consumerAgent.trim());
0860:
0861: try {
0862: ServiceDescriptionManager serviceDescriptionManager = producer
0863: .getServiceDescriptionManager();
0864:
0865: RegistrationManager registrationManager = producer
0866: .getRegistrationManager();
0867:
0868: GetServiceDescription gsd = new GetServiceDescription();
0869:
0870: ServiceDescription serviceDescription = serviceDescriptionManager
0871: .getServiceDescription(gsd);
0872:
0873: RegistrationValidator regValidator = registrationManager
0874: .getRegistrationValidator();
0875:
0876: int resultCode = regValidator.validate(registrationData,
0877: serviceDescription);
0878:
0879: if (resultCode < 0) {
0880: String registrationValidatorClassName = registrationManager
0881: .getRegistrationValidatorClassName();
0882:
0883: String key = registrationValidatorClassName
0884: + resultCode;
0885: throw new PSMBeanException(key);
0886: }
0887: } catch (OperationFailedFault e) {
0888: logger.log(Level.SEVERE, "PSWS_CSPWPAB0009", e);
0889: throw new PSMBeanException("SD error", e.getMessage());
0890: } catch (ProducerException e) {
0891: logger.log(Level.SEVERE, "PSWS_CSPWPAB0010", e);
0892: throw new PSMBeanException("Producer error", e.getMessage());
0893: }
0894: }
0895:
0896: private void setRegProp(List values, Map optionsMap, boolean set,
0897: Producer producer, RegistrationRecord rr)
0898: throws PSMBeanException {
0899:
0900: Property[] oldValues = rr.getRegistrationProperties();
0901: Property[] newValues = null;
0902:
0903: try {
0904: ServiceDescriptionManager sdm = producer
0905: .getServiceDescriptionManager();
0906: GetServiceDescription gsd = new GetServiceDescription();
0907: ServiceDescription sd = sdm.getServiceDescription(gsd);
0908: ModelDescription rpd = sd
0909: .getRegistrationPropertyDescription();
0910:
0911: if (rpd != null) {
0912: PropertyDescription[] propDesc = rpd
0913: .getPropertyDescriptions();
0914:
0915: if (propDesc != null) {
0916: newValues = new Property[propDesc.length];
0917:
0918: for (int i = 0; i < propDesc.length; i++) {
0919: String name = propDesc[i].getName();
0920: String value = null;
0921:
0922: if (oldValues != null) {
0923: for (int j = 0; j < oldValues.length; j++) {
0924: if (oldValues[j].getName().equals(name)) {
0925: value = oldValues[j]
0926: .getStringValue();
0927: break;
0928: }
0929: }
0930: }
0931:
0932: if (set) {
0933: value = getLastValueForName(name, values);
0934: } else {
0935: List addValues = (List) optionsMap
0936: .get(AttrOptionConstants.OPT_ADD);
0937:
0938: if (addValues != null) {
0939: String v = getLastValueForName(name,
0940: addValues);
0941:
0942: if (v != null) {
0943: value = v;
0944: }
0945: }
0946:
0947: List removeValues = (List) optionsMap
0948: .get(AttrOptionConstants.OPT_REMOVE);
0949:
0950: if (removeValues != null) {
0951: String v = getLastValueForName(name,
0952: removeValues);
0953:
0954: if (v != null) {
0955: value = null;
0956: }
0957: }
0958: }
0959:
0960: newValues[i] = new Property(name, lang, value,
0961: null);
0962: }
0963: }
0964: }
0965:
0966: rr.getRegistrationData().setRegistrationProperties(
0967: newValues);
0968: } catch (OperationFailedFault e) {
0969: logger.log(Level.SEVERE, "PSWS_CSPWPAB0009", e);
0970: throw new PSMBeanException("SD error", e.getMessage());
0971: } catch (ProducerException e) {
0972: logger.log(Level.SEVERE, "PSWS_CSPWPAB0010", e);
0973: throw new PSMBeanException("Producer error", e.getMessage());
0974: }
0975: }
0976:
0977: private String getLastValueForName(String name, List properties) {
0978: String result = null;
0979:
0980: for (int i = 0; i < properties.size(); i++) {
0981: String n = null;
0982: String v = null;
0983: String property = (String) properties.get(i);
0984: int index = property.indexOf("=");
0985:
0986: if (index >= 0) {
0987: n = property.substring(0, index).trim();
0988: v = property.substring(index + 1).trim();
0989: } else {
0990: n = property.trim();
0991: v = "";
0992: }
0993:
0994: if (n.equals(name)) {
0995: result = v;
0996: }
0997: }
0998:
0999: return result;
1000: }
1001: }
|