KickJava   Java API By Example, From Geeks To Geeks.

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


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

44     public void runCommand() throws CommandException, CommandValidationException
45     {
46         validateOptions();
47         try
48         {
49             MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
50                                                                   getUser(), getPassword());
51             //DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
52
//final Set s = domainRoot.getQueryMgr().queryJ2EETypeSet(XTypes.WEB_SERVICE_ENDPOINT_CONFIG);
53
String JavaDoc webServiceName = getOption(WEB_SERVICE_OPTION);
54             validateWebServiceName(webServiceName, false);
55             boolean nothingToList = listTransformationRules(mbsc);
56             if (nothingToList)
57             {
58                 CLILogger.getInstance().printMessage(getLocalizedString("NoElementsToList"));
59             }
60         CLILogger.getInstance().printDetailMessage(getLocalizedString(
61                                "CommandSuccessful",
62                                new Object JavaDoc[] {name}));
63         }
64         catch(Exception JavaDoc e)
65         {
66             displayExceptionMessage(e);
67         }
68     
69     }
70
71
72     /**
73      * Iterates throught WSEP config to find the transformation rules.
74      * @throws CommandException
75      */

76     private boolean listTransformationRules(MBeanServerConnection JavaDoc mbsc)
77                     throws CommandException, CommandValidationException
78     {
79         String JavaDoc webServiceName = getOption(WEB_SERVICE_OPTION);
80         if (webServiceName != null)
81         {
82             WebServiceEndpointConfig wsc =
83                     getWebServiceEndpointConfig(mbsc, webServiceName, false);
84             if (wsc == null)
85                 throw new CommandException(getLocalizedString("CannotFindWebservice"));
86             return displayTransformationRules(wsc);
87         }
88         DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
89         final Set JavaDoc s = domainRoot.getQueryMgr().queryJ2EETypeSet(XTypes.WEB_SERVICE_ENDPOINT_CONFIG);
90         final Iterator JavaDoc iter = s.iterator();
91         boolean nothingToList = true;
92         while (iter.hasNext() )
93         {
94             final WebServiceEndpointConfig wsc = (WebServiceEndpointConfig)iter.next();
95             if (wsc.getTransformationRuleConfigMap().size() > 0)
96             {
97                 CLILogger.getInstance().printMessage(wsc.getName());
98                 nothingToList = displayTransformationRules(wsc);
99             }
100         }
101         return nothingToList;
102     }
103
104
105     /**
106      * Display the transformation rules.
107      * @throws CommandException
108      */

109     private boolean displayTransformationRules(WebServiceEndpointConfig wsc)
110                     throws CommandException
111     {
112         Map JavaDoc rules = wsc.getTransformationRuleConfigMap();
113         for (Object JavaDoc key : rules.keySet())
114         {
115             CLILogger.getInstance().printMessage((String JavaDoc)key);
116         }
117         if (rules.size() > 0)
118             return false;
119         else
120             return true;
121     }
122 }
123
Popular Tags