KickJava   Java API By Example, From Geeks To Geeks.

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


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.WebServiceEndpointConfig;
32 import java.util.Iterator JavaDoc;
33 import java.util.Set JavaDoc;
34
35 public class DeleteTransformationRuleCommand extends BaseTransformationRuleCommand
36 {
37     private static final String JavaDoc WEB_SERVICE_OPTION = "webservicename";
38    
39     /**
40      * An abstract method that Executes the command
41      * @throws CommandException
42      */

43     public void runCommand() throws CommandException, CommandValidationException
44     {
45         validateOptions();
46         try
47         {
48             MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
49                                                                   getUser(), getPassword());
50             //DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
51
//final Set s = domainRoot.getQueryMgr().queryJ2EETypeSet(XTypes.WEB_SERVICE_ENDPOINT_CONFIG);
52
String JavaDoc webServiceName = getOption(WEB_SERVICE_OPTION);
53             validateWebServiceName(webServiceName, true);
54             WebServiceEndpointConfig wsc =
55                     getWebServiceEndpointConfig(mbsc, webServiceName, false);
56             if (wsc == null)
57                 throw new CommandException(getLocalizedString("CannotFindWebservice"));
58             String JavaDoc ruleName = (String JavaDoc) getOperands().get(0);
59            
60             wsc.removeTransformationRuleConfig(ruleName);
61
62         CLILogger.getInstance().printDetailMessage(getLocalizedString(
63                                "CommandSuccessful",
64                                new Object JavaDoc[] {name}));
65         }
66         catch(Exception JavaDoc e)
67         {
68             displayExceptionMessage(e);
69         }
70     
71     }
72
73
74     /**
75      * parse the operand to get the web service name
76      * Also validate if the operand is well formed.
77      * @throws CommandValidationException
78      */

79     private WebServiceEndpointConfig getWebServiceEndpointConfig(Set JavaDoc s) throws CommandException
80     {
81         // this webserviceName is fully qualified name
82
String JavaDoc fqWebServiceName = getOption(WEB_SERVICE_OPTION);
83         // extract the partially qualified web service endpoing config name
84
int firstHashIdx = fqWebServiceName.indexOf("#");
85         String JavaDoc wsName= null;
86         if ( firstHashIdx != -1 ) {
87             if ( firstHashIdx+1 == fqWebServiceName.length()) {
88                 // msg XXX
89
throw new CommandException(getLocalizedString("InvalidFormatForWebservice"));
90             }
91             wsName = fqWebServiceName.substring(firstHashIdx +1);
92         }
93         else
94         {
95             throw new CommandException(getLocalizedString("InvalidFormatForWebservice"));
96         }
97         final Iterator JavaDoc iter = s.iterator();
98         while (iter.hasNext() )
99         {
100             final WebServiceEndpointConfig wsc = (WebServiceEndpointConfig)iter.next();
101             CLILogger.getInstance().printDebugMessage(wsc.getName());
102             if (wsc.getName().equals(wsName))
103             {
104                 return wsc;
105             }
106         }
107         return null;
108     }
109 }
110
Popular Tags