KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import com.sun.enterprise.config.serverbeans.ServerTags;
29 import java.util.Map JavaDoc;
30 import java.util.HashMap JavaDoc;
31
32 public class CreateMBeanCommand extends GenericCommand
33 {
34     
35     public final static String JavaDoc TARGET_OPTION = "target";
36     public final static String JavaDoc NAME_OPTION = "name";
37     public final static String JavaDoc OBJECT_NAME_OPTION = "objectname";
38     public final static String JavaDoc ATTRIBUTES_OPTION = "attributes";
39     public final static String JavaDoc ATTRIBUTE_DELIMITER = ":";
40     public final static String JavaDoc ATTRIBUTE_VALUE_DELIMITER = "=";
41
42     /*
43      * Returns the Params from the properties
44      * @return params returns params
45      */

46     protected Object JavaDoc[] getParamsInfo()throws CommandException, CommandValidationException
47     {
48         Object JavaDoc[] paramsInfo = new Object JavaDoc[3];
49         paramsInfo[0] = getOption(TARGET_OPTION);
50         Map JavaDoc mbeanParams = new HashMap JavaDoc();
51         if (getOption(NAME_OPTION) != null)
52             mbeanParams.put(ServerTags.NAME, getOption(NAME_OPTION));
53         if (getOption(OBJECT_NAME_OPTION) != null)
54             mbeanParams.put(ServerTags.OBJECT_NAME, getOption(OBJECT_NAME_OPTION));
55         mbeanParams.put(ServerTags.IMPL_CLASS_NAME, getOperands().get(0));
56         paramsInfo[1] = mbeanParams;
57         paramsInfo[2] = getAttributesList(getOption(ATTRIBUTES_OPTION));
58         return paramsInfo;
59     }
60
61     
62     /**
63      * Formulate and Returns Properties from the given string
64      * @return Properties
65      */

66     private Map JavaDoc getAttributesList(String JavaDoc attributesStr)
67         throws CommandException, CommandValidationException
68     {
69         Map JavaDoc attributes = new HashMap JavaDoc();
70         if (attributesStr == null) return attributes;
71         final CLITokenizer attrTok = new CLITokenizer(attributesStr, ATTRIBUTE_DELIMITER);
72         while (attrTok.hasMoreTokens()) {
73             final String JavaDoc nameAndvalue = attrTok.nextToken();
74             final CLITokenizer nameTok = new CLITokenizer(nameAndvalue, ATTRIBUTE_VALUE_DELIMITER);
75             if (nameTok.countTokens() == 2)
76             {
77                 attributes.put(nameTok.nextTokenWithoutEscapeAndQuoteChars(),
78                                nameTok.nextTokenWithoutEscapeAndQuoteChars());
79             }
80             else
81             {
82                 throw new CommandValidationException(getLocalizedString("InvalidAttributeSyntax"));
83             }
84         }
85         CLILogger.getInstance().printDebugMessage("Got the Attributes List : " + attributes.toString());
86         return attributes;
87     }
88 }
89
Popular Tags