diff --git a/support/proxy/vwf.example.com/assert.js b/support/proxy/vwf.example.com/assert.js new file mode 100644 index 000000000..572d77717 --- /dev/null +++ b/support/proxy/vwf.example.com/assert.js @@ -0,0 +1,29 @@ +// Copyright 2014 Lockheed Martin Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +this.assert = function( value, message, dontHalt ) { + if ( !value ) { + if ( message ) { + this.logger.errorx( "assert", message ); + } else { + this.logger.errorx( "assert", "Assert failed!" ); + } + + if ( !dontHalt ) { + debugger; + } + } +} + +//@ sourceURL=http://vwf.example.com/assert.js diff --git a/support/proxy/vwf.example.com/assert.vwf.yaml b/support/proxy/vwf.example.com/assert.vwf.yaml new file mode 100644 index 000000000..d29cb91b1 --- /dev/null +++ b/support/proxy/vwf.example.com/assert.vwf.yaml @@ -0,0 +1,28 @@ +# Copyright 2014 Lockheed Martin Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- + +methods: + + # A C++ style assert + # NOTE: these only fire if you have the console open. + # Arguments: + # value - the value we're checking. If true, we log and halt. + # message - the message to log if the assert fails. Optional. + # dontHalt - if true, we just log the message. Optional. + assert: + +scripts: +- source: "http://vwf.example.com/assert.js" \ No newline at end of file diff --git a/support/proxy/vwf.example.com/sceneGetter.js b/support/proxy/vwf.example.com/sceneGetter.js new file mode 100644 index 000000000..575232fad --- /dev/null +++ b/support/proxy/vwf.example.com/sceneGetter.js @@ -0,0 +1,72 @@ +// Copyright 2014 Lockheed Martin Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +this.findInScene = function( objName, errorOnNotFound, warnOnTooMany ) { + if ( errorOnNotFound === undefined ) { + errorOnNotFound = true; + } + + if ( warnOnTooMany === undefined ) { + warnOnTooMany = true; + } + + if ( !this.scene ) { + this.logger.errorx( "findInScene", "Scene is undefined!" ); + return undefined; + } + + var results = this.scene.find( "//" + objName ); + + if ( errorOnNotFound && ( results.length < 1 ) ) { + this.logger.errorx( "findInScene", "Object '" + objName + + "' not found" ); + } else if ( warnOnTooMany && ( results.length > 1 ) ) { + this.logger.warnx( "findInScene", "Multiple objects named '" + + objName + "' found. Names should really " + + "be unique... but we'll return the first one." ); + } + + return results[ 0 ]; +} + +this.findTypeInScene = function( typeName, errorOnNotFound, + warnOnTooMany ) { + if ( errorOnNotFound === undefined ) { + errorOnNotFound = true; + } + + if ( warnOnTooMany === undefined ) { + warnOnTooMany = true; + } + + if (!this.scene) { + this.logger.errorx( "findTypeInScene", "Scene is undefined!" ); + return undefined; + } + + var results = this.scene.find( ".//element(*,'" + typeName + "')" ); + + if ( errorOnNotFound && ( results.length < 1 ) ) { + this.logger.errorx( "findTypeInScene", "Nothing found with type '" + + typeName + "'." ); + } else if ( warnOnTooMany && ( results.length > 1 ) ) { + this.logger.warnx( "findTypeInScene", "Multiple objects of type '" + + typeName + "' found. We'll return the first " + + "one." ); + } + + return results[ 0 ]; +} + +//@ sourceURL=http://vwf.example.com/sceneGetter.js diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 109f9bd2c..3f48065e0 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -18,7 +18,18 @@ properties: scene: get: | if ( !this.scene ) { - this.scene = this.find( this.scenePath || "/" )[ 0 ]; + var sp = this.scenePath || "/"; + this.scene = this.find( sp )[ 0 ]; + // If this is the prototype object then it will think that it is the + // scene (because it is directly attached to the root) - in that case, + // we want to make sure that we don't incorrectly set this.scene, so + // just short-circuit and return undefined. + if ( this.scene === this ) { + this.scene = undefined; + } else if ( !this.scene ) { + this.logger.errorx( "scene.get", + "Could not find scene node: '" + sp + "'" ); + } } return this.scene; //@ sourceURL=sceneGetter.scene.get @@ -31,3 +42,32 @@ properties: // Nullify the current scene so that next time it is gotten, it will find it from the new path this.scene = null; //@ sourceURL=sceneGetter.scenePath.set + +methods: + + # A helper that does basically what Find does, except that it handles some of + # the busywork (and assumes that we'll be looking in the scene). + # NOTE: THIS ONLY GETS THE FIRST OBJECT FOUND. If you want the whole array, + # you'll need to extend this function (or write another). + # Arguments: + # objectName - the name of the object to search for + # errorOnNotFound - if true (the default) we log an error if the object is + # not found. + # warnOnTooMany - if true (the default) we log a warning if more than one + # object is found. + findInScene: + + # Same as findInScene, except that this looks by type rather than by name. + # NOTE: THIS ONLY GETS THE FIRST OBJECT FOUND. If you want the whole array, + # you'll need to extend this function (or write another). + # Arguments: + # typeName - the type to search for (where the "type" is the filename + # that the object extends). + # errorOnNotFound - if true (the default) we log an error if the object is + # not found. + # warnOnTooMany - if true (the default) we log a warning if more than one + # object is found. + findTypeInScene: + +scripts: +- source: "http://vwf.example.com/sceneGetter.js"