Package com.sun.enterprise.admin.util

Examples of com.sun.enterprise.admin.util.CachedCommandModel


        eTag = eTag.substring(5).trim();
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, "Cached command model ETag is {0}", eTag);
        }
        String content = cachedModel.substring(ind + 1).trim();
        CachedCommandModel result = parseMetadata(content, eTag);
        return result;
    }
View Full Code Here


        }
        try {
            boolean sawFile = false;
            JSONObject obj = new JSONObject(str);
            obj = obj.getJSONObject("command");
            CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
            cm.dashOk = obj.optBoolean("@unknown-options-are-operands", false);
            cm.managedJob = obj.optBoolean("@managed-job", false);
            cm.setUsage(obj.optString("usage", null));
            Object optns = obj.opt("option");
            if (!JSONObject.NULL.equals(optns)) {
                JSONArray jsonOptions;
                if (optns instanceof JSONArray) {
                    jsonOptions = (JSONArray) optns;
                } else {
                    jsonOptions = new JSONArray();
                    jsonOptions.put(optns);
                }
                for (int i = 0; i < jsonOptions.length(); i++) {
                    JSONObject jsOpt = jsonOptions.getJSONObject(i);
                    String type = jsOpt.getString("@type");
                    ParamModelData opt = new ParamModelData(
                            jsOpt.getString("@name"),
                            typeOf(type),
                            jsOpt.optBoolean("@optional", false),
                            jsOpt.optString("@default"),
                            jsOpt.optString("@short"),
                            jsOpt.optBoolean("@obsolete", false),
                            jsOpt.optString("@alias"));
                    opt.param._acceptableValues = jsOpt.optString("@acceptable-values");
                    if ("PASSWORD".equals(type)) {
                        opt.param._password = true;
                        opt.prompt = jsOpt.optString("@prompt");
                        opt.promptAgain = jsOpt.optString("@prompt-again");
                    } else if ("FILE".equals(type)) {
                        sawFile = true;
                    }
                    if (jsOpt.optBoolean("@primary", false)) {
                        opt.param._primary = true;
                    }
                    if (jsOpt.optBoolean("@multiple", false)) {
                        if (opt.type == File.class) {
                            opt.type = File[].class;
                        } else {
                            opt.type = List.class;
                        }
                        opt.param._multiple = true;
                    }
                    cm.add(opt);
                }
            }
            if (sawFile) {
                cm.add(new ParamModelData("upload", Boolean.class,
                        true, null));
                addedUploadOption = true;
                cm.setAddedUploadOption(true);
            }
            this.usage = cm.getUsage();
            return cm;
        } catch (JSONException ex) {
            logger.log(Level.FINER, "Can not parse command metadata", ex);
            return null;
        }
View Full Code Here

            try {
                commandModel = AdminCacheUtils.getCache().get(createCommandCacheKey(), CommandModel.class);
                if (commandModel != null) {
                    this.commandModelFromCache = true;
                    if (commandModel instanceof CachedCommandModel) {
                        CachedCommandModel ccm = (CachedCommandModel) commandModel;
                        this.usage = ccm.getUsage();
                        addedUploadOption = ccm.isAddedUploadOption();
                    }
                    if (logger.isLoggable(Level.FINEST)) {
                        logger.log(Level.FINEST, "Command model for command {0} was successfully loaded from the cache. [Duration: {1} nanos]", new Object[] {name, System.nanoTime() - startNanos});
                    }
                } else {
View Full Code Here

            logger.finer("------- RAW METADATA RESPONSE ---------");
            logger.finer(response);
            logger.finer("------- RAW METADATA RESPONSE ---------");
        }

        CachedCommandModel cm = new CachedCommandModel(name);
        boolean sawFile = false;
        try {
            DocumentBuilder d =
                    DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = d.parse(in);
            NodeList cmd = doc.getElementsByTagName("command");
            Node cmdnode = cmd.item(0);
            if (cmdnode == null) {
                Node report = doc.getElementsByTagName("action-report").item(0);
                String cause = getAttr(report.getAttributes(), "failure-cause");
                if (ok(cause))
                    errors.append(cause);
                else {
                    Node mp = report.getFirstChild();   // message-part
                    if (mp != null)
                        cause = getAttr(mp.getAttributes(), "message");
                    if (ok(cause))
                        errors.append(cause);
                }
                // no command info, must be invalid command or something
                // wrong with command implementation
                return null;
            }
            NamedNodeMap cmdattrs = cmdnode.getAttributes();
            usage = getAttr(cmdattrs, "usage");
            cm.setUsage(usage);
            String dashOk = getAttr(cmdattrs, "unknown-options-are-operands");
            if (dashOk != null)
                cm.dashOk = Boolean.parseBoolean(dashOk);
            NodeList opts = doc.getElementsByTagName("option");
            for (int i = 0; i < opts.getLength(); i++) {
                Node n = opts.item(i);
                NamedNodeMap attributes = n.getAttributes();
                String sn = getAttr(attributes, "short");
                String def = getAttr(attributes, "default");
                String obs = getAttr(attributes, "obsolete");
                String alias = getAttr(attributes, "alias");
                ParamModelData opt = new ParamModelData(
                        getAttr(attributes, "name"),
                        typeOf(getAttr(attributes, "type")),
                        Boolean.parseBoolean(getAttr(attributes, "optional")),
                        def,
                        ok(sn) ? sn : null,
      ok(obs) ? Boolean.parseBoolean(obs) : false,
      alias);
                if (getAttr(attributes, "type").equals("PASSWORD")) {
                    opt.param._password = true;
                    opt.description = getAttr(attributes, "description");
                }
                cm.add(opt);
                if (opt.getType() == File.class)
                    sawFile = true;
            }
            // should be only one operand item
            opts = doc.getElementsByTagName("operand");
            for (int i = 0; i < opts.getLength(); i++) {
                Node n = opts.item(i);
                NamedNodeMap attributes = n.getAttributes();
                Class<?> type = typeOf(getAttr(attributes, "type"));
                if (type == File.class) {
                    sawFile = true;
                }
                int min = Integer.parseInt(getAttr(attributes, "min"));
                String max = getAttr(attributes, "max");
                boolean multiple = false;
                if (max.equals("unlimited")) {
                    multiple = true;
                    // XXX - should convert to array of whatever
                    if (type == File.class) {
                        type = File[].class;
                    } else {
                        type = List.class;
                    }
                }
                ParamModelData pm = new ParamModelData(
                    getAttr(attributes, "name"), type, min == 0, null);
                pm.param._primary = true;
                pm.param._multiple = multiple;
                cm.add(pm);
            }

            /*
             * If one of the options or operands is a FILE,
             * make sure there's also a --upload option available.
             * XXX - should only add it if it's not present
             * XXX - should just define upload parameter on remote command
             */
            if (sawFile) {
                cm.add(new ParamModelData("upload", Boolean.class,
                        true, null));
                addedUploadOption = true;
                cm.setAddedUploadOption(true);
            }
        } catch (ParserConfigurationException pex) {
            // ignore for now
            return null;
        } catch (SAXException sex) {
View Full Code Here

        eTag = eTag.substring(5).trim();
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, "Cached command model ETag is {0}", eTag);
        }
        String content = cachedModel.substring(ind + 1).trim();
        CachedCommandModel result = parseMetadata(content, eTag);
        Metrix.event("getCommandModelFromCahce() - done");
        return result;
    }
View Full Code Here

        }
        try {
            boolean sawFile = false;
            JSONObject obj = new JSONObject(str);
            obj = obj.getJSONObject("command");
            CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
            cm.dashOk = obj.optBoolean("@unknown-options-are-operands", false);
            cm.managedJob = obj.optBoolean("@managed-job", false);
            cm.setUsage(obj.optString("usage", null));
            Object optns = obj.opt("option");
            if (!JSONObject.NULL.equals(optns)) {
                JSONArray jsonOptions;
                if (optns instanceof JSONArray) {
                    jsonOptions = (JSONArray) optns;
                } else {
                    jsonOptions = new JSONArray();
                    jsonOptions.put(optns);
                }
                for (int i = 0; i < jsonOptions.length(); i++) {
                    JSONObject jsOpt = jsonOptions.getJSONObject(i);
                    String type = jsOpt.getString("@type");
                    ParamModelData opt = new ParamModelData(
                            jsOpt.getString("@name"),
                            typeOf(type),
                            jsOpt.optBoolean("@optional", false),
                            jsOpt.optString("@default"),
                            jsOpt.optString("@short"),
                            jsOpt.optBoolean("@obsolete", false),
                            jsOpt.optString("@alias"));
                    opt.param._acceptableValues = jsOpt.optString("@acceptable-values");
                    if ("PASSWORD".equals(type)) {
                        opt.param._password = true;
                        opt.description = jsOpt.optString("$");
                    } else if ("FILE".equals(type)) {
                        sawFile = true;
                    }
                    if (jsOpt.optBoolean("@primary", false)) {
                        opt.param._primary = true;
                    }
                    if (jsOpt.optBoolean("@multiple", false)) {
                        if (opt.type == File.class) {
                            opt.type = File[].class;
                        } else {
                            opt.type = List.class;
                        }
                        opt.param._multiple = true;
                    }
                    cm.add(opt);
                }
            }
            if (sawFile) {
                cm.add(new ParamModelData("upload", Boolean.class,
                        true, null));
                addedUploadOption = true;
                cm.setAddedUploadOption(true);
            }
            this.usage = cm.getUsage();
            Metrix.event("parseMetadata() = parse command model - done");
            return cm;
        } catch (JSONException ex) {
            logger.log(Level.FINER, "Can not parse command metadata", ex);
            Metrix.event("parseMetadata() = parse command model - done");
View Full Code Here

                bw.write(": true");
                bw.newLine();
            }
            //CachedCommandModel specific staff
            if (cm instanceof CachedCommandModel) {
                CachedCommandModel ccm = (CachedCommandModel) cm;
                //unknown are operands
                if (ccm.isAddedUploadOption()) {
                    bw.write(ADDEDUPLOADOPTIONS_ELEMENT);
                    bw.write(": true");
                    bw.newLine();
                }
                //usage
                str = ccm.getUsage();
                if (str != null && !str.isEmpty()) {
                    bw.write(USAGE_ELEMENT);
                    bw.write(": ");
                    bw.write(escapeEndLines(str));
                    bw.newLine();
View Full Code Here

    public Object toInstance(InputStream stream, Class clazz) throws IOException {
        return toInstanceSimpleFormat(stream);
    }
   
    private CommandModel toInstanceSimpleFormat(InputStream stream) throws IOException {
        CachedCommandModel result = null;
        InputStreamReader isr = null;
        BufferedReader r = null;
        boolean inParam = false;
        String name = null;
        String eTag = null;
        boolean unknownAreOperands = false;
        String usage = null;
        boolean addedUploadOption = false;
        String pName = null;
        Class pCls = null;
        boolean pOptional = false;
        String pDefaultValue = null;
        String pShortName = null;
        boolean pObsolete = false;
        String pAlias = null;
        boolean pPrimary = false;
        boolean pMultiple = false;
        boolean pPassword = false;
        String pDescription = null;
        try {
            isr = new InputStreamReader(stream, charset);
            r = new BufferedReader(isr);
            String line;
            while ((line = r.readLine()) != null) {
                int ind = line.indexOf(':');
                if (ind <= 0) {
                    continue;
                }
                String key = line.substring(0, ind);
                String value = line.substring(ind + 1).trim();
                // @todo Java SE 7: String switch-case
                if (inParam) {
                    if (NAME_ELEMENT.equals(key)) {
                        //Add before parameter
                        CommandModelData.ParamModelData pmd =
                                new CommandModelData.ParamModelData(pName,
                                pCls, pOptional, pDefaultValue, pShortName,
                                pObsolete, pAlias);
                        pmd.param._primary = pPrimary;
                        pmd.param._multiple = pMultiple;
                        pmd.param._password = pPassword;
                        pmd.description = pDescription;
                        result.add(pmd);
                        //Reset values
                        pCls = null;
                        pOptional = false;
                        pDefaultValue = null;
                        pShortName = null;
                        pObsolete = false;
                        pAlias = null;
                        pPrimary = false;
                        pMultiple = false;
                        pPassword = false;
                        pDescription = null;
                        //New param
                        pName = value;
                    } else if (CLASS_ELEMENT.equals(key)) {
                        if (!value.isEmpty()) {
                            try {
                                pCls = Class.forName(value);
                            } catch (Exception ex) {
                            }
                        }
                    } else if (OPTIONAL_ELEMENT.equals(key)) {
                        pOptional = value.startsWith("t");
                    } else if (DEFAULT_VALUE_ELEMENT.equals(key)) {
                        pDefaultValue = value;
                    } else if (SHORTNAME_ELEMENT.equals(key)) {
                        pShortName = value;
                    } else if (OBSOLETE_ELEMENT.equals(key)) {
                        pObsolete = value.startsWith("t");
                    } else if (ALIAS_ELEMENT.equals(key)) {
                        pAlias = value;
                    } else if (PRIMARY_ELEMENT.equals(key)) {
                        pPrimary = value.startsWith("t");
                    } else if (MULTIPLE_ELEMENT.equals(key)) {
                        pMultiple = value.startsWith("t");
                    } else if (PASSWORD_ELEMENT.equals(key)) {
                        pPassword = value.startsWith("t");
                    } else if (DESCRIPTION_ELEMENT.equals(key)) {
                        pAlias = resolveEndLines(value);
                    }
                } else {
                    if (ROOT_ELEMENT.equals(key)) {
                        name = value;
                    } else if (ETAG_ELEMENT.equals(key)) {
                        eTag = value;
                    } else if (UNKNOWN_ARE_OPERANDS_ELEMENT.equals(key)) {
                        unknownAreOperands = value.startsWith("t");
                    } else if (ADDEDUPLOADOPTIONS_ELEMENT.equals(key)) {
                        addedUploadOption = value.startsWith("t");
                    } else if (USAGE_ELEMENT.equals(key)) {
                        usage = resolveEndLines(value);
                    } else if (NAME_ELEMENT.equals(key)) {
                        //Create base
                        result = new CachedCommandModel(name, eTag);
                        result.dashOk = unknownAreOperands;
                        result.setUsage(usage);
                        result.setAddedUploadOption(addedUploadOption);
                        //Continue in params
                        inParam = true;
                        pName = value;
                    }
                }
            }
            if (inParam) {
                //Add parameter
                CommandModelData.ParamModelData pmd =
                        new CommandModelData.ParamModelData(pName,
                        pCls, pOptional, pDefaultValue, pShortName,
                        pObsolete, pAlias);
                pmd.param._primary = pPrimary;
                pmd.param._multiple = pMultiple;
                pmd.param._password = pPassword;
                pmd.description = pDescription;
                result.add(pmd);
            } else if (result == null && name != null && !name.isEmpty()) {
                result = new CachedCommandModel(name, eTag);
                result.dashOk = unknownAreOperands;
                result.setUsage(usage);
                result.setAddedUploadOption(addedUploadOption);
            }
        } finally {
            try {r.close();} catch (Exception ex) {}
            try {isr.close();} catch (Exception ex) {}
        }
View Full Code Here

        eTag = eTag.substring(5).trim();
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST, "Cached command model ETag is {0}", eTag);
        }
        String content = cachedModel.substring(ind + 1).trim();
        CachedCommandModel result = parseMetadata(content, eTag);
        Metrix.event("getCommandModelFromCahce() - done");
        return result;
    }
View Full Code Here

        }
        try {
            boolean sawFile = false;
            JSONObject obj = new JSONObject(str);
            obj = obj.getJSONObject("command");
            CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
            cm.dashOk = obj.optBoolean("@unknown-options-are-operands", false);
            cm.managedJob = obj.optBoolean("@managed-job", false);
            cm.setUsage(obj.optString("usage", null));
            Object optns = obj.opt("option");
            if (!JSONObject.NULL.equals(optns)) {
                JSONArray jsonOptions;
                if (optns instanceof JSONArray) {
                    jsonOptions = (JSONArray) optns;
                } else {
                    jsonOptions = new JSONArray();
                    jsonOptions.put(optns);
                }
                for (int i = 0; i < jsonOptions.length(); i++) {
                    JSONObject jsOpt = jsonOptions.getJSONObject(i);
                    String type = jsOpt.getString("@type");
                    ParamModelData opt = new ParamModelData(
                            jsOpt.getString("@name"),
                            typeOf(type),
                            jsOpt.optBoolean("@optional", false),
                            jsOpt.optString("@default"),
                            jsOpt.optString("@short"),
                            jsOpt.optBoolean("@obsolete", false),
                            jsOpt.optString("@alias"));
                    opt.param._acceptableValues = jsOpt.optString("@acceptable-values");
                    if ("PASSWORD".equals(type)) {
                        opt.param._password = true;
                        opt.description = jsOpt.optString("$");
                    } else if ("FILE".equals(type)) {
                        sawFile = true;
                    }
                    if (jsOpt.optBoolean("@primary", false)) {
                        opt.param._primary = true;
                    }
                    if (jsOpt.optBoolean("@multiple", false)) {
                        if (opt.type == File.class) {
                            opt.type = File[].class;
                        } else {
                            opt.type = List.class;
                        }
                        opt.param._multiple = true;
                    }
                    cm.add(opt);
                }
            }
            if (sawFile) {
                cm.add(new ParamModelData("upload", Boolean.class,
                        true, null));
                addedUploadOption = true;
                cm.setAddedUploadOption(true);
            }
            this.usage = cm.getUsage();
            Metrix.event("parseMetadata() = parse command model - done");
            return cm;
        } catch (JSONException ex) {
            logger.log(Level.FINER, "Can not parse command metadata", ex);
            Metrix.event("parseMetadata() = parse command model - done");
View Full Code Here

TOP

Related Classes of com.sun.enterprise.admin.util.CachedCommandModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.