001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.errorhandler;
042:
043: import java.net.*;
044: import java.io.*;
045: import java.util.StringTokenizer;
046:
047: /*
048: * DebugProtocol.java
049: * Created on January 6, 2004, 1:21 PM
050: */
051:
052: /**
053: * @author Winston Prakash
054: */
055:
056: public class DebugProtocol {
057: public static final int STATE_WAITING = 0;
058: public static final int STATE_DEBUG_REQUEST = 1;
059: public static final int STATE_CLIENT_RCOGNIZED = 2;
060: public static final int STATE_CLIENT_UNRCOGNIZED = 3;
061: public static final int STATE_DONE = 4;
062:
063: public static String DEBUG_CLIENT_ID = "DEBUG_CLIENT_ID"; // NOI18N
064: public static String DEBUG_CLIENT_NAME = "Creator Debug Client"; // NOI18N
065: public static String DEBUG_REQUEST_START = "DEBUG_REQUEST_START"; // NOI18N
066: public static String DEBUG_REQUEST_END = "DEBUG_REQUEST_END"; // NOI18N
067: public static String DEBUG_CLASS_NAME = "ClassName"; // NOI18N
068: public static String DEBUG_FILE_NAME = "FileName"; // NOI18N
069: public static String DEBUG_METHOD_NAME = "MethodName"; // NOI18N
070: public static String DEBUG_LINE_NUMBER = "LineNumber"; // NOI18N
071: public static String DEBUG_DELIMITER = ":"; // NOI18N
072:
073: private int state = STATE_WAITING;
074:
075: ErrorInfo errorInfo = null;
076:
077: StringTokenizer tokenizer;
078:
079: public String processInput(String inputString) {
080: String outputString = null;
081: if (state == STATE_WAITING) {
082: tokenizer = new StringTokenizer(inputString,
083: DEBUG_DELIMITER);
084: String param = tokenizer.nextToken();
085: if (param.startsWith(DEBUG_CLIENT_ID)) {
086: String clientName = tokenizer.nextToken();
087: if (clientName.equals(DEBUG_CLIENT_NAME)) {
088: outputString = "Client recognized"; // NOI18N
089: state = STATE_CLIENT_RCOGNIZED;
090: return outputString;
091: } else {
092: outputString = "Client unrecognized continuing .."; // NOI18N
093: state = STATE_CLIENT_UNRCOGNIZED;
094: }
095: return outputString;
096: } else {
097: outputString = "Client unrecognized disconnecting .."; // NOI18N
098: state = STATE_CLIENT_UNRCOGNIZED;
099: }
100: } else if (state == STATE_CLIENT_RCOGNIZED) {
101: if (inputString.startsWith(DEBUG_REQUEST_START)) {
102: outputString = "Debug Request Received"; // NOI18N
103: state = STATE_DEBUG_REQUEST;
104: errorInfo = new ErrorInfo();
105: return outputString;
106: }
107: } else if (state == STATE_DEBUG_REQUEST) {
108: if (inputString.startsWith(DEBUG_REQUEST_END)) {
109: outputString = "Debug Request Completed"; // NOI18N
110: processRequest();
111: state = STATE_DONE;
112: return outputString;
113: }
114: tokenizer = new StringTokenizer(inputString,
115: DEBUG_DELIMITER);
116: String param = tokenizer.nextToken();
117: if (param.startsWith(DEBUG_CLASS_NAME)) {
118: String className = tokenizer.nextToken();
119: outputString = "Class Name - " + className; // NOI18N
120: errorInfo.setClassName(className);
121: return outputString;
122: }
123: if (param.startsWith(DEBUG_FILE_NAME)) {
124: String fileName = tokenizer.nextToken();
125: outputString = "File Name - " + fileName; // NOI18N
126: errorInfo.setFileName(fileName);
127: return outputString;
128: }
129: if (param.startsWith(DEBUG_METHOD_NAME)) {
130: String methodName = tokenizer.nextToken();
131: outputString = "Method Name - " + methodName; // NOI18N
132: errorInfo.setMethodName(methodName);
133: return outputString;
134: }
135: if (param.startsWith(DEBUG_LINE_NUMBER)) {
136: String lineNumber = tokenizer.nextToken();
137: outputString = "Line Number - " + lineNumber; // NOI18N
138: try {
139: errorInfo.setLineNumber(Integer
140: .parseInt(lineNumber));
141: } catch (Exception exc) {
142: exc.printStackTrace();
143: }
144: return outputString;
145: }
146: }
147: return outputString;
148: }
149:
150: private void processRequest() {
151: //Process the request
152: }
153:
154: public int getState() {
155: return state;
156: }
157:
158: public void setState(int state) {
159: this .state = state;
160: if (state == STATE_WAITING)
161: errorInfo = null;
162: }
163:
164: public ErrorInfo getErrorInfo() {
165: return errorInfo;
166: }
167:
168: public class ErrorInfo {
169: String className = null;
170: String fileName = null;
171: String methodName = null;
172: String filePath = null;
173: int lineNumber;
174:
175: public void setClassName(String cName) {
176: className = cName;
177: }
178:
179: public void setMethodName(String mName) {
180: methodName = mName;
181: }
182:
183: public void setFileName(String fName) {
184: fileName = fName;
185: }
186:
187: public void setLineNumber(int lNumber) {
188: lineNumber = lNumber;
189: }
190:
191: public int getLineNumber() {
192: return lineNumber;
193: }
194:
195: public String getFilePath() {
196: return className.replace('.', '/') + ".java"; // NOI18N
197: }
198:
199: }
200: }
|