// Convert generic caps/reqs
if ("Import-Service".equals(h))
{
if (!"service".equals(mode))
{
Clause clause = hc[0];
String multiple = clause.getDirective("multiple");
String avail = clause.getDirective("availability");
String filter = clause.getAttribute("filter");
StringBuilder sb = new StringBuilder();
sb.append("osgi.service;effective:=active;");
if ("optional".equals(avail)) {
sb.append("resolution:=optional;");
}
if ("true".equals(multiple)) {
sb.append("cardinality:=multiple;");
}
if (filter == null) {
filter = "(" + Constants.OBJECTCLASS + "=" + clause.getName() + ")";
} else if (!filter.startsWith("(") && !filter.endsWith(")")) {
filter = "(&(" + Constants.OBJECTCLASS + "=" + clause.getName() + ")(" + filter + "))";
} else {
filter = "(&(" + Constants.OBJECTCLASS + "=" + clause.getName() + ")" + filter + ")";
}
sb.append("filter:=\"").append(filter).append("\"");
reqs.add(sb.toString());
}
else if (!"generic".equals(mode))
{
Set<Clause> clauses = hdrs.get(h);
if (clauses == null) {
clauses = new HashSet<Clause>();
hdrs.put(h, clauses);
}
clauses.addAll(Arrays.asList(hc));
}
}
else if ("Export-Service".equals(h))
{
if (!"service".equals(mode))
{
StringBuilder sb = new StringBuilder();
sb.append("osgi.service;effective:=active;objectClass");
if (hc.length > 1) {
sb.append(":List<String>=\"");
} else {
sb.append("=\"");
}
for (int i = 0; i < hc.length; i++)
{
if (i > 0)
{
sb.append(",");
}
sb.append(hc[i].getName());
}
sb.append("\"");
for (int i = 0; i < hc[0].getAttributes().length; i++)
{
sb.append(";");
sb.append(hc[0].getAttributes()[i].getName());
sb.append("=\"");
sb.append(hc[0].getAttributes()[i].getValue());
sb.append("\"");
}
caps.add(sb.toString());
}
else if (!"generic".equals(mode))
{
Set<Clause> clauses = hdrs.get(h);
if (clauses == null) {
clauses = new HashSet<Clause>();
hdrs.put(h, clauses);
}
clauses.addAll(Arrays.asList(hc));
}
}
else
{
Set<Clause> clauses = hdrs.get(h);
if (clauses == null)
{
clauses = new HashSet<Clause>();
hdrs.put(h, clauses);
}
clauses.addAll(Arrays.asList( hc ) );
}
}
if (!caps.isEmpty())
{
StringBuilder sb = new StringBuilder();
String header = analyzer.getProperty("Provide-Capability");
if (header != null)
{
sb.append(header);
}
for (String cap : caps) {
if (sb.length() > 0) {
sb.append(",");
}
sb.append(cap);
}
analyzer.setProperty("Provide-Capability", sb.toString());
}
if (!reqs.isEmpty())
{
StringBuilder sb = new StringBuilder();
String header = analyzer.getProperty("Require-Capability");
if (header != null)
{
sb.append(header);
}
for (String req : reqs) {
if (sb.length() > 0) {
sb.append(",");
}
sb.append(req);
}
analyzer.setProperty("Require-Capability", sb.toString());
}
// Merge
for ( String header : hdrs.keySet() )
{
if ( "Import-Class".equals( header ) || "Import-Package".equals( header ) )
{
Set<Clause> newAttr = hdrs.get(header);
for ( Clause a : newAttr )
{
String pkg = a.getName();
if ( "Import-Class".equals( header ) )
{
int n = a.getName().lastIndexOf( '.' );
if ( n > 0 )
{
pkg = pkg.subSequence( 0, n ).toString();
}
else
{
continue;
}
}
PackageRef pkgRef = analyzer.getPackageRef( pkg );
if ( !analyzer.getReferred().containsKey( pkgRef ) )
{
Attrs attrs = analyzer.getReferred().put(pkgRef);
for (Attribute attribute : a.getAttributes())
{
attrs.put(attribute.getName(), attribute.getValue());
}
}
}
}
else
{
Set<String> merge = Create.set();
String org = analyzer.getProperty(header);
if (org != null && !org.isEmpty())
{
for (Clause clause : parseHeader(org))
{
merge.add(clause.toString());
}
}
for (Clause clause : hdrs.get(header))
{
merge.add(clause.toString());
}
StringBuilder sb = new StringBuilder();
for (String clause : merge)
{
if ( sb.length() > 0 )