コード例 #1
0
ファイル: Exporter.java プロジェクト: chrisdolan/aQute
  public static void fromJSON(Reader r, ConfigurationAdmin admin) throws Exception {

    Decoder decoder = codec.dec().from(r);
    Protocol p = decoder.get(Protocol.class);
    for (int i = 0; i < p.size; i++) {
      Export e = decoder.get(Export.class);
      Configuration c;
      if (e.factoryPid != null) {
        c = admin.createFactoryConfiguration(e.factoryPid, "?*");
      } else {
        c = admin.getConfiguration(e.pid, "?*");
      }

      Dictionary<String, Object> d = getDictionary(e.types, e.values);
      c.update(d);
    }
  }
コード例 #2
0
ファイル: Exporter.java プロジェクト: chrisdolan/aQute
  public static void toJSON(ConfigurationAdmin admin, Writer osw, String filter) throws Exception {

    Configuration[] list = admin.listConfigurations(filter);
    Encoder encoder = codec.enc().to(osw);

    Protocol p = new Protocol();
    p.version = 1;
    p.date = new Date();
    p.size = list.length;
    encoder.put(p).append('\n');

    if (list != null)
      for (Configuration c : list) {
        Dictionary<String, Object> d = c.getProperties();
        Export export = new Export();
        export.values = new HashMap<String, Object>();
        export.factoryPid = c.getFactoryPid();
        export.pid = c.getPid();

        for (Enumeration<String> e = d.keys(); e.hasMoreElements(); ) {
          String k = e.nextElement();
          Object v = d.get(k);

          if (!(v instanceof String)) {

            if (export.types == null) export.types = new HashMap<String, Type>();

            Type type = new Type();

            Class<?> clazz = v.getClass();
            if (v instanceof Collection) {
              Collection<?> coll = (Collection<?>) v;
              clazz = String.class;
              if (coll.size() > 0) type.vectorOf = shortName(coll.iterator().next().getClass());
              else type.vectorOf = shortName(String.class);
            } else if (v.getClass().isArray()) {
              type.arrayOf = shortName(clazz.getComponentType());
            } else type.scalar = shortName(v.getClass());

            export.types.put(k, type);
          }
          export.values.put(k, v);
        }

        encoder.mark().put(export);
        // encoder.put(encoder.digest());
        encoder.append('\n');
      }
    osw.flush();
  }