@Test
  public void canGetAttributeByNameParts() {
    // Initially null
    assertNull(e.getAttributeByNameParts(COLOR.getNameParts()));

    // Once set, returns val
    e.setAttribute(COLOR, "red");
    assertEquals(e.getAttributeByNameParts(COLOR.getNameParts()), "red");
  }
  @SuppressWarnings("unchecked")
  @Override
  public void reconstruct(RebindContext rebindContext, EntityMemento memento) {
    if (LOG.isTraceEnabled()) LOG.trace("Reconstructing entity: {}", memento.toVerboseString());

    // Note that the id should have been set in the constructor; it is immutable
    entity.setDisplayName(memento.getDisplayName());

    for (Effector<?> eff : memento.getEffectors())
      ((EntityInternal) entity).getMutableEntityType().addEffector(eff);

    for (Map.Entry<ConfigKey<?>, Object> entry : memento.getConfig().entrySet()) {
      try {
        ConfigKey<?> key = entry.getKey();
        Object value = entry.getValue();
        Class<?> type =
            (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName());
        entity.setConfig((ConfigKey<Object>) key, value);
      } catch (ClassNotFoundException e) {
        throw Throwables.propagate(e);
      }
    }

    ((EntityInternal) entity).getConfigMap().addToLocalBag(memento.getConfigUnmatched());
    ((EntityInternal) entity).refreshInheritedConfig();

    for (Map.Entry<AttributeSensor<?>, Object> entry : memento.getAttributes().entrySet()) {
      try {
        AttributeSensor<?> key = entry.getKey();
        Object value = entry.getValue();
        Class<?> type =
            (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName());
        ((EntityInternal) entity)
            .setAttributeWithoutPublishing((AttributeSensor<Object>) key, value);
      } catch (ClassNotFoundException e) {
        throw Throwables.propagate(e);
      }
    }

    setParent(rebindContext, memento);
    addChildren(rebindContext, memento);
    addPolicies(rebindContext, memento);
    addEnrichers(rebindContext, memento);
    addMembers(rebindContext, memento);
    addTags(rebindContext, memento);
    addLocations(rebindContext, memento);

    doReconstruct(rebindContext, memento);
    ((AbstractEntity) entity).rebind();
  }
Esempio n. 3
0
 @SuppressWarnings("unchecked")
 private Object coerce(Object v) {
   if (v != PollConfig.UNSET) {
     return TypeCoercions.coerce(v, sensor.getType());
   } else {
     return v;
   }
 }
 @SuppressWarnings("unchecked")
 protected void setSensor(Object v) {
   if (v == FeedConfig.UNCHANGED) {
     // nothing
   } else if (v == FeedConfig.REMOVE) {
     ((EntityInternal) entity).removeAttribute(sensor);
   } else if (sensor == FeedConfig.NO_SENSOR) {
     // nothing
   } else {
     entity.setAttribute(sensor, TypeCoercions.coerce(v, sensor.getType()));
   }
 }
Esempio n. 5
0
 @Override
 public String getDescription() {
   return sensor.getName() + " @ " + entity.getId() + " <- " + config;
 }