01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.tools.remote.soap.axis.ser;
10:
11: import java.io.IOException;
12: import java.util.Iterator;
13: import java.util.Vector;
14: import javax.management.NotificationFilterSupport;
15: import javax.management.ObjectName;
16: import javax.management.relation.MBeanServerNotificationFilter;
17: import javax.xml.namespace.QName;
18:
19: import org.apache.axis.encoding.SerializationContext;
20: import org.apache.axis.wsdl.fromJava.Types;
21: import org.w3c.dom.Element;
22:
23: /**
24: * @version $Revision: 1.3 $
25: */
26: public class MBeanServerNotificationFilterSer extends
27: NotificationFilterSupportSer {
28: static final String ENABLED_OBJECT_NAME = "enabledObjectName";
29: static final String DISABLED_OBJECT_NAME = "disabledObjectName";
30: static final String ALL_DISABLED = "allDisabled";
31: static final String ALL_ENABLED = "allEnabled";
32: private static final QName ENABLED_OBJECT_NAME_QNAME = new QName(
33: "", ENABLED_OBJECT_NAME);
34: private static final QName DISABLED_OBJECT_NAME_QNAME = new QName(
35: "", DISABLED_OBJECT_NAME);
36: private static final QName ALL_DISABLED_QNAME = new QName("",
37: ALL_DISABLED);
38: private static final QName ALL_ENABLED_QNAME = new QName("",
39: ALL_ENABLED);
40:
41: protected void onSerialize(SerializationContext context,
42: NotificationFilterSupport filter) throws IOException {
43: super .onSerialize(context, filter);
44:
45: MBeanServerNotificationFilter serverFilter = (MBeanServerNotificationFilter) filter;
46: Vector enabledNames = serverFilter.getEnabledObjectNames();
47: Vector disabledNames = serverFilter.getDisabledObjectNames();
48:
49: // A special logic should be implemented: an empty vector has a different meaning than a null vector
50: // See JMX specification (javadocs) for further details
51: if (enabledNames != null) {
52: if (enabledNames.size() == 0) {
53: context.serialize(ALL_DISABLED_QNAME, null,
54: Boolean.TRUE);
55: } else {
56: context.serialize(ALL_DISABLED_QNAME, null,
57: Boolean.FALSE);
58: }
59: for (Iterator i = enabledNames.iterator(); i.hasNext();) {
60: ObjectName enabled = (ObjectName) i.next();
61: context.serialize(ENABLED_OBJECT_NAME_QNAME, null,
62: enabled);
63: }
64: }
65: if (disabledNames != null) {
66: if (disabledNames.size() == 0) {
67: context
68: .serialize(ALL_ENABLED_QNAME, null,
69: Boolean.TRUE);
70: } else {
71: context.serialize(ALL_ENABLED_QNAME, null,
72: Boolean.FALSE);
73: }
74: for (Iterator i = disabledNames.iterator(); i.hasNext();) {
75: ObjectName disabled = (ObjectName) i.next();
76: context.serialize(DISABLED_OBJECT_NAME_QNAME, null,
77: disabled);
78: }
79: }
80: }
81:
82: public Element writeSchema(Class javaType, Types types)
83: throws Exception {
84: // TODO: Use XML Schema syntax to specify that this is a subclass of NotificationFilterSupport
85: return null;
86: }
87: }
|