Package com.dubture.getcomposer.core.collection

Source Code of com.dubture.getcomposer.core.collection.Repositories

package com.dubture.getcomposer.core.collection;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import com.dubture.getcomposer.core.entities.AbstractJsonArray;
import com.dubture.getcomposer.core.repositories.Repository;
import com.dubture.getcomposer.core.repositories.RepositoryFactory;

/**
* Represents a repositories collection of a composer package
*
* @see http://getcomposer.org/doc/04-schema.md#repositories
* @author Thomas Gossmann <gos.si>
*/
public class Repositories extends AbstractJsonArray<Repository> {
 
  public Repositories() {
  }
 
  protected void parse(Object obj) {
    clear();
    if (obj instanceof JSONArray) {
      for (Object repo : (JSONArray) obj) {
        if (repo instanceof JSONObject && ((JSONObject)repo).containsKey("type")) {
          String type = (String)((JSONObject)repo).get("type");
          Repository r = RepositoryFactory.create(type);
          r.fromJson(repo);
          add(r);
        }
      }
    }
  }
}
TOP

Related Classes of com.dubture.getcomposer.core.collection.Repositories

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.