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

📄 obrcommandimpl.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * Oscar Bundle Repository * Copyright (c) 2004, Richard S. Hall * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * *   * Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer. *   * Redistributions in binary form must reproduce the above copyright *     notice, this list of conditions and the following disclaimer in *     the documentation and/or other materials provided with the *     distribution. *   * Neither the name of the ungoverned.org nor the names of its *     contributors may be used to endorse or promote products derived *     from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Contact: Richard S. Hall (heavy@ungoverned.org) * Contributor(s): ***/package org.ungoverned.osgi.bundle.bundlerepository;import java.io.*;import java.util.StringTokenizer;import org.osgi.framework.Bundle;import org.osgi.framework.BundleContext;import org.osgi.framework.Constants;import org.osgi.framework.InvalidSyntaxException;import org.ungoverned.osgi.service.bundlerepository.BundleRecord;import org.ungoverned.osgi.service.bundlerepository.BundleRepositoryService;import org.ungoverned.osgi.service.shell.Command;public class ObrCommandImpl implements Command{    private static final String HELP_CMD = "help";    private static final String URLS_CMD = "urls";    private static final String LIST_CMD = "list";    private static final String INFO_CMD = "info";    private static final String DEPLOY_CMD = "deploy";    private static final String INSTALL_CMD = "install";    private static final String START_CMD = "start";    private static final String UPDATE_CMD = "update";    private static final String SOURCE_CMD = "source";    private static final String NODEPS_SWITCH = "-nodeps";    private static final String CHECK_SWITCH = "-check";    private static final String EXTRACT_SWITCH = "-x";    private BundleContext m_context = null;    private BundleRepositoryService m_brs = null;    public ObrCommandImpl(BundleContext context, BundleRepositoryService brs)    {        m_context = context;        m_brs = brs;    }    public String getName()    {        return "obr";    }    public String getUsage()    {        return "obr help";    }    public String getShortDescription()    {        return "Oscar bundle repository.";    }    public synchronized void execute(String commandLine, PrintStream out, PrintStream err)    {        try        {            // Parse the commandLine to get the OBR command.            StringTokenizer st = new StringTokenizer(commandLine);            // Ignore the invoking command.            st.nextToken();            // Try to get the OBR command, default is HELP command.            String command = HELP_CMD;            try            {                command = st.nextToken();            }            catch (Exception ex)            {                // Ignore.            }                        // Perform the specified command.            if ((command == null) || (command.equals(HELP_CMD)))            {                help(out, st);            }            else            {                if (command.equals(URLS_CMD))                {                    urls(commandLine, command, out, err);                }                else if (command.equals(LIST_CMD))                {                    list(commandLine, command, out, err);                }                else if (command.equals(INFO_CMD))                {                    info(commandLine, command, out, err);                }                else if (command.equals(DEPLOY_CMD))                {                    deploy(commandLine, command, out, err);                }                else if (command.equals(INSTALL_CMD) || command.equals(START_CMD))                {                    install(commandLine, command, out, err);                }                else if (command.equals(UPDATE_CMD))                {                    update(commandLine, command, out, err);                }                else if (command.equals(SOURCE_CMD))                {                    source(commandLine, command, out, err);                }                else                {                    err.println("Unknown command: " + command);                }            }        }        catch (InvalidSyntaxException ex)        {            err.println("Syntax error: " + ex.getMessage());        }        catch (IOException ex)        {            err.println("Error: " + ex);        }    }    private void urls(        String commandLine, String command, PrintStream out, PrintStream err)        throws IOException    {        // Parse the commandLine.        StringTokenizer st = new StringTokenizer(commandLine);        // Ignore the "obr" command.        st.nextToken();        // Ignore the "urls" command.        st.nextToken();        int count = st.countTokens();        String[] urls = new String[count];        for (int i = 0; i < count; i++)        {            urls[i] = st.nextToken();        }            if (count > 0)        {            m_brs.setRepositoryURLs(urls);        }        else        {            urls = m_brs.getRepositoryURLs();            if (urls != null)            {                for (int i = 0; i < urls.length; i++)                {                    out.println(urls[i]);                }            }            else            {                out.println("No repository URLs are set.");            }        }    }    private void list(        String commandLine, String command, PrintStream out, PrintStream err)        throws IOException    {        // Create a stream tokenizer for the command line string,        // since the syntax for install/start is more sophisticated.        StringReader sr = new StringReader(commandLine);        StreamTokenizer tokenizer = new StreamTokenizer(sr);        tokenizer.resetSyntax();        tokenizer.quoteChar('\'');        tokenizer.quoteChar('\"');        tokenizer.whitespaceChars('\u0000', '\u0020');        tokenizer.wordChars('A', 'Z');        tokenizer.wordChars('a', 'z');        tokenizer.wordChars('0', '9');        tokenizer.wordChars('\u00A0', '\u00FF');        tokenizer.wordChars('.', '.');        tokenizer.wordChars('-', '-');        tokenizer.wordChars('_', '_');                            // Ignore the invoking command name and the OBR command.        int type = tokenizer.nextToken();        type = tokenizer.nextToken();        String substr = null;            for (type = tokenizer.nextToken();            type != StreamTokenizer.TT_EOF;            type = tokenizer.nextToken())        {            // Add a space in between tokens.            if (substr == null)            {                substr = "";            }            else            {                substr += " ";            }                                    if ((type == StreamTokenizer.TT_WORD) ||                (type == '\'') || (type == '"'))            {                substr += tokenizer.sval.toLowerCase();            }        }        boolean printed = false;        for (int i = 0; i < m_brs.getBundleRecordCount(); i++)        {            BundleRecord record = m_brs.getBundleRecord(i);            String name = (String) record.getAttribute(BundleRecord.BUNDLE_NAME);            if (name != null)            {                if ((substr == null) ||                    (name.toLowerCase().indexOf(substr) >= 0))                {                    if (!printed)                    {                        printed = true;                        out.println("");                    }                    String version =                        (String) record.getAttribute(BundleRecord.BUNDLE_VERSION);                    if (version != null)                    {                        out.println(name + " (" + version + ")");                    }                    else                    {                        out.println(name);                    }                }            }        }            if (printed)        {            out.println("");        }        else        {            out.println("No matching bundles.");        }    }    private void info(        String commandLine, String command, PrintStream out, PrintStream err)        throws IOException, InvalidSyntaxException    {        ParsedCommand pc = parseInfo(commandLine);        for (int i = 0; (pc != null) && (i < pc.getTargetCount()); i++)                        {            out.println("");            BundleRecord record = null;            // If there is no version, then try to retrieve by            // name, but error if there are multiple versions.            if (pc.getTargetVersion(i) == null)            {                BundleRecord[] records =                    m_brs.getBundleRecords(pc.getTargetName(i));                if (records.length == 1)                {                    record = records[0];                }            }            else            {                record = m_brs.getBundleRecord(                    pc.getTargetName(i),                    Util.parseVersionString(                        pc.getTargetVersion(i)));            }            if (record != null)            {                record.printAttributes(out);            }            else            {                err.println("Unknown bundle or amiguous version: "                    + pc.getTargetName(i));            }        }        out.println("");    }    private void deploy(        String commandLine, String command, PrintStream out, PrintStream err)        throws IOException, InvalidSyntaxException    {        ParsedCommand pc = parseInstallStart(commandLine);        for (int i = 0; (pc != null) && (i < pc.getTargetCount()); i++)                        {            // Find either the local bundle or the bundle            // record so we can get the update location attribute.            String updateLocation = null;            // First look for update location locally.                        Bundle bundle =                findLocalBundle(pc.getTargetName(i), pc.getTargetVersion(i));            if (bundle != null)            {                updateLocation = (String)                    bundle.getHeaders().get(Constants.BUNDLE_UPDATELOCATION);            }            // If update location wasn't found locally, look in repository.                        if (updateLocation == null)

⌨️ 快捷键说明

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