Class TopicPermission

java.lang.Object
java.security.Permission
org.osgi.service.event.TopicPermission
All Implemented Interfaces:
Serializable, Guard

public final class TopicPermission extends Permission
A bundle's authority to publish or subscribe to event on a topic.

A topic is a slash-separated string that defines a topic.

For example:

 org/osgi/service/foo/FooEvent/ACTION
 

TopicPermission has two actions: publish and subscribe.

See Also:
  • Field Details

    • serialVersionUID

      static final long serialVersionUID
      See Also:
    • PUBLISH

      public static final String PUBLISH
      The action string publish.
      See Also:
    • SUBSCRIBE

      public static final String SUBSCRIBE
      The action string subscribe.
      See Also:
    • ACTION_PUBLISH

      private static final int ACTION_PUBLISH
      See Also:
    • ACTION_SUBSCRIBE

      private static final int ACTION_SUBSCRIBE
      See Also:
    • ACTION_ALL

      private static final int ACTION_ALL
      See Also:
    • ACTION_NONE

      private static final int ACTION_NONE
      See Also:
    • action_mask

      private transient int action_mask
      The actions mask.
    • prefix

      private transient volatile String prefix
      prefix if the name is wildcarded.
    • actions

      private volatile String actions
      The actions in canonical form.
  • Constructor Details

    • TopicPermission

      public TopicPermission(String name, String actions)
      Defines the authority to publish and/or subscribe to a topic within the EventAdmin service.

      The name is specified as a slash-separated string. Wildcards may be used. For example:

          org/osgi/service/fooFooEvent/ACTION
          com/isv/*
          *
       

      A bundle that needs to publish events on a topic must have the appropriate TopicPermission for that topic; similarly, a bundle that needs to subscribe to events on a topic must have the appropriate TopicPermssion for that topic.

      Parameters:
      name - Topic name.
      actions - publish,subscribe (canonical order).
    • TopicPermission

      TopicPermission(String name, int mask)
      Package private constructor used by TopicPermissionCollection.
      Parameters:
      name - class name
      mask - action mask
  • Method Details

    • setTransients

      private void setTransients(int mask)
      Called by constructors and when deserialized.
      Parameters:
      name - topic name
      mask - action mask
    • getActionsMask

      int getActionsMask()
      Returns the current action mask.

      Used by the TopicPermissionCollection class.

      Returns:
      Current action mask.
    • parseActions

      private static int parseActions(String actions)
      Parse action string into action mask.
      Parameters:
      actions - Action string.
      Returns:
      action mask.
    • implies

      public boolean implies(Permission p)
      Determines if the specified permission is implied by this object.

      This method checks that the topic name of the target is implied by the topic name of this object. The list of TopicPermission actions must either match or allow for the list of the target object to imply the target TopicPermission action.

          x/y/*,"publish" -> x/y/z,"publish" is true
          *,"subscribe" -> x/y,"subscribe"   is true
          *,"publish" -> x/y,"subscribe"     is false
          x/y,"publish" -> x/y/z,"publish"   is false
       
      Specified by:
      implies in class Permission
      Parameters:
      p - The target permission to interrogate.
      Returns:
      true if the specified TopicPermission action is implied by this object; false otherwise.
    • getActions

      public String getActions()
      Returns the canonical string representation of the TopicPermission actions.

      Always returns present TopicPermission actions in the following order: publish,subscribe.

      Specified by:
      getActions in class Permission
      Returns:
      Canonical string representation of the TopicPermission actions.
    • newPermissionCollection

      public PermissionCollection newPermissionCollection()
      Returns a new PermissionCollection object suitable for storing TopicPermission objects.
      Overrides:
      newPermissionCollection in class Permission
      Returns:
      A new PermissionCollection object.
    • equals

      public boolean equals(Object obj)
      Determines the equality of two TopicPermission objects. This method checks that specified TopicPermission has the same topic name and actions as this TopicPermission object.
      Specified by:
      equals in class Permission
      Parameters:
      obj - The object to test for equality with this TopicPermission object.
      Returns:
      true if obj is a TopicPermission, and has the same topic name and actions as this TopicPermission object; false otherwise.
    • hashCode

      public int hashCode()
      Returns the hash code value for this object.
      Specified by:
      hashCode in class Permission
      Returns:
      A hash code value for this object.
    • writeObject

      private void writeObject(ObjectOutputStream s) throws IOException
      WriteObject is called to save the state of this permission object to a stream. The actions are serialized, and the superclass takes care of the name.
      Throws:
      IOException
    • readObject

      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
      readObject is called to restore the state of this permission from a stream.
      Throws:
      IOException
      ClassNotFoundException