@Override
 @SuppressWarnings("unchecked")
 public Object bind(
     String name,
     @SuppressWarnings("rawtypes") Class clazz,
     java.lang.reflect.Type type,
     Annotation[] annotations,
     Map<String, String[]> params) {
   if (Model.class.isAssignableFrom(clazz)) {
     String keyName = modelFactory(clazz).keyName();
     String idKey = name + "." + keyName;
     if (params.containsKey(idKey)
         && params.get(idKey).length > 0
         && params.get(idKey)[0] != null
         && params.get(idKey)[0].trim().length() > 0) {
       String id = params.get(idKey)[0];
       try {
         Object o = ds().createQuery(clazz).filter(keyName, new ObjectId(id)).get();
         return Model.edit(o, name, params, annotations);
       } catch (Exception e) {
         return null;
       }
     }
     return Model.create(clazz, name, params, annotations);
   }
   return super.bind(name, clazz, type, annotations, params);
 }
示例#2
0
  /**
   * @return a new model in which all occurrences of the old namespace are replaced by the new one.
   *     All replaced resources are summarized in the map if not null. If resourcesToIgnore != null,
   *     ignore resources listed there.
   */
  public static Model replaceNamespace(Model m, String o, String n, Map o2n, Set resourcesToIgnore)
      throws ModelException {

    Model res = m.create();
    NodeFactory f = m.getNodeFactory();
    Enumeration en = m.elements();
    while (en.hasMoreElements()) {

      Statement st = (Statement) en.nextElement();
      res.add(replaceNamespace(st, o, n, f, o2n, resourcesToIgnore));
    }
    return res;
  }
示例#3
0
  /**
   * @return a new model in which all occurrences of the old resources are replaced by the new ones.
   *     Returns number replacements done.
   */
  public static int replaceResources(Model m, Map o2n) throws ModelException {

    NodeFactory f = m.getNodeFactory();
    Enumeration en = m.elements();

    Model toRemove = m.create();
    Model toAdd = m.create();

    while (en.hasMoreElements()) {

      Statement st = (Statement) en.nextElement();
      Statement st_n = replaceResources(st, f, o2n);

      if (st_n != st) { // yes, pointer comparison
        toAdd.add(st_n);
        toRemove.add(st);
      }
    }

    SetOperations.subtract(m, toRemove);
    SetOperations.unite(m, toAdd);

    return toAdd.size();
  }
示例#4
0
  /**
   * returns a subgraph of "m" containing "r" and all nodes reachable from "r" via directed edges.
   * These edges are also included in the resulting model.
   */
  public static Model getReachable(Resource r, Model m) throws ModelException {

    Model result = m.create();
    getReachable(r, m, result);
    return result;
  }