Java Code Examples for org.mozilla.javascript.Scriptable#NOT_FOUND

The following examples show how to use org.mozilla.javascript.Scriptable#NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Environment.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Object get(String name, Scriptable start) {
    if (this == thePrototypeInstance)
        return super.get(name, start);

    String result = System.getProperty(name);
    if (result != null)
        return ScriptRuntime.toObject(getParentScope(), result);
    else
        return Scriptable.NOT_FOUND;
}
 
Example 2
Source File: AppRunnerInterpreter.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public Object getObject(String name) {
    Object obj = scope.get(name, scope);
    if (obj == Scriptable.NOT_FOUND) {
        return null;
    }
    return obj;
}
 
Example 3
Source File: Environment.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object get(String name, Scriptable start) {
    if (this == thePrototypeInstance)
        return super.get(name, start);

    String result = System.getProperty(name);
    if (result != null)
        return ScriptRuntime.toObject(getParentScope(), result);
    else
        return Scriptable.NOT_FOUND;
}
 
Example 4
Source File: CrosstabScriptHandler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the JavaScript funtion by given name.
 * 
 * @param sFunctionName
 *            The name of the function to be searched for
 * @return An instance of the function being searched for or null if it
 *         isn't found
 */
private Function getJavascriptFunction( String sFunctionName )
{
	// TODO impl real function cache

	// use names cache for quick validation to improve performance
	if ( javaScriptFunctionNamesCache == null
			|| javaScriptFunctionNamesCache.indexOf( sFunctionName ) < 0 )
	{
		return null;
	}

	Context.enter( );
	try
	{
		final Object oFunction = scope.get( sFunctionName, scope );
		if ( oFunction != Scriptable.NOT_FOUND
				&& oFunction instanceof Function )
		{
			return (Function) oFunction;
		}
		return null;
	}
	finally
	{
		Context.exit( );
	}
}
 
Example 5
Source File: AbstractScriptHandler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the JavaScript funtion by given name.
 * 
 * @param sFunctionName
 *            The name of the function to be searched for
 * @return An instance of the function being searched for or null if it
 *         isn't found
 */
private final Function getJavascriptFunction( String sFunctionName )
{
	// TODO: CACHE PREVIOUSLY CREATED FUNCTION REFERENCES IN A HASHTABLE?

	// use names cache for quick validation to improve performance
	if ( javaScriptFunctionNamesCache == null
			|| javaScriptFunctionNamesCache.indexOf( sFunctionName ) < 0 )
	{
		return null;
	}

	Context.enter( );
	try
	{
		final Object oFunction = scope.get( sFunctionName, scope );
		if ( oFunction != Scriptable.NOT_FOUND
				&& oFunction instanceof Function )
		{
			return (Function) oFunction;
		}
		return null;
	}
	finally
	{
		Context.exit( );
	}
}
 
Example 6
Source File: JsValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
static boolean isValidJsValue( Object val )
{
	return ( val != Scriptable.NOT_FOUND
			&& !( val instanceof Undefined )
			&& !( val instanceof NativeJavaMethod )
			&& !( val instanceof NativeJavaConstructor ) && !( val instanceof NativeJavaPackage ) );

}
 
Example 7
Source File: NativeJavaLinkedHashMap.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public Object get( int index, Scriptable start )
{
	List list = new ArrayList( ( (Map) javaObject ).values( ) );
	if ( list.size( ) > index )
		return list.get( index );

	return Scriptable.NOT_FOUND;
}
 
Example 8
Source File: JSAcceptFacet.java    From emissary with Apache License 2.0 4 votes vote down vote up
/**
 * Test the specified payload and itinerary entries for acceptance. Itinerary steps will be removed from the list if
 * they are not accepted.
 *
 * @param payload the data object being routed
 * @param itinerary list of keys selected so far, can be modified
 */
public void accept(final IBaseDataObject payload, final List<DirectoryEntry> itinerary) {
    // Check conditions
    if (payload == null || itinerary == null) {
        logger.debug("Cannot operate on null payload or null itinerary");
        return;
    }

    if (itinerary.size() == 0) {
        return;
    }

    final Context ctx = this.contextFactory.enterContext();
    try {
        // One standard scope will do
        final Scriptable scope = makeAcceptFacetScope(ctx);

        // Get a function for each itinerary key present
        // and call the accept method on it
        // nb: no enhanced for loop due to i.remove() below
        for (Iterator<DirectoryEntry> i = itinerary.iterator(); i.hasNext();) {
            final DirectoryEntry de = i.next();
            logger.debug("Looking at itinerary item " + de.getKey());
            final Function func = getFunction(de);
            if (func == null) {
                continue;
            }

            MDC.put(MDCConstants.SERVICE_LOCATION, getResourceName(de));
            try {
                final Object accepted = func.call(ctx, scope, scope, new Object[] {payload});

                // If the javascript function says not to accept
                // we remote the key from the itinerary here
                if (accepted != Scriptable.NOT_FOUND && Boolean.FALSE.equals(accepted)) {
                    logger.debug("Removing directory entry " + getFunctionKey(de) + " due to js function false");
                    i.remove();
                }
            } catch (Exception ex) {
                logger.warn("Unable to run function for " + getFunctionKey(de), ex);
            } finally {
                MDC.remove(MDCConstants.SERVICE_LOCATION);
            }
        }
    } finally {
        Context.exit();
    }
}
 
Example 9
Source File: ProviderFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void publishImpl(File f, String epAddr, boolean isBase) throws Exception {
    if (!f.exists()) {
        throw new Exception(f.getPath() + NO_SUCH_FILE);
    }
    boolean isE4X = f.getName().endsWith(".jsx");
    StringBuilder sb = new StringBuilder();
    try (BufferedReader bufrd = new BufferedReader(new FileReader(f))) {
        String line = null;
        for (;;) {
            line = bufrd.readLine();
            if (line == null) {
                break;
            }
            sb.append(line).append('\n');
        }
    }

    String scriptStr = sb.toString();

    Context cx = ContextFactory.getGlobal().enterContext();
    boolean providerFound = false;
    try {
        Scriptable scriptScope = cx.initStandardObjects(null, true);
        Object[] ids = compileScript(cx, scriptStr, scriptScope, f);
        if (ids.length > 0) {
            Service.Mode mode = Service.Mode.PAYLOAD;
            for (Object idObj : ids) {
                if (!(idObj instanceof String)) {
                    continue;
                }
                String id = (String)idObj;
                if (!id.startsWith("WebServiceProvider")) {
                    continue;
                }
                Object obj = scriptScope.get(id, scriptScope);
                if (!(obj instanceof Scriptable)) {
                    continue;
                }
                Scriptable wspVar = (Scriptable)obj;
                providerFound = true;
                obj = wspVar.get("ServiceMode", wspVar);
                if (obj != Scriptable.NOT_FOUND) {
                    if (obj instanceof String) {
                        String value = (String)obj;
                        if ("PAYLOAD".equalsIgnoreCase(value)) {
                            mode = Service.Mode.PAYLOAD;
                        } else if ("MESSAGE".equalsIgnoreCase(value)) {
                            mode = Service.Mode.MESSAGE;
                        } else {
                            throw new Exception(f.getPath() + ILLEGAL_SVCMD_MODE + value);
                        }
                    } else {
                        throw new Exception(f.getPath() + ILLEGAL_SVCMD_TYPE);
                    }
                }
                AbstractDOMProvider provider
                    = createProvider(mode, scriptScope, wspVar,
                                     epAddr, isBase, isE4X);
                try {
                    provider.publish();
                    providers.add(provider);
                } catch (AbstractDOMProvider.JSDOMProviderException ex) {
                    StringBuilder msg = new StringBuilder(f.getPath());
                    msg.append(": ").append(ex.getMessage());
                    throw new Exception(msg.toString());
                }
            }
        }
    } finally {
        Context.exit();
    }
    if (!providerFound) {
        throw new Exception(f.getPath() + NO_PROVIDER);
    }
}
 
Example 10
Source File: AbstractDOMProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void publish() throws Exception {
    String addr = epAddress;
    String wsdlLoc = null;
    String svcNm = null;
    String portNm = null;
    String tgtNmspc = null;
    String binding = null;
    Object obj = webSvcProviderVar.get("wsdlLocation", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_WSDL_LOCATION);
    }
    if (obj instanceof String) {
        wsdlLoc = (String)obj;
    }
    obj = webSvcProviderVar.get("serviceName", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_SERVICE_NAME);
    }
    if (obj instanceof String) {
        svcNm = (String)obj;
    }
    obj = webSvcProviderVar.get("portName", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_PORT_NAME);
    }
    if (obj instanceof String) {
        portNm = (String)obj;
    }
    obj = webSvcProviderVar.get("targetNamespace", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_TGT_NAMESPACE);
    }
    if (obj instanceof String) {
        tgtNmspc = (String)obj;
    }
    if (addr == null) {
        obj = webSvcProviderVar.get("EndpointAddress", scriptScope);
        if (obj != Scriptable.NOT_FOUND && obj instanceof String) {
            addr = (String)obj;
            isBaseAddr = false;
        }
    }
    if (addr == null) {
        throw new JSDOMProviderException(NO_EP_ADDR);
    }
    if (isBaseAddr) {
        if (addr.endsWith("/")) {
            addr += portNm;
        } else {
            addr = addr + "/" + portNm;
        }
    }
    obj = webSvcProviderVar.get("BindingType", scriptScope);
    if (obj != Scriptable.NOT_FOUND && obj instanceof String) {
        binding = (String)obj;
    }
    obj = webSvcProviderVar.get("invoke", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_INVOKE);
    }
    if (obj instanceof Function) {
        invokeFunc = (Function)obj;
    } else {
        throw new JSDOMProviderException(ILLEGAL_INVOKE_TYPE);
    }

    Bus bus = BusFactory.getThreadDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setWsdlLocation(wsdlLoc);
    factory.setBindingId(binding);
    factory.setServiceName(new QName(tgtNmspc, svcNm));
    factory.setEndpointName(new QName(tgtNmspc, portNm));
    ep = new EndpointImpl(bus, this, factory);
    ep.publish(addr);
}
 
Example 11
Source File: JavaScriptEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
     * Return an object from an extension.
     * @param object Object on which to make the call (ignored).
     * @param method The name of the method to call.
     * @param args an array of arguments to be
     * passed to the extension, which may be either
     * Vectors of Nodes, or Strings.
     */
    public Object call(Object object, String method, Object[] args)
        throws BSFException {

        Object retval = null;
        Context cx;

        try {
            cx = Context.enter();

            // REMIND: convert arg list Vectors here?

            Object fun = global.get(method, global);
            // NOTE: Source and line arguments are nonsense in a call().
            //       Any way to make these arguments *sensible?
            if (fun == Scriptable.NOT_FOUND)
                throw new EvaluatorException("function " + method +
                                             " not found.", "none", 0);

            cx.setOptimizationLevel(-1);
            cx.setGeneratingDebug(false);
            cx.setGeneratingSource(false);
            cx.setOptimizationLevel(0);
            cx.setDebugger(null, null);
            
            retval =
                ((Function) fun).call(cx, global, global, args);
            
//                ScriptRuntime.call(cx, fun, global, args, global);

            if (retval instanceof Wrapper)
                retval = ((Wrapper) retval).unwrap();
        } 
        catch (Throwable t) {
            handleError(t);
        } 
        finally {
            Context.exit();
        }
        return retval;
    }