Пример #1
0
  private static void populateManagedPropertyFromProperty(
      Property property,
      PropertyDefinition propertyDefinition,
      @NotNull ManagedProperty managedProperty,
      @Nullable PropertySimple customProperty) {
    // See if there is a custom adapter defined for this property.
    PropertyAdapter propertyAdapter =
        PropertyAdapterFactory.getCustomPropertyAdapter(customProperty);

    MetaValue metaValue = managedProperty.getValue();
    if (metaValue != null) {
      LOG.trace(
          "Populating existing MetaValue of type "
              + metaValue.getMetaType()
              + " from RHQ property "
              + property
              + " with definition "
              + propertyDefinition
              + "...");
      if (propertyAdapter == null) {
        propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaValue);
      }
      propertyAdapter.populateMetaValueFromProperty(property, metaValue, propertyDefinition);
    } else {
      MetaType metaType = managedProperty.getMetaType();
      if (propertyAdapter == null) {
        propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaType);
      }
      LOG.trace(
          "Converting property "
              + property
              + " with definition "
              + propertyDefinition
              + " to MetaValue of type "
              + metaType
              + "...");
      metaValue = propertyAdapter.convertToMetaValue(property, propertyDefinition, metaType);
      managedProperty.setValue(metaValue);
    }
  }
Пример #2
0
 /**
  * Takes the Configuration parameter object and converts it into a MetaValue array, which can them
  * be passed in with the invoke method to the ProfileService to fire the operation of a resource.
  *
  * @param managedOperation Operation that will be fired and stores the parameter types for the
  *     operation
  * @param parameters set of Parameter Values that the OperationFacet sent to the Component
  * @param operationDefinition the RHQ operation definition
  * @return MetaValue[] array of MetaValues representing the parameters; if there are no
  *     parameters, an empty array will be returned
  */
 @NotNull
 public static MetaValue[] convertOperationsParametersToMetaValues(
     @NotNull ManagedOperation managedOperation,
     @NotNull Configuration parameters,
     @NotNull OperationDefinition operationDefinition) {
   ConfigurationDefinition paramsConfigDef =
       operationDefinition.getParametersConfigurationDefinition();
   if (paramsConfigDef == null) return new MetaValue[0];
   ManagedParameter[] managedParams =
       managedOperation.getParameters(); // this is guaranteed to be non-null
   Map<String, PropertyDefinition> paramPropDefs = paramsConfigDef.getPropertyDefinitions();
   MetaValue[] paramMetaValues = new MetaValue[managedParams.length];
   for (int i = 0; i < managedParams.length; i++) {
     ManagedParameter managedParam = managedParams[i];
     String paramName = managedParam.getName();
     Property paramProp = parameters.get(paramName);
     PropertyDefinition paramPropDef = paramPropDefs.get(paramName);
     MetaType metaType = managedParam.getMetaType();
     PropertyAdapter propertyAdapter = PropertyAdapterFactory.getPropertyAdapter(metaType);
     LOG.trace(
         "Converting RHQ operation param property "
             + paramProp
             + " with definition "
             + paramPropDef
             + " to MetaValue of type "
             + metaType
             + "...");
     MetaValue paramMetaValue =
         propertyAdapter.convertToMetaValue(paramProp, paramPropDef, metaType);
     // NOTE: There's no need to set the value on the ManagedParameter, since the invoke() API
     // takes an array of
     //       MetaValues.
     paramMetaValues[i] = paramMetaValue;
   }
   return paramMetaValues;
 }