Source Code Cross Referenced for SubsystemWrapper.java in  » Portal » Open-Portal » com » sun » portal » monitoring » 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.monitoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.monitoring;
006:
007:        import com.sun.portal.log.common.PortalLogger;
008:
009:        import javax.management.*;
010:        import javax.management.openmbean.*;
011:        import java.util.*;
012:        import java.util.logging.Logger;
013:        import java.util.logging.Level;
014:        import java.util.logging.LogRecord;
015:
016:        public class SubsystemWrapper implements  ResourceBundleWrapper,
017:                CompositeDataWrapper, MBeanInfoWrapper {
018:            private static final Logger logger = PortalLogger
019:                    .getLogger(SubsystemWrapper.class);
020:
021:            private static LogRecord getLogRecord(Level level, String message,
022:                    Object[] parameters, Throwable t) {
023:                LogRecord result = new LogRecord(level, message);
024:                result.setLoggerName(logger.getName());
025:                result.setParameters(parameters);
026:                result.setThrown(t);
027:                return result;
028:            }
029:
030:            public SubsystemWrapper(Boolean disabled,
031:                    MonitoringContext monitoringContext) {
032:                this .monitoringContext = monitoringContext;
033:
034:                itemValues = new Object[] {
035:                        disabled,
036:                        new Integer(Integer.parseInt(monitoringContext
037:                                .getSslContext().getPort())),
038:                        new Integer(Integer.parseInt(monitoringContext
039:                                .getHtmlAdaptorPort())),
040:                        monitoringContext.getUseJavaPlatformMBeanServer() };
041:            }
042:
043:            private MonitoringContext monitoringContext;
044:            private Object[] itemValues;
045:
046:            public String getResourceBundleBaseName() {
047:                return resourceBundleBaseName;
048:            }
049:
050:            public void setResourceBundleBaseName(String resourceBundleBaseName) {
051:                this .resourceBundleBaseName = resourceBundleBaseName;
052:            }
053:
054:            public Locale getLocale() {
055:                return locale;
056:            }
057:
058:            public void setLocale(Locale locale) {
059:                this .locale = locale;
060:            }
061:
062:            private String resourceBundleBaseName;
063:            private Locale locale;
064:
065:            private ResourceBundle getResourceBundle() {
066:                if (resourceBundle == null) {
067:                    resourceBundle = ResourceBundleHelper
068:                            .getResourceBundle(this );
069:                }
070:
071:                return resourceBundle;
072:            }
073:
074:            private ResourceBundle resourceBundle;
075:
076:            public String getCompositeTypeName() {
077:                if (compositeTypeName != null) {
078:                    return compositeTypeName;
079:                }
080:
081:                return getClass().getName();
082:            }
083:
084:            public void setCompositeTypeName(String compositeTypeName) {
085:                this .compositeTypeName = compositeTypeName;
086:            }
087:
088:            public String getCompositeTypeDescription() {
089:                try {
090:                    return getResourceBundle().getString(
091:                            getCompositeTypeName() + "."
092:                                    + COMPOSITE_TYPE_DESCRIPTION);
093:                } catch (MissingResourceException e) {
094:                    if (logger.isLoggable(Level.CONFIG)) {
095:                        LogRecord logRecord = new LogRecord(Level.CONFIG,
096:                                "PSMN_CSPM0001");
097:                        logRecord.setParameters(new Object[] { e
098:                                .getLocalizedMessage() });
099:                        logRecord.setThrown(e);
100:                        logger.log(logRecord);
101:                    }
102:                    return COMPOSITE_TYPE_DESCRIPTION;
103:                } catch (NullPointerException e) {
104:                    if (logger.isLoggable(Level.CONFIG)) {
105:                        logger.log(getLogRecord(Level.CONFIG, "PSMN_CSPM0001",
106:                                new Object[] { e.getLocalizedMessage() }, e));
107:                    }
108:                    return COMPOSITE_TYPE_DESCRIPTION;
109:                }
110:            }
111:
112:            public String[] getItemNames() {
113:                return SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES;
114:            }
115:
116:            public String[] getItemDescriptions() {
117:                List list = new ArrayList();
118:                for (int i = 0; i < SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES.length; i++) {
119:                    list.add(SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[i]
120:                            + "Description");
121:                }
122:                return (String[]) list.toArray(new String[list.size()]);
123:            }
124:
125:            public OpenType[] getItemTypes() {
126:                return new OpenType[] { SimpleType.BOOLEAN, SimpleType.INTEGER,
127:                        SimpleType.INTEGER, SimpleType.BOOLEAN };
128:            }
129:
130:            public Object[] getItemValues() {
131:                return itemValues;
132:            }
133:
134:            private void checkNullValue(Attribute attribute)
135:                    throws InvalidAttributeValueException {
136:                Object value = attribute.getValue();
137:                if (value == null) {
138:                    throw new InvalidAttributeValueException("Attribute <"
139:                            + attribute.getName() + "> value cannot be null");
140:                }
141:            }
142:
143:            private void checkValueType(Attribute attribute, Class type)
144:                    throws InvalidAttributeValueException {
145:                Object value = attribute.getValue();
146:
147:                if (!(value.getClass().equals(type))) {
148:                    throw new InvalidAttributeValueException("Attribute <"
149:                            + attribute.getName()
150:                            + "> value should be of type <" + type.getName()
151:                            + ">");
152:                }
153:            }
154:
155:            private void setDisable(Object value)
156:                    throws InvalidAttributeValueException {
157:                int i = 0;
158:                Attribute attribute = new Attribute(
159:                        SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[i], value);
160:                checkNullValue(attribute);
161:                checkValueType(attribute, Boolean.class);
162:                itemValues[i] = value;
163:                monitoringContext.setMonitoringDisable(((Boolean) value));
164:            }
165:
166:            private void setConnectorServerPort(Object value)
167:                    throws InvalidAttributeValueException {
168:                int i = 1;
169:                Attribute attribute = new Attribute(
170:                        SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[i], value);
171:                checkNullValue(attribute);
172:                checkValueType(attribute, Integer.class);
173:                itemValues[i] = value;
174:                monitoringContext.getSslContext().setPort(
175:                        ((Integer) value).toString());
176:            }
177:
178:            private void setHtmlAdapterPortPort(Object value)
179:                    throws InvalidAttributeValueException {
180:                int i = 2;
181:                Attribute attribute = new Attribute(
182:                        SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[i], value);
183:                checkNullValue(attribute);
184:                checkValueType(attribute, Integer.class);
185:                itemValues[i] = value;
186:                monitoringContext.setHtmlAdaptorPort(((Integer) value)
187:                        .toString());
188:            }
189:
190:            private void setUseJavaPlatformMBeanServer(Object value)
191:                    throws InvalidAttributeValueException {
192:                int i = 3;
193:                Attribute attribute = new Attribute(
194:                        SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[i], value);
195:                checkNullValue(attribute);
196:                checkValueType(attribute, Boolean.class);
197:                itemValues[i] = value;
198:                monitoringContext
199:                        .setUseJavaPlatformMBeanServer(((Boolean) value));
200:            }
201:
202:            public void setItemValues(CompositeData compositeData)
203:                    throws InvalidAttributeValueException {
204:                setDisable(compositeData
205:                        .get(SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[0]));
206:                setConnectorServerPort(compositeData
207:                        .get(SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[1]));
208:                setHtmlAdapterPortPort(compositeData
209:                        .get(SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[2]));
210:                setUseJavaPlatformMBeanServer(compositeData
211:                        .get(SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES[3]));
212:            }
213:
214:            public CompositeType getCompositeType() throws OpenDataException {
215:                if (compositeType == null) {
216:                    String[] itemNames = getItemNames();
217:                    String[] itemDescriptions = getItemDescriptions();
218:                    OpenType[] itemTypes = getItemTypes();
219:
220:                    ResourceBundle resourceBundle = getResourceBundle();
221:                    if (resourceBundle != null) {
222:                        for (int i = 0; i < itemDescriptions.length; i++) {
223:                            try {
224:                                itemDescriptions[i] = resourceBundle
225:                                        .getString(getCompositeTypeName() + "."
226:                                                + itemDescriptions[i]);
227:                            } catch (MissingResourceException e) {
228:                                if (logger.isLoggable(Level.CONFIG)) {
229:                                    logger
230:                                            .log(getLogRecord(
231:                                                    Level.CONFIG,
232:                                                    "PSMN_CSPM0001",
233:                                                    new Object[] { e
234:                                                            .getLocalizedMessage() },
235:                                                    e));
236:                                }
237:                            } catch (NullPointerException e) {
238:                                if (logger.isLoggable(Level.CONFIG)) {
239:                                    logger
240:                                            .log(getLogRecord(
241:                                                    Level.CONFIG,
242:                                                    "PSMN_CSPM0001",
243:                                                    new Object[] { e
244:                                                            .getLocalizedMessage() },
245:                                                    e));
246:                                }
247:                            }
248:                        }
249:                    }
250:
251:                    compositeType = new CompositeType(getCompositeTypeName(),
252:                            getCompositeTypeDescription(), itemNames,
253:                            itemDescriptions, itemTypes);
254:                }
255:
256:                return compositeType;
257:            }
258:
259:            public CompositeData toCompositeData() throws OpenDataException {
260:                return new CompositeDataSupport(getCompositeType(),
261:                        getItemNames(), getItemValues());
262:            }
263:
264:            public void fromCompositeData(CompositeData compositeData)
265:                    throws OpenDataException, InvalidAttributeValueException {
266:                if (!getCompositeType()
267:                        .equals(compositeData.getCompositeType())) {
268:                    throw new InvalidOpenTypeException(
269:                            "CompositeType mismatch: supports <"
270:                                    + getCompositeType().getTypeName()
271:                                    + "> and received <"
272:                                    + compositeData.getCompositeType()
273:                                            .getTypeName() + ">");
274:                }
275:
276:                setItemValues(compositeData);
277:            }
278:
279:            private CompositeType compositeType;
280:            private String compositeTypeName;
281:            private static final String COMPOSITE_TYPE_DESCRIPTION = "CompositeTypeDescription";
282:
283:            public Map getMBeanAttributeInfo() throws OpenDataException {
284:                Set itemNames = getCompositeType().keySet();
285:                Map result = new HashMap(itemNames.size());
286:                for (Iterator iterator = itemNames.iterator(); iterator
287:                        .hasNext();) {
288:                    String itemName = (String) iterator.next();
289:                    MBeanAttributeInfo mBeanAttributeInfo = new OpenMBeanAttributeInfoSupport(
290:                            itemName, getCompositeType().getDescription(
291:                                    itemName), getCompositeType().getType(
292:                                    itemName), true, true, false);
293:                    result.put(itemName, mBeanAttributeInfo);
294:                }
295:
296:                return result;
297:            }
298:
299:            public MBeanConstructorInfo[] getMBeanConstructorInfo() {
300:                return new MBeanConstructorInfo[0];
301:            }
302:
303:            public Map getMBeanOperationInfo() {
304:                Map result = new HashMap(3);
305:
306:                ResourceBundle resourceBundle = ResourceBundleHelper
307:                        .getResourceBundle(this );
308:                if (resourceBundle != null) {
309:                    try {
310:                        getRegistryDescription = resourceBundle
311:                                .getString(getCompositeTypeName() + "."
312:                                        + getRegistryDescription);
313:                        resetDescription = resourceBundle
314:                                .getString(getCompositeTypeName() + "."
315:                                        + resetDescription);
316:                        destroyDescription = resourceBundle
317:                                .getString(getCompositeTypeName() + "."
318:                                        + destroyDescription);
319:                    } catch (MissingResourceException e) {
320:                        if (logger.isLoggable(Level.CONFIG)) {
321:                            logger.log(getLogRecord(Level.CONFIG,
322:                                    "PSMN_CSPM0001", new Object[] { e
323:                                            .getLocalizedMessage() }, e));
324:                        }
325:                    }
326:                }
327:
328:                result.put("getRegistry", new MBeanOperationInfo("getRegistry",
329:                        getRegistryDescription, null, "java.util.Map",
330:                        MBeanOperationInfo.INFO));
331:                result.put("reset", new MBeanOperationInfo("reset",
332:                        resetDescription, null, "void",
333:                        MBeanOperationInfo.ACTION));
334:                result.put("destroy", new MBeanOperationInfo("destroy",
335:                        destroyDescription, null, "void",
336:                        MBeanOperationInfo.ACTION));
337:
338:                return result;
339:            }
340:
341:            public Map getMBeanNotificationInfo() {
342:                Map result = new HashMap(1);
343:
344:                ResourceBundle resourceBundle = ResourceBundleHelper
345:                        .getResourceBundle(this );
346:                if (resourceBundle != null) {
347:                    try {
348:                        notificationDescription = resourceBundle
349:                                .getString(getCompositeTypeName() + "."
350:                                        + notificationDescription);
351:                    } catch (MissingResourceException e) {
352:                        if (logger.isLoggable(Level.CONFIG)) {
353:                            logger.log(getLogRecord(Level.CONFIG,
354:                                    "PSMN_CSPM0001", new Object[] { e
355:                                            .getLocalizedMessage() }, e));
356:                        }
357:                    }
358:                }
359:                result
360:                        .put(
361:                                "javax.management.AttributeChangeNotification",
362:                                new MBeanNotificationInfo(
363:                                        new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE },
364:                                        "javax.management.AttributeChangeNotification",
365:                                        notificationDescription));
366:
367:                return result;
368:            }
369:
370:            public MBeanInfo getMBeanInfo() throws OpenDataException {
371:                if (mBeanInfo == null) {
372:                    Collection attributeInfos = getMBeanAttributeInfo()
373:                            .values();
374:                    MBeanAttributeInfo[] mBeanAttributeInfos = (MBeanAttributeInfo[]) attributeInfos
375:                            .toArray(new MBeanAttributeInfo[attributeInfos
376:                                    .size()]);
377:
378:                    Collection operationInfos = getMBeanOperationInfo()
379:                            .values();
380:                    MBeanOperationInfo[] mBeanOperationInfos = (MBeanOperationInfo[]) operationInfos
381:                            .toArray(new MBeanOperationInfo[operationInfos
382:                                    .size()]);
383:
384:                    Collection notificationInfos = getMBeanNotificationInfo()
385:                            .values();
386:                    MBeanNotificationInfo[] mBeanNotificationInfos = (MBeanNotificationInfo[]) notificationInfos
387:                            .toArray(new MBeanNotificationInfo[notificationInfos
388:                                    .size()]);
389:
390:                    mBeanInfo = new MBeanInfo(getCompositeType().getTypeName(),
391:                            getCompositeType().getDescription(),
392:                            mBeanAttributeInfos, getMBeanConstructorInfo(),
393:                            mBeanOperationInfos, mBeanNotificationInfos);
394:                }
395:
396:                return mBeanInfo;
397:            }
398:
399:            public void setMBeanInfo(MBeanInfo mBeanInfo) {
400:                this .mBeanInfo = mBeanInfo;
401:            }
402:
403:            private MBeanInfo mBeanInfo;
404:            private String getRegistryDescription = "getRegistryDescription";
405:            private String resetDescription = "resetDescription";
406:            private String destroyDescription = "destroyDescription";
407:            private String notificationDescription = "notificationDescription";
408:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.