Package com.sun.grid.jgdi.configuration

Examples of com.sun.grid.jgdi.configuration.ShareTreeImpl


    /**
     * Converts text to map of PropertyDescriptors ... line, based on obj type
     * Each line is also converted to the intermediate format.
     */
    static ShareTree parseShareTreeText(String text) throws IOException {
        ShareTreeImpl node = null;
        ShareTreeImpl rootNode = null;
        text = trimText(text);
        Map<Integer, ShareTreeImpl> map = new HashMap<Integer, ShareTreeImpl>();
        StringTokenizer st = new StringTokenizer(text);
        while (st.hasMoreTokens()) {
            // id
            try {
                String line = st.nextToken("\n");
                String attr = line.split("=")[0].trim();
                line = (line.length() == attr.length()) ? "" : line.substring(attr.length() + 1);
                if (line.length() == 0) {
                    throw new IllegalArgumentException("Expected at least 2 tokens name and value got: \"" + attr + "\"");
                }
                if (attr.equals("id")) {
                    Integer id = Integer.parseInt(line);
                    node = map.get(id);
                    if (node == null) {
                        node = new ShareTreeImpl();
                        node.setId(id);
                        map.put(id, node);
                    }
                }
            } catch (NoSuchElementException nse) {
                throw new IllegalArgumentException("Expected id entry");
            }
            // name
            try {
                String line = st.nextToken("\n");
                String attr = line.split("=")[0].trim();
                line = (line.length() == attr.length()) ? "" : line.substring(attr.length() + 1);
                if (line.length() == 0) {
                    throw new IllegalArgumentException("Expected at least 2 tokens name and value got: \"" + attr + "\"");
                }
                if (attr.equals("name")) {
                    node.setName(line);
                }
            } catch (NoSuchElementException nse) {
                throw new IllegalArgumentException("Expected name entry");
            }

            // type
            try {
                String line = st.nextToken("\n");
                String attr = line.split("=")[0].trim();
                line = (line.length() == attr.length()) ? "" : line.substring(attr.length() + 1);
                if (line.length() == 0) {
                    throw new IllegalArgumentException("Expected at least 2 tokens name and value got: \"" + attr + "\"");
                }
                if (attr.equals("type")) {
                    int type = Integer.parseInt(line);
                    node.setType(type);
                }
            } catch (NoSuchElementException nse) {
                throw new IllegalArgumentException("Expected type entry");
            }

            // shares
            try {
                String line = st.nextToken("\n");
                String attr = line.split("=")[0].trim();
                line = (line.length() == attr.length()) ? "" : line.substring(attr.length() + 1);
                if (line.length() == 0) {
                    throw new IllegalArgumentException("Expected at least 2 tokens name and value got: \"" + attr + "\"");
                }
                if (attr.equals("shares")) {
                    int shares = Integer.parseInt(line);
                    node.setShares(shares);
                }
            } catch (NoSuchElementException nse) {
                throw new IllegalArgumentException("Expected shares entry");
            }

            // children
            try {
                String line = st.nextToken("\n");
                String attr = line.split("=")[0].trim();
                line = (line.length() == attr.length()) ? "" : line.substring(attr.length() + 1);
                if (line.length() == 0) {
                    throw new IllegalArgumentException("Expected at least 2 tokens name and value got: \"" + attr + "\"");
                }
                if (attr.equals("childnodes")) {
                    if (!line.equalsIgnoreCase("none")) {
                        ShareTreeImpl subnode;
                        StringTokenizer ct = new StringTokenizer(line, ",");
                        while (ct.hasMoreTokens()) {
                            Integer id = Integer.parseInt(ct.nextToken());
                            if (id == node.getId()) {
                                throw new IllegalArgumentException("self referencing nodes are not allowed");
                            }
                            subnode = map.get(id);
                            if (subnode == null) {
                                subnode = new ShareTreeImpl();
                                subnode.setId(id);
                                map.put(id, subnode);
                            }
                            node.addChildren(subnode);
                        }
                    }
View Full Code Here


            stree = jgdi.getShareTree("Root");
        } catch (JGDIException je) {
            // ignore no sharetree defined and fill in a template element instead
        }
        if (stree == null) {
            stree = new ShareTreeImpl("template");
        }
        String treeAsText = showShareTree(stree, "Root", true);
        String userTypedText = runEditor(treeAsText);
        if (userTypedText != null) {
            List<JGDIAnswer> answers = new LinkedList<JGDIAnswer>();
            ShareTreeImpl node = new ShareTreeImpl();
            node = GEObjectEditor.updateObjectWithText(jgdi, node, userTypedText);
            // pw.println(node.dump());
            jgdi.updateShareTreeWithAnswer(node, answers);
            printAnswers(answers);
        }
View Full Code Here

        out.println(showShareTree(stree, "Root", true));
    }

    @OptionAnnotation(value = "-dstree", min = 0)
    public void deleteShareTree(final OptionInfo oi) throws JGDIException {
        ShareTree empty = new ShareTreeImpl(true);
        List<JGDIAnswer> answers = new LinkedList<JGDIAnswer>();
        jgdi.deleteShareTreeWithAnswer(answers);
        printAnswers(answers);
    }
View Full Code Here

TOP

Related Classes of com.sun.grid.jgdi.configuration.ShareTreeImpl

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.