Example #1
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()});
  }
Example #2
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());
   }
 }
Example #3
0
  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();
  }
  /**
   * Get the names of all properties for this resource. This implementation reads all the properties
   * and then extracts their names.
   *
   * @return a MultiStatus of PropertyResponses (PropertyValue.value is always null,
   *     PropertyValue.status contains the status)
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus getPropertyNames() throws WebDAVException {
    MultiStatus multiStatus = resource.getProperties(resource.getContext());
    Enumeration responses = multiStatus.getResponses();

    // we have the result, but all of the properties in our structure contain
    //    values.  We don't want to include values.  Just names.  The following
    //    code strips out the content of these elements.
    while (responses.hasMoreElements()) {
      PropertyResponse response = (PropertyResponse) responses.nextElement();
      Dictionary properties = response.getPropertiesByPropName();
      Enumeration keys = properties.keys();

      while (keys.hasMoreElements()) {
        PropertyName key = (PropertyName) keys.nextElement();
        Element value = (Element) response.getProperty(key).getValue();
        response.setProperty(
            key, new PropertyValue((Element) value.cloneNode(false), WebDAVStatus.SC_OK));
      }
    }

    return multiStatus;
  }
 public Enumeration<String> keys() {
   return headers.keys();
 }
 public Enumeration<String> getAttributeNames() {
   Dictionary<String, Object> attributes = proxyContext.getContextAttributes(httpContext);
   return attributes.keys();
 }