Interface Attributes


public interface Attributes
Implementations of Attributes can be requested from component proxy lookup to store key/value data for individual components.

In earlier versions of PraxisLIVE, attributes were stored as script comments. They are now backed by the ComponentProtocol.META property. This API still provides an easier way to merge and retrieve attributes. To listen for changes, use a property listener on the meta property.

  • Method Details

    • setAttribute

      void setAttribute(String key, String value)
      Set an attribute. A null or empty value will clear the attribute.
      Parameters:
      key - attribute key
      value - attribute value
    • getAttribute

      String getAttribute(String key)
      Get an attribute. If not set then null is returned.
      Parameters:
      key - attribute key
      Returns:
      attribute value or null
    • setAttributeValue

      default void setAttributeValue(String key, org.praxislive.core.Value value)
      Set an attribute as a Value, or clear the attribute if the value is null or empty (see Value.isEmpty()).
      Parameters:
      key - attribute key
      value - attribute value
    • getAttributeValue

      default <T extends org.praxislive.core.Value> T getAttributeValue(Class<T> type, String key)
      Get an attribute as the specified Value type. If the attribute is not set or cannot be converted to the given type this method will return null.
      Type Parameters:
      T - value type
      Parameters:
      type - value type as class
      key - attribute key
      Returns:
      attribute as value type or null
    • clear

      static void clear(ComponentProxy cmp, String key)
      Clear the attribute on the given component. If the component does not support Attributes, the instruction is ignored.
      Parameters:
      cmp - component on which to clear attribute
      key - attribute key
    • get

      static String get(ComponentProxy cmp, String key, String def)
      Get a String attribute from the given component. If the component does not support attributes or the attribute is not present, the provided default value is returned.
      Parameters:
      cmp - component from which to get attribute
      key - attribute key
      def - default fallback value (null allowed)
      Returns:
      attribute value as String, or default
    • get

      static <T extends org.praxislive.core.Value> T get(ComponentProxy cmp, Class<T> type, String key, T def)
      Get an attribute of a specific Value type from the given component. If the component does not support attributes, the attribute is not present, or the attribute cannot be converted to the given type, then the provided default value is returned.
      Type Parameters:
      T - value type
      Parameters:
      cmp - component from which to get attribute
      type - value type class
      key - attribute key
      def - default fallback value (null allowed)
      Returns:
      attribute value as requested type, or default
    • set

      static void set(ComponentProxy cmp, String key, String value)
      Set an attribute on the given component. A null or empty value will clear the attribute. If the component does not support Attributes, the instruction is ignored.
      Parameters:
      cmp - component on which to set attribute
      key - attribute key
      value - attribute string value or null
    • set

      static void set(ComponentProxy cmp, String key, org.praxislive.core.Value value)
      Set an attribute on the given component. A null or empty value will clear the attribute. If the component does not support Attributes, the instruction is ignored.
      Parameters:
      cmp - component on which to set attribute
      key - attribute key
      value - attribute value or null