Interface Wrapper<W>

Type Parameters:
W - the class that is wrapped
All Superinterfaces:
UI
All Known Implementing Classes:
AbstractWrapper, ConnectionContainerWrapper, InteractiveWebViewsResultWrapper, NativeNodeContainerWrapper, NodeContainerWrapper, NodeInPortWrapper, NodeOutPortWrapper, SingleInteractiveWebViewResultWrapper, SingleNodeContainerWrapper, SubNodeContainerWrapper, WorkflowContextWrapper, WorkflowDefWrapper, WorkflowInPortWrapper, WorkflowManagerWrapper, WorkflowOutPortWrapper, WorkflowPersistorWrapper

public interface Wrapper<W> extends UI
Wraps another object and provides static methods to wrap and unwrap those. Only intended for UI-stuff.
Author:
Martin Horn, University of Konstanz
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ConcurrentMap<Integer,Wrapper<?>>
    The global wrapper map - not for direct access - use wrapOrGet(Object, Function) instead!
  • Method Summary

    Modifier and Type
    Method
    Description
    Unwraps the wrapped object.
    static <W> W
    unwrap(UI wrapper, Class<W> wrappedObjectClass)
    Checks if the passed object is a wrapper (i.e.
    static org.knime.core.node.workflow.ConnectionContainer
    unwrapCC(UI wrapper)
    Shortcut for unwrap(wrapper, ConnectionContainer.class).
    static org.knime.core.node.workflow.NodeContainer
    unwrapNC(UI wrapper)
    Shortcut for unwrap(wrapper, NodeContainer.class).
    static Optional<org.knime.core.node.workflow.NodeContainer>
    Shortcut for unwrapOptional(wrapper, NodeContainer.class).
    static <W> Optional<W>
    unwrapOptional(UI wrapper, Class<W> wrappedObjectClass)
    Checks if the passed object is a wrapper (i.e.
    static org.knime.core.node.workflow.WorkflowManager
    unwrapWFM(UI wrapper)
    Shortcut for unwrap(wrapper, WorkflowManager.class).
    static Optional<org.knime.core.node.workflow.WorkflowManager>
    Shortcut for unwrapOptional(wrapper, WorkflowManager.class).
    static UI
    wrap(Object obj)
    Tries to wrap the passed object into its specific UI-wrapper, e.g.
    static <W> Wrapper<W>
    wrapOrGet(W object, Function<W,Wrapper<W>> wrap)
    Either returns a wrapper object stored in a central global wrapper map (with the identity hashcode as key - see System.identityHashCode(Object)).
    static <W> boolean
    wraps(Object wrapper, Class<W> wrappedObjectClass)
    Checks whether a object wraps a certain object of a given class.
  • Field Details

  • Method Details

    • unwrap

      W unwrap()
      Unwraps the wrapped object.
      Returns:
      the wrapped object
    • unwrapWFM

      static org.knime.core.node.workflow.WorkflowManager unwrapWFM(UI wrapper)
      Shortcut for unwrap(wrapper, WorkflowManager.class).
      Parameters:
      wrapper -
      Returns:
      the wrapped workflow manager
    • unwrapWFMOptional

      static Optional<org.knime.core.node.workflow.WorkflowManager> unwrapWFMOptional(UI wrapper)
      Shortcut for unwrapOptional(wrapper, WorkflowManager.class).
      Parameters:
      wrapper -
      Returns:
      the wrapped workflow manager
    • unwrapNC

      static org.knime.core.node.workflow.NodeContainer unwrapNC(UI wrapper)
      Shortcut for unwrap(wrapper, NodeContainer.class).
      Parameters:
      wrapper -
      Returns:
      the unwrapped node container
    • unwrapNCOptional

      static Optional<org.knime.core.node.workflow.NodeContainer> unwrapNCOptional(UI wrapper)
      Shortcut for unwrapOptional(wrapper, NodeContainer.class).
      Parameters:
      wrapper -
      Returns:
      the unwrapped node container or an empty optional
      Since:
      3.6
    • unwrapCC

      static org.knime.core.node.workflow.ConnectionContainer unwrapCC(UI wrapper)
      Shortcut for unwrap(wrapper, ConnectionContainer.class).
      Parameters:
      wrapper -
      Returns:
      the unwrapped node container
    • wrapOrGet

      static <W> Wrapper<W> wrapOrGet(W object, Function<W,Wrapper<W>> wrap)
      Either returns a wrapper object stored in a central global wrapper map (with the identity hashcode as key - see System.identityHashCode(Object)). Or wraps the given object (see #wrap(Object, Class)). Its primary purpose is to workaround "1:1" wrappers. Within the eclipse UI very often instances are checked for object equality. Consequently, there must be exactly one wrapper class instance for a certain object to be wrapped. Two wrapper instances wrapping the same object should be avoided (this happens if, e.g. a getter method is called twice and each time a new wrapper instance is created around the same object returned). The global wrapper map caches object instances (weak references) for look up with the identity hashcode as key.
      Parameters:
      object - the object to be wrapped. Its identity hashcode serves as the key to look for an already existing wrapper
      wrap - function that does the wrapping if no already existing wrapper has been found (i.e. was cached)
      Returns:
      a new or already existing wrapper instance that wraps an object of the given type
    • unwrap

      static <W> W unwrap(UI wrapper, Class<W> wrappedObjectClass)
      Checks if the passed object is a wrapper (i.e. implements Wrapper) and returns the wrapped object. Otherwise an IllegalArgumentException is thrown.
      Parameters:
      wrapper - the supposed wrapper
      wrappedObjectClass - the class of the object to be unwrapped
      Returns:
      the unwrapped object
      Throws:
      IllegalArgumentException - if the wrapper object is not a wrapper
    • unwrapOptional

      static <W> Optional<W> unwrapOptional(UI wrapper, Class<W> wrappedObjectClass)
      Checks if the passed object is a wrapper (i.e. implements Wrapper) and returns the wrapped object. Otherwise an empty optional is returned.
      Parameters:
      wrapper - the supposed wrapper
      wrappedObjectClass - the class of the object to be unwrapped
      Returns:
      the unwrapped object or an empty optional if it coudn't be unwrapped
      Throws:
      IllegalArgumentException - if the unwrapped object is not compatible with the given wrapped object class
    • wraps

      static <W> boolean wraps(Object wrapper, Class<W> wrappedObjectClass)
      Checks whether a object wraps a certain object of a given class.
      Parameters:
      wrapper - the supposed wrapper
      wrappedObjectClass - the class of the object to check for
      Returns:
      true if the object wraps an object with the given class, false if it doesn't wrap it OR the object is not of type Wrapper
    • wrap

      static UI wrap(Object obj)
      Tries to wrap the passed object into its specific UI-wrapper, e.g. WorkflowManager into WorkflowManagerUI. If it's already a UI-class, the very same object is just returned.
      Parameters:
      obj - the object to possibly wrap
      Returns:
      the object wrapped into a UI-wrapper or itself if already UI
      Throws:
      IllegalArgumentException - if the object is _not_ of type UI, ConnectionContainer or NodeContainer