[nobug] share new project for JSD2 support
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/.classpath b/development/org.eclipse.wst.jsdt.debug.jsd2/.classpath
new file mode 100644
index 0000000..2fbb7a2
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/.options b/development/org.eclipse.wst.jsdt.debug.jsd2/.options
new file mode 100644
index 0000000..e1a1bab
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/.options
@@ -0,0 +1,25 @@
+###############################################################################
+# Copyright (c) 2012 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+#option file for tracing options for JSD2 debugger port
+org.eclipse.wst.jsdt.debug.jsd2/debug=true
+
+#option to trace packets being sent / received
+org.eclipse.wst.jsdt.debug.jsd2/packets=false
+
+#option to trace the event queue
+org.eclipse.wst.jsdt.debug.jsd2/eventqueue=false
+
+#option to trace the JSDI impl* elements
+org.eclipse.wst.jsdt.debug.jsd2/jsdi=false
+
+#option to trace the JSON parser
+org.eclipse.wst.jsdt.debug.jsd2/json=false
\ No newline at end of file
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/.project b/development/org.eclipse.wst.jsdt.debug.jsd2/.project
new file mode 100644
index 0000000..9813a5c
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.jsdt.debug.jsd2</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/.settings/org.eclipse.jdt.core.prefs b/development/org.eclipse.wst.jsdt.debug.jsd2/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..de9eac3
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,90 @@
+#Fri Apr 30 10:04:28 CDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=error
+org.eclipse.jdt.core.compiler.problem.deadCode=error
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=error
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=error
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=error
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=error
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=error
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=error
+org.eclipse.jdt.core.compiler.problem.unusedLabel=error
+org.eclipse.jdt.core.compiler.problem.unusedLocal=error
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=error
+org.eclipse.jdt.core.compiler.problem.unusedParameter=error
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/.settings/org.eclipse.pde.prefs b/development/org.eclipse.wst.jsdt.debug.jsd2/.settings/org.eclipse.pde.prefs
new file mode 100644
index 0000000..0fc43a4
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/.settings/org.eclipse.pde.prefs
@@ -0,0 +1,32 @@
+compilers.f.unresolved-features=1
+compilers.f.unresolved-plugins=1
+compilers.incompatible-environment=1
+compilers.p.build=1
+compilers.p.build.bin.includes=1
+compilers.p.build.encodings=2
+compilers.p.build.java.compiler=2
+compilers.p.build.java.compliance=1
+compilers.p.build.missing.output=2
+compilers.p.build.output.library=1
+compilers.p.build.source.library=1
+compilers.p.build.src.includes=1
+compilers.p.deprecated=1
+compilers.p.discouraged-class=1
+compilers.p.internal=1
+compilers.p.missing-packages=2
+compilers.p.missing-version-export-package=2
+compilers.p.missing-version-import-package=2
+compilers.p.missing-version-require-bundle=2
+compilers.p.no-required-att=0
+compilers.p.not-externalized-att=2
+compilers.p.unknown-attribute=1
+compilers.p.unknown-class=1
+compilers.p.unknown-element=1
+compilers.p.unknown-identifier=1
+compilers.p.unknown-resource=1
+compilers.p.unresolved-ex-points=1
+compilers.p.unresolved-import=0
+compilers.s.create-docs=false
+compilers.s.doc-folder=doc
+compilers.s.open-tags=1
+eclipse.preferences.version=1
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/META-INF/MANIFEST.MF b/development/org.eclipse.wst.jsdt.debug.jsd2/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..775bd78
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.eclipse.wst.jsdt.debug.jsd2;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.wst.jsdt.debug.internal.jsd2.JSD2Plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.wst.jsdt.debug.core;bundle-version="3.1.100",
+ org.eclipse.wst.jsdt.debug.transport;bundle-version="1.0.200"
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %Bundle-Vendor
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/OSGI-INF/l10n/bundle.properties b/development/org.eclipse.wst.jsdt.debug.jsd2/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000..85bd94b
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,12 @@
+###############################################################################
+# Copyright (c) 2010 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+Bundle-Vendor = Eclipse Web Tools Platform
+Bundle-Name = Crossfire JavaScript Debug
\ No newline at end of file
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/about.html b/development/org.eclipse.wst.jsdt.debug.jsd2/about.html
new file mode 100644
index 0000000..b3906a9
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/about.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>April 20, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+<h3>Third Party Content</h3>
+
+<p>The Content includes items that have been sourced from third parties as set out below. If you
+did not receive this Content directly from the Eclipse Foundation, the following is provided
+for informational purposes only, and you should look to the Redistributor’s license for
+terms and conditions of use.</p>
+
+<h4>Ispell 3.1.20</h4>
+
+<p>The plug-in is accompanied by software developed by Geoff Kuenning. The following files:</p>
+<ul>
+ <li>dictionaries/en_US.dictionary</li>
+ <li>dictionaries/en_GB.dictionary</li>
+</ul>
+
+<p>are based on Ispell 3.1.20. The home page for Ispell is located at <a href="http://lasr.cs.ucla.edu/geoff/ispell.html" target="_blank">http://lasr.cs.ucla.edu/geoff/ispell.html</a>.</p>
+
+<p>Your use of Ispell 3.1.20 in the plug-in is subject to the terms and conditions of the Ispell license. A copy of the Ispell license is included in
+<a href="about_files/ispell-license.txt" target="_blank">about_files/ispell-license.txt</a> and is also reproduced below:</p>
+
+<blockquote>
+ Copyright 1993, Geoff Kuenning, Granada Hills, CA<br />
+ All rights reserved.<br />
+<br />
+ Redistribution and use in source and binary forms, with or without<br />
+ modification, are permitted provided that the following conditions<br />
+ are met:<br />
+<br />
+ 1. Redistributions of source code must retain the above copyright<br />
+ notice, this list of conditions and the following disclaimer.<br />
+ 2. Redistributions in binary form must reproduce the above copyright<br />
+ notice, this list of conditions and the following disclaimer in the<br />
+ documentation and/or other materials provided with the distribution.<br />
+ 3. All modifications to the source code must be clearly marked as<br />
+ such. Binary redistributions based on modified source code<br />
+ must be clearly marked as modified versions in the documentation<br />
+ and/or other materials provided with the distribution.<br />
+ 4. All advertising materials mentioning features or use of this software<br />
+ must display the following acknowledgment:<br />
+ This product includes software developed by Geoff Kuenning and<br />
+ other unpaid contributors.<br />
+ 5. The name of Geoff Kuenning may not be used to endorse or promote<br />
+ products derived from this software without specific prior<br />
+ written permission.<br />
+<br />
+ THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS<br />
+ IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br />
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS<br />
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEOFF<br />
+ KUENNING OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,<br />
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,<br />
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;<br />
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER<br />
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN<br />
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br />
+ POSSIBILITY OF SUCH DAMAGE.<br />
+</blockquote>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/build.properties b/development/org.eclipse.wst.jsdt.debug.jsd2/build.properties
new file mode 100644
index 0000000..fdef019
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/build.properties
@@ -0,0 +1,18 @@
+###############################################################################
+# Copyright (c) 2011 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ OSGI-INF/,\
+ about.html,\
+ .options
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/plugin.xml b/development/org.eclipse.wst.jsdt.debug.jsd2/plugin.xml
new file mode 100644
index 0000000..6563f08
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.wst.jsdt.debug.core.launchingConnectors">
+ <connector
+ class="org.eclipse.wst.jsdt.debug.internal.jsd2.connect.JSD2AttachingConnector"
+ id="org.eclipse.wst.jsdt.debug.jsd2.attaching.connector">
+ </connector>
+ </extension>
+
+</plugin>
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/JSD2Plugin.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/JSD2Plugin.java
new file mode 100644
index 0000000..14d4788
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/JSD2Plugin.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class JSD2Plugin extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.debug.jsd2"; //$NON-NLS-1$
+
+ // The shared instance
+ private static JSD2Plugin plugin;
+
+ /**
+ * The constructor
+ */
+ public JSD2Plugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static JSD2Plugin getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/Tracing.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/Tracing.java
new file mode 100644
index 0000000..9d5c724
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/Tracing.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2;
+
+import org.eclipse.wst.jsdt.debug.internal.jsd2.transport.JSON;
+
+/**
+ * Helper class for common tracing functions
+ *
+ * @since 1.0
+ */
+public class Tracing {
+
+ public static final String PRINTABLE_LINE_FEED = "\\\\r\\\\n"; //$NON-NLS-1$
+
+ /**
+ * Writes the string to system out cleaning it of control chars before printing it
+ *
+ * @param string
+ */
+ public static void writeString(String string) {
+ String s = string.replaceAll(JSON.LINE_FEED, PRINTABLE_LINE_FEED);
+ s = s.replaceAll("\r", "\\\\r"); //$NON-NLS-1$//$NON-NLS-2$
+ s = s.replaceAll("\n", "\\\\n"); //$NON-NLS-1$//$NON-NLS-2$
+ System.out.println("[CROSSFIRE]" + s); //$NON-NLS-1$
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/HostArgument.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/HostArgument.java
new file mode 100644
index 0000000..e36fb2f
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/HostArgument.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.StringArgument;
+import org.eclipse.wst.jsdt.debug.transport.Constants;
+
+/**
+ * Implementation of a string argument that describes the host argument
+ *
+ * @since 1.0
+ */
+public class HostArgument implements StringArgument {
+
+ private static final long serialVersionUID = 3057403815318177030L;
+ private String host;
+
+ /**
+ * Host attribute name
+ */
+ public static final String HOST = "host"; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param arg
+ */
+ public HostArgument(String arg) {
+ setValue(arg);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.host_arg_desc;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.StringArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ return value != null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.host_arg_name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return HOST;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String arg) {
+ if(arg == null) {
+ this.host = Constants.LOCALHOST;
+ }
+ else {
+ if (!isValid(arg)) {
+ throw new IllegalArgumentException();
+ }
+ this.host = arg;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return host;
+ }
+
+ /**
+ * Returns if the given host is <code>localhost</code> or <code>127.0.0.1</code>
+ * @param host
+ * @return true if the given host it localhost (127.0.0.1) false otherwise
+ */
+ public static boolean isLocalhost(String host) {
+ return host.equals(Constants.LOCALHOST) || host.equals(Constants.LOCALHOST_IP);
+ }
+}
\ No newline at end of file
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/JSD2AttachingConnector.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/JSD2AttachingConnector.java
new file mode 100644
index 0000000..1cbb002
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/JSD2AttachingConnector.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.connect;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector;
+import org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi.VirtualMachineImpl;
+import org.eclipse.wst.jsdt.debug.transport.Connection;
+import org.eclipse.wst.jsdt.debug.transport.DebugSession;
+
+/**
+ * An attaching connector for JSD2
+ *
+ * @see https://wiki.mozilla.org/Remote_Debugging_Protocol
+ * @see https://wiki.mozilla.org/DevTools/Features/Debugger
+ */
+public class JSD2AttachingConnector implements AttachingConnector {
+
+ /**
+ * The id of the connector as defined in plugin.xml
+ */
+ public static final String CONNECTR_ID = "org.eclipse.wst.jsdt.debug.jsd2.attaching.connector"; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ */
+ public JSD2AttachingConnector() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#defaultArguments()
+ */
+ public Map defaultArguments() {
+ HashMap args = new HashMap(5);
+ args.put(HostArgument.HOST, new HostArgument(null));
+ args.put(PortArgument.PORT, new PortArgument(5000));
+ args.put(TimeoutArgument.TIMEOUT, new TimeoutArgument());
+ return args;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#description()
+ */
+ public String description() {
+ return Messages.JSD2AttachingConnector_description;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#name()
+ */
+ public String name() {
+ return Messages.JSD2AttachingConnector_name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector#id()
+ */
+ public String id() {
+ return CONNECTR_ID;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.AttachingConnector#attach(java.util.Map)
+ */
+ public VirtualMachine attach(Map arguments) throws IOException {
+ Connection c = null;
+ //TODO make it connect
+ DebugSession session = new DebugSession(c);
+ return new VirtualMachineImpl(session);
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/Messages.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/Messages.java
new file mode 100644
index 0000000..4a15eeb
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/Messages.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.connect;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.wst.jsdt.debug.internal.crossfire.connect.messages"; //$NON-NLS-1$
+ public static String cannot_launch_browser_not_localhost;
+ public static String failed_to_attach_to_auto_browser;
+ public static String host_arg_desc;
+ public static String host_arg_name;
+ public static String JSD2AttachingConnector_description;
+ public static String JSD2AttachingConnector_name;
+ public static String port_arg_desc;
+ public static String port_arg_name;
+ public static String timeout;
+ public static String timeout_desc;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/PortArgument.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/PortArgument.java
new file mode 100644
index 0000000..15bbee7
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/PortArgument.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument;
+
+/**
+ * Implementation of an {@link IntegerArgument} that describes the port to try connecting to
+ *
+ * @since 1.0
+ */
+public class PortArgument implements IntegerArgument {
+
+ private static final long serialVersionUID = -1954469572907116388L;
+ private int port;
+
+ /**
+ * The port attribute name
+ */
+ public static final String PORT = "port"; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param port
+ */
+ public PortArgument(int arg) {
+ setValue(arg);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#intValue()
+ */
+ public int intValue() {
+ return port;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#isValid(int)
+ */
+ public boolean isValid(int intValue) {
+ return intValue > 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#max()
+ */
+ public int max() {
+ return Integer.MAX_VALUE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#min()
+ */
+ public int min() {
+ return 1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#setValue(int)
+ */
+ public void setValue(int arg) {
+ this.port = arg;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.port_arg_desc;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ try {
+ int intValue = Integer.parseInt(value);
+ return isValid(intValue);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.port_arg_name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return PORT;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ try {
+ int intValue = Integer.parseInt(value);
+ setValue(intValue);
+ } catch (NumberFormatException nfe) {
+ // re-throw IllegalArgumentException
+ throw new IllegalArgumentException(nfe.getMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Integer.toString(port);
+ }
+}
\ No newline at end of file
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/TimeoutArgument.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/TimeoutArgument.java
new file mode 100644
index 0000000..10ee7cc
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/TimeoutArgument.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.connect;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument;
+
+/**
+ * Argument used to specify a timeout (in ms)
+ *
+ * @since 1.0
+ */
+public class TimeoutArgument implements IntegerArgument {
+
+ /**
+ * Argument to specify a timeout
+ */
+ public static final String TIMEOUT = "timeout"; //$NON-NLS-1$
+ /**
+ * default connecting timeout
+ */
+ public static final Integer CONNECT_TIMEOUT = new Integer(30000);
+
+ /**
+ * The timeout
+ */
+ private int timeout = 0;
+
+ /**
+ * Constructor
+ */
+ public TimeoutArgument() {
+ setValue(CONNECT_TIMEOUT.intValue());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#description()
+ */
+ public String description() {
+ return Messages.timeout_desc;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#label()
+ */
+ public String label() {
+ return Messages.timeout;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#mustSpecify()
+ */
+ public boolean mustSpecify() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#name()
+ */
+ public String name() {
+ return TIMEOUT;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ try {
+ timeout = Integer.parseInt(value);
+ }
+ catch(NumberFormatException nfe) {
+ //do nothing the new value will not be set
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.Argument#value()
+ */
+ public String value() {
+ return Integer.toString(timeout);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#intValue()
+ */
+ public int intValue() {
+ return timeout;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#isValid(int)
+ */
+ public boolean isValid(int intValue) {
+ return intValue > 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#isValid(java.lang.String)
+ */
+ public boolean isValid(String value) {
+ try {
+ return Integer.parseInt(value) > 0;
+ }
+ catch(NumberFormatException bfe) {
+ //do nothing, just not valid
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#max()
+ */
+ public int max() {
+ return Integer.MAX_VALUE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#min()
+ */
+ public int min() {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.connect.Connector.IntegerArgument#setValue(int)
+ */
+ public void setValue(int intValue) {
+ timeout = intValue;
+ }
+
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/messages.properties b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/messages.properties
new file mode 100644
index 0000000..350eea0
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/connect/messages.properties
@@ -0,0 +1,20 @@
+###############################################################################
+# Copyright (c) 2012 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+cannot_launch_browser_not_localhost=You cannot launch a browser on a different host than localhost (127.0.0.1)
+failed_to_attach_to_auto_browser=Failed to attach to debugger at {0} on port {1}
+host_arg_desc=The name of the host address to try attaching to.
+host_arg_name=&Host:
+JSD2AttachingConnector_description=Allows you to attach to a Mozilla-based browser that is running the remoting JSD2 server
+JSD2AttachingConnector_name=JSD2 - Remote Attach
+port_arg_desc=The port on the host machine to try attaching to.
+port_arg_name=&Port:
+timeout=&Timeout (ms):
+timeout_desc=A timeout value in milliseconds to wait for a debugger to connect
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/MirrorImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/MirrorImpl.java
new file mode 100644
index 0000000..d8aae4e
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/MirrorImpl.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.Mirror;
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+
+/**
+ * Default implementation for JSD2.
+ *
+ * @since 1.0
+ */
+public class MirrorImpl implements Mirror {
+
+ /**
+ * Flag for tracing
+ */
+ static boolean TRACE = false;
+
+ private VirtualMachine vm = null;
+
+ /**
+ * Constructor
+ *
+ * @param vm the underlying {@link VirtualMachine}
+ */
+ public MirrorImpl(VirtualMachine vm) {
+ this.vm = vm;
+ }
+
+ /**
+ * Constructor
+ *
+ * Used for the {@link VirtualMachineImpl} instantiation case
+ */
+ protected MirrorImpl() {
+ this.vm = (VirtualMachine) this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.Mirror#virtualMachine()
+ */
+ public VirtualMachine virtualMachine() {
+ return vm;
+ }
+
+ /**
+ * Returns the {@link VMImpl} backing this {@link Mirror} object
+ *
+ * @return the backing {@link VMImpl}
+ */
+ protected VirtualMachineImpl jsd2VM() {
+ return (VirtualMachineImpl)vm;
+ }
+
+ /**
+ * Re-throws the given exception as a {@link RuntimeException} with the given message
+ * @param message
+ * @param t
+ */
+ protected void handleException(String message, Throwable t) {
+ throw new RuntimeException(message, t);
+ }
+
+ /**
+ * Enables / Disables tracing in the all of the JSDI implementations
+ *
+ * @param trace
+ */
+ public static void setTracing(boolean trace) {
+ TRACE = trace;
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/NullValueImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/NullValueImpl.java
new file mode 100644
index 0000000..b730a7b
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/NullValueImpl.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.NullValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+
+/**
+ * JSD2 implementation of {@link NullValue}
+ *
+ * @since 1.0
+ */
+public class NullValueImpl extends MirrorImpl implements NullValue {
+
+ /**
+ * String representation of the value<br><br>
+ * Value is: <code>null</code>
+ */
+ public static final String NULL = "null"; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param vm the underlying {@link VirtualMachine}
+ */
+ public NullValueImpl(VirtualMachine vm) {
+ super(vm);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.Value#valueString()
+ */
+ public String valueString() {
+ return NULL;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return valueString();
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/UndefinedValueImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/UndefinedValueImpl.java
new file mode 100644
index 0000000..9ae31db
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/UndefinedValueImpl.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi;
+
+import org.eclipse.wst.jsdt.debug.core.jsdi.UndefinedValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+
+/**
+ * Default implementation of {@link UndefinedValue} for JSD2.
+ *
+ * @since 1.0
+ */
+public class UndefinedValueImpl extends MirrorImpl implements UndefinedValue {
+
+ /**
+ * Textual representation of undefined<br><br>
+ * value is: <code>undefined</code>
+ */
+ public static final String UNDEFINED = "undefined"; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param vm the underlying {@link VirtualMachine}
+ */
+ public UndefinedValueImpl(VirtualMachine vm) {
+ super(vm);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.Value#valueString()
+ */
+ public String valueString() {
+ return UNDEFINED;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return valueString();
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/VirtualMachineImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/VirtualMachineImpl.java
new file mode 100644
index 0000000..746f685
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/jsdi/VirtualMachineImpl.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptBreakpoint;
+import org.eclipse.wst.jsdt.debug.core.jsdi.BooleanValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.NullValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.NumberValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.StringValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.UndefinedValue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine;
+import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventQueue;
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequestManager;
+import org.eclipse.wst.jsdt.debug.transport.DebugSession;
+
+/**
+ * The JSD2 implementation of a {@link VirtualMachine}
+ * @since 1.0
+ */
+public class VirtualMachineImpl implements VirtualMachine {
+
+ final NullValue fNullValue = new NullValueImpl(this);
+ final UndefinedValue fUndefinedValue = new UndefinedValueImpl(this);
+
+ /**
+ * The backing debug session
+ */
+ DebugSession fSession = null;
+
+ private Map fThreads = null;
+ private Map fScripts = null;
+
+ /**
+ * Constructor
+ * @param session
+ */
+ public VirtualMachineImpl(DebugSession session) {
+ fSession = session;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#resume()
+ */
+ public void resume() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#suspend()
+ */
+ public void suspend() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#terminate()
+ */
+ public void terminate() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#name()
+ */
+ public String name() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#description()
+ */
+ public String description() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#version()
+ */
+ public String version() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#allThreads()
+ */
+ public List/*<ThreadReference>*/ allThreads() {
+ if(fThreads == null) {
+ fThreads = Collections.synchronizedMap(new HashMap());
+ }
+ return new ArrayList(fThreads.values());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#allScripts()
+ */
+ public List/*<ScriptReference>*/ allScripts() {
+ if(fScripts == null) {
+ fScripts = Collections.synchronizedMap(new HashMap());
+ }
+ return new ArrayList(fScripts.values());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#dispose()
+ */
+ public void dispose() {
+ if(fScripts != null) {
+ fScripts.clear();
+ fScripts = null;
+ }
+ if(fThreads != null) {
+ fThreads.clear();
+ fThreads = null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#mirrorOfUndefined()
+ */
+ public UndefinedValue mirrorOfUndefined() {
+ return fUndefinedValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#mirrorOfNull()
+ */
+ public NullValue mirrorOfNull() {
+ return fNullValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#mirrorOf(boolean)
+ */
+ public BooleanValue mirrorOf(boolean bool) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#mirrorOf(java.lang.Number)
+ */
+ public NumberValue mirrorOf(Number number) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#mirrorOf(java.lang.String)
+ */
+ public StringValue mirrorOf(String string) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#eventRequestManager()
+ */
+ public EventRequestManager eventRequestManager() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#eventQueue()
+ */
+ public EventQueue eventQueue() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#canUpdateBreakpoints()
+ */
+ public boolean canUpdateBreakpoints() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.jsdi.VirtualMachine#updateBreakpoint(org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptBreakpoint)
+ */
+ public void updateBreakpoint(IJavaScriptBreakpoint breakpoint) {
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/Attributes.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/Attributes.java
new file mode 100644
index 0000000..31e6363
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/Attributes.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+/**
+ * Interface for all the attribute constants
+ *
+ * @since 1.0
+ */
+public interface Attributes {
+
+ /**
+ * The "to" attribute
+ */
+ public static final String TO = "to"; //$NON-NLS-1$
+ /**
+ * The "from" attribute
+ */
+ public static final String FROM = "from"; //$NON-NLS-1$
+ /**
+ * The "type" attribute
+ */
+ public static final String TYPE = "type"; //$NON-NLS-1$
+
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/EventPacketImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/EventPacketImpl.java
new file mode 100644
index 0000000..4da3cd9
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/EventPacketImpl.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.wst.jsdt.debug.transport.packet.Event;
+
+/**
+ * Default event implementation for JSD2
+ *
+ * @since 1.0
+ */
+public class EventPacketImpl extends PacketImpl implements Event {
+
+ /**
+ * The type of this packet
+ */
+ public static final String EVENT = "event"; //$NON-NLS-1$
+ /**
+ * The name of the event
+ */
+ final String fEvent;
+ /**
+ * The body of the event
+ */
+ final Map fBody;
+
+ /**
+ * Constructor
+ */
+ public EventPacketImpl(String event) {
+ super(EVENT);
+ fEvent = event;
+ fBody = Collections.synchronizedMap(new HashMap());
+ }
+
+ /**
+ * Constructor
+ *
+ * @param json
+ */
+ public EventPacketImpl(Map json) {
+ super(json);
+ fEvent = (String) json.get(EVENT);
+ Assert.isNotNull(fEvent, Messages.EventPacketImpl_cannot_create_event_packet_null_event_name);
+ //TODO collect the body from the JSON properly
+ fBody = Collections.synchronizedMap(new HashMap());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Event#getEvent()
+ */
+ public String getEvent() {
+ return fEvent;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Event#getBody()
+ */
+ public Map getBody() {
+ return fBody;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.internal.crossfire.transport.CFPacket#toJSON()
+ */
+ public Map toJSON() {
+ Map json = new HashMap();
+ json.put(EVENT, fEvent);
+ if(fBody != null && fBody.size() > 0) {
+ //TODO add the body spec
+ }
+ return json;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Object json = toJSON();
+ buffer.append("EventPacketImpl: "); //$NON-NLS-1$
+ JSON.writeValue(json, buffer);
+ return buffer.toString();
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/JSON.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/JSON.java
new file mode 100644
index 0000000..7b3f219
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/JSON.java
@@ -0,0 +1,540 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+import java.math.BigDecimal;
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.internal.jsd2.Tracing;
+import org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi.NullValueImpl;
+import org.eclipse.wst.jsdt.debug.internal.jsd2.jsdi.UndefinedValueImpl;
+
+/**
+ * Class for reading / writing JSON objects
+ * <br><br>
+ * Crossfire has the following types:
+ * <ul>
+ * <li>object</li>
+ * <li>function</li>
+ * <li>boolean</li>
+ * <li>number</li>
+ * <li>string</li>
+ * <li>undefined</li>
+ * <li>ref</li>
+ * </ul>
+ * @since 1.0
+ */
+public final class JSON {
+
+ static boolean TRACE = false;
+
+ /**
+ * Standard line feed / control feed terminus for Crossfire packets
+ */
+ public static final String LINE_FEED = "\r\n"; //$NON-NLS-1$
+ /**
+ * The default <code>Content-Length:</code> preamble
+ */
+ public static final String CONTENT_LENGTH = "Content-Length:"; //$NON-NLS-1$
+ /**
+ * Enables / Disables tracing in the all of the JSDI implementations
+ *
+ * @param trace
+ */
+ public static void setTracing(boolean trace) {
+ TRACE = trace;
+ }
+
+ /**
+ * Constructor
+ *
+ * No instantiation
+ */
+ private JSON() {}
+
+ /**
+ * Writes the given key / value pair to the buffer in the form: <code>"key":["]value["]</code>
+ *
+ * @param key
+ * @param value
+ * @param buffer
+ */
+ public static void writeKeyValue(String key, Object value, StringBuffer buffer) {
+ writeString(key, buffer);
+ buffer.append(':');
+ writeValue(value, buffer);
+ }
+
+ /**
+ * Writes out the given value to the buffer. <br><br>
+ * Values are written out as:
+ * <ul>
+ * <li>Boolean / Number: <code>value.toString()</code></li>
+ * <li>String: <code>"value"</code></li>
+ * <li>null: <code>null</code>
+ * <li>Collection: <code>[{@link #writeValue(Object, StringBuffer)},...]</code></li>
+ * <li>Map: <code>{"key":{@link #writeValue(Object, StringBuffer)},...}</code></li>
+ * </ul>
+ *
+ * @param value
+ * @param buffer
+ */
+ public static void writeValue(Object value, StringBuffer buffer) {
+ if (value == null) {
+ buffer.append(NullValueImpl.NULL);
+ }
+ else if (value instanceof Boolean || value instanceof Number) {
+ buffer.append(value.toString());
+ }
+ else if (value instanceof String) {
+ writeString((String) value, buffer);
+ }
+ else if(value instanceof Collection) {
+ writeArray((Collection) value, buffer);
+ }
+ else if(value instanceof Map) {
+ writeObject((Map) value, buffer);
+ }
+ }
+
+ /**
+ * Writes the given {@link String} into the given {@link StringBuffer} properly escaping
+ * all control characters
+ *
+ * @param string
+ * @param buffer
+ */
+ public static void writeString(String string, StringBuffer buffer) {
+ buffer.append('"');
+ int length = string.length();
+ for (int i = 0; i < length; i++) {
+ char c = string.charAt(i);
+ switch (c) {
+ case '"' :
+ case '\\' :
+ case '/' : {
+ buffer.append('\\');
+ buffer.append(c);
+ break;
+ }
+ case '\b' : {
+ buffer.append("\\b"); //$NON-NLS-1$
+ break;
+ }
+ case '\f' : {
+ buffer.append("\\f"); //$NON-NLS-1$
+ break;
+ }
+ case '\n' : {
+ buffer.append("\\n"); //$NON-NLS-1$
+ break;
+ }
+ case '\r' : {
+ buffer.append("\\r"); //$NON-NLS-1$
+ break;
+ }
+ case '\t' : {
+ buffer.append("\\t"); //$NON-NLS-1$
+ break;
+ }
+ default :
+ if (Character.isISOControl(c)) {
+ buffer.append("\\u"); //$NON-NLS-1$
+ String hexString = Integer.toHexString(c);
+ for (int j = hexString.length(); j < 4; j++) {
+ buffer.append('0');
+ }
+ buffer.append(hexString);
+ } else {
+ buffer.append(c);
+ }
+ }
+ }
+ buffer.append('"');
+ }
+
+ /**
+ * Writes the given collection into an array string of the form: <code>[{@link #writeValue(Object, StringBuffer)},...]</code>
+ *
+ * @param collection
+ * @param buffer
+ */
+ static void writeArray(Collection collection, StringBuffer buffer) {
+ buffer.append('[');
+ for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
+ writeValue(iterator.next(), buffer);
+ if(iterator.hasNext()) {
+ buffer.append(',');
+ }
+ }
+ buffer.append(']');
+ }
+
+ /**
+ * Writes an object mapping to the given buffer in the form: <code>{"key":{@link #writeValue(Object, StringBuffer)},...}</code>
+ *
+ * @param map
+ * @param buffer
+ */
+ public static void writeObject(Map map, StringBuffer buffer) {
+ buffer.append('{');
+ for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
+ String key = (String) iterator.next();
+ writeString(key, buffer);
+ buffer.append(':');
+ writeValue(map.get(key), buffer);
+ if(iterator.hasNext()) {
+ buffer.append(',');
+ }
+ }
+ buffer.append('}');
+ }
+
+ /**
+ * Writes the <code>Content-Length:N</code> preamble to the head of the given buffer
+ *
+ * @param buffer
+ * @param length
+ */
+ public static void writeContentLength(StringBuffer buffer, int length) {
+ StringBuffer buff = new StringBuffer(18);
+ buff.append(CONTENT_LENGTH).append(length).append(LINE_FEED).append(LINE_FEED);
+ buffer.insert(0, buff.toString());
+ }
+
+ /**
+ * Serializes the given {@link PacketImpl} to a {@link String}
+ *
+ * @param packet the packet to serialize
+ *
+ * @return the serialized {@link String}, never <code>null</code>
+ */
+ public static String serialize(PacketImpl packet) {
+ Object json = packet.toJSON();
+ StringBuffer buffer = new StringBuffer();
+ writeValue(json, buffer);
+ int length = buffer.length();
+ writeContentLength(buffer, length);
+ buffer.append(LINE_FEED);
+ if(TRACE) {
+ Tracing.writeString("SERIALIZE: " + packet.getType() +" packet as "+buffer.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Reads and returns a new object from the given JSON {@link String}. This method
+ * will throw an {@link IllegalStateException} if parsing fails.
+ *
+ * @param jsonString
+ * @return the object, never <code>null</code>
+ */
+ public static Object read(String jsonString) {
+ return parse(new StringCharacterIterator(jsonString));
+ }
+
+ /**
+ * Reads and returns a new object form the given {@link CharacterIterator} that corresponds to
+ * a properly formatted JSON string. This method will throw an {@link IllegalStateException} if
+ * parsing fails.
+ *
+ * @param it the {@link CharacterIterator} to parse
+ * @return the object, never <code>null</code>
+ */
+ public static Object parse(CharacterIterator it) {
+ parseWhitespace(it);
+ Object result = parseValue(it);
+ parseWhitespace(it);
+ if (it.current() != CharacterIterator.DONE) {
+ throw error("should be done", it); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /**
+ * Creates an {@link IllegalStateException} for the given message and iterator
+ *
+ * @param message the message for the exception
+ * @param it the {@link CharacterIterator} to parse
+ *
+ * @return a new {@link IllegalStateException}
+ */
+ private static RuntimeException error(String message, CharacterIterator it) {
+ return new IllegalStateException("[" + it.getIndex() + "] " + message); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ /**
+ * Chews up whitespace from the iterator
+ *
+ * @param it the {@link CharacterIterator} to parse
+ */
+ private static void parseWhitespace(CharacterIterator it) {
+ char c = it.current();
+ while (Character.isWhitespace(c)) {
+ c = it.next();
+ }
+ }
+
+ /**
+ * Parses the {@link Object} from the {@link CharacterIterator}. This method
+ * delegates to the proper parsing method depending on the current iterator context.
+ * This method will throw an {@link IllegalStateException} if parsing fails.
+ *
+ * @param it the {@link CharacterIterator} to parse
+ *
+ * @return the new object, never <code>null</code>
+ * @see #parseString(CharacterIterator)
+ * @see #parseNumber(CharacterIterator)
+ * @see #parseArray(CharacterIterator)
+ * @see #parseObject(CharacterIterator)
+ */
+ private static Object parseValue(CharacterIterator it) {
+ switch (it.current()) {
+ case '{' : {
+ return parseObject(it);
+ }
+ case '[' : {
+ return parseArray(it);
+ }
+ case '"' : {
+ return parseString(it);
+ }
+ case '-' :
+ case '0' :
+ case '1' :
+ case '2' :
+ case '3' :
+ case '4' :
+ case '5' :
+ case '6' :
+ case '7' :
+ case '8' :
+ case '9' : {
+ return parseNumber(it);
+ }
+ case 't' : {
+ parseText(Boolean.TRUE.toString(), it);
+ return Boolean.TRUE;
+ }
+ case 'f' : {
+ parseText(Boolean.FALSE.toString(), it);
+ return Boolean.FALSE;
+ }
+ case 'n' : {
+ parseText(NullValueImpl.NULL, it);
+ return null;
+ }
+ case 'u': {
+ parseText(UndefinedValueImpl.UNDEFINED, it);
+ return null;
+ }
+ }
+ throw error("Bad JSON starting character '" + it.current() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$;
+ }
+
+ /**
+ * Parses the JSON string from the {@link CharacterIterator}
+ *
+ * @param it the {@link CharacterIterator} to parse
+ * @return the JSON {@link String}, never <code>null</code>
+ */
+ private static String parseString(CharacterIterator it) {
+ char c = it.next();
+ if (c == '"') {
+ it.next();
+ return ""; //$NON-NLS-1$
+ }
+ StringBuffer buffer = new StringBuffer();
+ while (c != CharacterIterator.DONE && c != '"') {
+ if (Character.isISOControl(c)) {
+ //ignore it and continue
+ c = it.next();
+ continue;
+ //throw error("illegal ISO control character: '" + Integer.toHexString(c) + "'", it); //$NON-NLS-1$ //$NON-NLS-2$);
+ }
+ if (c == '\\') {
+ c = it.next();
+ switch (c) {
+ case '"' :
+ case '\\' :
+ case '/' : {
+ buffer.append(c);
+ break;
+ }
+ case 'b' : {
+ buffer.append('\b');
+ break;
+ }
+ case 'f' : {
+ buffer.append('\f');
+ break;
+ }
+ case 'n' : {
+ buffer.append('\n');
+ break;
+ }
+ case 'r' : {
+ buffer.append('\r');
+ break;
+ }
+ case 't' : {
+ buffer.append('\t');
+ break;
+ }
+ case 'u' : {
+ StringBuffer unicode = new StringBuffer(4);
+ for (int i = 0; i < 4; i++) {
+ unicode.append(it.next());
+ }
+ try {
+ buffer.append((char) Integer.parseInt(unicode.toString(), 16));
+ } catch (NumberFormatException e) {
+ throw error("expected a unicode hex number but was '" + unicode.toString() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$););
+ }
+ break;
+ }
+ default : {
+ throw error("illegal escape character '" + c + "'", it); //$NON-NLS-1$ //$NON-NLS-2$););
+ }
+ }
+ } else {
+ buffer.append(c);
+ }
+ c = it.next();
+ }
+ c = it.next();
+ return buffer.toString();
+ }
+
+ /**
+ * Parses an {@link Map} object from the iterator or throws an
+ * {@link IllegalStateException} if parsing fails.
+ *
+ * @param it the {@link CharacterIterator} to parse
+ * @return a new {@link Map} object, never <code>null</code>
+ */
+ private static Map parseObject(CharacterIterator it) {
+ it.next();
+ parseWhitespace(it);
+ if (it.current() == '}') {
+ it.next();
+ return Collections.EMPTY_MAP;
+ }
+
+ Map map = new HashMap();
+ while (it.current() != CharacterIterator.DONE) {
+ if (it.current() != '"') {
+ throw error("expected a string start '\"' but was '" + it.current() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ String key = parseString(it);
+ if (map.containsKey(key)) {
+ throw error("' already defined" + "key '" + key, it); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ parseWhitespace(it);
+ if (it.current() != ':') {
+ throw error("expected a pair separator ':' but was '" + it.current() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ it.next();
+ parseWhitespace(it);
+ Object value = parseValue(it);
+ map.put(key, value);
+ parseWhitespace(it);
+ if (it.current() == ',') {
+ it.next();
+ parseWhitespace(it);
+ continue;
+ }
+ if (it.current() != '}') {
+ throw error("expected an object close '}' but was '" + it.current() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ break;
+ }
+ it.next();
+ return map;
+ }
+
+ /**
+ * Parses an {@link ArrayList} from the given iterator or throws an
+ * {@link IllegalStateException} if parsing fails
+ *
+ * @param it the {@link CharacterIterator} to parse
+ * @return a new {@link ArrayList} object never <code>null</code>
+ */
+ private static List parseArray(CharacterIterator it) {
+ it.next();
+ parseWhitespace(it);
+ if (it.current() == ']') {
+ it.next();
+ return Collections.EMPTY_LIST;
+ }
+
+ List list = new ArrayList();
+ while (it.current() != CharacterIterator.DONE) {
+ Object value = parseValue(it);
+ list.add(value);
+ parseWhitespace(it);
+ if (it.current() == ',') {
+ it.next();
+ parseWhitespace(it);
+ continue;
+ }
+ if (it.current() != ']') {
+ throw error("expected an array close ']' but was '" + it.current() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ break;
+ }
+ it.next();
+ return list;
+ }
+
+ /**
+ * @param string
+ * @param it
+ */
+ private static void parseText(String string, CharacterIterator it) {
+ int length = string.length();
+ char c = it.current();
+ for (int i = 0; i < length; i++) {
+ if (c != string.charAt(i)) {
+ throw error("expected to parse '" + string + "' but character " + (i + 1) + " was '" + c + "'", it); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$;
+ }
+ c = it.next();
+ }
+ }
+
+ /**
+ * Parses a {@link Number} object from the given {@link CharacterIterator}
+ *
+ * @param it
+ * @return a new {@link Number}, never <code>null</code>
+ */
+ private static Object parseNumber(CharacterIterator it) {
+ StringBuffer buffer = new StringBuffer();
+ char c = it.current();
+ while (Character.isDigit(c) || c == '-' || c == '+' || c == '.' || c == 'e' || c == 'E') {
+ buffer.append(c);
+ c = it.next();
+ }
+ try {
+ return new BigDecimal(buffer.toString());
+ } catch (NumberFormatException e) {
+ throw error("expected a number but was '" + buffer.toString() + "'", it); //$NON-NLS-1$ //$NON-NLS-2$;
+ }
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/Messages.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/Messages.java
new file mode 100644
index 0000000..74368b4
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/Messages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.wst.jsdt.debug.internal.jsd2.transport.messages"; //$NON-NLS-1$
+ public static String EventPacketImpl_cannot_create_event_packet_null_event_name;
+ public static String PacketImpl_cannot_create_packet_null_json;
+ public static String PacketImpl_cannot_create_packet_null_type;
+ public static String RequestPacketImpl_cannot_create_request_packet_null_command;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/PacketImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/PacketImpl.java
new file mode 100644
index 0000000..eb6c4a2
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/PacketImpl.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.wst.jsdt.debug.transport.packet.Packet;
+
+/**
+ * Basic implementation of a packet for JSD2
+ *
+ * @since 1.0
+ */
+public abstract class PacketImpl implements Packet {
+
+ String fType = null;
+
+ /**
+ * Constructor
+ *
+ * @param type the type of the packet
+ */
+ public PacketImpl(String type) {
+ fType = type;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param json the JSON from the connection
+ */
+ public PacketImpl(Map json) {
+ Assert.isNotNull(json, Messages.PacketImpl_cannot_create_packet_null_json);
+ fType = getType(json);
+ Assert.isNotNull(fType, Messages.PacketImpl_cannot_create_packet_null_type);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Packet#getType()
+ */
+ public String getType() {
+ return fType;
+ }
+
+ /**
+ * Returns the type from the given JSON map.<br>
+ * <br>
+ * This method can return <code>null</code> if the map is not correctly
+ * formed.
+ *
+ * @param json the JSON map, <code>null</code> is not accepted
+ * @return the type from the JSON map or <code>null</code>
+ */
+ public static String getType(Map json) {
+ if(json == null) {
+ throw new IllegalArgumentException("A null JSON map is not allowed when trying to get the packet type"); //$NON-NLS-1$
+ }
+ String type = (String) json.get(Attributes.TO);
+ if(type == null) {
+ type = (String) json.get(Attributes.FROM);
+ }
+ if(type == null) {
+ }
+ return type;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Object json = toJSON();
+ buffer.append("PacketImpl: "); //$NON-NLS-1$
+ JSON.writeValue(json, buffer);
+ return buffer.toString();
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/RequestPacketImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/RequestPacketImpl.java
new file mode 100644
index 0000000..8d1db3c
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/RequestPacketImpl.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.wst.jsdt.debug.transport.packet.Request;
+
+/**
+ * Default request implementation for JSD2
+ *
+ * @since 1.0
+ */
+public class RequestPacketImpl extends PacketImpl implements Request {
+
+ /**
+ * The overall sequence number for all request packets
+ */
+ static int currentSequence = 0;
+ /**
+ * the current sequence for this request packet
+ */
+ final int fSequence;
+ /**
+ * The command for this request
+ */
+ String fCommand = null;
+
+ /**
+ * Constructor
+ * @param command
+ */
+ public RequestPacketImpl(String command) {
+ super(Attributes.TO);
+ fCommand = command;
+ fSequence = incSeqence();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param json
+ */
+ public RequestPacketImpl(Map json) {
+ super(json);
+ fCommand = (String) json.get(Attributes.TYPE);
+ Assert.isNotNull(fCommand, Messages.RequestPacketImpl_cannot_create_request_packet_null_command);
+ //TODO collect this from the packet if we end up storing it in there
+ fSequence = incSeqence();
+ }
+
+ /**
+ * Creates a new sequence number for all request packets
+ * @return the new request identifier
+ */
+ static int incSeqence() {
+ return ++currentSequence;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Packet#toJSON()
+ */
+ public Map toJSON() {
+ Map json = new HashMap();
+ json.put(Attributes.TYPE, fCommand);
+ //TODO add all supported JSD2 attributes
+ //TODO also decide if we want to pass the sequence along
+ return json;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getCommand()
+ */
+ public String getCommand() {
+ return fCommand;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getSequence()
+ */
+ public int getSequence() {
+ return fSequence;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Request#getArguments()
+ */
+ public Map getArguments() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Object json = toJSON();
+ buffer.append("RequestPacketImpl: "); //$NON-NLS-1$
+ JSON.writeValue(json, buffer);
+ return buffer.toString();
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/ResponsePacketImpl.java b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/ResponsePacketImpl.java
new file mode 100644
index 0000000..c09f6bb
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/ResponsePacketImpl.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.jsd2.transport;
+
+import java.util.Map;
+
+import org.eclipse.wst.jsdt.debug.transport.packet.Response;
+
+/**
+ * Default response packet implementation for JSD2
+ *
+ * @since 1.0
+ */
+public class ResponsePacketImpl extends PacketImpl implements Response {
+
+ /**
+ * The name of the command from the original request
+ */
+ String fCommand;
+
+ /**
+ * Constructor
+ *
+ * @param command
+ */
+ public ResponsePacketImpl(String command) {
+ super(Attributes.FROM);
+ fCommand = command;
+ }
+
+ /**
+ * Constructor
+ * @param json
+ */
+ public ResponsePacketImpl(Map json) {
+ super(json);
+ fCommand = (String) json.get(Attributes.TYPE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getCommand()
+ */
+ public String getCommand() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getRequestSequence()
+ */
+ public int getRequestSequence() {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#getBody()
+ */
+ public Map getBody() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#isSuccess()
+ */
+ public boolean isSuccess() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Response#isRunning()
+ */
+ public boolean isRunning() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.transport.packet.Packet#toJSON()
+ */
+ public Map toJSON() {
+ return null;
+ }
+}
diff --git a/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/messages.properties b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/messages.properties
new file mode 100644
index 0000000..85d8c80
--- /dev/null
+++ b/development/org.eclipse.wst.jsdt.debug.jsd2/src/org/eclipse/wst/jsdt/debug/internal/jsd2/transport/messages.properties
@@ -0,0 +1,4 @@
+EventPacketImpl_cannot_create_event_packet_null_event_name=You cannot create a new event packet with a null event name
+PacketImpl_cannot_create_packet_null_json=You cannot create a new packet from a null JSON mapping
+PacketImpl_cannot_create_packet_null_type=You cannot create a new packet with a null type
+RequestPacketImpl_cannot_create_request_packet_null_command=You cannot create a new request packet with a null command name