public static Map<String, Object> dictionaryToMap(
      Dictionary<String, Object> dictionary, OCD ocd) {
    if (dictionary == null) {
      return null;
    }

    Map<String, AD> ads = new HashMap<String, AD>();
    if (ocd != null) {
      for (AD ad : ocd.getAD()) {
        ads.put(ad.getId(), ad);
      }
    }
    Map<String, Object> map = new HashMap<String, Object>();
    Enumeration<String> keys = dictionary.keys();
    while (keys.hasMoreElements()) {

      String key = keys.nextElement();
      Object value = dictionary.get(key);
      AD ad = ads.get(key);
      if (ad != null && ad.getType() != null && Scalar.PASSWORD.equals(ad.getType())) {
        if (value instanceof char[]) {
          map.put(key, new Password((char[]) value));
        } else {
          map.put(key, new Password(value.toString()));
        }
      } else {
        map.put(key, value);
      }
    }
    return map;
  }
  /**
   * Analyze configuration to get meter names
   *
   * @return set of String of meter names
   */
  private Set<String> getNames(Dictionary<String, ?> config) {
    Set<String> set = new HashSet<String>();

    Enumeration<String> keys = config.keys();
    while (keys.hasMoreElements()) {

      String key = (String) keys.nextElement();

      // the config-key enumeration contains additional keys that we
      // don't want to process here ...
      if ("service.pid".equals(key) || "refresh".equals(key)) {
        continue;
      }

      Matcher meterMatcher = METER_CONFIG_PATTERN.matcher(key);

      if (!meterMatcher.matches()) {
        logger.debug(
            "given config key '"
                + key
                + "' does not follow the expected pattern '<meterName>.<serialPort|baudRateChangeDelay|echoHandling>'");
        continue;
      }

      meterMatcher.reset();
      meterMatcher.find();

      set.add(meterMatcher.group(1));
    }
    return set;
  }
Esempio n. 3
0
 private void writeResponse(
     JSONWriter write, ResponseWrapper responseWrapper, RequestInfo requestData)
     throws JSONException {
   try {
     String body = responseWrapper.getDataAsString();
     write.object();
     write.key("url");
     write.value(requestData.getUrl());
     write.key("success");
     write.value(true);
     write.key("body");
     write.value(body);
     write.key("status");
     write.value(responseWrapper.getResponseStatus());
     write.key("headers");
     write.object();
     Dictionary<String, String> headers = responseWrapper.getResponseHeaders();
     Enumeration<String> keys = headers.keys();
     while (keys.hasMoreElements()) {
       String k = keys.nextElement();
       write.key(k);
       write.value(headers.get(k));
     }
     write.endObject();
     write.endObject();
   } catch (UnsupportedEncodingException e) {
     writeFailedRequest(write, requestData);
   }
 }
Esempio n. 4
0
  public static <E, F> void addRange(Dictionary<E, F> destino, Dictionary<E, F> valores) {
    List<E> keys = Collections.list(valores.keys());

    for (E key : keys) {
      destino.put(key, valores.get(key));
    }
  }
  protected void encodeObject(
      org.w3c.dom.Document document,
      org.w3c.dom.Element node,
      edu.cmu.cs.stage3.io.DirectoryTreeStorer storer,
      edu.cmu.cs.stage3.alice.core.ReferenceGenerator referenceGenerator)
      throws java.io.IOException {
    java.util.Dictionary dict = getDictionaryValue();
    if (dict != null) {
      java.util.Enumeration enum0 = dict.keys();
      while (enum0.hasMoreElements()) {
        Object key = enum0.nextElement();
        Object value = dict.get(key);

        org.w3c.dom.Element entryNode = document.createElement("entry");

        org.w3c.dom.Element keyNode = document.createElement("key");
        keyNode.setAttribute("class", key.getClass().getName());
        keyNode.appendChild(createNodeForString(document, key.toString()));

        org.w3c.dom.Element valueNode = document.createElement("value");
        valueNode.setAttribute("class", value.getClass().getName());
        valueNode.appendChild(createNodeForString(document, value.toString()));

        entryNode.appendChild(keyNode);
        entryNode.appendChild(valueNode);
        node.appendChild(entryNode);
      }
    }
  }
Esempio n. 6
0
 /**
  * @param props
  * @exception IllegalArgumentException
  */
 public synchronized void copyFrom(Dictionary props) throws IllegalArgumentException {
   Enumeration keys = props.keys();
   Enumeration values = props.elements();
   while (keys.hasMoreElements()) {
     put(keys.nextElement(), values.nextElement());
   }
 }
Esempio n. 7
0
  /**
   * Convert dictionary and contents to a Map, compatible with the JSON model. Arrays are encoded
   * with special meta-data entries marking their origin as array.
   *
   * @param dict the (OSGi configuration) dictionary
   * @return the converted map
   */
  Map<String, Object> dictToMap(Dictionary dict) {
    Map<String, Object> convert = new HashMap<String, Object>();
    Enumeration keysEnum = dict.keys();
    while (keysEnum.hasMoreElements()) {
      String key = (String) keysEnum.nextElement();
      Object rawValue = dict.get(key);
      // Deal with outdated collection classes
      Object putValue = rawValue;
      if (rawValue instanceof Dictionary) {
        putValue =
            dictToMap((Dictionary) rawValue); // Beware, does not support recursive dictionaries
      } else if (rawValue instanceof Vector) {
        putValue = new ArrayList((Vector) rawValue);
      } else if (rawValue instanceof Object[]) {
        List convList = new ArrayList(Arrays.asList((Object[]) rawValue));

        // Add marker entries to mark this as coming from an array
        convList.add(OPENIDM_ORIG_ARRAY);
        convList.add(OPENIDM_ORIG_ARRAY_TYPE + rawValue.getClass().getComponentType().getName());

        putValue = convList;
      }
      convert.put(toEscapedKey(key), putValue);
    }
    return convert;
  }
  public void destroy() {

    final Enumeration<String> e = m_services.keys();
    while (e.hasMoreElements()) {
      deleted(e.nextElement());
    }
  }
  private void initializeProperties(Dictionary<String, Object> dict) {
    // Create a case-insensitive map for the properties.
    Map<String, Object> props = new StringMap();

    if (dict != null) {
      // Make sure there are no duplicate keys.
      Enumeration<String> keys = dict.keys();
      while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        if (props.get(key) == null) {
          props.put(key, dict.get(key));
        } else {
          throw new IllegalArgumentException("Duplicate service property: " + key);
        }
      }
    }

    // Add the framework assigned properties.
    props.put(Constants.OBJECTCLASS, m_classes);
    props.put(Constants.SERVICE_ID, m_serviceId);
    props.put(Constants.SERVICE_BUNDLEID, m_bundle.getBundleId());
    if (m_factory != null) {
      props.put(
          Constants.SERVICE_SCOPE,
          (m_factory instanceof PrototypeServiceFactory
              ? Constants.SCOPE_PROTOTYPE
              : Constants.SCOPE_BUNDLE));
    } else {
      props.put(Constants.SERVICE_SCOPE, Constants.SCOPE_SINGLETON);
    }

    // Update the service property map.
    m_propMap = props;
  }
Esempio n. 10
0
 private static StringBuffer printMapOrDict(
     StringBuffer out, java.util.Map map, java.util.Dictionary dict, Conf conf) {
   if (map != null && map.size() == 0) return out.append("{}");
   if (dict != null && dict.size() == 0) return out.append("{}");
   indent(out, conf);
   out.append('{');
   newline(out, conf);
   conf.currentIndent++;
   if (map != null)
     for (java.util.Iterator it = map.keySet().iterator(); it.hasNext(); ) {
       Object key = it.next();
       Object value = map.get(key);
       printKeyValue(out, key, value, conf);
     }
   else
     for (java.util.Enumeration en = dict.keys(); en.hasMoreElements(); ) {
       Object key = en.nextElement();
       Object value = dict.get(key);
       printKeyValue(out, key, value, conf);
     }
   conf.currentIndent--;
   indent(out, conf);
   out.append('}');
   return newline(out, conf);
 }
Esempio n. 11
0
 @SuppressWarnings("rawtypes")
 protected Object doExecute() throws Exception {
   Configuration[] configs = configRepository.getConfigAdmin().listConfigurations(query);
   if (configs != null) {
     Map<String, Configuration> sortedConfigs = new TreeMap<String, Configuration>();
     for (Configuration config : configs) {
       sortedConfigs.put(config.getPid(), config);
     }
     for (String pid : sortedConfigs.keySet()) {
       Configuration config = sortedConfigs.get(pid);
       System.out.println("----------------------------------------------------------------");
       System.out.println("Pid:            " + config.getPid());
       if (config.getFactoryPid() != null) {
         System.out.println("FactoryPid:     " + config.getFactoryPid());
       }
       System.out.println("BundleLocation: " + config.getBundleLocation());
       if (config.getProperties() != null) {
         System.out.println("Properties:");
         Dictionary props = config.getProperties();
         Map<String, Object> sortedProps = new TreeMap<String, Object>();
         for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
           Object key = e.nextElement();
           sortedProps.put(key.toString(), props.get(key));
         }
         for (String key : sortedProps.keySet()) {
           System.out.println("   " + key + " = " + sortedProps.get(key));
         }
       }
     }
   }
   return null;
 }
  public ServiceRegistrationImpl(
      BundleImpl bundle,
      long serviceId,
      String[] classNames,
      Object service,
      Dictionary<String, ?> properties) {
    this.bundle = bundle;
    this.serviceId = serviceId;
    this.classNames = classNames;
    this.service = service;

    if ((properties == null) || properties.isEmpty()) this.properties = EMPTY_PROPERTIES;
    else {
      Enumeration<String> keys = properties.keys();
      Map<String, Object> thisProperties = newCaseInsensitiveMapInstance();

      while (keys.hasMoreElements()) {
        String key = keys.nextElement();

        if (Constants.OBJECTCLASS.equalsIgnoreCase(key)
            || Constants.SERVICE_ID.equalsIgnoreCase(key)) continue;
        else if (thisProperties.containsKey(key)) throw new IllegalArgumentException(key);
        else thisProperties.put(key, properties.get(key));
      }

      this.properties = thisProperties.isEmpty() ? EMPTY_PROPERTIES : thisProperties;
    }
  }
  public CaseInsensitiveDictionary(Dictionary props) {
    this();

    if (props != null) {
      Enumeration keys = props.keys();
      while (keys.hasMoreElements()) {
        Object key = keys.nextElement();

        // check the correct syntax of the key
        checkKey(key);

        // check uniqueness of key
        String lowerCase = ((String) key).toLowerCase();
        if (internalMap.containsKey(lowerCase)) {
          throw new IllegalArgumentException("Key [" + key + "] already present in different case");
        }

        // check the value
        Object value = props.get(key);
        value = checkValue(value);

        // add the key/value pair
        internalMap.put(lowerCase, value);
        originalKeys.put(lowerCase, key);
      }
    }
  }
Esempio n. 14
0
  /** @param aProperties the updated properties. */
  @SuppressWarnings("rawtypes")
  final void setProperties(final Dictionary aProperties) {
    final Map<String, String> newProps = new HashMap<String, String>();

    Enumeration keys = aProperties.keys();
    while (keys.hasMoreElements()) {
      final String key = (String) keys.nextElement();
      if (!KNOWN_KEYS.contains(key) && !IGNORED_KEYS.contains(key)) {
        LOG.log(Level.WARNING, "Unknown/unsupported profile key: " + key);
        continue;
      }

      final String value = aProperties.get(key).toString();
      newProps.put(key, value.trim());
    }

    // Verify whether all known keys are defined...
    final List<String> checkedKeys = new ArrayList<String>(KNOWN_KEYS);
    checkedKeys.removeAll(newProps.keySet());
    if (!checkedKeys.isEmpty()) {
      throw new IllegalArgumentException(
          "Profile settings not complete! Missing keys are: " + checkedKeys.toString());
    }

    this.properties.putAll(newProps);

    LOG.log(
        Level.INFO,
        "New device profile settings applied for {1} ({0}) ...", //
        new Object[] {getType(), getDescription()});
  }
  /**
   * Invokes the updated method. This method build the dictionary containing all valued properties,
   * as well as properties propagated to the provided service handler ( only if the propagation is
   * enabled).
   *
   * @param instance the instance on which the callback must be called. If <code>null</code> the
   *     callback is called on all the existing object.
   */
  private void notifyUpdated(Object instance) {
    if (m_updated == null) {
      return;
    }
    Properties props = new Properties();
    for (int i = 0; i < m_configurableProperties.size(); i++) {
      String n = ((Property) m_configurableProperties.get(i)).getName();
      Object v = ((Property) m_configurableProperties.get(i)).getValue();
      if (v != Property.NO_VALUE) {
        props.put(n, v);
      }
    }
    // add propagated properties to the list if propagation enable
    if (m_mustPropagate) {
      // Start by properties from the configuration admin,
      if (m_propagatedFromCA != null) {

        Enumeration e = m_propagatedFromCA.keys();
        while (e.hasMoreElements()) {
          String k = (String) e.nextElement();
          if (!k.equals("instance.name")) {
            props.put(k, m_propagatedFromCA.get(k));
          }
        }
      }
      // Do also the one from the instance configuration
      if (m_propagatedFromInstance != null) {
        Enumeration e = m_propagatedFromInstance.keys();
        while (e.hasMoreElements()) {
          String k = (String) e.nextElement();
          if (!k.equals("instance.name")) { // Skip instance.name
            props.put(k, m_propagatedFromInstance.get(k));
          }
        }
      }
    }

    try {
      if (instance == null) {
        m_updated.call(new Object[] {props});
      } else {
        m_updated.call(instance, new Object[] {props});
      }
    } catch (Exception e) {
      error("Cannot call the updated method " + m_updated.getMethod() + " : " + e.getMessage());
    }
  }
 public <T extends K> void putAll(Dictionary<T, ? extends V> dictionary) {
   if (dictionary != null)
     // copy the dictionary
     for (Enumeration<T> enm = dictionary.keys(); enm.hasMoreElements(); ) {
       T key = enm.nextElement();
       map.put(key, dictionary.get(key));
     }
 }
Esempio n. 17
0
 private Map<String, Object> toMap(@SuppressWarnings("rawtypes") Dictionary properties) {
   Builder<String, Object> b = ImmutableMap.builder();
   for (Enumeration<?> e = properties.keys(); e.hasMoreElements(); ) {
     String k = (String) e.nextElement();
     b.put(k, properties.get(k));
   }
   return b.build();
 }
Esempio n. 18
0
 public void updateDic(Dictionary dic) {
   Enumeration e = dic.keys();
   while (e.hasMoreElements()) {
     String varName = (String) e.nextElement();
     Object varValue = dic.get(varName);
     stateVars.put(varName, varValue);
   }
 }
 public java.util.Enumeration keys() {
   java.util.Dictionary dict = getDictionaryValue();
   if (dict != null) {
     return dict.keys();
   } else {
     return null;
   }
 }
Esempio n. 20
0
 private static <K, V> Map<K, V> convertToMap(Dictionary<K, V> source) {
   Map<K, V> map = new Hashtable<>();
   for (Enumeration<K> keys = source.keys(); keys.hasMoreElements(); ) {
     K key = keys.nextElement();
     map.put(key, source.get(key));
   }
   return map;
 }
Esempio n. 21
0
 private TreeMap<Integer, String> getSortedTree() {
   Dictionary dictionary = jSlider.getLabelTable();
   TreeMap<Integer, String> treeMap = new TreeMap<Integer, String>();
   for (Enumeration indices = dictionary.keys(); indices.hasMoreElements(); ) {
     Integer index = (Integer) indices.nextElement();
     JComponent component = (JComponent) dictionary.get(index);
     treeMap.put(index, ComponentUtils.getDisplayedName(component));
   }
   return treeMap;
 }
Esempio n. 22
0
 private int getIndexForLabel(String label) {
   Dictionary dictionary = jSlider.getLabelTable();
   for (Enumeration indices = dictionary.keys(); indices.hasMoreElements(); ) {
     Integer index = (Integer) indices.nextElement();
     JComponent component = (JComponent) dictionary.get(index);
     if (label.equals(ComponentUtils.getDisplayedName(component))) {
       return index;
     }
   }
   return -1;
 }
Esempio n. 23
0
  public void printProps() {
    Dictionary<Object, Object> dic = htmlDoc.getDocumentProperties();
    Enumeration e = dic.keys();

    while (e.hasMoreElements()) {

      Object keyObj = e.nextElement();
      Object valObj = dic.get(keyObj);
      logger.debug(keyObj + " " + valObj);
    }
  }
Esempio n. 24
0
 /**
  * Get the buses defined in the configuration.
  *
  * @return the list of bus ID defined
  */
 public List<String> getBuses() throws Exception {
   ArrayList<String> buses = new ArrayList<String>();
   if (properties != null) {
     Enumeration keys = properties.keys();
     while (keys.hasMoreElements()) {
       String key = (String) keys.nextElement();
       LOGGER.debug("Adding CXF bus {}", key);
       buses.add(key);
     }
   }
   return buses;
 }
  public void startup() {

    //        Dictionary<?, ?> dict = cmPropertyPlaceholder.getConfigAdmin()
    //                .getConfiguration(cmPropertyPlaceholder.getPersistentId()).getProperties();
    Dictionary<?, ?> dict = properties;
    // System.out.println("### ZOOKEEPER :: dictionary : " + dict);

    LOG.info("Staring up ZooKeeper server");

    if (dict == null) {
      LOG.info("Ignoring configuration update because updated configuration is empty.");
      shutdown();
      return;
    }

    if (main != null) {
      // stop the current instance
      shutdown();
      // then reconfigure and start again.
    }

    if (dict.get("clientPort") == null) {
      LOG.info("Ignoring configuration update because required property 'clientPort' isn't set.");
      return;
    }

    Properties props = new Properties();
    for (Enumeration<?> e = dict.keys(); e.hasMoreElements(); ) {
      Object key = e.nextElement();
      props.put(key, dict.get(key));
    }

    try {
      main = ZookeeperServerImpl.getZookeeperServer(props);

      zkMainThread =
          new Thread(
              new Runnable() {
                public void run() {
                  try {
                    main.startup();
                  } catch (IOException e) {
                    LOG.log(Level.SEVERE, "Problem running ZooKeeper server.", e);
                  }
                }
              });
      zkMainThread.start();

      LOG.info("Applied configuration update :" + props);
    } catch (Exception th) {
      LOG.log(Level.SEVERE, "Problem applying configuration update: " + props, th);
    }
  }
 /*
  * Explode the dictionary into a ,-delimited list of key=value pairs
  */
 private static String explode(Dictionary dictionary) {
   Enumeration keys = dictionary.keys();
   StringBuffer result = new StringBuffer();
   while (keys.hasMoreElements()) {
     Object key = keys.nextElement();
     result.append(String.format("%s=%s", key, dictionary.get(key)));
     if (keys.hasMoreElements()) {
       result.append(", ");
     }
   }
   return result.toString();
 }
 @Override
 protected SecondaryNameNode doCreate(Dictionary properties) throws Exception {
   Configuration conf = new Configuration();
   for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
     Object key = e.nextElement();
     Object val = properties.get(key);
     conf.set(key.toString(), val.toString());
   }
   SecondaryNameNode secondaryNameNode = new SecondaryNameNode(conf);
   new Daemon(secondaryNameNode).start();
   return secondaryNameNode;
 }
Esempio n. 28
0
 private String getCurrentLabel() {
   int value = jSlider.getValue();
   Dictionary dictionary = jSlider.getLabelTable();
   for (Enumeration indices = dictionary.keys(); indices.hasMoreElements(); ) {
     Integer index = (Integer) indices.nextElement();
     JComponent component = (JComponent) dictionary.get(index);
     if (Utils.equals(index, value)) {
       return ComponentUtils.getDisplayedName(component);
     }
   }
   return null;
 }
Esempio n. 29
0
 /**
  * Create a case insensitive map from the specified dictionary.
  *
  * @param dictionary
  * @throws IllegalArgumentException If {@code dictionary} contains case variants of the same key
  *     name.
  */
 CaseInsensitiveMap(Dictionary<String, ?> dictionary) {
   if (dictionary == null) {
     this.dictionary = null;
     this.keys = new String[0];
     return;
   }
   this.dictionary = dictionary;
   List<String> keyList = new ArrayList<String>(dictionary.size());
   for (Enumeration<?> e = dictionary.keys(); e.hasMoreElements(); ) {
     Object k = e.nextElement();
     if (k instanceof String) {
       String key = (String) k;
       for (String i : keyList) {
         if (key.equalsIgnoreCase(i)) {
           throw new IllegalArgumentException("Duplicate dictionary keys: " + dictionary.keys());
         }
       }
       keyList.add(key);
     }
   }
   this.keys = keyList.toArray(new String[keyList.size()]);
 }
Esempio n. 30
0
  private final Manifest toManifest(Dictionary<String, String> headers) {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    Enumeration<String> names = headers.keys();

    while (names.hasMoreElements()) {
      String name = names.nextElement();
      String value = headers.get(name);

      attributes.putValue(name, value);
    }
    return manifest;
  }