KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > CallflowCommand


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27 import javax.management.AttributeList JavaDoc;
28 import javax.management.Attribute JavaDoc;
29 import javax.management.MBeanServerConnection JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31
32
33 /**
34  * This class is the implementation for start-callflow-monitoring and
35  * start-callflow-monitoring command.
36  * @author <a HREF="mailto:jane.young@sun.com">Jane Young</a>
37  * @version $Revision: 1.4 $
38  **/

39
40 public class CallflowCommand extends S1ASCommand
41 {
42     private static final String JavaDoc FILTER_TYPE_OPTION = "filtertype";
43     private static final String JavaDoc CALLER_IPFILTER = "CallerIPFilter";
44     private static final String JavaDoc CALLER_PRINCIPALFILTER = "CallerPrincipalFilter";
45     private static final String JavaDoc ENABLED = "Enabled";
46     private static final String JavaDoc FILTER_TYPE_USER = "user";
47     private static final String JavaDoc FILTER_TYPE_IP = "ip";
48     private static final String JavaDoc START_CALL_FLOW= "start-callflow-monitoring";
49     private String JavaDoc sFilterIP = null;
50     private String JavaDoc sFilterUserID = null;
51
52     
53     /**
54      * An abstract method that Executes the command
55      * @throws CommandException
56      */

57     public void runCommand() throws CommandException, CommandValidationException
58     {
59         if (!validateOptions())
60             throw new CommandValidationException("Validation is false");
61         
62         //use http connector
63
MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
64                                                               getUser(), getPassword());
65         final String JavaDoc objectName = getObjectName();
66         
67         //Set the Enabled Attribute
68
try
69         {
70             mbsc.setAttributes(new ObjectName JavaDoc(objectName),
71                                createCallflowAttributeList());
72         }
73         catch(Exception JavaDoc e)
74         {
75             displayExceptionMessage(e);
76         }
77
78         CLILogger.getInstance().printDetailMessage(getLocalizedString(
79                                                    "CommandSuccessful",
80                                                    new Object JavaDoc[] {name}));
81     }
82
83
84     /**
85      * This method creates AttributesList for CallFlowMonitor MBean.
86      * @throws CommandException, CommandValidationException
87      **/

88     private AttributeList JavaDoc createCallflowAttributeList()
89          throws CommandException, CommandValidationException
90     {
91         validateFilterType();
92         final boolean bEnable = name.equals(START_CALL_FLOW)?true:false;
93         
94         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
95         attrList.add(new Attribute JavaDoc(ENABLED, bEnable));
96         if (sFilterIP != null)
97             attrList.add(new Attribute JavaDoc(CALLER_IPFILTER, sFilterIP));
98         if (sFilterUserID != null)
99             attrList.add(new Attribute JavaDoc(CALLER_PRINCIPALFILTER, sFilterUserID));
100         return attrList;
101     }
102     
103
104
105     /**
106      * This method validates filtertype.
107      * There are currently two filtertype. They are user and ip.
108      * If type user, the attribute to set is CALLER_PRINCIPALFILTER.
109      * If type ip, the attribute to set is CALLER_IPFILTER.
110      * If type other than user or ip then throw a CommandValidationException
111      * If type is not in the correct format, then an exception is thrown.
112      * filterypte should be in the format of name=value with : as the delimiter.
113      * @throws CommandException and CommandValidationException
114      **/

115     private void validateFilterType() throws CommandException, CommandValidationException
116     {
117         if (getOption(FILTER_TYPE_OPTION) != null) {
118             final String JavaDoc filterType = getOption(FILTER_TYPE_OPTION);
119             
120             final CLITokenizer filterTypeTok = new CLITokenizer(filterType, PROPERTY_DELIMITER);
121             while (filterTypeTok.hasMoreTokens()) {
122                 final String JavaDoc nameAndvalue = filterTypeTok.nextToken();
123                 final CLITokenizer nameTok = new CLITokenizer(nameAndvalue, PARAM_VALUE_DELIMITER);
124                 if (nameTok.countTokens() == 2)
125                 {
126                     final String JavaDoc sName = nameTok.nextTokenWithoutEscapeAndQuoteChars();
127                     final String JavaDoc sValue = nameTok.nextTokenWithoutEscapeAndQuoteChars();
128                     if (sName.equals(FILTER_TYPE_IP))
129                         sFilterIP = sValue;
130                     else if (sName.equals(FILTER_TYPE_USER))
131                         sFilterUserID = sValue;
132                     else
133                         throw new CommandValidationException(getLocalizedString("InvalidFilterName", new Object JavaDoc[] {sName}));
134                 } else {
135                         throw new CommandValidationException(getLocalizedString("InvalidFilterType", new Object JavaDoc[] {filterType}));
136                 }
137                 
138             }
139         }
140     }
141     
142     
143 }
144
Popular Tags