Top Description Inners Fields Constructors Methods
org.osgi.framework

public final Class ServicePermission

Additional top-level class in compilation unit: ServicePermissionCollection.

extends BasicPermission
Class Inheritance
Imports
java.io.IOException, .NotSerializableException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField, java.security.AccessController, .BasicPermission, .Permission, .PermissionCollection, .PrivilegedAction, java.util.AbstractMap, .ArrayList, .Collection, .Collections, .Enumeration, .HashMap, .HashSet, .Hashtable, .List, .Map, .Set

A bundle's authority to register or get a service. Permission to get a service is required in order to detect events regarding the service. Untrusted bundles should not be able to detect the presence of certain services unless they have the appropriate ServicePermission to get the specific service.
Author
$Id: ff7fc46dd623c0a09b49965048dd6faa2b111b39 $

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
pack-priv transient int
action_mask

The actions mask.

pack-priv static final int
private static final int
private volatile String
actions

The actions in canonical form.

pack-priv transient Filter
filter

If this ServicePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.

public static final String
GET

The action string get.

pack-priv final transient String[]
objectClass

The object classes for this ServicePermission.

private transient String
prefix

If constructed with a name and the name ends with ".*", this contains the name without the final "*".

private transient volatile Map<String, Object>
properties

This map holds the properties of the permission, used to match a filter in implies.

public static final String
REGISTER

The action string register.

pack-priv static final long
pack-priv final transient ServiceReference<?>
service

The service used by this ServicePermission.

private transient boolean
wildcard

Hides java.security.BasicPermission.wildcard.

True if constructed with a name and the name is "*" or ends with ".*".

Constructor Summary

AccessConstructor and Description
public
ServicePermission(String
The service class name
name
,
String
get,register (canonical order)
actions
)

Create a new ServicePermission.

public
ServicePermission(ServiceReference<?>
The requested service.
reference
,
String
The action get.
actions
)

Creates a new requested ServicePermission object to be used by code that must perform checkPermission for the get action.

pack-priv
ServicePermission(String
class name
name
,
int
action mask
mask
)

Package private constructor used by ServicePermissionCollection.

Method Summary

Modifier and TypeMethod and Description
private static String

Returns:

permission name.
createName
(ServiceReference<?>
ServiceReference to use to create permission name.
reference
)

Create a permission name from a ServiceReference

public boolean

Returns:

true if obj is a ServicePermission, and has the same class name and actions as this ServicePermission object; false otherwise.
equals
(Object
The object to test for equality.
obj
)

Overrides java.security.BasicPermission.equals.

Determines the equality of two ServicePermission objects.

public String

Returns:

The canonical string representation of the actions.
getActions
()

Overrides java.security.BasicPermission.getActions.

Returns the canonical string representation of the actions.

private Map<String, Object>

Returns:

a map of properties for this permission.
getProperties
()

Called by ServicePermission#implies(Permission).

public int

Returns:

Hash code value for this object.
hashCode
()

Overrides java.security.BasicPermission.hashCode.

Returns the hash code value for this object.

public boolean

Returns:

true if the specified permission is implied by this object; false otherwise.
implies
(Permission
The target permission to check.
p
)

Overrides java.security.BasicPermission.implies.

Determines if a ServicePermission object "implies" the specified permission.

pack-priv boolean

Returns:

true if the specified permission is implied by this object; false otherwise.
implies0
(ServicePermission
The requested ServicePermission which has already be validated as a proper argument. The requested ServicePermission must not have a filter expression.
requested
,
int
The effective actions with which to start.
effective
)

Internal implies method.

public PermissionCollection

Returns:

A new PermissionCollection object suitable for storing ServicePermission objects.
newPermissionCollection
()

Overrides java.security.BasicPermission.newPermissionCollection.

Returns a new PermissionCollection object for storing ServicePermission objects.

private static int

Returns:

action mask.
parseActions
(String
Action string.
actions
)

Parse action string into action mask.

private static Filter

Returns:

a Filter for this bundle. If the specified filterString is not a filter expression, then null is returned.
parseFilter
(String
The filter string to parse.
filterString
)

Parse filter string into a Filter object.

private synchronized void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
s
)

Hides java.security.BasicPermission.readObject.

readObject is called to restore the state of this permission from a stream.

private void
setTransients(Filter f, int
action mask
mask
)

Called by constructors and when deserialized.

private synchronized void
writeObject(ObjectOutputStream s)

WriteObject is called to save the state of this permission to a stream.

Field Detail

ACTION_ALLback to summary
private static final int ACTION_ALL
ACTION_GETback to summary
private static final int ACTION_GET
action_maskback to summary
pack-priv transient int action_mask

The actions mask.

ACTION_NONEback to summary
pack-priv static final int ACTION_NONE
ACTION_REGISTERback to summary
private static final int ACTION_REGISTER
actionsback to summary
private volatile String actions

The actions in canonical form.

filterback to summary
pack-priv transient Filter filter

If this ServicePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.

GETback to summary
public static final String GET

The action string get.

objectClassback to summary
pack-priv final transient String[] objectClass

The object classes for this ServicePermission. Must be null if not constructed with a service.

prefixback to summary
private transient String prefix

If constructed with a name and the name ends with ".*", this contains the name without the final "*".

propertiesback to summary
private transient volatile Map<String, Object> properties

This map holds the properties of the permission, used to match a filter in implies. This is not initialized until necessary, and then cached in this object.

REGISTERback to summary
public static final String REGISTER

The action string register.

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.security.BasicPermission.serialVersionUID.

serviceback to summary
pack-priv final transient ServiceReference<?> service

The service used by this ServicePermission. Must be null if not constructed with a service.

wildcardback to summary
private transient boolean wildcard

Hides java.security.BasicPermission.wildcard.

True if constructed with a name and the name is "*" or ends with ".*".

Constructor Detail

ServicePermissionback to summary
public ServicePermission(String name, String actions)

Create a new ServicePermission.

The name of the service is specified as a fully qualified class name. Wildcards may be used.

name ::= <class name> | <class name ending in ".*"> | *
Examples:
org.osgi.service.http.HttpService
org.osgi.service.http.*
*
For the get action, the name can also be a filter expression. The filter gives access to the service properties as well as the following attributes:
  • signer - A Distinguished Name chain used to sign the bundle publishing the service. Wildcards in a DN are not matched according to the filter string rules, but according to the rules defined for a DN chain.
  • location - The location of the bundle publishing the service.
  • id - The bundle ID of the bundle publishing the service.
  • name - The symbolic name of the bundle publishing the service.
Since the above attribute names may conflict with service property names used by a service, you can prefix an attribute name with '@' in the filter expression to match against the service property and not one of the above attributes. Filter attribute names are processed in a case sensitive manner unless the attribute references a service property. Service properties names are case insensitive.

There are two possible actions: get and register. The get permission allows the owner of this permission to obtain a service with this name. The register permission allows the bundle to register a service under that name.

Parameters
name:String

The service class name

actions:String

get,register (canonical order)

Exceptions
IllegalArgumentException:
If the specified name is a filter expression and either the specified action is not get or the filter has an invalid syntax.
ServicePermissionback to summary
public ServicePermission(ServiceReference<?> reference, String actions)

Creates a new requested ServicePermission object to be used by code that must perform checkPermission for the get action. ServicePermission objects created with this constructor cannot be added to a ServicePermission permission collection.

Parameters
reference:ServiceReference<?>

The requested service.

actions:String

The action get.

Exceptions
IllegalArgumentException:
If the specified action is not get or reference is null.
Since
1.5
ServicePermissionback to summary
pack-priv ServicePermission(String name, int mask)

Package private constructor used by ServicePermissionCollection.

Parameters
name:String

class name

mask:int

action mask

Method Detail

createNameback to summary
private static String createName(ServiceReference<?> reference)

Create a permission name from a ServiceReference

Parameters
reference:ServiceReference<?>

ServiceReference to use to create permission name.

Returns:String

permission name.

equalsback to summary
public boolean equals(Object obj)

Overrides java.security.BasicPermission.equals.

Determines the equality of two ServicePermission objects. Checks that specified object has the same class name and action as this ServicePermission.

Parameters
obj:Object

The object to test for equality.

Returns:boolean

true if obj is a ServicePermission, and has the same class name and actions as this ServicePermission object; false otherwise.

Annotations
@Override
getActionsback to summary
public String getActions()

Overrides java.security.BasicPermission.getActions.

Returns the canonical string representation of the actions. Always returns present actions in the following order: get, register.

Returns:String

The canonical string representation of the actions.

Annotations
@Override
getPropertiesback to summary
private Map<String, Object> getProperties()

Called by ServicePermission#implies(Permission). This method is only called on a requested permission which cannot have a filter set.

Returns:Map<String, Object>

a map of properties for this permission.

hashCodeback to summary
public int hashCode()

Overrides java.security.BasicPermission.hashCode.

Returns the hash code value for this object.

Returns:int

Hash code value for this object.

Annotations
@Override
impliesback to summary
public boolean implies(Permission p)

Overrides java.security.BasicPermission.implies.

Determines if a ServicePermission object "implies" the specified permission.

Parameters
p:Permission

The target permission to check.

Returns:boolean

true if the specified permission is implied by this object; false otherwise.

Annotations
@Override
implies0back to summary
pack-priv boolean implies0(ServicePermission requested, int effective)

Internal implies method. Used by the implies and the permission collection implies methods.

Parameters
requested:ServicePermission

The requested ServicePermission which has already be validated as a proper argument. The requested ServicePermission must not have a filter expression.

effective:int

The effective actions with which to start.

Returns:boolean

true if the specified permission is implied by this object; false otherwise.

newPermissionCollectionback to summary
public PermissionCollection newPermissionCollection()

Overrides java.security.BasicPermission.newPermissionCollection.

Returns a new PermissionCollection object for storing ServicePermission objects.

Returns:PermissionCollection

A new PermissionCollection object suitable for storing ServicePermission objects.

Annotations
@Override
parseActionsback to summary
private static int parseActions(String actions)

Parse action string into action mask.

Parameters
actions:String

Action string.

Returns:int

action mask.

parseFilterback to summary
private static Filter parseFilter(String filterString)

Parse filter string into a Filter object.

Parameters
filterString:String

The filter string to parse.

Returns:Filter

a Filter for this bundle. If the specified filterString is not a filter expression, then null is returned.

Exceptions
IllegalArgumentException:
If the filter syntax is invalid.
readObjectback to summary
private synchronized void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides java.security.BasicPermission.readObject.

readObject is called to restore the state of this permission from a stream.

Parameters
s:ObjectInputStream

Doc from java.security.BasicPermission.readObject.

the ObjectInputStream from which data is read

Exceptions
IOException:

Doc from java.security.BasicPermission.readObject.

if an I/O error occurs

ClassNotFoundException:

Doc from java.security.BasicPermission.readObject.

if a serialized class cannot be loaded

setTransientsback to summary
private void setTransients(Filter f, int mask)

Called by constructors and when deserialized.

Parameters
mask:int

action mask

writeObjectback to summary
private synchronized void writeObject(ObjectOutputStream s) throws IOException

WriteObject is called to save the state of this permission to a stream. The actions are serialized, and the superclass takes care of the name.

org.osgi.framework back to summary

private final Class ServicePermission.Properties

extends AbstractMap<String, Object>
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private transient volatile Set<Map.Entry<String, Object>>
private final Map<String, Object>
private final ServiceReference<?>

Constructor Summary

AccessConstructor and Description
pack-priv
Properties(Map<String, Object> properties, ServiceReference<?> service)

Method Summary

Modifier and TypeMethod and Description
public Set<Map.Entry<String, Object>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public Object
get(Object
the key whose associated value is to be returned
k
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Inherited from java.util.AbstractMap:
clearclonecontainsKeycontainsValueequalshashCodeisEmptykeySetputputAllremovesizetoStringvalues

Field Detail

entriesback to summary
private transient volatile Set<Map.Entry<String, Object>> entries
propertiesback to summary
private final Map<String, Object> properties
serviceback to summary
private final ServiceReference<?> service

Constructor Detail

Propertiesback to summary
pack-priv Properties(Map<String, Object> properties, ServiceReference<?> service)

Method Detail

entrySetback to summary
public Set<Map.Entry<String, Object>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<String, Object>>

a set view of the mappings contained in this map

getback to summary
public Object get(Object k)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
k:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:Object

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
org.osgi.framework back to summary

private final Class ServicePermission.Properties.Entry

extends Object
implements Map.Entry<String, Object>
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry

Field Summary

Modifier and TypeField and Description
private final String
k

private final Object
v

Constructor Summary

AccessConstructor and Description
pack-priv
Entry(String key, Object value)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
object to be compared for equality with this map entry
obj
)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Compares the specified object with this entry for equality.

public String
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

public Object
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry.

public Object
setValue(Object
new value to be stored in this entry
value
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

kback to summary
private final String k
vback to summary
private final Object v

Constructor Detail

Entryback to summary
pack-priv Entry(String key, Object value)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Doc from java.util.Map.Entry.equals.

Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

    (e1.getKey()==null ?
     e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
    (e1.getValue()==null ?
     e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
Parameters
obj:Object

object to be compared for equality with this map entry

Returns:boolean

true if the specified object is equal to this map entry

Annotations
@Override
getKeyback to summary
public String getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:String

the key corresponding to this entry

getValueback to summary
public Object getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:Object

the value corresponding to this entry

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Doc from java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:

    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
Returns:int

the hash code value for this map entry

Annotations
@Override
setValueback to summary
public Object setValue(Object value)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
value:Object

new value to be stored in this entry

Returns:Object

old value corresponding to the entry

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override