KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.admin.common.JMXFileTransfer;
28 import javax.management.MBeanServerConnection JavaDoc;
29 import com.sun.appserv.management.client.ProxyFactory;
30 import com.sun.appserv.management.DomainRoot;
31 import com.sun.appserv.management.config.WebServiceEndpointConfig;
32 import com.sun.appserv.management.base.UploadDownloadMgr;
33 import java.util.Iterator JavaDoc;
34 import java.io.File JavaDoc;
35 import java.io.FileInputStream JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.io.FileNotFoundException JavaDoc;
38
39 public class CreateTransformationRuleCommand extends BaseTransformationRuleCommand
40 {
41     private static final String JavaDoc RULE_LOCATION_OPTION = "rulefilelocation";
42     private static final String JavaDoc APPLY_TO_OPTION = "applyto";
43     private static final String JavaDoc ENABLED_OPTION = "enabled";
44     private static final String JavaDoc WEB_SERVICE_OPTION = "webservicename";
45    
46     /**
47      * An abstract method that Executes the command
48      * @throws CommandException
49      */

50     public void runCommand() throws CommandException, CommandValidationException
51     {
52         validateOptions();
53         try
54         {
55             MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
56                                                                   getUser(), getPassword());
57             DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
58             //final Set s = domainRoot.getQueryMgr().queryJ2EETypeSet(XTypes.WEB_SERVICE_ENDPOINT_CONFIG);
59
String JavaDoc webServiceName = getOption(WEB_SERVICE_OPTION);
60             validateWebServiceName(webServiceName, true);
61             WebServiceEndpointConfig wsc =
62                     getWebServiceEndpointConfig(mbsc, webServiceName, true);
63             if (wsc == null)
64                 throw new CommandException(getLocalizedString("CannotFindWebservice"));
65             String JavaDoc ruleName = (String JavaDoc) getOperands().get(0);
66             String JavaDoc ruleLocation = getOption(RULE_LOCATION_OPTION);
67             boolean enabled = getBooleanOption(ENABLED_OPTION);
68             String JavaDoc applyTo = getOption(APPLY_TO_OPTION);
69             // please remember the file needs to uploaded to the location mentioned, then only
70
// transformation rule can be active.
71
File JavaDoc ruleFile = new File JavaDoc(ruleLocation);
72             String JavaDoc msg = null;
73             
74             if (! ruleFile.exists())
75                 msg = getLocalizedString("FileDoesNotExist", new Object JavaDoc[] {ruleLocation});
76             else if(ruleFile.length() <= 0)
77                 msg = getLocalizedString("FileIsEmpty", new Object JavaDoc[] {ruleLocation});
78             else if(! ruleFile.canRead())
79                 msg = getLocalizedString("FileNotReadable", new Object JavaDoc[] {ruleLocation});
80
81             if(msg != null)
82                 throw new CommandValidationException(msg);
83             
84             String JavaDoc remoteLocation = uploadFileToServer(mbsc);
85             //File uploadedFile = uploadFile(domainRoot, ruleLocation);
86

87             CLILogger.getInstance().printDebugMessage("uploadedFile = " +
88                                             remoteLocation);
89             wsc.createTransformationRuleConfig(ruleName,
90                     remoteLocation, enabled, applyTo, null);
91
92         CLILogger.getInstance().printDetailMessage(getLocalizedString(
93                                "CommandSuccessful",
94                                new Object JavaDoc[] {name}));
95         }
96         catch(Exception JavaDoc e)
97         {
98             displayExceptionMessage(e);
99         }
100     
101     }
102
103     /**
104      *Uploads file to temp location on server.
105      *@throws CommandException
106      */

107     private String JavaDoc uploadFileToServer(MBeanServerConnection JavaDoc mbsc)
108                         throws CommandException, IOException JavaDoc
109     {
110         String JavaDoc ruleLocation = getOption(RULE_LOCATION_OPTION);
111         return new JMXFileTransfer(mbsc).uploadFile(ruleLocation);
112     }
113 }
114
Popular Tags