FileDocCategorySizeDatePackage
CreateTransformationRuleCommand.javaAPI DocGlassfish v2 API5746Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

CreateTransformationRuleCommand

public class CreateTransformationRuleCommand extends BaseTransformationRuleCommand

Fields Summary
private static final String
RULE_LOCATION_OPTION
private static final String
APPLY_TO_OPTION
private static final String
ENABLED_OPTION
private static final String
WEB_SERVICE_OPTION
Constructors Summary
Methods Summary
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException

   
                    
         
    
        validateOptions();
        try
        { 
            MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 
                                                                  getUser(), getPassword());
            DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
            //final Set s = domainRoot.getQueryMgr().queryJ2EETypeSet(XTypes.WEB_SERVICE_ENDPOINT_CONFIG);
            String webServiceName = getOption(WEB_SERVICE_OPTION);
            validateWebServiceName(webServiceName, true);
            WebServiceEndpointConfig wsc = 
                    getWebServiceEndpointConfig(mbsc, webServiceName, true);
            if (wsc == null)
                throw new CommandException(getLocalizedString("CannotFindWebservice"));
            String ruleName = (String) getOperands().get(0);
            String ruleLocation = getOption(RULE_LOCATION_OPTION);
            boolean enabled = getBooleanOption(ENABLED_OPTION);
            String applyTo = getOption(APPLY_TO_OPTION);
            // please remember the file needs to uploaded to the location mentioned, then only
            // transformation rule can be active.
			File ruleFile = new File(ruleLocation);
			String msg = null;
			
			if (! ruleFile.exists()) 
                msg = getLocalizedString("FileDoesNotExist", new Object[] {ruleLocation});
			else if(ruleFile.length() <= 0)
                msg = getLocalizedString("FileIsEmpty", new Object[] {ruleLocation});
			else if(! ruleFile.canRead())
                msg = getLocalizedString("FileNotReadable", new Object[] {ruleLocation});

			if(msg != null)
				throw new CommandValidationException(msg);
			
            String remoteLocation = uploadFileToServer(mbsc);
            //File uploadedFile = uploadFile(domainRoot, ruleLocation);
			
            CLILogger.getInstance().printDebugMessage("uploadedFile = " + 
                                            remoteLocation);
            wsc.createTransformationRuleConfig(ruleName,
                    remoteLocation, enabled, applyTo, null);

	    CLILogger.getInstance().printDetailMessage(getLocalizedString(
						       "CommandSuccessful",
						       new Object[] {name}));
        }
        catch(Exception e)
        {
            displayExceptionMessage(e);
        }        
    
    
private java.lang.StringuploadFileToServer(javax.management.MBeanServerConnection mbsc)
Uploads file to temp location on server.

throws
CommandException

        String ruleLocation = getOption(RULE_LOCATION_OPTION);
        return new JMXFileTransfer(mbsc).uploadFile(ruleLocation);