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

📄 cmcommands.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                + cs.length                                + " configurations. "                                + "Refine your selection to match exactly one configuration.");            }            retcode = 0; // Success!        } catch (Exception e) {            out.println("Edit failed. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } finally {            if (srvCA != null) {                bc.ungetService(refCA);            }        }        return retcode;    }    public final static String USAGE_CURRENT = "";    public final static String[] HELP_CURRENT = new String[] { "Show the currently open configuration." };    public int cmdCurrent(Dictionary opts, Reader in, PrintWriter out,            Session session) {        Configuration cfg = getCurrent(session);        if (cfg == null) {            out.println("No configuration open currently");        } else {            if (isEditing(session)) {                printDictionary(out, getEditingDict(session));            } else {                Dictionary d = cfg.getProperties();                if (d == null) {                    out.println("No properties set in current configuration");                } else {                    printDictionary(out, d);                }            }        }        return 0;    }    public final static String USAGE_SAVE = "[-force]";    public final static String[] HELP_SAVE = new String[] {            "Save the currently open configuration in the CM.",            "-force   Force the save" };    public int cmdSave(Dictionary opts, Reader in, PrintWriter out,            Session session) {        int retcode = 1; // 1 initially not set to 0 until end of try block        boolean forceOptionNotSpecified = opts.get("-force") == null;        ConfigurationAdmin srvCA = null;        try {            Configuration cfg = getCurrent(session);            if (cfg == null) {                throw new Exception("No configuration open currently");            }            srvCA = getCA();            if (forceOptionNotSpecified && configurationHasChanged(srvCA, cfg)) {                throw new Exception(                        "The configuration has changed in CM since it was opened."                                + "Use -force option if you want to force saving of your changes.");            }            if (isEditing(session)) {                cfg.update(getEditingDict(session));                setEditingDict(session, null);            } else {                throw new Exception("No changes to save");            }            retcode = 0; // Success!        } catch (Exception e) {            out.println("Save failed. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } finally {            if (srvCA != null) {                bc.ungetService(refCA);            }        }        return retcode;    }    public final static String USAGE_SET = "<property> <value> [<type>]";    public final static String[] HELP_SET = new String[] {            "Set a property in the currently open configuration.",            "<property> Name of property to set in configuration",            "<value>    New value of property", "<type>     Type of value",            "Allowed types:", "  String|Integer|Long|Float|Double|Byte|Short|",            "  Character|Boolean|BigInteger|BigDecimal" };    public int cmdSet(Dictionary opts, Reader in, PrintWriter out,            Session session) {        int retcode = 1; // 1 initially not set to 0 until end of try block        try {            if (getCurrent(session) == null)                throw new Exception("No configuration open currently");            String p = (String) opts.get("property");            String v = (String) opts.get("value");            String t = (String) opts.get("type");            Dictionary dict = getEditingDict(session);            Object ov = dict.get(p);            if (t == null) {                if (ov == null) {                    dict.put(p, v);                } else {                    Class ovc = ov.getClass();                    Object nv = stringToObjectOfClass(v, ovc);                    if (nv == null) {                        throw new Exception(                                "Unable to convert argument to the same type as old value of property");                    }                    dict.put(p, nv);                }            } else {                Object o = null;                try {                    o = createValue(t, v);                } catch (Exception e) {                    o = null;                }                if (o == null) {                    throw new Exception("Unable to convert " + v + " to " + t);                }                dict.put(p, o);            }            retcode = 0; // Success!        } catch (Exception e) {            out.println("Set failed. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } finally {            // bluerg        }        return retcode;    }    public final static String USAGE_UNSET = "<property>";    public final static String[] HELP_UNSET = new String[] {            "Remove a property from the currently open configuration.",            "<property> Name of property to remove from the configuration." };    public int cmdUnset(Dictionary opts, Reader in, PrintWriter out,            Session session) {        int retcode = 1; // 1 initially not set to 0 until end of try block        try {            if (getCurrent(session) == null) {                throw new Exception("No configuration open currently");            }            String p = (String) opts.get("property");            Dictionary dict = getEditingDict(session);            Object o = dict.remove(p);            if (o == null) {                throw new Exception("No property named " + p                        + " in current configuration.");            }            retcode = 0; // Success!        } catch (Exception e) {            out.println("Unset failed. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } finally {        }        return retcode;    }    public final static String USAGE_IMPORT = "<url>";    public final static String[] HELP_IMPORT = new String[] {            "Import configuration data from xml file at url.",            "<url>   URL to an xml file containing configuration data" };    public int cmdImport(Dictionary opts, Reader in, final PrintWriter out,            Session session) {        int retcode = 1; // 1 initially not set to 0 until end of try block        try {            final String spec = (String) opts.get("url");            final URL url = new URL(spec);            if (url == null) {                throw new Exception("URL Object construction failed");            }            AccessController.doPrivileged(new PrivilegedExceptionAction() {                public Object run() throws Exception {                    ConfigurationAdmin configAdmin = null;                    PushbackReader reader = null;                    try {                        configAdmin = getCA();                        CMDataReader cmDataReader = new CMDataReader();                        reader = new PushbackReader(new BufferedReader(                                new InputStreamReader(url.openStream(),                                        CMDataReader.ENCODING), 8192), 8);                        Hashtable[] configs = cmDataReader.readCMDatas(reader);                        for (int i = 0; i < configs.length; i++) {                            String pid = (String) configs[i]                                    .get(CMDataReader.SERVICE_PID);                            String fpid = (String) configs[i]                                    .get(CMDataReader.FACTORY_PID);                            Configuration config;                            if (fpid == null) {                                config = configAdmin                                        .getConfiguration(pid, null);                            } else {                                config = configAdmin                                        .createFactoryConfiguration(fpid, null);                            }                            if (config.getBundleLocation() != null) {                                config.setBundleLocation(null);                            }                            if (configs[i].get("service.bundleLocation") != null) {                                configs[i].remove("service.bundleLocation");                            }                            config.update(configs[i]);                        }                    } finally {                        if (reader != null) {                            reader.close();                        }                        if (configAdmin != null) {                            bc.ungetService(refCA);                        }                    }                    return null;                }            });            retcode = 0; // Success!        } catch (MalformedURLException e) {            out.println("Could not create URL. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } catch (IOException e) {            out.println("Import failed. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } catch (PrivilegedActionException pae) {            out.println("Import failed. Details:");            String reason = pae.getException().toString();            out.println(reason == null ? "<unknown>" : reason);        } catch (Exception e) {            out.println("Import failed. Details:");            String reason = e.getMessage();            out.println(reason == null ? "<unknown>" : reason);        } finally {        }        return retcode;    }    /*     * public final static String USAGE_EXPORT = "[-template] <file> [<selection>]     * ...";     *      * public final static String[] HELP_EXPORT = new String[] { "Export     * configuration data in xml format to a file.", "-template If the output     * should be a template.", "<file> Path to file to write xml to.", "<selection>     * A pid that can contain wildcards '*',", " or an ldap filter, or an index     * in output", " from the latest use of the 'list' command.", " If no     * selection is given all existing ", " configurations will be exported." };     *      * public int cmdExport(Dictionary opts, Reader in, PrintWriter out, Session     * session) { int retcode = 1; // 1 initially not set to 0 until end of try     * block OutputStream os = null; ConfigurationAdmin srvCA = null; try {     * srvCA = getCA();     *      * boolean isTemplate = opts.get("-template") != null; String[] selection =     * (String[]) opts.get("selection"); boolean deleteAllOldConfigs = false;     * Configuration[] cs = null; if (selection == null || selection.length ==     * 0) { deleteAllOldConfigs = true; cs = srvCA.listConfigurations(null); }     * else { cs = getConfigurations(session, srvCA, selection); }     *      * if (cs == null || cs.length == 0) { throw new Exception("No     * configurations matching selection."); }     *      * final String fileName = (String) opts.get("file"); final File f = new     * File(fileName); os = (FileOutputStream) AccessController     * .doPrivileged(new PrivilegedExceptionAction() { public Object run()     * throws Exception { return new FileOutputStream(f); } }); try {     * CMDataManager.exportCMData(cs, deleteAllOldConfigs, isTemplate, srvCA,     * os); } finally { os.close(); } retcode = 0; // Success! } catch     * (IOException e) { out.println("Export failed. Details:"); String reason =     * e.getMessage(); out.println(reason == null ? "<unknown>" : reason); }     * catch (PrivilegedActionException pae) { out.println("Export failed.     * Details:"); String reason = pae.getException().getMessage();     * out.println(reason == null ? "<unknown>" : reason); } catch (Exception     * e) { out.println("Export failed. Details:"); String reason =     * e.getMessage(); out.println(reason == null ? "<unknown>" : reason); }     * finally { if (srvCA != null) { bc.ungetService(refCA); } } return     * retcode; }     */    /** Helper method that get the CA service. */    ConfigurationAdmin getCA() throws Exception {        ConfigurationAdmin srvCA = null;        if (refCA == null) {            throw new Exception("CM service is not available");        }        try {            srvCA = (ConfigurationAdmin) AccessController                    .doPrivileged(new PrivilegedExceptionAction() {                        public Object run() throws Exception {                            return bc.getService(refCA);                        }                    });        } catch (PrivilegedActionException pae) {            // Rethrow wrapped exception            throw pae.getException();        }        if (srvCA == null) {            throw new Exception("CM service is not available");        }        return srvCA;    }    /***************************************************************************     * Helper method that gets the current configuration from the session.     * Returns <code>null</code> if not availble.*     **************************************************************************/    private Configuration getCurrent(Session session) {        return (Configuration) session.getProperties().get(CURRENT);    }    /***************************************************************************     * Helper method that sets the current configuration in the session.*     **************************************************************************/    private void setSessionProperty(Session session, String key, Object value) {        if (value == null) {            session.getProperties().remove(key);        } else {            session.getProperties().put(key, value);        }    }    /***************************************************************************     * Helper method that sets the current configuration in the session.*     **************************************************************************/    private void setCurrent(Session session, Configuration cfg) {        setSessionProperty(session, CURRENT, cfg);    }    /***************************************************************************     * Helper method that returns true if the current configuration is * set and     * its dictionary has been fetched. I.e. it returns true if the EDITING     * property of the session is set.*     **************************************************************************/

⌨️ 快捷键说明

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