コード例 #1
0
  protected Collection<StateVariableValue> getCurrentState(String[] variableNames)
      throws Exception {
    lock();
    try {
      Collection<StateVariableValue> values = new ArrayList<StateVariableValue>();
      for (String variableName : variableNames) {
        variableName = variableName.trim();

        StateVariable stateVariable = getService().getStateVariable(variableName);
        if (stateVariable == null || !stateVariable.getEventDetails().isSendEvents()) {
          log.fine("Ignoring unknown or non-evented state variable: " + variableName);
          continue;
        }

        StateVariableAccessor accessor = getService().getAccessor(stateVariable);
        if (accessor == null) {
          log.warning("Ignoring evented state variable without accessor: " + variableName);
          continue;
        }
        values.add(accessor.read(stateVariable, getImplementation()));
      }
      return values;
    } finally {
      unlock();
    }
  }
コード例 #2
0
 @Override
 public Collection<StateVariableValue> getCurrentState() throws Exception {
   lock();
   try {
     Collection<StateVariableValue> values = readInitialEventedStateVariableValues();
     if (values != null) {
       log.fine(
           "Obtained initial state variable values for event, skipping individual state variable accessors");
       return values;
     }
     values = new ArrayList();
     for (StateVariable stateVariable : getService().getStateVariables()) {
       if (stateVariable.getEventDetails().isSendEvents()) {
         StateVariableAccessor accessor = getService().getAccessor(stateVariable);
         if (accessor == null)
           throw new IllegalStateException("No accessor for evented state variable");
         values.add(accessor.read(stateVariable, getImplementation()));
       }
     }
     return values;
   } finally {
     unlock();
   }
 }
コード例 #3
0
  private void generateStateVariable(
      StateVariable stateVariable, Document descriptor, Element serviveStateTableElement) {

    Element stateVariableElement =
        appendNewElement(descriptor, serviveStateTableElement, ELEMENT.stateVariable);

    appendNewElementIfNotNull(
        descriptor, stateVariableElement, ELEMENT.name, stateVariable.getName());

    if (stateVariable.getTypeDetails().getDatatype() instanceof CustomDatatype) {
      appendNewElementIfNotNull(
          descriptor,
          stateVariableElement,
          ELEMENT.dataType,
          ((CustomDatatype) stateVariable.getTypeDetails().getDatatype()).getName());
    } else {
      appendNewElementIfNotNull(
          descriptor,
          stateVariableElement,
          ELEMENT.dataType,
          stateVariable.getTypeDetails().getDatatype().getBuiltin().getDescriptorName());
    }

    appendNewElementIfNotNull(
        descriptor,
        stateVariableElement,
        ELEMENT.defaultValue,
        stateVariable.getTypeDetails().getDefaultValue());

    // The default is 'yes' but we generate it anyway just to be sure
    if (stateVariable.getEventDetails().isSendEvents()) {
      stateVariableElement.setAttribute(ATTRIBUTE.sendEvents.toString(), "yes");
    } else {
      stateVariableElement.setAttribute(ATTRIBUTE.sendEvents.toString(), "no");
    }

    if (stateVariable.getTypeDetails().getAllowedValues() != null) {
      Element allowedValueListElement =
          appendNewElement(descriptor, stateVariableElement, ELEMENT.allowedValueList);
      for (String allowedValue : stateVariable.getTypeDetails().getAllowedValues()) {
        appendNewElementIfNotNull(
            descriptor, allowedValueListElement, ELEMENT.allowedValue, allowedValue);
      }
    }

    if (stateVariable.getTypeDetails().getAllowedValueRange() != null) {
      Element allowedValueRangeElement =
          appendNewElement(descriptor, stateVariableElement, ELEMENT.allowedValueRange);
      appendNewElementIfNotNull(
          descriptor,
          allowedValueRangeElement,
          ELEMENT.minimum,
          stateVariable.getTypeDetails().getAllowedValueRange().getMinimum());
      appendNewElementIfNotNull(
          descriptor,
          allowedValueRangeElement,
          ELEMENT.maximum,
          stateVariable.getTypeDetails().getAllowedValueRange().getMaximum());
      if (stateVariable.getTypeDetails().getAllowedValueRange().getStep() >= 1l) {
        appendNewElementIfNotNull(
            descriptor,
            allowedValueRangeElement,
            ELEMENT.step,
            stateVariable.getTypeDetails().getAllowedValueRange().getStep());
      }
    }
  }