Example usage for java.util ListIterator previous

List of usage examples for java.util ListIterator previous

Introduction

In this page you can find the example usage for java.util ListIterator previous.

Prototype

E previous();

Source Link

Document

Returns the previous element in the list and moves the cursor position backwards.

Usage

From source file:org.rifidi.emulator.reader.thingmagic.commandobjects.SetCommand.java

public SetCommand(String command, ThingMagicReaderSharedResources tmsr) throws CommandCreationException {
    // TODO Auto-generated constructor stub
    this.command = command;
    this.tmsr = tmsr;

    List<String> tokens = new ArrayList<String>();

    logger.debug("Parsing command: " + command);

    Pattern tokenizer = Pattern.compile(
            // anything less...
            "[^\\s\\w,<>=\\(\\)\\u0027]|" +
            // groups we are looking for...
                    "\\w+|" + "\\u0027|" + "\\s*<>\\*|" + "\\s*>=\\s*|" + "\\s*<=\\s*|" + "\\s*=\\s*|"
                    + "\\s*,\\s*|" + "\\s*>\\s*|" + "\\s*<\\s*|" + "\\s?+|" + "\\(|" + "\\)|",
            Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher tokenFinder = tokenizer.matcher(command.toLowerCase().trim());

    while (tokenFinder.find()) {
        String temp = tokenFinder.group();
        /*/*from   w w  w. j  a  v a 2  s  .c  o  m*/
         * no need to add empty strings at tokens.
         */
        // TODO: Figure out why we are getting empty stings as tokens.
        if (temp.equals(""))
            continue;
        tokens.add(temp);
    }

    ListIterator<String> tokenIterator = tokens.listIterator();

    String token = tokenIterator.next();

    if (!token.equals("set"))
        throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

    try {

        token = tokenIterator.next();

        if (!token.matches(WHITE_SPACE)) {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }

        /*
         * here possible syntax can diverge into two possible directions...
         */
        token = tokenIterator.next();
        if (token.matches("auto")) {
            logger.debug("Expecting to turn on or off AutoMode");

            /*
             * here possible syntax can diverge into two possible directions
             */
            token = tokenIterator.next();
            if (token.matches(EQUALS_WITH_WS)) {
                logger.debug("Expecting to turn of AutoMode");
                setUpStop(tokenIterator);
            } else if (token.matches(WHITE_SPACE)) {
                logger.debug("Expecting to turn of AutoMode");
                setUpStart(tokenIterator);
            } else {
                throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
            }

        } else if (token.matches("repeat")) {
            logger.debug("Expecting to set cursorListRepeatDelay");
            setUpCursorListDelay(tokenIterator);
        } else {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }

        // check if the command correctly ends in a semicolon
        if (tokenIterator.hasNext()) {
            token = tokenIterator.next();

            if (token.matches(WHITE_SPACE)) {
                token = tokenIterator.next();
            }

            if (!token.equals(";")) {
                throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
            }
        } else {
            throw new CommandCreationException("Error 0100:     syntax error at '\n'");
        }

    } catch (NoSuchElementException e) {
        /*
         * if we get here... we run out of tokens prematurely... Our job now
         * is to walk backwards to find the last non space tokens and throw
         * an exception saying that there is an syntax error at that point.
         */

        /*
         * look for the last offending command block that is not a series of
         * whitespaces.
         */

        token = tokenIterator.previous();
        while (token.matches(WHITE_SPACE)) {
            token = tokenIterator.previous();
        }
        logger.debug("Premature end of token list detected.");
        throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

    }

}

From source file:marytts.modules.phonemiser.AllophoneSet.java

/**
 * Syllabify a string of allophones. If stress markers are provided, they are preserved; otherwise, primary stress will be
 * assigned to the initial syllable.//from  w  ww  .  j ava2 s  .c  om
 * <p>
 * The syllabification algorithm itself follows the <i>Core Syllabification Principle (CSP)</i> from <blockquote>G.N. Clements
 * (1990) "The role of the sonority cycle in core syllabification." In: J. Kingston &amp; M.E. Beckman (Eds.),
 * <em>Papers in Laboratory Phonology I: Between the Grammar and Physics of Speech</em>, Ch. 17, pp. 283-333, Cambridge
 * University Press.</blockquote>
 *
 * @param phoneString
 *            phoneString
 * @return a syllabified string; individual allophones are separated by spaces, and syllables, by dashes.
 * @throws IllegalArgumentException
 *             if the <b>phoneString</b> is empty or contains a symbol that satisfies none of the following conditions:
 *             <ol>
 *             <li>the symbol corresponds to an Allophone, or</li> <li>the symbol is a stress symbol (cf. {@link Stress}), or
 *             </li> <li>the symbol is a syllable boundary (<code>-</code>)</li>
 *             </ol>
 * 
 */
public String syllabify(String phoneString) throws IllegalArgumentException {
    // Before we process, a sanity check:
    if (phoneString.trim().isEmpty()) {
        throw new IllegalArgumentException("Cannot syllabify empty phone string");
    }

    // First, split phoneString into a List of allophone Strings...
    List<String> allophoneStrings = splitIntoAllophoneList(phoneString, true);
    // ...and create from it a List of generic Objects
    List<Object> phonesAndSyllables = new ArrayList<Object>(allophoneStrings);

    // Create an iterator
    ListIterator<Object> iterator = phonesAndSyllables.listIterator();

    // First iteration (left-to-right):
    // CSP (a): Associate each [+syllabic] segment to a syllable node.
    Syllable currentSyllable = null;
    while (iterator.hasNext()) {
        String phone = (String) iterator.next();
        try {
            // either it's an Allophone
            Allophone allophone = getAllophone(phone);
            if (allophone.isSyllabic()) {
                // if /6/ immediately follows a non-diphthong vowel, it should be appended instead of forming its own syllable
                boolean appendR = false;
                if (allophone.getFeature("ctype").equals("r")) {
                    // it's an /6/
                    if (iterator.previousIndex() > 1) {
                        Object previousPhoneOrSyllable = phonesAndSyllables.get(iterator.previousIndex() - 1);
                        if (previousPhoneOrSyllable == currentSyllable) {
                            // the /6/ immediately follows the current syllable
                            if (!currentSyllable.getLastAllophone().isDiphthong()) {
                                // the vowel immediately preceding the /6/ is not a diphthong
                                appendR = true;
                            }
                        }
                    }
                }
                if (appendR) {
                    iterator.remove();
                    currentSyllable.appendAllophone(allophone);
                } else {
                    currentSyllable = new Syllable(allophone);
                    iterator.set(currentSyllable);
                }
            }
        } catch (IllegalArgumentException e) {
            // or a stress or boundary marker
            if (!getIgnoreChars().contains(phone)) {
                throw e;
            }
        }
    }

    // Second iteration (right-to-left):
    // CSP (b): Given P (an unsyllabified segment) preceding Q (a syllabified segment), adjoin P to the syllable containing Q
    // iff P has lower sonority rank than Q (iterative).
    currentSyllable = null;
    boolean foundPrimaryStress = false;
    iterator = phonesAndSyllables.listIterator(phonesAndSyllables.size());
    while (iterator.hasPrevious()) {
        Object phoneOrSyllable = iterator.previous();
        if (phoneOrSyllable instanceof Syllable) {
            currentSyllable = (Syllable) phoneOrSyllable;
        } else if (currentSyllable == null) {
            // haven't seen a Syllable yet in this iteration
            continue;
        } else {
            String phone = (String) phoneOrSyllable;
            try {
                // it's an Allophone -- prepend to the Syllable
                Allophone allophone = getAllophone(phone);
                if (allophone.sonority() < currentSyllable.getFirstAllophone().sonority()) {
                    iterator.remove();
                    currentSyllable.prependAllophone(allophone);
                }
            } catch (IllegalArgumentException e) {
                // it's a provided stress marker -- assign it to the Syllable
                switch (phone) {
                case Stress.PRIMARY:
                    iterator.remove();
                    currentSyllable.setStress(Stress.PRIMARY);
                    foundPrimaryStress = true;
                    break;
                case Stress.SECONDARY:
                    iterator.remove();
                    currentSyllable.setStress(Stress.SECONDARY);
                    break;
                case "-":
                    iterator.remove();
                    // TODO handle syllable boundaries
                    break;
                default:
                    throw e;
                }
            }
        }
    }

    // Third iteration (left-to-right):
    // CSP (c): Given Q (a syllabified segment) followed by R (an unsyllabified segment), adjoin R to the syllable containing
    // Q iff has a lower sonority rank than Q (iterative).
    Syllable initialSyllable = currentSyllable;
    currentSyllable = null;
    iterator = phonesAndSyllables.listIterator();
    while (iterator.hasNext()) {
        Object phoneOrSyllable = iterator.next();
        if (phoneOrSyllable instanceof Syllable) {
            currentSyllable = (Syllable) phoneOrSyllable;
        } else {
            String phone = (String) phoneOrSyllable;
            try {
                // it's an Allophone -- append to the Syllable
                Allophone allophone;
                try {
                    allophone = getAllophone(phone);
                } catch (IllegalArgumentException e) {
                    // or a stress or boundary marker -- remove
                    if (getIgnoreChars().contains(phone)) {
                        iterator.remove();
                        continue;
                    } else {
                        throw e;
                    }
                }
                if (currentSyllable == null) {
                    // haven't seen a Syllable yet in this iteration
                    iterator.remove();
                    if (initialSyllable == null) {
                        // haven't seen any syllable at all
                        initialSyllable = new Syllable(allophone);
                        iterator.add(initialSyllable);
                    } else {
                        initialSyllable.prependAllophone(allophone);
                    }
                } else {
                    // append it to the last seen Syllable
                    iterator.remove();
                    currentSyllable.appendAllophone(allophone);
                }
            } catch (IllegalArgumentException e) {
                throw e;
            }
        }
    }

    // if primary stress was not provided, assign it to initial syllable
    if (!foundPrimaryStress) {
        initialSyllable.setStress(Stress.PRIMARY);
    }

    // join Syllables with dashes and return the String
    return StringUtils.join(phonesAndSyllables, " - ");
}

From source file:com.datatorrent.stram.StreamingContainerManager.java

@SuppressWarnings("StatementWithEmptyBody")
void addCheckpoint(PTOperator node, Checkpoint checkpoint) {
    synchronized (node.checkpoints) {
        if (!node.checkpoints.isEmpty()) {
            Checkpoint lastCheckpoint = node.checkpoints.getLast();
            // skip unless checkpoint moves
            if (lastCheckpoint.windowId != checkpoint.windowId) {
                if (lastCheckpoint.windowId > checkpoint.windowId) {
                    // list needs to have max windowId last
                    LOG.warn("Out of sequence checkpoint {} last {} (operator {})", checkpoint, lastCheckpoint,
                            node);/*from   w w w . j av a  2s  .c o  m*/
                    ListIterator<Checkpoint> li = node.checkpoints.listIterator();
                    while (li.hasNext() && li.next().windowId < checkpoint.windowId) {
                        //continue;
                    }
                    if (li.previous().windowId != checkpoint.windowId) {
                        li.add(checkpoint);
                    }
                } else {
                    node.checkpoints.add(checkpoint);
                }
            }
        } else {
            node.checkpoints.add(checkpoint);
        }
    }
}

From source file:org.rifidi.emulator.reader.thingmagic.commandobjects.DeclareCommand.java

public DeclareCommand(String command, ThingMagicReaderSharedResources tmsr) throws CommandCreationException {

    this.tmsr = tmsr;
    this.command = command;

    List<String> tokens = tokenizer(command);

    ListIterator<String> tokenIterator = tokens.listIterator();

    String token = tokenIterator.next();

    if (!token.equals("declare"))
        throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

    try {//  www  . jav a2s  .co m
        token = tokenIterator.next();

        if (!token.matches(WHITE_SPACE))
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

        token = tokenIterator.next();
        if (token.matches(A_WORD)) {
            cursorName = token;
            logger.debug("Cursor name is " + cursorName);
        } else {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }
        token = tokenIterator.next();

        if (!token.matches(WHITE_SPACE))
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

        token = tokenIterator.next();

        if (!token.equals("cursor"))
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

        token = tokenIterator.next();

        if (!token.matches(WHITE_SPACE))
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

        token = tokenIterator.next();

        if (!token.equals("for"))
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

        token = tokenIterator.next();

        if (!token.matches(WHITE_SPACE))
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

        StringBuffer cursorCommandBuf = new StringBuffer();
        token = tokenIterator.next();

        cursorCommandBuf.append(token);

        while (tokenIterator.hasNext()) {
            cursorCommandBuf.append(tokenIterator.next());
        }

        logger.debug("Command is \"" + cursorCommandBuf.toString() + "\"");

        if (token.equals("select")) {
            cursorCommand = new SelectCommand(cursorCommandBuf.toString(), tmsr);
        } else if (token.equals("update")) {
            cursorCommand = new UpdateCommand(cursorCommandBuf.toString(), tmsr);
        } else {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }

        /*
         * The SelectCommand and UpdateCommand both check for the semicolon
         * at the end, so we don't have to do that here.
         */
    } catch (NoSuchElementException e) {
        /*
         * if we get here... we run out of tokens prematurely... Our job now
         * is to walk backwards to find the last non space tokens and throw
         * an exception saying that there is an syntax error at that point.
         */

        /*
         * look for the last offending command block that is not a series of
         * whitespaces.
         */

        token = tokenIterator.previous();
        while (token.matches("\\s+")) {
            token = tokenIterator.previous();
        }
        logger.debug("Premature end of token list detected.");
        throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

    }

    // if (!(tmsr.getCursorCommandRegistry().size() <= 16)) {
    // /* we can only hold no more than 16 cursors
    // *
    // */
    //         
    // //TODO Correct the messsage.
    // throw new CommandCreationExeption(
    // "Error 0100:     Can not old no more than 16 cursors.");
    // }

    if (tmsr.getCursorCommandRegistry().containsKey(cursorName)) {
        // TODO Correct the message.
        throw new CommandCreationException("Error 0100:   Cursor already exists");
    }

}

From source file:com.ichi2.libanki.Sched.java

private List<DeckDueTreeNode> _groupChildrenMain(List<DeckDueTreeNode> grps) {
    List<DeckDueTreeNode> tree = new ArrayList<DeckDueTreeNode>();
    // group and recurse
    ListIterator<DeckDueTreeNode> it = grps.listIterator();
    while (it.hasNext()) {
        DeckDueTreeNode node = it.next();
        String head = node.names[0];
        // Compose the "tail" node list. The tail is a list of all the nodes that proceed
        // the current one that contain the same name[0]. I.e., they are subdecks that stem
        // from this node. This is our version of python's itertools.groupby.
        List<DeckDueTreeNode> tail = new ArrayList<DeckDueTreeNode>();
        tail.add(node);//  w  ww .  j  a  v a 2 s.  c om
        while (it.hasNext()) {
            DeckDueTreeNode next = it.next();
            if (head.equals(next.names[0])) {
                // Same head - add to tail of current head.
                tail.add(next);
            } else {
                // We've iterated past this head, so step back in order to use this node as the
                // head in the next iteration of the outer loop.
                it.previous();
                break;
            }
        }
        Long did = null;
        int rev = 0;
        int _new = 0;
        int lrn = 0;
        List<DeckDueTreeNode> children = new ArrayList<DeckDueTreeNode>();
        for (DeckDueTreeNode c : tail) {
            if (c.names.length == 1) {
                // current node
                did = c.did;
                rev += c.revCount;
                lrn += c.lrnCount;
                _new += c.newCount;
            } else {
                // set new string to tail
                String[] newTail = new String[c.names.length - 1];
                System.arraycopy(c.names, 1, newTail, 0, c.names.length - 1);
                c.names = newTail;
                children.add(c);
            }
        }
        children = _groupChildrenMain(children);
        // tally up children counts
        for (DeckDueTreeNode ch : children) {
            rev += ch.revCount;
            lrn += ch.lrnCount;
            _new += ch.newCount;
        }
        // limit the counts to the deck's limits
        JSONObject conf = mCol.getDecks().confForDid(did);
        JSONObject deck = mCol.getDecks().get(did);
        try {
            if (conf.getInt("dyn") == 0) {
                rev = Math.max(0, Math.min(rev,
                        conf.getJSONObject("rev").getInt("perDay") - deck.getJSONArray("revToday").getInt(1)));
                _new = Math.max(0, Math.min(_new,
                        conf.getJSONObject("new").getInt("perDay") - deck.getJSONArray("newToday").getInt(1)));
            }
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        tree.add(new DeckDueTreeNode(head, did, rev, lrn, _new, children));
    }
    return tree;
}

From source file:org.rifidi.emulator.reader.thingmagic.commandobjects.SelectCommand.java

public SelectCommand(String command, ThingMagicReaderSharedResources tmsr) throws CommandCreationException {
    this.tmsr = tmsr;
    this.command = command;

    // TODO Auto-generated constructor stub

    logger.debug("Parsing command: " + command);

    List<String> tokens = tokenizer(command);

    ListIterator<String> tokenIterator = tokens.listIterator();

    String token = tokenIterator.next();

    if (!token.equals("select")) {
        throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");

    }//from w ww  . jav a  2 s  . c  o  m

    logger.debug("Huray! we are in the correct command object!");
    // TODO Refine the error handling to mirror more exactly what the
    // thingmagic would return;
    try {
        token = tokenIterator.next();

        /*
         * Look for white spaces
         */
        if (!token.matches(WHITE_SPACE)) {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }

        logger.debug("Expected whitespace found.");
        do {
            token = tokenIterator.next();

            /*
             * look a word
             */
            if (token.matches(A_WORD)) {
                columns.add(token);
            } else {
                throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
            }
            token = tokenIterator.next();
            /*
             * look for a comma with any number of white spaces on either
             * side.
             */
        } while (token.matches(COMMA_WITH_WS));

        if (tokenIterator.next().equals("from")) {

            if (!token.matches(WHITE_SPACE))
                throw new CommandCreationException("Error 0100:     syntax error at 'from'");

        } else {
            throw new CommandCreationException("Error 0100:     syntax error at ','");
        }

        token = tokenIterator.next();
        /*
         * Look for white spaces
         */
        if (!token.matches(WHITE_SPACE)) {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }

        token = tokenIterator.next();

        /*
         * Look for words
         */
        if (token.matches(A_WORD)) {
            table = token;
        } else {
            throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
        }

        if (tokenIterator.hasNext()) {
            token = tokenIterator.next();

            if (token.matches(WHITE_SPACE)) {

                if (tokenIterator.hasNext()) {
                    token = tokenIterator.next();

                    if (token.equals("where")) {

                        token = tokenIterator.next();

                        if (!token.matches(WHITE_SPACE)) {
                            throw new CommandCreationException(
                                    "Error 0100:     syntax error at '" + token + "'");
                        }

                        filter = new MasterFilter(tokenIterator, table, tmsr);
                    } else {
                        //No where clause found... back up..
                        tokenIterator.previous();
                        tokenIterator.previous();
                    }
                }

            } else {
                //No where clause found... back up..
                tokenIterator.previous();
            }
        }

        //TODO: Add the parsing for the "SET key=value ..." clause here.

        // check if the command correctly ends in a semicolon
        logger.debug("Checking for correct terminating sequence...");
        if (tokenIterator.hasNext()) {
            token = tokenIterator.next();

            if (token.matches(WHITE_SPACE)) {
                token = tokenIterator.next();
            }

            if (!token.equals(";")) {
                throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
            }
        } else {
            throw new CommandCreationException("Error 0100:     syntax error at '\n'");
        }

    } catch (NoSuchElementException e) {
        /*
         * if we get here... we run out of tokens prematurely... Our job now
         * is to walk backwards to find the last non space tokens and throw
         * an exception saying that there is an syntax error at that point.
         */

        /*
         * look for the last offending command block that is not a series of
         * whitespaces.
         */

        token = tokenIterator.previous();
        while (token.matches("\\s+")) {
            token = tokenIterator.previous();
        }
        logger.debug("Premature end of token list detected.");
        throw new CommandCreationException("Error 0100:     syntax error at '" + token + "'");
    }

    IDBTable tableImpl = tmsr.getDataBase().getTable(table);
    if (tableImpl == null) {
        throw new CommandCreationException("Error 0100:     syntax error at '" + table + "'");
    }

    /*
     * This is an exception to the rule for the thingmagic reader. If we are
     * reading a tag... make best effort to complete the command in an
     * orderly and predictable manner.
     */
    if (tableImpl instanceof DBTagID) {
        return;
    }

    for (int x = 0; x < tableImpl.size(); x++) {
        IDBRow row = tableImpl.get(x);
        for (String column : columns) {
            if (!row.containsColumn(column)) {
                throw new CommandCreationException("Error 0100:     Unknown " + column);
            }

            if (!row.isReadable(column)) {
                throw new CommandCreationException(
                        "Error 0100:     Could not read from '" + column + "' in '" + table + "'");
            }
        }
    }
}

From source file:org.fenixedu.academic.domain.student.Registration.java

final public ICurriculum getCurriculum(final DateTime when, final ExecutionYear executionYear,
        final CycleType cycleType) {
    if (getStudentCurricularPlansSet().isEmpty()) {
        return Curriculum.createEmpty(executionYear);
    }/*from   w ww .j  av  a 2  s .co  m*/

    if (getDegreeType().isBolonhaType()) {
        final StudentCurricularPlan studentCurricularPlan = getLastStudentCurricularPlan();
        if (studentCurricularPlan == null) {
            return Curriculum.createEmpty(executionYear);
        }

        if (cycleType == null) {
            return studentCurricularPlan.getCurriculum(when, executionYear);
        }

        final CycleCurriculumGroup cycleCurriculumGroup = studentCurricularPlan.getCycle(cycleType);
        if (cycleCurriculumGroup == null) {
            return Curriculum.createEmpty(executionYear);
        }

        return cycleCurriculumGroup.getCurriculum(when, executionYear);
    } else {
        final List<StudentCurricularPlan> sortedSCPs = getSortedStudentCurricularPlans();
        final ListIterator<StudentCurricularPlan> sortedSCPsIterator = sortedSCPs
                .listIterator(sortedSCPs.size());
        final StudentCurricularPlan lastStudentCurricularPlan = sortedSCPsIterator.previous();

        final ICurriculum curriculum;
        curriculum = lastStudentCurricularPlan.getCurriculum(when, executionYear);

        for (; sortedSCPsIterator.hasPrevious();) {
            final StudentCurricularPlan studentCurricularPlan = sortedSCPsIterator.previous();
            if (executionYear == null
                    || studentCurricularPlan.getStartExecutionYear().isBeforeOrEquals(executionYear)) {
                ((Curriculum) curriculum).add(studentCurricularPlan.getCurriculum(when, executionYear));
            }
        }

        return curriculum;

    }
}

From source file:au.org.emii.portal.composer.MapComposer.java

public void loadUserSession(String sessionid) {
    Scanner scanner = null;/*from   www  . ja  v  a  2s .  co m*/
    try {

        String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/"
                + sessionid;

        File sessfolder = new File(sfld);
        if (!sessfolder.exists()) {
            showMessage("Session information does not exist. Please provide a valid session id");
            return;
        }

        scanner = new Scanner(new File(sfld + "/details.txt"));

        // first grab the zoom level and bounding box
        String[] mapdetails = scanner.nextLine().split(",");

        BoundingBox bb = new BoundingBox();
        bb.setMinLongitude(Float.parseFloat(mapdetails[1]));
        bb.setMinLatitude(Float.parseFloat(mapdetails[2]));
        bb.setMaxLongitude(Float.parseFloat(mapdetails[3]));
        bb.setMaxLatitude(Float.parseFloat(mapdetails[4]));
        openLayersJavascript.setAdditionalScript(openLayersJavascript.zoomToBoundingBox(bb, true));

        String[] scatterplotNames = null;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.startsWith("scatterplotNames")) {
                scatterplotNames = line.substring(17).split("___");
            }
        }
        ArrayUtils.reverse(scatterplotNames);

        // ignore fields not found
        XStream xstream = new XStream(new DomDriver()) {

            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {
                    public boolean shouldSerializeMember(Class definedIn, String fieldName) {
                        if (definedIn == Object.class || !super.shouldSerializeMember(definedIn, fieldName))
                            System.out.println("faled to read: " + definedIn + ", " + fieldName);

                        return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName)
                                : false;
                    }
                };
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader) {
                Object o = super.unmarshal(reader);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root) {
                Object o = super.unmarshal(reader, root);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
                Object o = super.unmarshal(reader, root, dataHolder);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }
        };

        PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld), xstream);

        List list = new XmlArrayList(strategy);

        ListIterator it = list.listIterator(list.size());
        int scatterplotIndex = 0;
        while (it.hasPrevious()) {
            Object o = it.previous();
            MapLayer ml = null;
            if (o instanceof MapLayer) {
                ml = (MapLayer) o;
                LOGGER.debug("Loading " + ml.getName() + " -> " + ml.isDisplayed());
                addUserDefinedLayerToMenu(ml, false);
            } else if (o instanceof ScatterplotDataDTO) {
                ScatterplotDataDTO spdata = (ScatterplotDataDTO) o;
                loadScatterplot(spdata, "My Scatterplot " + scatterplotIndex++);

            }

            if (ml != null) {
                addUserDefinedLayerToMenu(ml, true);
            }
        }

    } catch (Exception e) {
        try {

            File f = new File("/data/sessions/" + sessionid + ".txt");

            PrintWriter pw = new PrintWriter(f);

            e.printStackTrace(pw);

            pw.close();

        } catch (Exception ex) {

        }
        LOGGER.error("Unable to load session data", e);
        showMessage("Unable to load session data");

    } finally {
        if (scanner != null) {
            scanner.close();
        }
        try {

            File f = new File("/data/sessions/ok/" + sessionid + ".txt");

            FileUtils.writeStringToFile(f, "ok");

        } catch (Exception ex) {

        }
    }
}