001: package com.sun.portal.wireless.admin;
002:
003: import java.util.List;
004: import java.util.Map;
005: import java.util.HashMap;
006:
007: import com.sun.portal.admin.common.PSMBeanException;
008: import com.sun.portal.admin.common.AttrOptionConstants;
009: import com.sun.portal.fabric.common.GenericDSAMEAttributeHandler;
010:
011: /**
012: * Get/set handler for Mobile Mail service
013: *
014: * @author ashwin.mathew@sun.com
015: */
016: public abstract class AbstractMobileGetSetAttributeHandler extends
017: GenericDSAMEAttributeHandler {
018:
019: public static final String KEY_OLD_VALUES = "mobileaccess.oldvalues";
020: public static final String KEY_OVERRIDE_VALUES = "mobileaccess.overridevalues";
021:
022: private static final String TRUE_VALUE = "true";
023: private static final String FALSE_VALUE = "false";
024:
025: /* (non-Javadoc)
026: * @see com.sun.portal.fabric.common.AttributeHandler#getAttributeName(java.lang.String)
027: */
028: public String getAttributeName(String userFriendlyName) {
029: String attributeName = null;
030:
031: MobileAppAttributeHandler handler = MobileAppAttributeHandlerRegistry
032: .findHandler(userFriendlyName, getComponentName());
033:
034: if (handler != null) {
035: attributeName = handler.getAttributeName();
036: }
037:
038: return attributeName;
039: }
040:
041: /* (non-Javadoc)
042: * @see com.sun.portal.fabric.common.AttributeHandler#getComponentName(java.lang.String)
043: */
044: public String getComponentName(String userFriendlyName) {
045: // Always the same, regardless of userFriendlyName, since
046: // we have one implementation per MA service.
047: return getComponentName();
048: }
049:
050: public abstract String getComponentName();
051:
052: /* (non-Javadoc)
053: * @see com.sun.portal.fabric.common.AttributeHandler#validate(java.util.Map)
054: */
055: public void validate(List values, Map optionsMap)
056: throws PSMBeanException {
057: String attributeName = ((String) optionsMap
058: .get(AttrOptionConstants.OPT_ATTR_NAME));
059:
060: if (attributeName == null) {
061: // We don't have to do anything
062: // This will happen for list-attributes
063: return;
064: }
065:
066: MobileAppAttributeHandler handler = MobileAppAttributeHandlerRegistry
067: .findHandler(attributeName, getComponentName());
068:
069: if (handler == null) {
070: // The user has specified an invalid attribute for mail
071: throw new PSMBeanException(
072: "error.psadmin.invalid.attribute.name");
073: //throw new PSMBeanException("Validating attribute: " + attributeName);
074: }
075:
076: if (handler.requiresOldValues()) {
077: Map getOptionsMap = new HashMap(optionsMap);
078: List oldValues = super .getAttribute(getOptionsMap);
079: optionsMap.put(KEY_OLD_VALUES, oldValues);
080: }
081:
082: handler.validate(values, optionsMap);
083:
084: // Validate rule format
085: // Validate that rule exists when mapping to view
086: // Validate that view exists when mapping to device
087: // Maybe (maybe!) also validate that device profile name is valid for above
088:
089: // Set flags - global, etc.
090: switch (handler.getScope()) {
091: case MobileAppAttributeHandler.SCOPE_GLOBAL:
092: optionsMap.put(AttrOptionConstants.OPT_GLOBAL, TRUE_VALUE);
093: break;
094: case MobileAppAttributeHandler.SCOPE_ORGANIZATION:
095: optionsMap.put(AttrOptionConstants.OPT_ORG, TRUE_VALUE);
096: break;
097: case MobileAppAttributeHandler.SCOPE_USER:
098: break;
099: case MobileAppAttributeHandler.SCOPE_DYNAMIC:
100: break;
101: }
102: }
103:
104: /* (non-Javadoc)
105: * @see com.sun.portal.fabric.common.AttributeHandler#getAttribute(java.util.Map)
106: */
107: public List getAttribute(Map optionsMap) throws PSMBeanException {
108: //validate(null, optionsMap);
109:
110: // If we're dealing with a URL-like value
111: // i.e., sunConfigurationTemplates,
112: // extract the value from the list, then extract the requested
113: // attribute from the URL
114: String attributeName = ((String) optionsMap
115: .get(AttrOptionConstants.OPT_ATTR_NAME));
116:
117: MobileAppAttributeHandler handler = MobileAppAttributeHandlerRegistry
118: .findHandler(attributeName, getComponentName());
119:
120: if (handler == null) {
121: // The user has specified an invalid attribute for mail
122: throw new PSMBeanException(
123: "error.psadmin.invalid.attribute.name");
124: //throw new PSMBeanException("Getting attribute " + attributeName);
125: }
126:
127: List values = super .getAttribute(optionsMap);
128:
129: values = handler.processGetValue(values);
130:
131: return values;
132: }
133:
134: /* (non-Javadoc)
135: * @see com.sun.portal.fabric.common.AttributeHandler#setAttribute(java.util.List, java.util.Map)
136: */
137: public void setAttribute(List values, Map optionsMap)
138: throws PSMBeanException {
139: List overrideValues = (List) optionsMap
140: .get(KEY_OVERRIDE_VALUES);
141: if (overrideValues != null) {
142: values = overrideValues;
143: }
144:
145: // If we're dealing with a URL-like value
146: // i.e., sunConfigurationTemplates,
147: // extract the value from the list, then extract the requested
148: // attribute from the URL
149: String attributeName = ((String) optionsMap
150: .get(AttrOptionConstants.OPT_ATTR_NAME)).toLowerCase();
151:
152: MobileAppAttributeHandler handler = MobileAppAttributeHandlerRegistry
153: .findHandler(attributeName, getComponentName());
154:
155: if (handler == null) {
156: // The user has specified an invalid attribute for mail
157: throw new PSMBeanException(
158: "error.psadmin.invalid.attribute.name");
159: }
160:
161: values = handler.processSetValue(values);
162:
163: super .setAttribute(values, optionsMap);
164: }
165:
166: /* (non-Javadoc)
167: * @see com.sun.portal.fabric.common.AttributeHandler#listAttributes(java.util.Map)
168: */
169: public Map listAttributes(Map optionsMap) throws PSMBeanException {
170: return MobileAppAttributeHandlerRegistry
171: .listAttributes(getComponentName());
172: }
173:
174: }
|