Package org.apache.felix.utils.resource
Class RequirementImpl
- java.lang.Object
-
- org.apache.felix.utils.resource.RequirementImpl
-
- All Implemented Interfaces:
org.osgi.resource.Requirement
public class RequirementImpl extends java.lang.Object implements org.osgi.resource.Requirement
Implementation of the OSGi Requirement interface.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.Object>
attributes
Optional attributes.protected java.util.Map<java.lang.String,java.lang.String>
directives
Optional attributes.protected java.lang.String
namespace
The namespace.protected org.osgi.resource.Resource
resource
The resource.
-
Constructor Summary
Constructors Constructor Description RequirementImpl(org.osgi.resource.Resource res, java.lang.String ns, java.lang.String filter)
Create a requirement with a namespace and a filter.RequirementImpl(org.osgi.resource.Resource res, java.lang.String ns, java.util.Map<java.lang.String,java.lang.String> dirs, java.util.Map<java.lang.String,java.lang.Object> attrs)
Create a requirement.RequirementImpl(org.osgi.resource.Resource resource, java.lang.String path, java.util.Map<java.lang.String,java.lang.String> dirs, java.util.Map<java.lang.String,java.lang.Object> attrs, SimpleFilter sf)
RequirementImpl(org.osgi.resource.Resource resource, org.osgi.resource.Requirement requirement)
Create a requirement based on an existing requirement, providing the resource.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>
getAttributes()
Return the attributes.java.util.Map<java.lang.String,java.lang.String>
getDirectives()
Return the directives.SimpleFilter
getFilter()
static SimpleFilter
getFilter(org.osgi.resource.Requirement requirement)
Utility method to obtain a SimpleFilter from a given requirement.java.lang.String
getNamespace()
Return the namespace.org.osgi.resource.Resource
getResource()
Return the resource.boolean
isOptional()
static boolean
isOptional(org.osgi.resource.Requirement requirement)
Utility method to check whether a requirement is optional.boolean
matches(org.osgi.resource.Capability cap)
java.lang.String
toString()
-
-
-
Field Detail
-
resource
protected final org.osgi.resource.Resource resource
The resource. Required.
-
namespace
protected final java.lang.String namespace
The namespace. Required.
-
directives
protected final java.util.Map<java.lang.String,java.lang.String> directives
Optional attributes. Never null.
-
attributes
protected final java.util.Map<java.lang.String,java.lang.Object> attributes
Optional attributes. Never null.
-
-
Constructor Detail
-
RequirementImpl
public RequirementImpl(org.osgi.resource.Resource res, java.lang.String ns, java.util.Map<java.lang.String,java.lang.String> dirs, java.util.Map<java.lang.String,java.lang.Object> attrs)
Create a requirement.- Parameters:
res
- The resource associated with the requirement.ns
- The namespace of the requirement.attrs
- The attributes of the requirement.dirs
- The directives of the requirement.
-
RequirementImpl
public RequirementImpl(org.osgi.resource.Resource res, java.lang.String ns, java.lang.String filter)
Create a requirement with a namespace and a filter. This is a convenience method that creates a requirement with an empty attributes map and a single 'filter' directive.- Parameters:
res
- The resource associated with the requirement.ns
- The namespace for the requirement.filter
- The filter.
-
RequirementImpl
public RequirementImpl(org.osgi.resource.Resource resource, org.osgi.resource.Requirement requirement)
Create a requirement based on an existing requirement, providing the resource. The namespace, attributes and directives are copied from the provided requirement.- Parameters:
requirement
- The requirement to base the new requirement on.resource
- The resource to be associated with the requirement
-
RequirementImpl
public RequirementImpl(org.osgi.resource.Resource resource, java.lang.String path, java.util.Map<java.lang.String,java.lang.String> dirs, java.util.Map<java.lang.String,java.lang.Object> attrs, SimpleFilter sf)
-
-
Method Detail
-
matches
public boolean matches(org.osgi.resource.Capability cap)
-
isOptional
public boolean isOptional()
-
getFilter
public SimpleFilter getFilter()
-
isOptional
public static boolean isOptional(org.osgi.resource.Requirement requirement)
Utility method to check whether a requirement is optional. This method works with any object implementing the requirement interface.- Parameters:
requirement
- A requirement- Returns:
true
if the requirement it optional,false
otherwise.
-
getFilter
public static SimpleFilter getFilter(org.osgi.resource.Requirement requirement)
Utility method to obtain a SimpleFilter from a given requirement. If the requirement contains aConstants.FILTER_DIRECTIVE
directive, it will be used, else, the filter will be derived from the attributes.- Parameters:
requirement
- A requirement- Returns:
- a valid filter, never
null
.
-
getNamespace
public java.lang.String getNamespace()
Return the namespace.- Returns:
- The namespace. This is never @{code null}.
-
getAttributes
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Return the attributes.- Returns:
- The attributes, might be empty.
-
getDirectives
public java.util.Map<java.lang.String,java.lang.String> getDirectives()
Return the directives.- Returns:
- The directives, might be empty.
-
getResource
public org.osgi.resource.Resource getResource()
Return the resource.- Returns:
- The resource or @{code null}.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-