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

📄 frameworkcommandgroup.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        if (args == null) {            args = new String[0];        }        methodArgs = new Object[args.length];        try {            Method m = findMethod(s.getClass(), method, args.length);            if (m != null) {                parameterTypes = m.getParameterTypes();            } else {                parameterTypes = new Class[args.length];            }            for (int i = 0; i < args.length; i++) {                String val = args[i];                String className = String.class.getName();                int ix = val.indexOf("::");                if (ix != -1) {                    className = val.substring(ix + 2);                    val = val.substring(0, ix);                }                if (m == null) {                    methodArgs[i] = makeObject(val, className);                    parameterTypes[i] = getClass(className);                } else {                    methodArgs[i] = makeObject(val, parameterTypes[i].getName());                }            }            if (m == null) {                m = s.getClass().getMethod(method, parameterTypes);            }            out.println("Result: " + Util.showObject(m.invoke(s, methodArgs)));            res = 0;        } catch (InvocationTargetException e) {            out.println("Exception thrown by call");            e.getTargetException().printStackTrace(out);        } catch (IllegalAccessException e) {            out.println("Call method not accessible (must be public)");        } catch (NullPointerException e) {            out.println("Internal error: " + e);        } catch (IllegalArgumentException e) {            out.println("Internal error: " + e);        } catch (NoSuchMethodException e) {            out.println("No method '" + method + "' with matching arguments: "                    + e);        }        bc.ungetService(sr);        return res;    }    Class getClass(String className) {        try {            if ("int".equals(className)) {                return Integer.TYPE;            } else if ("boolean".equals(className)) {                return Boolean.TYPE;            } else if ("long".equals(className)) {                return Long.TYPE;            } else if ("string".equals(className)) {                return String.class;            }            if (-1 == className.indexOf(".")) {                className = "java.lang." + className;            }            return Class.forName(className);        } catch (Exception e) {            throw new IllegalArgumentException("Unknown class " + className);        }    }    Method findMethod(Class clazz, String name, int nArgs) {        Method[] methods = clazz.getDeclaredMethods();        Vector v = new Vector();        for (int i = 0; i < methods.length; i++) {            if (methods[i].getName().equals(name)                    && methods[i].getParameterTypes().length == nArgs) {                v.addElement(methods[i]);            }        }        if (v.size() == 1) {            return (Method) v.elementAt(0);        }        return null;    }    Object makeObject(String val, String className) {        try {            Class clazz = getClass(className);            if (clazz == Integer.TYPE) {                return new Integer(val);            }            if (clazz == Long.TYPE) {                return new Long(val);            }            if (clazz == Boolean.TYPE) {                return "true".equals(val) ? Boolean.TRUE : Boolean.FALSE;            }            if (clazz == String.class) {                return val;            }            Constructor cons = clazz                    .getConstructor(new Class[] { String.class });            Object r = cons.newInstance(new Object[] { val });            return r;        } catch (Exception e) {            throw new IllegalArgumentException("makeObject(" + val + ", "                    + className + "): " + e);        }    }    //    // Deletepermission command    //    public final static String USAGE_DELETEPERMISSION = "[-r] -b #bundle# | -d | -l #location# <type> <name> <actions>";    public final static String[] HELP_DELETEPERMISSION = new String[] {            "Delete permissions from a bundle",            "-b #bundle#   Delete permission for bundle name or id",            "-d            Delete default permissions",            "-l #location# Delete permission for location",            "-r            Remove entry if empty",            "<type>        Permission type (*, match all)",            "<name>        Permission name (*, match all)",            "<actions>     Permission actions (*, match all)" };    public int cmdDeletepermission(Dictionary opts, Reader in, PrintWriter out,            Session session) {        if (permissionAdmin == null) {            out.println("Permission Admin service is not available");            return 1;        }        String loc = null;        PermissionInfo[] pi;        String selection = (String) opts.get("-b");        if (selection != null) {            Bundle[] b = bc.getBundles();            Util.selectBundles(b, new String[] { selection });            for (int i = 0; i < b.length; i++) {                if (b[i] != null) {                    if (loc == null) {                        loc = b[i].getLocation();                    } else {                        out.println("ERROR! Multiple bundles selected");                        return 1;                    }                }            }            if (loc == null) {                out.println("ERROR! No matching bundle");                return 1;            }            pi = permissionAdmin.getPermissions(loc);        } else if (opts.get("-d") != null) {            pi = permissionAdmin.getDefaultPermissions();        } else {            loc = (String) opts.get("-l");            pi = permissionAdmin.getPermissions(loc);        }        if (pi != null) {            String type = (String) opts.get("type");            String name = (String) opts.get("name");            String actions = (String) opts.get("actions");            int size = 0;            for (int i = 0; i < pi.length; i++) {                if (("*".equals(type) || pi[i].getType().equals(type))                        && ("*".equals(name) || pi[i].getName().equals(name))                        && ("*".equals(actions) || pi[i].getActions().equals(                                actions))) {                    pi[i] = null;                } else {                    size++;                }            }            if (size == 0) {                if (opts.get("-r") != null) {                    pi = null;                } else {                    pi = new PermissionInfo[0];                }            } else {                PermissionInfo[] npi = new PermissionInfo[size];                for (int i = pi.length - 1; i >= 0; i--) {                    if (pi[i] != null) {                        npi[--size] = pi[i];                    }                }                pi = npi;            }            if (loc != null) {                permissionAdmin.setPermissions(loc, pi);            } else {                permissionAdmin.setDefaultPermissions(pi);            }        }        return 0;    }    //    // Headers command    //    public final static String USAGE_HEADERS = "[-i] <bundle> ...";    public final static String[] HELP_HEADERS = new String[] {            "Show bundle header values", "-i       Sort on bundle id",            "<bundle> Name or id of bundle" };    public int cmdHeaders(Dictionary opts, Reader in, PrintWriter out,            Session session) {        Bundle[] b = getBundles((String[]) opts.get("bundle"),                opts.get("-i") != null);        boolean found = false;        for (int i = 0; i < b.length; i++) {            if (b[i] != null) {                out.println("Bundle: " + showBundle(b[i]));                Dictionary d = b[i].getHeaders();                for (Enumeration e = d.keys(); e.hasMoreElements();) {                    String key = (String) e.nextElement();                    out.println("  " + key + " = "                            + Util.showObject(d.get(key)));                }                found = true;            }        }        if (!found) {            out.println("ERROR! No matching bundle");            return 1;        }        return 0;    }    //    // Install command    //    public final static String USAGE_INSTALL = "[-s] <location> ...";    public final static String[] HELP_INSTALL = new String[] {            "Install one or more bundles", "-s         Start bundle(s)",            "<location> Name or id of bundle" };    public int cmdInstall(Dictionary opts, Reader in, PrintWriter out,            Session session) {        String[] loc = (String[]) opts.get("location");        String url = null;        try {            for (int i = 0; i < loc.length; i++) {                url = completeLocation(loc[i]);                Bundle b = bc.installBundle(url);                out.println("Installed: " + showBundle(b));                if (opts.get("-s") != null) {                    b.start();                    out.println("Started: " + showBundle(b));                }            }        } catch (BundleException e) {            Throwable t = e;            while (t instanceof BundleException                    && ((BundleException) t).getNestedException() != null)                t = ((BundleException) t).getNestedException();            if (t instanceof FileNotFoundException) {                out.println("Couldn't install/start bundle: URL not found: "                        + url);            } else {                out.println("Couldn't install/start bundle: " + url                        + " (due to: " + t + ")");                t.printStackTrace(out);            }            return 1;        }        return 0;    }    //    // Package command    //    public final static String USAGE_PACKAGE = "[-l] -b | -p [<selection>] ...";    public final static String[] HELP_PACKAGE = new String[] {            "Show java package information",            "If no package or bundle is specified show all packages",            "-l         Verbose output",            "-b         Only look at selected bundles",            "-p         Only look at selected packages",            "<selection>  Package or bundle" };    public int cmdPackage(Dictionary opts, Reader in, PrintWriter out,            Session session) {        if (packageAdmin == null) {            out.println("Package Admin service is not available");            return 1;        }        boolean verbose = opts.get("-l") != null;        ExportedPackage[] epkgs;        String[] selection = (String[]) opts.get("selection");        if (opts.get("-b") != null) {            Bundle[] b = getBundles(selection, false);            epkgs = new ExportedPackage[0];            for (int i = 0; i < b.length; i++) {                if (b[i] != null) {                    ExportedPackage[] e = packageAdmin                            .getExportedPackages(b[i]);                    if (e != null) {                        if (verbose) {                            ExportedPackage[] ne = new ExportedPackage[e.length                                    + epkgs.length];                            System.arraycopy(epkgs, 0, ne, 0, epkgs.length);                            System.arraycopy(e, 0, ne, epkgs.length, e.length);                            epkgs = ne;                        } else {                            out.println("Exported by " + showBundle(b[i]));                            out.println("   Package: " + e[0].getName());                            for (int j = 1; j < e.length; j++) {                                out.println("            " + e[j].getName());                            }                        }                    }                }            }            if (!verbose) {                return 0;            }        } else {            if (selection != null) {                epkgs = new ExportedPackage[selection.length];                for (int i = 0; i < selection.length; i++) {                    epkgs[i] = packageAdmin.getExportedPackage(selection[i]);                }            } else {                epkgs = packageAdmin.getExportedPackages(null);                // TODO: We should sort here            }        }        for (int i = 0; i < epkgs.length; i++) {            if (epkgs[i] != null) {                out.print("Package: " + epkgs[i].getName());                Bundle b = epkgs[i].getExportingBundle();                if (verbose) {                    out.println();                    out.println("   specification version: "                            + epkgs[i].getSpecificationVersion());                    out.println("   removal pending: "                            + epkgs[i].isRemovalPending());                    out.println("   exporting bundle: " + showBundle(b));                    Bundle[] ib = epkgs[i].getImportingBundles();                    if (ib.length > 0) {                        out                                .println("   importing bundle: "                                        + showBundle(ib[0]));                        for (int j = 1; j < ib.length; j++) {                            out.println("                     "

⌨️ 快捷键说明

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