001: /*
002: * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.jdwpgen;
027:
028: import java.util.*;
029:
030: class Context {
031:
032: static final int outer = 0;
033: static final int readingReply = 1;
034: static final int writingCommand = 2;
035:
036: final String whereJava;
037: final String whereC;
038:
039: int state = outer;
040: private boolean inEvent = false;
041:
042: Context() {
043: whereJava = "";
044: whereC = "";
045: }
046:
047: private Context(String whereJava, String whereC) {
048: this .whereJava = whereJava;
049: this .whereC = whereC;
050: }
051:
052: Context subcontext(String level) {
053: Context ctx;
054: if (whereC.length() == 0) {
055: ctx = new Context(level, level);
056: } else {
057: ctx = new Context(whereJava + "." + level, whereC + "_"
058: + level);
059: }
060: ctx.state = state;
061: ctx.inEvent = inEvent;
062: return ctx;
063: }
064:
065: private Context cloneContext() {
066: Context ctx = new Context(whereJava, whereC);
067: ctx.state = state;
068: ctx.inEvent = inEvent;
069: return ctx;
070: }
071:
072: Context replyReadingSubcontext() {
073: Context ctx = cloneContext();
074: ctx.state = readingReply;
075: return ctx;
076: }
077:
078: Context commandWritingSubcontext() {
079: Context ctx = cloneContext();
080: ctx.state = writingCommand;
081: return ctx;
082: }
083:
084: Context inEventSubcontext() {
085: Context ctx = cloneContext();
086: ctx.inEvent = true;
087: return ctx;
088: }
089:
090: boolean inEvent() {
091: return inEvent;
092: }
093:
094: boolean isWritingCommand() {
095: return state == writingCommand;
096: }
097:
098: boolean isReadingReply() {
099: return state == readingReply;
100: }
101: }
|