コード例 #1
0
  /**
   * @deprecated since 0.7.0; only used for legacy brooklyn types where constructor is called
   *     directly
   */
  @Override
  @Deprecated
  @SuppressWarnings({"unchecked", "rawtypes"})
  public AbstractEntityAdjunct configure(Map flags) {
    // TODO only set on first time through
    boolean isFirstTime = true;

    // allow config keys, and fields, to be set from these flags if they have a SetFromFlag
    // annotation
    // or if the value is a config key
    for (Iterator<Map.Entry> iter = flags.entrySet().iterator(); iter.hasNext(); ) {
      Map.Entry entry = iter.next();
      if (entry.getKey() instanceof ConfigKey) {
        ConfigKey key = (ConfigKey) entry.getKey();
        if (adjunctType.getConfigKeys().contains(key)) {
          setConfig(key, entry.getValue());
        } else {
          log.warn("Unknown configuration key {} for policy {}; ignoring", key, this);
          iter.remove();
        }
      }
    }

    ConfigBag bag = new ConfigBag().putAll(flags);
    FlagUtils.setFieldsFromFlags(this, bag, isFirstTime);
    FlagUtils.setAllConfigKeys(this, bag, false);
    leftoverProperties.putAll(bag.getUnusedConfig());

    // replace properties _contents_ with leftovers so subclasses see leftovers only
    flags.clear();
    flags.putAll(leftoverProperties);
    leftoverProperties = flags;

    if (!truth(name) && flags.containsKey("displayName")) {
      // TODO inconsistent with entity and location, where name is legacy and displayName is
      // encouraged!
      // 'displayName' is a legacy way to refer to a policy's name
      Preconditions.checkArgument(
          flags.get("displayName") instanceof CharSequence,
          "'displayName' property should be a string");
      setDisplayName(flags.remove("displayName").toString());
    }

    // set leftover flags should as config items; particularly useful when these have come from a
    // brooklyn.config map
    for (Object flag : flags.keySet()) {
      ConfigKey<Object> key = ConfigKeys.newConfigKey(Object.class, Strings.toString(flag));
      if (config().getRaw(key).isPresent()) {
        log.warn("Config '" + flag + "' on " + this + " conflicts with key already set; ignoring");
      } else {
        config().set(key, flags.get(flag));
      }
    }

    return this;
  }
コード例 #2
0
 @Override
 protected AbstractBrooklynObject configure(Map<?, ?> flags) {
   FlagUtils.setFieldsFromFlags(flags, this);
   return this;
 }