Package org.vertx.java.core.json

Examples of org.vertx.java.core.json.JsonArray


    public void handle(final Message<JsonObject> message) {
      final GetFileContentsImpl request = GetFileContentsImpl.fromJsonString(Dto.get(message));

      // Resolve the resource IDs from the requested path.
      vertx.eventBus().send("tree.getResourceIds",
          new JsonObject().putArray("paths", new JsonArray().addString(request.getPath())),
          new Handler<Message<JsonObject>>() {

            /**
             * Sends the contents of a file to the requester. The files will be served out of the
             * FileEditSession if the contents are being edited, otherwise they will simply be
             * served from disk.
             */
              @Override
            public void handle(Message<JsonObject> event) {
              JsonArray resourceIdArr = event.body.getArray("resourceIds");
              Object[] resourceIds = resourceIdArr.toArray();
              String resourceId = (String) resourceIds[0];

              String currentPath = stripLeadingSlash(request.getPath());
              FileEditSession editSession = editSessions.get(resourceId);

View Full Code Here


    }

    void saveAll() {
      Set<Entry<String, FileEditSession>> entries = editSessions.entrySet();
      Iterator<Entry<String, FileEditSession>> entryIter = entries.iterator();
      final JsonArray resourceIds = new JsonArray();
      while (entryIter.hasNext()) {
        Entry<String, FileEditSession> entry = entryIter.next();
        String resourceId = entry.getKey();
        FileEditSession editSession = entry.getValue();
        if (editSession.hasChanges()) {
          resourceIds.addString(resourceId);
        }
      }

      // Resolve the current paths of opened files in case they have been moved.
      eb.send("tree.getCurrentPaths", new JsonObject().putArray("resourceIds", resourceIds),
          new Handler<Message<JsonObject>>() {
              @Override
            public void handle(Message<JsonObject> event) {
              JsonArray currentPaths = event.body.getArray("paths");
              Iterator<Object> pathIter = currentPaths.iterator();
              Iterator<Object> resourceIter = resourceIds.iterator();

              if (currentPaths.size() != resourceIds.size()) {
                logger.error(String.format(
                    "Received [%d] paths in response to a request specifying [%d] resourceIds",
                    currentPaths.size(), resourceIds.size()));
              }

              // Iterate through all the resolved paths and save the files to disk.
              while (pathIter.hasNext()) {
                String path = (String) pathIter.next();
View Full Code Here

   * currently exist.
   */
  class PathResolver implements Handler<Message<JsonObject>> {
    @Override
    public void handle(Message<JsonObject> message) {
      JsonArray resourceIds = message.body.getArray("resourceIds");
      JsonObject result = new JsonObject();
      JsonArray paths = new JsonArray();
      result.putArray("paths", paths);
      synchronized (FileTree.this.lock) {
        for (Object id : resourceIds) {
          assert id instanceof String;
          NodeInfoExt node = resourceIdToNode.get(id);
          if (node == null) {
            paths.addString(null);
          } else {
            paths.addString(pathString(node));
          }
        }
      }
      message.reply(result);
    }
View Full Code Here

   * stable for the lifetime of this verticle.
   */
  class ResourceIdResolver implements Handler<Message<JsonObject>> {
    @Override
    public void handle(Message<JsonObject> message) {
      JsonArray paths = message.body.getArray("paths");
      JsonObject result = new JsonObject();
      JsonArray resourceIds = new JsonArray();
      result.putArray("resourceIds", resourceIds);
      synchronized (FileTree.this.lock) {
        for (Object path : paths) {
          NodeInfoExt found = findResource(stripSlashes((String) path));
          resourceIds.addString(found == null ? null : found.getFileEditSessionKey());
        }
      }
      message.reply(result);
    }
View Full Code Here

                    .setRunTarget(runTarget).setWorkspaceName(webRoot);

            if (lastOpenedFileId != null) {
              // Resolve file to a path.
              vertx.eventBus().send("tree.getCurrentPaths", new JsonObject().putArray(
                  "resourceIds", new JsonArray().addString(lastOpenedFileId)),
                  new Handler<Message<JsonObject>>() {
                      @Override
                    public void handle(Message<JsonObject> event) {
                      List<String> openFiles = new ArrayList<String>();
                      openFiles.add((String) event.body.getArray("paths").toArray()[0]);
View Full Code Here

    sendBatch(message, cursor, batchSize);
  }

  private void sendBatch(Message<JsonObject> message, final DBCursor cursor, final int max) {
    int count = 0;
    JsonArray results = new JsonArray();
    while (cursor.hasNext() && count < max) {
      DBObject obj = cursor.next();
      String s = obj.toString();
      JsonObject m = new JsonObject(s);
      results.add(m);
      count++;
    }
    if (cursor.hasNext()) {
      JsonObject reply = createBatchMessage("more-exist", results);
View Full Code Here

    try {
      InternetAddress[] addresses = null;
      if (oto instanceof String) {
        addresses = InternetAddress.parse((String)oto, true);
      } else if (oto instanceof JsonArray) {
        JsonArray loto = (JsonArray)oto;
        addresses = new InternetAddress[loto.size()];
        int count = 0;
        for (Object addr: loto) {
          if (addr instanceof String == false) {
            sendError(message, "Invalid " + fieldName + " field");
            return null;
View Full Code Here

        return config.getNumber(CONFIG_MAX_BODY_SIZE, DEFAULT_MAX_BODY_SIZE).intValue();
    }

    protected ResourceConfig getResourceConfig() {
        checkState();
        JsonArray resources = config.getArray(CONFIG_RESOURCES, null);

        if (resources == null || resources.size() == 0) {
            throw new RuntimeException("At lease one resource package name must be specified in the config " +
                    CONFIG_RESOURCES);
        }

        String[] resourceArr = new String[resources.size()];
        for (int i = 0; i < resources.size(); i++) {
            resourceArr[i] = String.valueOf(resources.get(i));
        }

        ResourceConfig rc = new ResourceConfig();
        rc.packages(resourceArr);

        ClassLoader cl = Thread.currentThread().getContextClassLoader();

        JsonArray features = config.getArray(CONFIG_FEATURES, null);
        if (features != null && features.size() > 0) {
            for (int i = 0; i < features.size(); i++) {
                try {
                    Class<?> clazz = cl.loadClass(String.valueOf(features.get(i)));
                    rc.register(clazz);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        JsonArray binders = config.getArray(CONFIG_BINDERS, null);
        if (binders != null && binders.size() > 0) {
            for (int i = 0; i < binders.size(); i++) {
                try {
                    Class<?> clazz = cl.loadClass(String.valueOf(binders.get(i)));
                    rc.register(clazz.newInstance());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
View Full Code Here

    private Verticle createRealVerticle(Class<?> clazz) throws Exception {

        JsonObject config = container.config();
        Object field = config.getField(CONFIG_BOOTSTRAP_BINDER_NAME);
        JsonArray bootstrapNames;
        List<Binder> bootstraps = new ArrayList<>();

        if (field instanceof JsonArray) {
            bootstrapNames = (JsonArray) field;
        } else {
            bootstrapNames = new JsonArray().add((field == null ? BOOTSTRAP_BINDER_NAME : field));
        }

        for (int i = 0; i < bootstrapNames.size(); i++) {
            String bootstrapName = bootstrapNames.get(i);
            try {
                Class bootstrapClass = cl.loadClass(bootstrapName);
                Object obj = bootstrapClass.newInstance();

                if (obj instanceof Binder) {
View Full Code Here

        if (!(address instanceof JsonArray)) {
            if (mandatory) throw new AddressException("Mandatory field " + field + " is missing");
            return null;
        }

        JsonArray addresses = (JsonArray) address;
        InternetAddress[] internetAddresses = new InternetAddress[addresses.size()];

        for (int i = 0; i < addresses.size(); i++) {
            internetAddresses[i] = new InternetAddress((String) addresses.get(i));
        }

        return internetAddresses;
    }
View Full Code Here

TOP

Related Classes of org.vertx.java.core.json.JsonArray

Copyright © 2018 www.massapicom. 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.