Subversion Repositories pub

Compare Revisions

No changes between revisions

Ignore whitespace Rev 64 → Rev 65

/pluggablejs/trunk/src/net/outlyer/plugins/Internal.java
0,0 → 1,96
package net.outlyer.plugins;
 
/*
* Copyright (c) 2008, Toni Corvera. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
// $Id$
 
import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
 
/**
* This class provides centralised access to features used internally.
*/
class Internal {
 
/**
* The reserved object is the only concrete variable name reserved
* in the global namespace.
* @return $net_outlyer
*/
static String getReservedObjectName() {
return "$net_outlyer";
}
/**
* Gets the name of the runtime object
* @return
*/
static String getRuntimeObjectName() {
return getReservedObjectName()+".runtime";
}
 
/**
* Gets the name of the internal object.
* Fields of this object provide access to internal features.
*/
static String getInternalObjectName() {
return getRuntimeObjectName()+".internal";
}
 
static String getInternalObjectFieldName(final String fieldName) {
return getInternalObjectName()+"."+fieldName;
}
private static String mapName = "$_";
static String getInternalInitialisation() {
return String.format("= {\n" +
" %2$s: new java.util.HashMap(),\n" +
" set: function(n,v) {\n"+
" %1$s.put(n,v);\n" +
" return v;\n" +
" },\n" +
" get: function(n) {\n" +
" return %1$s.get(n);\n" +
" }\n"+
"};",
getInternalObjectFieldName(mapName),
mapName);
}
 
static void setInternalValue(final ScriptEngine engine,
final String name,
final Object value) throws ScriptException {
final Map map = (Map) engine.eval(getInternalObjectFieldName(mapName));
map.put(name, value);
}
 
static Object getInternalValue(final ScriptEngine e,
final String name) throws ScriptException {
final Map map = (Map) e.eval(getInternalObjectFieldName(mapName));
return map.get(name);
}
}
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property