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-2006 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.php.dbgp.packets;
042:
043: import org.netbeans.modules.php.dbgp.packets.DbgpStream.StreamType;
044: import org.w3c.dom.Node;
045:
046: /**
047: * @author ads
048: *
049: */
050: class MessageBuilder {
051:
052: private static final String TYPE = "type"; // NOI18N
053:
054: private MessageBuilder() {
055: // avoid inst-ion
056: }
057:
058: static DbgpMessage createStream(Node node) {
059: Node attr = node.getAttributes().getNamedItem(TYPE);
060: assert attr != null;
061: String type = attr.getNodeValue();
062: if (StreamType.STDOUT.equals(type)) {
063: return new DbgpStream(node, StreamType.STDOUT);
064: } else if (StreamType.STDERR.equals(type)) {
065: return new DbgpStream(node, StreamType.STDERR);
066: } else {
067: assert false;
068: return null;
069: }
070: }
071:
072: static DbgpMessage createResponse(Node node) {
073: String command = DbgpMessage.getAttribute(node,
074: DbgpResponse.COMMAND);
075: assert command != null;
076: if (command.equals(RunCommand.RUN)
077: || command.equals(StatusCommand.STATUS)
078: || command.equals(StepOutCommand.STEP_OUT)
079: || command.equals(StepOverCommand.STEP_OVER)
080: || command.equals(StepIntoCommand.STEP_INTO)
081: || command.equals(StopCommand.STOP)) {
082: return new StatusResponse(node);
083: } else if (command.equals(BrkpntSetCommand.BREAKPOINT_SET)) {
084: return new BrkpntSetResponse(node);
085: } else if (command.equals(BrkpntUpdateCommand.UPDATE)) {
086: return new BrkpntUpdateResponse(node);
087: } else if (command.equals(BrkpntRemoveCommand.REMOVE)) {
088: return new BrkpntRemoveResponse(node);
089: } else if (command.equals(ContextNamesCommand.CONTEXT_NAMES)) {
090: return new ContextNamesResponse(node);
091: } else if (command.equals(ContextGetCommand.CONTEXT_GET)) {
092: return new ContextGetResponse(node);
093: } else if (command.equals(StackDepthCommand.STACK_DEPTH)) {
094: return new StackDepthResponse(node);
095: } else if (command.equals(StackGetCommand.STACK_GET)) {
096: return new StackGetResponse(node);
097: } else if (command.equals(TypeMapGetCommand.TYPEMAP_GET)) {
098: return new TypeMapGetResponse(node);
099: } else if (command.equals(PropertySetCommand.PROPERTY_SET)) {
100: return new PropertySetResponse(node);
101: } else if (command.equals(PropertyGetCommand.PROPERTY_GET)) {
102: return new PropertyGetResponse(node);
103: } else if (command.equals(PropertyValueCommand.PROPERTY_VALUE)) {
104: return new PropertyValueResponse(node);
105: } else if (command.equals(SourceCommand.SOURCE)) {
106: return new SourceResponse(node);
107: } else if (command.equals(StreamType.STDERR.toString())
108: || command.equals(StreamType.STDOUT.toString())) {
109: return new StreamResponse(node);
110: } else if (command.equals(FeatureGetCommand.FEATURE_GET)) {
111: return new FeatureGetResponse(node);
112: } else if (command.equals(FeatureSetCommand.FEATURE_SET)) {
113: return new FeatureSetResponse(node);
114: } else if (command.equals(BreakCommand.BREAK)) {
115: return new BreakResponse(node);
116: } else if (command.equals(EvalCommand.EVAL)) {
117: return new EvalResponse(node);
118: } else if (command.equals(ExprCommand.EXPR)) {
119: return new ExprResponse(node);
120: } else if (command.equals(ExecCommand.EXEC)) {
121: return new ExecResponse(node);
122: }
123: return null;
124: }
125:
126: }
|