KickJava   Java API By Example, From Geeks To Geeks.

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


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.MBeanServerConnection JavaDoc;
28 import com.sun.appserv.management.client.ProxyFactory;
29 import com.sun.appserv.management.DomainRoot;
30 import com.sun.appserv.management.base.XTypes;
31 import com.sun.appserv.management.config.J2EEApplicationConfig;
32 import com.sun.appserv.management.config.WebServiceEndpointConfig;
33 import com.sun.appserv.management.config.WebServiceEndpointConfigKeys;
34 import java.util.StringTokenizer JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.Set JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.HashMap JavaDoc;
39
40 public class ConfigureWebServiceCommand extends BaseTransformationRuleCommand
41 {
42     private static final String JavaDoc MONITORING_OPTION = "monitoring";
43     private static final String JavaDoc MAX_HISTORY_SIZE_OPTION = "maxhistorysize";
44    
45     /**
46      * An abstract method that Executes the command
47      * @throws CommandException
48      */

49     public void runCommand() throws CommandException, CommandValidationException
50     {
51         validateOptions();
52         try
53         {
54             MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
55                                                                   getUser(), getPassword());
56             DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
57             //final Set s = domainRoot.getQueryMgr().queryJ2EETypeSet(XTypes.WEB_SERVICE_ENDPOINT_CONFIG);
58
String JavaDoc webServiceName = (String JavaDoc) getOperands().get(0);
59             validateWebServiceName(webServiceName, true);
60             WebServiceEndpointConfig wsc =
61                     getWebServiceEndpointConfig(mbsc, webServiceName, true);
62             if (wsc == null)
63                 throw new CommandException(getLocalizedString("CannotFindWebservice"));
64
65             String JavaDoc maxHistorySize = getOption(MAX_HISTORY_SIZE_OPTION);
66             String JavaDoc monitoring = getOption(MONITORING_OPTION);
67             if (maxHistorySize != null)
68             {
69                 wsc.setMaxHistorySize(maxHistorySize);
70             }
71             if (monitoring != null)
72             {
73                 wsc.setMonitoringLevel(monitoring);
74             }
75         CLILogger.getInstance().printDetailMessage(getLocalizedString(
76                                "CommandSuccessful",
77                                new Object JavaDoc[] {name}));
78         }
79         catch(Exception JavaDoc e)
80         {
81             displayExceptionMessage(e);
82         }
83     
84     }
85
86
87     /**
88      * parse the operand to get the web service name
89      * Also validate if the operand is well formed.
90      * @throws CommandValidationException
91      */

92     private String JavaDoc getWebServiceName() throws CommandException
93     {
94         String JavaDoc operand = (String JavaDoc) getOperands().get(0);
95         StringTokenizer JavaDoc paramsTokenizer = new StringTokenizer JavaDoc(operand, "#");
96         int size = paramsTokenizer.countTokens();
97         if (size != 3)
98             throw new CommandException(getLocalizedString("InvalidWebServiceEndpoint"));
99         return paramsTokenizer.nextToken();
100     }
101
102
103     /**
104      * parse the operand to get the webservice endpoint
105      * @throws CommandValidationException
106      */

107     private String JavaDoc getWebServiceEndPoint() throws CommandException
108     {
109         String JavaDoc operand = (String JavaDoc) getOperands().get(0);
110         int index = operand.indexOf("#");
111         return operand.substring(index+1);
112     }
113
114
115     /**
116      * return the map containing the monitoring & maxhistorysize attrs.
117      * @throws CommandValidationException
118      */

119     private Map JavaDoc getOptionMap() throws CommandException
120     {
121         HashMap JavaDoc map = new HashMap JavaDoc();
122         String JavaDoc maxHistorySize = getOption(MAX_HISTORY_SIZE_OPTION);
123         String JavaDoc monitoring = getOption(MONITORING_OPTION);
124         map.put(WebServiceEndpointConfigKeys.MONITORING_LEVEL_KEY, monitoring);
125         map.put(WebServiceEndpointConfigKeys.MAX_HISTORY_SIZE_KEY, maxHistorySize);
126         return map;
127     }
128 }
129
Popular Tags