Examples of NativeObject


Examples of org.mozilla.javascript.NativeObject

            String serviceName = serviceAnnotationParser.getServiceName();

            // Setting Axis Parameters given in serviceParameters annotation
            Object serviceParametersObject = serviceAnnotationParser.getServiceParameters();
            if (serviceParametersObject instanceof NativeObject) {
                NativeObject nativeObject = (NativeObject) serviceParametersObject;
                Object[] propertyNames = nativeObject.getIds();
                for (Object propertyNameObject : propertyNames) {
                    if (propertyNameObject instanceof String) {
                        String propertyName = (String) propertyNameObject;
                        Object propertyValueObject = nativeObject.get(propertyName, nativeObject);
                        if (propertyValueObject instanceof String) {
                            try {
                                OMFactory factory = OMAbstractFactory.getOMFactory();
                                OMElement parameterElement = factory.createOMElement("parameter", null);
                                parameterElement.addAttribute("name", propertyName, null);
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

        // If the output of the function is complex we need to get the parameter names of the
        // complex object into an array so that we can reuse the same function we use to genarate
        // schema for the input message
        if (output instanceof NativeObject) {
            NativeObject nativeObject = (NativeObject) output;
            Object[] objects = ScriptableObject.getPropertyIds(nativeObject);
            int length = objects.length;
            if (length == 0) {
                return null;
            }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

     *
     * @param params A String array that holds the parameters
     * @return NativeObject that wrapps the parameters
     */
    private NativeObject createNativeObject(String params[]) {
        NativeObject nativeObject = new NativeObject();
        for (int i = 0; i < params.length; i++) {
            NativeObject.putProperty(nativeObject, params[i].trim(), "any");
        }
        return nativeObject;
    }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

                                           String elementName,
                                           String[] params, String methodName)
            throws AxisFault {
        XmlSchemaElement xmlSchemaElement;
        if (object instanceof NativeObject) {
            NativeObject nativeObject = (NativeObject) object;
            xmlSchemaElement =
                    handleNativeObject(message, nativeObject, elementName, params, methodName);
            if (xmlSchemaElement != null) {
                message.addParameter(MashupConstants.ANNOTATED, Boolean.TRUE);
            } else {
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

            } else if (paramType instanceof String) {
                if ((xmlSchemaElement = createXMLSchemaElement(paramName, paramType)) != null) {
                    xmlSchemaSequence.getItems().add(xmlSchemaElement);
                }
            } else if (paramType instanceof NativeObject) {
                NativeObject nativeObject = (NativeObject) paramType;
                Object[] objects = ScriptableObject.getPropertyIds(nativeObject);
                String[] innerParams = new String[objects.length];
                for (int j = 0; j < objects.length; j++) {
                    Object object = objects[j];
                    if (object instanceof String) {
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

                }
            } else if (jsObject instanceof NativeObject) {
                element.addAttribute("type", "object", namespace);
                element.declareNamespace(xsiNamespace);
                element.declareNamespace(xsNamespace);
                NativeObject nativeObject = (NativeObject) jsObject;
                Object[] objects = NativeObject.getPropertyIds(nativeObject);
                for (Object object : objects) {
                    Object o;
                    if (object instanceof String) {
                        String property = (String) object;
                        o = nativeObject.get(property, nativeObject);
                        OMElement paramElement = createResponseElement(o, property, true);
                        element.addChild(paramElement);
                    }
                }
            } else if (jsObject instanceof Undefined || jsObject instanceof UniqueTag) {
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

      generatedJsExprsAsJsArray.append("]");

      Context context = new ContextFactory().enterContext();
      context.setOptimizationLevel(-1)// Only running once.
      ScriptableObject globalScope = context.initStandardObjects();
      NativeObject navigator = new NativeObject();
      ScriptableObject.putConstProperty(navigator, "userAgent", "testZilla");
      globalScope.defineProperty("navigator", navigator, ScriptableObject.DONTENUM);

      try {
        String soyutilsPath = getSoyUtilsPath();
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

      Long lastTimeStamp = lastTimeStamps.get(jslibFile);
      if(lastTimeStamp == null || lastTimeStamp < jslibFile.lastModified()){
        Transaction.startTransaction();
        lastTimeStamps.put(jslibFile, jslibFile.lastModified());
        FileInputStream inStream = new FileInputStream(jslibFile);
        exportObject = new NativeObject();
        ScriptRuntime.setObjectProtoAndParent((ScriptableObject) exportObject, global);
        ScriptableObject moduleObject = new NativeObject();
        ScriptRuntime.setObjectProtoAndParent((ScriptableObject) moduleObject, global);
        moduleObject.put("id", moduleObject, id);
        // setup the module scope
        ScriptableObject moduleScope = new NativeObject();
        moduleScope.setParentScope(global);
        int lastSlash = filename.lastIndexOf('/');
        currentJslibPath = lastSlash == -1 ? "" : filename.substring(0,lastSlash + 1);
        moduleScope.put("exports", moduleScope, exportObject);
        moduleScope.put("module", moduleScope, moduleObject);
        // memoize
        exports.put(jslibFile, exportObject);
        // evaluate the script
        try {
          cx.evaluateString(moduleScope, IOUtils.toString(inStream, "UTF-8"), filename, 1, null);
        } catch (RuntimeException e) {
          // revert
          exports.remove(jslibFile);
          throw e;
        }
        // re-retrieve it in case the library changed it
        exportObject = (ScriptableObject) moduleScope.get("exports", moduleScope);
        exports.put(jslibFile, exportObject);

        if("jsgi-app.js".equals(filename)){
          // handle jackconfig.js, setting up the app if it is there
          global.put("app", global, exportObject.get("app", exportObject));
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

      }
    });
  }
  public static void setupSecurity() {
    Scriptable global = GlobalData.getGlobalScope();
    ScriptableObject security = new NativeObject();
    global.put("security", global, security);
   
    global.put("createUser", global, createUserHandler);
    delegateToGlobalHandler(security,"createUser");
    global.put("grantAccess", global, grantAccessHandler);
    delegateToGlobalHandler(security,"grantAccess");
    global.put("authenticate", global, authenticateHandler);
    delegateToGlobalHandler(security,"authenticate");
    global.put("getAccessLevel", global, getAccessLevelHandler);
    delegateToGlobalHandler(security,"getAccessLevel");
    global.put("hasAccessLevel", global, hasAccessLevelHandler);
    delegateToGlobalHandler(security,"hasAccessLevel");
    global.put("hasPermission", global, hasPermissionHandler);
    delegateToGlobalHandler(security,"hasPermission");
    security.put("getCapabilities", security, new PersevereNativeFunction() {
      @Override
      public Object call(final Context cx, final Scriptable scope,
          final Scriptable thisObj, Object[] args) {
        Object user;
        if(args.length == 0 || args[0] == Undefined.instance){
          user = UserSecurity.currentUser();
        }else if (args[0] instanceof String){
          user = CapabilityUser.getUserByUsername((String)args[0]);
        }else
          user = args[0];
        Capability[] capabilities = getCapabilitiesForUser(user);
        List capArray = Persevere.newArray();
        if(capabilities != null)
          capArray.addAll(Arrays.asList(capabilities));
        return capArray;
        }
      public String toString() {
        return "function(target,resource,accessLevel){/*native code*/}";
      }
    });
    security.put("_refresh", security, new PersevereNativeFunction() {
      @Override
      public Object call(final Context cx, final Scriptable scope,
          final Scriptable thisObj, Object[] args) {
        Capability capability = ((Capability)args[0]);
        capability.allGranted = null;
        capability.computedPermissions.clear();
        Transaction currentTransaction = Transaction.suspendTransaction();
        List<Object> oldMembers = new ArrayList(capability.getAllMembers());
        if(currentTransaction!=null) currentTransaction.enterTransaction();
        List<Object> newMembers = args.length == 1 ?
            new ArrayList(capability.getAllMembers()) :
              new ArrayList();
        oldMembers.removeAll(newMembers);
        for (Object member : oldMembers){
          capability.removeFromUserCapabilities(member);
        }
        for (Object member : newMembers){
          capability.addToUserCapabilities(member);
        }
        return true;
        }
      public String toString() {
        return "function(content, target, property){/*native code*/}";
      }
    });
    security.put("changePassword", security, new PersevereNativeFunction() {
      @Override
      public Object call(final Context cx, final Scriptable scope,
          final Scriptable thisObj, Object[] args) {
        final Object user = UserSecurity.currentUser();
        if(user == null){
          throw new SecurityException("Can not change the user's password, no user is logged in");
        }
        if(!(user instanceof CapabilityUser)){
          throw new SecurityException("Can not change the user's password, the current user is not Persevere defined user");
        }
        ((CapabilityUser)user).setPassword(args[0].toString());
        return true;
        }
      public String toString() {
        return "function(newPassword){/*native code*/}";
      }
    });
    security.setGetterOrSetter("currentUser", 0, new PersevereNativeFunction() {
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        return UserSecurity.currentUser();
      }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

   * @param target
   * @param jsonPath
   * @return
   */
  private Object doJsonPath(Persistable target, String jsonPath) {
    Scriptable paramScope = new NativeObject();
    if (jsonPath.matches("new "))
      throw new RuntimeException("Invalid query");
    if (jsonPath.matches("[^\\?\\+\\=\\-\\*\\/\\!]\\("))
      throw new RuntimeException("Invalid query");
    if (parameters != null) {
      int poundIndex;
      while((poundIndex = jsonPath.indexOf('$', 1)) > -1) {
        int i = Integer.parseInt(jsonPath.substring(poundIndex + 1, poundIndex + 2)) - 1;
        jsonPath = jsonPath.substring(0,poundIndex) + "args.param" + i + jsonPath.substring(poundIndex + 2)
        paramScope.put("param" + i, paramScope, parameters[i]);
      }
    }
    //TODO: Once we have more of the JSONQuery expressions being handled at the data source
    //  level, we should set the optimization level to -1 for quicker evaluation:
    PersevereContextFactory.getContext().setOptimizationLevel(-1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.