⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namespaceservice.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            return handleList(info);        else if (request.equals("query"))            return handleQuery(info);        else if (request.equals("set"))            return handleSet(info);        else if (request.equals("get"))            return handleGet(info);        else if (request.equals("help"))            return handleHelp(info);        else if (request.equals("version"))            return handleVersion(info);        else        {            return new STAFResult(                STAFResult.InvalidRequestString,                "Unknown Namespace Service Request: " + lowerRequest);        }    }    /**     * Handle a HELP request     */     private STAFResult handleHelp(STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 1        STAFResult trustResult = STAFUtil.validateTrust(            1, fServiceName, "HELP", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Parse the request        STAFCommandParseResult parsedRequest = fHelpParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(STAFResult.InvalidRequestString,                                  parsedRequest.errorBuffer);        }        // Return help text for the service        return new STAFResult(            STAFResult.Ok,            "Namespace Service Help" +            fLineSep + fLineSep +            "CREATE  NAMESPACE <Name> DESCRIPTION <Description>" +            " [PARENT <Name>]" +            fLineSep +            "MODIFY  NAMESPACE <Name> [DESCRIPTION <Description>] " +            "[PARENT <Name>]" +            fLineSep +            "DELETE  NAMESPACE <Name> < VAR <Key>... | CONFIRM >" +            fLineSep +            "LIST    [NAMESPACES | <NAMESPACE <Name> [ONLY]>]" +            fLineSep +            "QUERY   NAMESPACE <Name> [TREE]" +            fLineSep +            "SET     VAR <Key=Value> [VAR <Key=Value>]... NAMESPACE <Name>" +            fLineSep +            "GET     VAR <Key> NAMESPACE <Name>" +            fLineSep +            "VERSION" +            fLineSep +            "HELP");    }    /**     * Handle a VERSION request     */     private STAFResult handleVersion(        STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 1        STAFResult trustResult = STAFUtil.validateTrust(            1, fServiceName, "VERSION", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Parse the request        STAFCommandParseResult parsedRequest = fVersionParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(STAFResult.InvalidRequestString,                                  parsedRequest.errorBuffer);        }        // Return the service's version        return new STAFResult(STAFResult.Ok, kVersion);    }    /**     * Handle a CREATE request     */     private STAFResult handleCreate(        STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 3        STAFResult trustResult = STAFUtil.validateTrust(            3, fServiceName, "CREATE", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Parse the request        STAFCommandParseResult parsedRequest = fCreateParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(STAFResult.InvalidRequestString,                                  parsedRequest.errorBuffer);        }        // Resolve any STAF variables in the NAMESPACE option's value        STAFResult res = STAFUtil.resolveRequestVar(            parsedRequest.optionValue("NAMESPACE"),            fHandle, info.requestNumber);        if (res.rc != STAFResult.Ok) return res;        String namespace = res.result;        // Don't resolve STAF variables in the DESCRIPTION option's value        String description = parsedRequest.optionValue("DESCRIPTION");        String parent = Namespace.sNONE;        if (parsedRequest.optionTimes("PARENT") > 0)        {            // Resolve any STAF variables in the PARENT option's value            res = STAFUtil.resolveRequestVar(                parsedRequest.optionValue("PARENT"),                fHandle, info.requestNumber);            if (res.rc != STAFResult.Ok) return res;                    parent = res.result;        }                Namespace parentNS = null;        // Synchronized on the Namespace service so that only one request        // to the Namespace service can run at a time (to ensure that nothing        // else can change the Namespace data while this code is running).        synchronized(this)        {            // Check if the namespace already exists            if (fNamespaceManager.get(namespace) != null)            {                return new STAFResult(                    STAFResult.AlreadyExists,                    "Namespace '" + namespace + "' already exists");            }            if (!parent.equalsIgnoreCase(Namespace.sNONE))            {                // Get the parent namespace                parentNS = fNamespaceManager.get(parent);                if (parentNS == null)                {                    return new STAFResult(                        STAFResult.DoesNotExist,                        "Parent namespace '" + parent + "' does not exist");                 }                // Get the right casing for the parent name                parent = parentNS.getName();            }                    // Create a new namespace and add to the namespace map            Namespace ns = new Namespace(namespace, description, parent);            fNamespaceManager.create(namespace, ns);            if (parentNS != null)            {                parentNS.addChild(namespace, ns);            }            // Save namespaces to persistent data storage            res = storeData(info);            if (res.rc != STAFResult.Ok) return res;        }                        return new STAFResult(STAFResult.Ok);    }        /**     * Handle a MODIFY request     */     private STAFResult handleModify(        STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 3        STAFResult trustResult = STAFUtil.validateTrust(            3, fServiceName, "MODIFY", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Parse the request        STAFCommandParseResult parsedRequest = fModifyParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(STAFResult.InvalidRequestString,                                  parsedRequest.errorBuffer);        }        // Resolve any STAF variables in the NAMESPACE option's value        STAFResult res = STAFUtil.resolveRequestVar(            parsedRequest.optionValue("NAMESPACE"),            fHandle, info.requestNumber);        if (res.rc != STAFResult.Ok) return res;                String namespace = res.result;        String description = null;        if (parsedRequest.optionTimes("DESCRIPTION") > 0)        {            // Don't resolve STAF variables in the DESCRIPTION option's value            description = parsedRequest.optionValue("DESCRIPTION");        }                String parent = null;        if (parsedRequest.optionTimes("PARENT") > 0)        {            // Resolve any STAF variables in the PARENT option's value            res = STAFUtil.resolveRequestVar(                parsedRequest.optionValue("PARENT"),                fHandle, info.requestNumber);            if (res.rc != STAFResult.Ok) return res;                    parent = res.result;        }        if ((parsedRequest.optionTimes("DESCRIPTION") == 0) &&            (parsedRequest.optionTimes("PARENT") == 0))        {            return new STAFResult(                STAFResult.InvalidRequestString,                "You must have at least 1 of the option(s), " +                "DESCRIPTION PARENT");        }        // Synchronized on the Namespace service so that only one request        // to the Namespace service can run at a time (to ensure that nothing        // else can change the Namespace data while this code is running).        synchronized(this)        {            // Make sure the namespace already exists            Namespace ns = fNamespaceManager.get(namespace);            if (ns == null)            {                return new STAFResult(                    STAFResult.DoesNotExist,                    "Namespace '" + namespace + "' does not exist");            }                    namespace = ns.getName();            if (parent != null)            {                // Make sure the parent namespace already exists                if (!parent.equalsIgnoreCase(Namespace.sNONE))                {                    // Get the parent namespace                    Namespace parentNS = fNamespaceManager.get(parent);                    if (parentNS == null)                    {                        return new STAFResult(                            STAFResult.DoesNotExist,                            "Parent namespace '" + parent +                            "' does not exist");                     }                                        parent = parentNS.getName();                                // Verify the change of parent will not create a                    // cyclic dependency by walking up the parent tree                    // and making sure that the namespace name is not found                                        String nsName = parent;                    while (!nsName.equalsIgnoreCase(Namespace.sNONE))                    {                        if (nsName.equalsIgnoreCase(namespace))                        {                            return new STAFResult(                                STAFResult.InvalidValue,                                "Parent namespace '" + nsName +                                "' is invalid due to a cyclic dependency.");                        }                        else                        {                            nsName = fNamespaceManager.get(nsName).                                getParent();                        }                    }                                        // Add namespace to new parent's children                    parentNS.addChild(namespace, ns);                }                // Remove namespace from previous parent's children                String prevParent = ns.getParent();                if (!prevParent.equalsIgnoreCase(Namespace.sNONE))                {                    Namespace prevParentNS = fNamespaceManager.                        get(prevParent);                    prevParentNS.removeChild(namespace);                }                // Update the namespace's parent                ns.setParent(parent);            }            if (description != null)            {                // Update the description for the namespace                ns.setDescription(description);            }            // Save namespaces to persistent data storage            res = storeData(info);            if (res.rc != STAFResult.Ok) return res;        }                return new STAFResult(STAFResult.Ok);    }    /**     * Handle a LIST request     */     private STAFResult handleList(        STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 2        STAFResult trustResult = STAFUtil.validateTrust(            2, fServiceName, "LIST", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Parse the request        STAFCommandParseResult parsedRequest = fListParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(STAFResult.InvalidRequestString,                                  parsedRequest.errorBuffer);        }        STAFMarshallingContext mc = new STAFMarshallingContext();        // Create an empty result list to contain the result        List resultList = new ArrayList();        // Check if specified namespace        if (parsedRequest.optionTimes("NAMESPACE") > 0)        {            // LIST NAMESPACE [ONLY]            // Resolve any STAF variables in the NAMESPACE option's value                STAFResult res = STAFUtil.resolveRequestVar(                parsedRequest.optionValue("NAMESPACE"),                fHandle, info.requestNumber);            if (res.rc != STAFResult.Ok) return res;                    String namespace = res.result;            boolean only = false;            if (parsedRequest.optionTimes("ONLY") > 0)                only = true;            mc.setMapClassDefinition(fListVariablesMapClass);                        // Synchronized on the Namespace service so that only one request            // to the Namespace service can run at a time (to ensure that            // nothing else can change the Namespace data while this code is            // running).            synchronized(this)            {                // Make sure the namespace exists                Namespace ns = fNamespaceManager.get(namespace);                if (ns == null)                {                    return new STAFResult(                        STAFResult.DoesNotExist,                        "Namespace '" + namespace + "' does not exist");                }                String name = ns.getName();                Map variableMap = ns.getVariables();                Iterator iter = variableMap.values().iterator();                while (iter.hasNext())                {                    // Add an entry for each variable to the result list

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -