Source Code Cross Referenced for DesktopGetSetAttributeHandler.java in  » Portal » Open-Portal » com » sun » portal » desktop » admin » mbeans » tasks » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.desktop.admin.mbeans.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: DesktopGetSetAttributeHandler.java,v 1.15 2006/05/19 11:10:18 sd155185 Exp $
003:         * Copyright 2004 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.desktop.admin.mbeans.tasks;
014:
015:        import java.util.Map;
016:        import java.util.HashMap;
017:        import java.util.Set;
018:        import java.util.HashSet;
019:        import java.util.List;
020:        import java.util.ArrayList;
021:        import java.util.Iterator;
022:        import java.util.StringTokenizer;
023:
024:        import com.sun.portal.fabric.common.GenericDSAMEAttributeHandler;
025:        import com.sun.portal.admin.common.AttrOptionConstants;
026:        import com.sun.portal.admin.common.DesktopConstants;
027:        import com.sun.portal.admin.common.PSMBeanException;
028:        import com.sun.portal.admin.common.AttributeInfo;
029:        import com.sun.portal.desktop.context.DSAMEMultiPortalConstants;
030:
031:        public class DesktopGetSetAttributeHandler extends
032:                GenericDSAMEAttributeHandler implements  DesktopConstants {
033:
034:            private static final String TRUE_VALUE = "true";
035:            private static final String FALSE_VALUE = "false";
036:
037:            //Following are additional attribute types, not defined in AttributeInfo
038:            //These will be required for special handling
039:            private static final int SINGLE_COMMA_SEPERATED_STRING = 99;
040:
041:            private DSAMEMultiPortalConstants dmpc = null;
042:            private Map dynAttrMap = new HashMap();
043:            private Map globalAttrMap = new HashMap();
044:            private Map attrInfoMap = new HashMap();
045:
046:            public void init(String component, String domainId, String portalId)
047:                    throws PSMBeanException {
048:                super .init(component, domainId, portalId);
049:                //get an instance of DSAMEMultiPortalConstants, to get
050:                //real service name and real attribute name
051:                DSAMEMultiPortalConstants.createInstance(portalId);
052:                dmpc = DSAMEMultiPortalConstants.getInstance(portalId);
053:                buildAttrMaps();
054:            }
055:
056:            private void buildAttrMaps() {
057:
058:                dynAttrMap.put(DESKTOP_TYPE, dmpc.MP_ATTR_DESKTOP_TYPE);
059:                dynAttrMap.put(EDIT_CHANNEL,
060:                        dmpc.MP_ATTR_EDITPROVIDERCONTAINERNAME);
061:                dynAttrMap
062:                        .put(DEFAULT_CHANNEL, dmpc.MP_ATTR_DEFAULTCHANNELNAME);
063:
064:                //To solve CR6362631. This is added to maintain consitency between psconsole and cli attribute name
065:                dynAttrMap.put(PARENT_CONTAINER,
066:                        dmpc.MP_ATTR_DEFAULTCHANNELNAME);
067:                dynAttrMap.put(SHOW_DESKTOP_ATTRIBUTE, dmpc.ATTR_DP_CAN_VIEW);
068:                dynAttrMap.put(COMMUNITY_PARENT_CONTAINER_URL_PARAMETER,
069:                        dmpc.MP_ATTR_COMMUNITY_PARENT_CONTAINER_URL_PARAMETER);
070:                dynAttrMap.put(COMMUNITY_HOME_CONTAINER,
071:                        dmpc.MP_ATTR_COMMUNITY_HOME_CONTAINER_NAME);
072:                dynAttrMap.put(COMMUNITY_CREATE_CONTAINER,
073:                        dmpc.MP_ATTR_COMMUNITY_CREATE_CONTAINER_NAME);
074:                dynAttrMap.put(COS_PRIORITY,
075:                        GenericDSAMEAttributeHandler.COS_PRIORITY_STRING);
076:
077:                globalAttrMap.put(NAMESPACE_URI, dmpc.ATTR_DP_NAMESPACEURI);
078:                globalAttrMap.put(ENABLE_AUTHLESS,
079:                        dmpc.ATTR_ENABLE_AUTHLESS_DESKTOP);
080:                globalAttrMap.put(ENABLE_FEDERATION,
081:                        dmpc.ATTR_ENABLE_FEDERATION);
082:                globalAttrMap.put(HOSTED_PROVIDER_ID,
083:                        dmpc.ATTR_HOSTED_PROVIDER_ID);
084:                globalAttrMap.put(MAX_CLIENT_SESSION,
085:                        dmpc.ATTR_CLIENT_SESSIONS_MAX);
086:                globalAttrMap.put(DEFAULT_AUTHLESS_UID,
087:                        dmpc.ATTR_DEFAULTAUTHLESSUID);
088:                globalAttrMap.put(ENABLE_XML_VALIDATION,
089:                        dmpc.ATTR_DP_ISVALIDATING);
090:                globalAttrMap.put(AUTHORIZED_AUTHLESS_UIDS,
091:                        dmpc.ATTR_AUTHORIZEDAUTHLESSUIDS);
092:                globalAttrMap.put(CLIENT_SESSION_REAP_INTV,
093:                        dmpc.ATTR_CLIENT_SESSION_REAP_INTERVAL);
094:                globalAttrMap.put(CLIENT_SESSION_MAX_INACTIVE,
095:                        dmpc.ATTR_CLIENT_SESSION_INACTIVE_MAX);
096:                globalAttrMap.put(DIS_AUTHLESS_FOR_FEDERATED_USERS,
097:                        dmpc.ATTR_DISABLE_AUTHLESS_FOR_FEDERATED_USERS);
098:                globalAttrMap.put(ACCESS_URL, dmpc.ATTR_ACCESS_URL);
099:
100:                attrInfoMap.put(DESKTOP_TYPE, new Integer(
101:                        SINGLE_COMMA_SEPERATED_STRING));
102:                attrInfoMap.put(EDIT_CHANNEL, new Integer(
103:                        AttributeInfo.SINGLE_STRING));
104:                attrInfoMap.put(DEFAULT_CHANNEL, new Integer(
105:                        AttributeInfo.SINGLE_STRING));
106:                attrInfoMap.put(PARENT_CONTAINER, new Integer(
107:                        AttributeInfo.SINGLE_STRING));
108:                attrInfoMap.put(SHOW_DESKTOP_ATTRIBUTE, new Integer(
109:                        AttributeInfo.SINGLE_BOOLEAN));
110:                attrInfoMap.put(NAMESPACE_URI, new Integer(
111:                        AttributeInfo.SINGLE_STRING));
112:                attrInfoMap.put(ENABLE_AUTHLESS, new Integer(
113:                        AttributeInfo.SINGLE_BOOLEAN));
114:                attrInfoMap.put(ENABLE_FEDERATION, new Integer(
115:                        AttributeInfo.SINGLE_BOOLEAN));
116:                attrInfoMap.put(HOSTED_PROVIDER_ID, new Integer(
117:                        AttributeInfo.SINGLE_STRING));
118:                attrInfoMap.put(MAX_CLIENT_SESSION, new Integer(
119:                        AttributeInfo.SINGLE_NUMERIC));
120:                attrInfoMap.put(DEFAULT_AUTHLESS_UID, new Integer(
121:                        AttributeInfo.SINGLE_STRING));
122:                attrInfoMap.put(ENABLE_XML_VALIDATION, new Integer(
123:                        AttributeInfo.SINGLE_BOOLEAN));
124:                attrInfoMap.put(AUTHORIZED_AUTHLESS_UIDS, new Integer(
125:                        AttributeInfo.LIST_STRING));
126:                attrInfoMap.put(CLIENT_SESSION_REAP_INTV, new Integer(
127:                        AttributeInfo.SINGLE_NUMERIC));
128:                attrInfoMap.put(CLIENT_SESSION_MAX_INACTIVE, new Integer(
129:                        AttributeInfo.SINGLE_NUMERIC));
130:                attrInfoMap.put(DIS_AUTHLESS_FOR_FEDERATED_USERS, new Integer(
131:                        AttributeInfo.SINGLE_BOOLEAN));
132:                attrInfoMap.put(COMMUNITY_PARENT_CONTAINER_URL_PARAMETER,
133:                        new Integer(AttributeInfo.SINGLE_STRING));
134:                attrInfoMap.put(COMMUNITY_HOME_CONTAINER, new Integer(
135:                        AttributeInfo.SINGLE_STRING));
136:                attrInfoMap.put(COMMUNITY_CREATE_CONTAINER, new Integer(
137:                        AttributeInfo.SINGLE_STRING));
138:                attrInfoMap.put(COS_PRIORITY, new Integer(
139:                        AttributeInfo.SINGLE_NUMERIC));
140:                attrInfoMap.put(ACCESS_URL, new Integer(
141:                        AttributeInfo.SINGLE_STRING));
142:            }
143:
144:            public String getComponentName(String userFriendlyName) {
145:                return dmpc.MP_SUN_DESKTOP_SERVICE;
146:            }
147:
148:            public String getAttributeName(String userFriendlyName) {
149:                String name = (String) dynAttrMap.get(userFriendlyName);
150:                if (name == null) {
151:                    name = (String) globalAttrMap.get(userFriendlyName);
152:                }
153:                return name;
154:            }
155:
156:            /**
157:             * Overridden to pass real name for user friendly attribute and service name.
158:             * @param optionsMap
159:             * @return
160:             * @throws PSMBeanException
161:             */
162:
163:            public List getAttribute(Map optionsMap) throws PSMBeanException {
164:
165:                setAttributeType(optionsMap);
166:                return super .getAttribute(optionsMap);
167:
168:            }
169:
170:            /**
171:             * Overridden to do extra validation for set as well as
172:             * necessary massaging of values.
173:             * @param values
174:             * @param optionsMap
175:             * @throws PSMBeanException
176:             */
177:            public void setAttribute(List values, Map optionsMap)
178:                    throws PSMBeanException {
179:                boolean inheritStr = Boolean.valueOf(
180:                        (String) optionsMap
181:                                .get(AttrOptionConstants.OPT_INHERIT))
182:                        .booleanValue();
183:
184:                String attributeName = (String) optionsMap
185:                        .get(AttrOptionConstants.OPT_ATTR_NAME);
186:
187:                int attributeValueType = ((Integer) attrInfoMap
188:                        .get(attributeName)).intValue();
189:
190:                if (!inheritStr) {
191:
192:                    //Following code will validate add/remove/value option/operand against
193:                    // attribute type.
194:                    if (attributeValueType == AttributeInfo.LIST_STRING) {
195:                        validateListTypeAttribute(attributeName, values,
196:                                optionsMap);
197:                    }
198:                    if (attributeValueType != AttributeInfo.LIST_STRING
199:                            && attributeValueType != SINGLE_COMMA_SEPERATED_STRING) {
200:                        validateSingleValueAttribute(values, optionsMap,
201:                                attributeValueType);
202:                    }
203:
204:                    //Do the required massage of values
205:                    //This is required for attribute like desktop which
206:                    //store values as comma seperated strings.
207:                    if (attributeValueType == SINGLE_COMMA_SEPERATED_STRING) {
208:                        values = doAttributeValuesMassage(values, optionsMap);
209:                    }
210:
211:                }
212:
213:                //Set whether attribute is dynamic/global
214:                setAttributeType(optionsMap);
215:
216:                try {
217:                    super .setAttribute(values, optionsMap);
218:                } catch (Exception e) {
219:                    throw new PSMBeanException("error.psadmin.set.failed", e
220:                            .getMessage(), e);
221:                }
222:
223:            }
224:
225:            /**
226:             * Does not support add/remove/inherit operations.
227:             */
228:            public void setAttributes(Map nameValues, Map optionsMap)
229:                    throws PSMBeanException {
230:
231:                //No massage is required as add/remove are not supported
232:
233:                Set attrNames = (Set) optionsMap
234:                        .get(AttrOptionConstants.OPT_ATTR_NAMES);
235:
236:                //Map object for seperate storage of dynamic and global attributes
237:                Map globalAttrNameValueMap = new HashMap();
238:                Map dymanicAttrNameValueMap = new HashMap();
239:
240:                //populate global and dynamic name-value map
241:                Iterator iter = attrNames.iterator();
242:                while (iter.hasNext()) {
243:                    String attributeName = (String) iter.next();
244:                    if (isDynamic(attributeName)) {
245:                        dymanicAttrNameValueMap.put(attributeName, nameValues
246:                                .get(attributeName));
247:                    } else {
248:                        globalAttrNameValueMap.put(attributeName, nameValues
249:                                .get(attributeName));
250:                    }
251:                }
252:
253:                //Strore dynamic attributes
254:                if (dymanicAttrNameValueMap.size() > 0) {
255:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
256:                            dymanicAttrNameValueMap.keySet());
257:                    optionsMap.put(AttrOptionConstants.OPT_GLOBAL, FALSE_VALUE);
258:                    super .setAttributes(dymanicAttrNameValueMap, optionsMap);
259:                }
260:
261:                //Strore global attributes
262:                if (globalAttrNameValueMap.size() > 0) {
263:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
264:                            globalAttrNameValueMap.keySet());
265:                    optionsMap.put(AttrOptionConstants.OPT_GLOBAL, TRUE_VALUE);
266:                    super .setAttributes(globalAttrNameValueMap, optionsMap);
267:                }
268:
269:            }
270:
271:            public Map getAttributes(Map optionsMap) throws PSMBeanException {
272:
273:                Map retMap = new HashMap();
274:                Set attrNames = (Set) optionsMap
275:                        .get(AttrOptionConstants.OPT_ATTR_NAMES);
276:
277:                //Map object for seperate storage of dynamic and global attributes
278:                Set globalAttrSet = new HashSet();
279:                Set dymanicAttrSet = new HashSet();
280:
281:                //populate global and dynamic name-value map
282:                Iterator iter = attrNames.iterator();
283:                while (iter.hasNext()) {
284:                    String attributeName = (String) iter.next();
285:                    if (isDynamic(attributeName)) {
286:                        dymanicAttrSet.add(attributeName);
287:                    } else {
288:                        globalAttrSet.add(attributeName);
289:                    }
290:                }
291:
292:                //Retrieve global attributes
293:                if (globalAttrSet.size() > 0) {
294:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
295:                            globalAttrSet);
296:                    optionsMap.put(AttrOptionConstants.OPT_GLOBAL, TRUE_VALUE);
297:                    retMap.putAll(super .getAttributes(optionsMap));
298:                }
299:
300:                //Retrieve dynamic attributes
301:                if (dymanicAttrSet.size() > 0) {
302:                    optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
303:                            dymanicAttrSet);
304:                    optionsMap.put(AttrOptionConstants.OPT_GLOBAL, FALSE_VALUE);
305:                    retMap.putAll(super .getAttributes(optionsMap));
306:                }
307:
308:                return retMap;
309:            }
310:
311:            /**
312:             * Overridden because of the following reasons
313:             * 1) No validation for list operation call
314:             * 2) No need for validation if get/set operation is being called from console
315:             * 3)
316:             * @param values
317:             * @param optionsMap
318:             * @throws PSMBeanException
319:             */
320:            public void validate(List values, Map optionsMap)
321:                    throws PSMBeanException {
322:
323:                String operationName = (String) optionsMap.get("operation");
324:
325:                //No validation is required for list operation.
326:                if (operationName.equals("list")) {
327:                    return;
328:                }
329:
330:                if (optionsMap.get(AttrOptionConstants.OPT_ATTR_NAME) != null) {
331:                    //This means, handler is serving CLI request
332:                    doSingleAttributeValidation(optionsMap);
333:                } else {
334:                    //This means, handler is servihg Console request
335:                    //No validation is required.
336:                    return;
337:                }
338:
339:            }
340:
341:            /**
342:             * This method does validation for CLI call
343:             * From CLI, user can pass only one attribute for get/set.
344:             * This method does following validation
345:             * 1. Validate if attribute name is valid
346:             * 2. Validate if dn is specified for any global attribute
347:             * 3. Validate if inherit options is provided for non - dynamic attribute
348:             * @param optionsMap
349:             * @throws PSMBeanException
350:             */
351:            private void doSingleAttributeValidation(Map optionsMap)
352:                    throws PSMBeanException {
353:
354:                String attributeName = (String) optionsMap
355:                        .get(AttrOptionConstants.OPT_ATTR_NAME);
356:
357:                //to distinguish between dynamic and global attributes
358:                boolean isDynamicAttribute = false;
359:
360:                //Check whether the attribute name is correct or not.
361:                if (dynAttrMap.containsKey(attributeName)) {
362:                    isDynamicAttribute = true;
363:                } else if (!globalAttrMap.containsKey(attributeName)) {
364:                    //this means, user is specifying some non-existing attribute
365:                    throw new PSMBeanException(
366:                            "error.psadmin.invalid.attribute.name");
367:                }
368:
369:                boolean inheritStr = Boolean.valueOf(
370:                        (String) optionsMap
371:                                .get(AttrOptionConstants.OPT_INHERIT))
372:                        .booleanValue();
373:
374:                String dn = (String) optionsMap.get(AttrOptionConstants.OPT_DN);
375:
376:                //dn is not required for global attribute
377:                if (!isDynamicAttribute && (dn != null)) {
378:                    throw new PSMBeanException(
379:                            "error.psadmin.attribute.not.dn.specific");
380:                }
381:
382:                //can't inherit non-dynamic attribute
383:                if (inheritStr && !isDynamicAttribute) {
384:                    throw new PSMBeanException(
385:                            "error.psadmin.inherit.available.only.for.dynamic.attribute");
386:                }
387:
388:            }
389:
390:            /**
391:             * Overridden to provide component specific attribute information
392:             * @param optionsMap
393:             * @return java.uti.Map
394:             * @throws PSMBeanException
395:             */
396:
397:            public Map listAttributes(Map optionsMap) throws PSMBeanException {
398:
399:                Map attributeMap = new HashMap();
400:
401:                attributeMap.put(DESKTOP_TYPE, getAttributeInfoList(
402:                        AttributeInfo.LIST_STRING,
403:                        "psadmin.list.desktop.desktoptype.desc",
404:                        AttributeInfo.READ_WRITE, null));
405:
406:                attributeMap.put(PARENT_CONTAINER, getAttributeInfoList(
407:                        AttributeInfo.SINGLE_STRING,
408:                        "psadmin.list.desktop.defaultchannel.desc",
409:                        AttributeInfo.READ_WRITE, null));
410:
411:                attributeMap.put(EDIT_CHANNEL, getAttributeInfoList(
412:                        AttributeInfo.SINGLE_STRING,
413:                        "psadmin.list.desktop.editchannel.desc",
414:                        AttributeInfo.READ_WRITE, null));
415:
416:                attributeMap.put(SHOW_DESKTOP_ATTRIBUTE, getAttributeInfoList(
417:                        AttributeInfo.SINGLE_BOOLEAN,
418:                        "psadmin.list.desktop.showdesktopattribute.desc",
419:                        AttributeInfo.READ_WRITE, null));
420:
421:                attributeMap
422:                        .put(
423:                                CLIENT_SESSION_REAP_INTV,
424:                                getAttributeInfoList(
425:                                        AttributeInfo.SINGLE_NUMERIC,
426:                                        "psadmin.list.desktop.clientsessionreapinterval.desc",
427:                                        AttributeInfo.READ_WRITE, null));
428:
429:                attributeMap
430:                        .put(
431:                                CLIENT_SESSION_MAX_INACTIVE,
432:                                getAttributeInfoList(
433:                                        AttributeInfo.SINGLE_NUMERIC,
434:                                        "psadmin.list.desktop.clientsessionmaximuminactive.desc",
435:                                        AttributeInfo.READ_WRITE, null));
436:
437:                attributeMap.put(MAX_CLIENT_SESSION, getAttributeInfoList(
438:                        AttributeInfo.SINGLE_NUMERIC,
439:                        "psadmin.list.desktop.maxclientsessions.desc",
440:                        AttributeInfo.READ_WRITE, null));
441:
442:                attributeMap.put(ENABLE_XML_VALIDATION, getAttributeInfoList(
443:                        AttributeInfo.SINGLE_BOOLEAN,
444:                        "psadmin.list.desktop.enablexmlvalidation.desc",
445:                        AttributeInfo.READ_WRITE, null));
446:
447:                attributeMap.put(NAMESPACE_URI, getAttributeInfoList(
448:                        AttributeInfo.SINGLE_STRING,
449:                        "psadmin.list.desktop.namespaceuri.desc",
450:                        AttributeInfo.READ_WRITE, null));
451:
452:                attributeMap.put(ENABLE_FEDERATION, getAttributeInfoList(
453:                        AttributeInfo.SINGLE_BOOLEAN,
454:                        "psadmin.list.desktop.enablefederation.desc",
455:                        AttributeInfo.READ_WRITE, null));
456:
457:                attributeMap.put(HOSTED_PROVIDER_ID, getAttributeInfoList(
458:                        AttributeInfo.SINGLE_STRING,
459:                        "psadmin.list.desktop.hostedproviderid.desc",
460:                        AttributeInfo.READ_WRITE, null));
461:
462:                attributeMap
463:                        .put(
464:                                DIS_AUTHLESS_FOR_FEDERATED_USERS,
465:                                getAttributeInfoList(
466:                                        AttributeInfo.SINGLE_BOOLEAN,
467:                                        "psadmin.list.desktop.disableauthlessforfederatedusers.desc",
468:                                        AttributeInfo.READ_WRITE, null));
469:
470:                attributeMap.put(ACCESS_URL, getAttributeInfoList(
471:                        AttributeInfo.SINGLE_STRING,
472:                        "psadmin.list.desktop.accessurl.desc",
473:                        AttributeInfo.READ_WRITE, null));
474:
475:                attributeMap.put(DEFAULT_AUTHLESS_UID, getAttributeInfoList(
476:                        AttributeInfo.SINGLE_STRING,
477:                        "psadmin.list.desktop.defaultauthlessuid.desc",
478:                        AttributeInfo.READ_WRITE, null));
479:
480:                attributeMap
481:                        .put(
482:                                AUTHORIZED_AUTHLESS_UIDS,
483:                                getAttributeInfoList(
484:                                        AttributeInfo.LIST_STRING,
485:                                        "psadmin.list.desktop.authorizedauthlessuserids.desc",
486:                                        AttributeInfo.READ_WRITE, null));
487:
488:                attributeMap.put(ENABLE_AUTHLESS, getAttributeInfoList(
489:                        AttributeInfo.SINGLE_BOOLEAN,
490:                        "psadmin.list.desktop.enableauthless.desc",
491:                        AttributeInfo.READ_WRITE, null));
492:
493:                attributeMap
494:                        .put(
495:                                COMMUNITY_PARENT_CONTAINER_URL_PARAMETER,
496:                                getAttributeInfoList(
497:                                        AttributeInfo.SINGLE_STRING,
498:                                        "psadmin.list.desktop.communityparentcontainerurlparameter.desc",
499:                                        AttributeInfo.READ_WRITE, null));
500:
501:                attributeMap
502:                        .put(
503:                                COMMUNITY_HOME_CONTAINER,
504:                                getAttributeInfoList(
505:                                        AttributeInfo.SINGLE_STRING,
506:                                        "psadmin.list.desktop.communityhomecontainer.desc",
507:                                        AttributeInfo.READ_WRITE, null));
508:
509:                attributeMap
510:                        .put(
511:                                COMMUNITY_CREATE_CONTAINER,
512:                                getAttributeInfoList(
513:                                        AttributeInfo.SINGLE_STRING,
514:                                        "psadmin.list.desktop.communitycreatecontainer.desc",
515:                                        AttributeInfo.READ_WRITE, null));
516:
517:                attributeMap.put(COS_PRIORITY, getAttributeInfoList(
518:                        AttributeInfo.SINGLE_NUMERIC,
519:                        "psadmin.list.desktop.cosPriority.desc",
520:                        AttributeInfo.READ_WRITE, null));
521:
522:                return attributeMap;
523:
524:            }
525:
526:            /**
527:             * Helper method for list command
528:             * @param attributeType
529:             * @param desc
530:             * @param privilege
531:             * @param exampleKey
532:             * @return java.util.List
533:             */
534:            private List getAttributeInfoList(int attributeType, String desc,
535:                    int privilege, String exampleKey) {
536:
537:                List infoList = new ArrayList();
538:                infoList.add(new Integer(attributeType));
539:                infoList.add(desc);
540:                infoList.add(new Integer(privilege));
541:                infoList.add(exampleKey);
542:                return infoList;
543:
544:            }
545:
546:            /**
547:             * This method does following validations
548:             * 1) add/remove options are not allowed for single valued attribute
549:             * 2) boolean attribute can have only true/fase as their values
550:             * 3) numeric attribute can have only numeric value
551:             * @param values
552:             * @param optionsMap
553:             * @param attributeType
554:             * @throws PSMBeanException
555:             */
556:            private void validateSingleValueAttribute(List values,
557:                    Map optionsMap, int attributeType) throws PSMBeanException {
558:
559:                List addValues = (List) optionsMap
560:                        .get(AttrOptionConstants.OPT_ADD);
561:                List removeValues = (List) optionsMap
562:                        .get(AttrOptionConstants.OPT_REMOVE);
563:
564:                if (addValues != null || removeValues != null
565:                        || values.size() != 1) {
566:                    throw new PSMBeanException(
567:                            "error.psadmin.attribute.is.single.valued");
568:                }
569:
570:                String value_str = (String) values.get(0);
571:
572:                switch (attributeType) {
573:                case AttributeInfo.SINGLE_BOOLEAN:
574:                    if (!(value_str.equalsIgnoreCase(TRUE_VALUE) || value_str
575:                            .equalsIgnoreCase(FALSE_VALUE))) {
576:                        throw new PSMBeanException(
577:                                "error.psadmin.attribute.is.boolean");
578:                    }
579:                    break;
580:                case AttributeInfo.SINGLE_NUMERIC:
581:                    try {
582:                        Integer.parseInt(value_str);
583:                    } catch (NumberFormatException e) {
584:                        throw new PSMBeanException(
585:                                "error.psadmin.attribute.is.number");
586:                    }
587:                    break;
588:                default:
589:                    break;
590:                }
591:
592:            }
593:
594:            /**
595:             * This method does following validations.
596:             * 1) Whether user has provided password For AUTHORIZED_AUTHLESS_UIDS (CR 6335164)
597:             * @param attributeName
598:             * @param values
599:             * @throws PSMBeanException
600:             */
601:            private void validateListTypeAttribute(String attributeName,
602:                    List values, Map optionMap) throws PSMBeanException {
603:
604:                if (attributeName.equals(AUTHORIZED_AUTHLESS_UIDS)) {
605:                    validateAuthorizedAuthlessUserIds(values, optionMap);
606:                }
607:            }
608:
609:            private void validateAuthorizedAuthlessUserIds(List values,
610:                    Map optionMap) throws PSMBeanException {
611:
612:                if (optionMap.get(AttrOptionConstants.OPT_REMOVE) == null) {
613:                    //Following is required only for add and set operation
614:                    List valuesToVarify = values;
615:                    //If this is not set operation, it must be add
616:                    if (valuesToVarify == null || values.size() == 0) {
617:                        valuesToVarify = ((List) optionMap
618:                                .get(AttrOptionConstants.OPT_ADD));
619:                    }
620:
621:                    if (valuesToVarify != null && valuesToVarify.size() > 0) {
622:                        for (int i = 0; i < valuesToVarify.size(); i++) {
623:                            String uid_pwd = (String) valuesToVarify.get(i);
624:                            //Following will check whether | is missing
625:                            //or if it is first character.
626:                            if (uid_pwd.indexOf("|") < 1)
627:                                throw new PSMBeanException(
628:                                        "desktop.errorAuthorizedAuthlessUserIds");
629:                        }
630:                    }
631:                }
632:            }
633:
634:            /**
635:             * This method parses list returned by getAttribute method.
636:             * List passed as method parameter has only one string element.
637:             * This string element may be a concatination of multiple values
638:             * seperated by commas.
639:             * Returned list contains these values as seperate elements
640:             * @param valuesList
641:             * @return
642:             */
643:            private List getListFromCommaSeperatedString(List valuesList) {
644:
645:                List valueList = new ArrayList();
646:                if (valuesList == null || valuesList.size() == 0) {
647:                    return valueList;
648:                }
649:                //First element in the list is comma seperated string
650:                String commaSeperatedString = (String) valuesList.get(0);
651:                //Parse this comma seperated string to get individual values
652:                StringTokenizer st = new StringTokenizer(commaSeperatedString,
653:                        ",");
654:                while (st.hasMoreTokens()) {
655:                    valueList.add(st.nextToken());
656:                }
657:                return valueList;
658:
659:            }
660:
661:            /**
662:             * Following method removes values specified by --remove option
663:             * from the original list
664:             * @param orgList
665:             * @param removeItemList
666:             */
667:            private void removeValuesFromOrgList(List orgList,
668:                    List removeItemList) {
669:
670:                if (removeItemList != null && removeItemList.size() > 0) {
671:                    orgList.removeAll(removeItemList);
672:                }
673:
674:            }
675:
676:            /**
677:             * Following method add values specified by --add option
678:             * or passed as oprerand of the command in to the original list
679:             * @param orgList
680:             * @param addItemList
681:             */
682:            private void addValuesIntoOrgList(List orgList, List addItemList) {
683:
684:                if (addItemList != null && addItemList.size() > 0) {
685:                    orgList.addAll(addItemList);
686:                }
687:
688:            }
689:
690:            /**
691:             * Helper method which create comma-seperated string from a list of values
692:             * @param valuesList
693:             * @return
694:             */
695:            private String getCommaSeperatedStringFromList(List valuesList) {
696:
697:                StringBuffer commSeperatedStringBuffer = new StringBuffer();
698:                for (Iterator ite = valuesList.iterator(); ite.hasNext();) {
699:                    commSeperatedStringBuffer.append(ite.next());
700:                    commSeperatedStringBuffer.append(",");
701:                }
702:
703:                if (commSeperatedStringBuffer.length() > 0) {
704:                    commSeperatedStringBuffer
705:                            .deleteCharAt(commSeperatedStringBuffer.length() - 1);
706:                }
707:
708:                return commSeperatedStringBuffer.toString();
709:
710:            }
711:
712:            /**
713:             * Following method should be called only from setAttribute() method
714:             * Also, it is called for attribute that stores multiple values
715:             * in a single string with individual values seperated by commas
716:             * The only example of this type if attribute is 'DesktopType'
717:             * @param values
718:             * @param optionsMap
719:             * @return
720:             * @throws PSMBeanException
721:             */
722:            private List doAttributeValuesMassage(List values, Map optionsMap)
723:                    throws PSMBeanException {
724:                //Here we will do following work.
725:                //Step 1  - check whether new values are coming as operand.
726:                //         If yes, we simply need to replace currently existing value by
727:                //         the new value. For that, we need to create a comma seperated
728:                //         string from new values. If above is not true, go further
729:                //Step 2 - Get the currently stored value
730:                //Step 3 - parse it to get the list of individual values,
731:                //         say it, newValuesList
732:                //Step 4 - if remove is specified, remove the values from newValuesList
733:                //         also delete 'remove' option from the optionsMap
734:                //Step 5 - if add is specified add the values in the orgList
735:                //         also delete 'add' option from the optionsMap
736:                //Step 6 - create a comma seperated string from the list
737:                //Step 7 - Reset the list passed in this method. Set this comma seperated
738:                //         string as the first element in the list. This final list
739:                //         (actually only one element in the list) will be used for set.
740:
741:                //Following string will contain final comma seperated values
742:                String newValuesString = new String();
743:
744:                if (values != null && values.size() > 0) {
745:                    //This means user has provided values as operand
746:                    //Step 2
747:                    newValuesString = getCommaSeperatedStringFromList(values);
748:                } else {
749:                    //This means user has provided values by --add/remove options
750:                    //Step 3
751:                    List orgListWithCommaSeperatedValues = getAttribute(optionsMap);
752:                    //Step 4
753:                    List newValuesList = getListFromCommaSeperatedString(orgListWithCommaSeperatedValues);
754:                    //Step 5
755:                    removeValuesFromOrgList(newValuesList, (List) optionsMap
756:                            .get(AttrOptionConstants.OPT_REMOVE));
757:                    optionsMap.remove(AttrOptionConstants.OPT_REMOVE);
758:                    //Step 6
759:                    addValuesIntoOrgList(newValuesList, (List) optionsMap
760:                            .get(AttrOptionConstants.OPT_ADD));
761:                    optionsMap.remove(AttrOptionConstants.OPT_ADD);
762:                    //Step 7
763:                    newValuesString = getCommaSeperatedStringFromList(newValuesList);
764:                }
765:
766:                //Step 8
767:                //We are creating a new List as the values list passed in this method call
768:                //may be immutable.
769:                List returnValues = new ArrayList();
770:                returnValues.add(newValuesString);
771:
772:                return returnValues;
773:
774:            }
775:
776:            /**
777:             * This method decides about the type (default/global) of the attribute
778:             * and set this information in the option map. This information is used
779:             * by buildExtraInfo() method to get the SCHEMA_TYPE.
780:             * @param optionsMap
781:             */
782:            private void setAttributeType(Map optionsMap) {
783:                String attributeName = (String) optionsMap
784:                        .get(AttrOptionConstants.OPT_ATTR_NAME);
785:
786:                if (isDynamic(attributeName)) {
787:                    optionsMap.put(AttrOptionConstants.OPT_GLOBAL, "false");
788:                } else {
789:                    optionsMap.put(AttrOptionConstants.OPT_GLOBAL, "true");
790:                }
791:            }
792:
793:            private boolean isDynamic(String name) {
794:                if (dynAttrMap.containsKey(name)) {
795:                    return true;
796:                }
797:                return false;
798:            }
799:
800:        }
w_ww.__ja__v_a__2_s___.c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.