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