blob: 84de220db51b7d1d20b66b0514a21c4e89ecca05 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.felix.resolver;
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.Version;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.resource.Capability;
import org.osgi.resource.Namespace;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
public class Util
{
public static String getSymbolicName(Resource resource)
{
List<Capability> caps = resource.getCapabilities(null);
for (Capability cap : caps)
{
if (cap.getNamespace().equals(IdentityNamespace.IDENTITY_NAMESPACE))
{
return cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE).toString();
}
}
return null;
}
public static Version getVersion(Resource resource)
{
List<Capability> caps = resource.getCapabilities(null);
for (Capability cap : caps)
{
if (cap.getNamespace().equals(IdentityNamespace.IDENTITY_NAMESPACE))
{
return (Version)
cap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
}
}
return null;
}
public static boolean isFragment(Resource resource)
{
List<Capability> caps = resource.getCapabilities(null);
for (Capability cap : caps)
{
if (cap.getNamespace().equals(IdentityNamespace.IDENTITY_NAMESPACE))
{
String type = (String)
cap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
return (type != null) && type.equals(IdentityNamespace.TYPE_FRAGMENT);
}
}
return false;
}
public static boolean isOptional(Requirement req)
{
String resolution = req.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
return Namespace.RESOLUTION_OPTIONAL.equalsIgnoreCase(resolution);
}
public static boolean isMultiple(Requirement req)
{
return Namespace.CARDINALITY_MULTIPLE.equals(req.getDirectives()
.get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE)) && !isDynamic(req);
}
public static boolean isDynamic(Requirement req)
{
return PackageNamespace.RESOLUTION_DYNAMIC.equals(req.getDirectives()
.get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
}
public static List<Requirement> getDynamicRequirements(List<Requirement> reqs)
{
List<Requirement> result = new ArrayList<Requirement>();
if (reqs != null)
{
for (Requirement req : reqs)
{
String resolution = req.getDirectives()
.get(PackageNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE);
if ((resolution != null)
&& resolution.equals(PackageNamespace.RESOLUTION_DYNAMIC))
{
result.add(req);
}
}
}
return result;
}
}
|