Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KARAF-7517] [KARAF-7518] [KARAF-7515] [KARAF-7433] Karaf Cellar DOSGi rework #91

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dosgi/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!--

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
*/
public abstract class Constants {

public static final String DOT = ".";
public static final String SEPARATOR = "/";
public static final String ALL_INTERFACES = "*";
public static final String INTERFACE_SEPARATOR = ",";
public static final String COMMA_SEPARATOR = ",";
public static final String SERVICE_DOT = "service.";
public static final String INTERFACE_PREFIX = "org.apache.karaf.cellar.dosgi";
public static final String REQUEST_PREFIX = "org.apache.karaf.cellar.dosgi.request";
public static final String RESULT_PREFIX = "org.apache.karaf.cellar.dosgi.result";
public static final String REMOTE_ENDPOINTS = "org.apache.karaf.cellar.dosgi.endpoints";
public static final String EXPORTED_INTERFACES = "service.exported.interfaces";
public static final String ENDPOINT_FRAMEWORK_UUID = "frameworkUUID";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,80 @@
public class EndpointDescription implements MultiNode {

private final String id;
private final Set<Node> nodes = new LinkedHashSet<Node>();
private final Map<String, Object> properties = new HashMap<String, Object>();
private final String filter;
private final Set<Node> nodes = new LinkedHashSet();
private final Map<String, Object> properties = new HashMap();

/**
* Constructor
* Constructor with service properties
*
* @param id
* @param node
* @param properties
*/
public EndpointDescription(String id, Node node) {
public EndpointDescription(String id, Node node, Map<String, Object> properties) {
this.id = id;
this.nodes.add(node);
properties.put(org.osgi.framework.Constants.OBJECTCLASS,getServiceClass());
this.properties.putAll(properties);
this.filter = createFilterString(properties, false);
}

/**
* Constructor LDAP filter string from service properties
* with or without object class
*
* @param properties
* @param includeObjectClass
*/
public static String createFilterString(Map<String, Object> properties, boolean includeObjectClass) {
if (properties.size() == 0) {
return null;
}
int filterCount = 0;
StringBuilder filterStringBuilder = new StringBuilder();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
if (entry.getValue() instanceof String) {
switch (entry.getKey()) {
case org.osgi.framework.Constants.OBJECTCLASS:
if (includeObjectClass) {
filterStringBuilder.append("(").append(entry.getKey()).append("=").append(entry.getValue()).append(")");
filterCount++;
}
break;
default:
filterStringBuilder.append("(").append(entry.getKey()).append("=").append(entry.getValue()).append(")");
filterCount++;
break;
}
}
}
if (filterCount == 1) {
return filterStringBuilder.toString();
} else if (filterCount > 1) {
return filterStringBuilder.insert(0, "(&").append(')').toString();
} else {
return null;
}
}

/**
* Tests the properties of this <code>EndpointDescription</code> against
* the given filter using a case insensitive match.
*
* @param filter The filter to test.
* @param filterString The filter to test.
* @return <code>true</code> If the properties of this
* <code>EndpointDescription</code> match the filter,
* <code>false</code> otherwise.
* <code>EndpointDescription</code> match the filter,
* <code>false</code> otherwise.
* @throws IllegalArgumentException If <code>filter</code> contains an
* invalid filter string that cannot be parsed.
*/
public boolean matches(String filter) {
Filter f;
public boolean matches(String filterString) {
Filter filter;
try {
f = FrameworkUtil.createFilter(filter);
filter = FrameworkUtil.createFilter(filterString);
} catch (InvalidSyntaxException e) {
IllegalArgumentException iae = new IllegalArgumentException(e.getMessage());
iae.initCause(e);
throw iae;
IllegalArgumentException illegalArgumentException = new IllegalArgumentException(e.getMessage(), e);
throw illegalArgumentException;
}

Dictionary dictionary = new Properties();
Expand All @@ -76,42 +115,46 @@ public boolean matches(String filter) {
dictionary.put(key, value);
}
/*
* we can use matchCase here since properties already supports case
* insensitive key lookup.
*/
return f.matchCase(dictionary);
* we can use matchCase here since properties already supports case-insensitive key lookup.
*/
return filter.matchCase(dictionary);
}

public String getId() {
return id;
}

public String getVersion() {
String result = null;
String[] parts = id.split(Constants.SEPARATOR);
if (parts != null && parts.length > 0) {
result = parts[parts.length - 1];
}
return result;
}

public String getFilter() {
return filter;
}

public Set<Node> getNodes() {
return nodes;
}

public void setNodes(Set<Node> nodes) {
if(nodes != null) {
for(Node node:nodes) {
this.nodes.add(node);
}
}
}
public void setNodes(Set<Node> nodes) {
if (nodes != null) {
for (Node node : nodes) {
this.nodes.add(node);
}
}
}

public Map<String, Object> getProperties() {
return properties;
}

public final String getServiceClass() {
String result = null;

if(id != null) {
String[] parts = id.split(Constants.SEPARATOR);
if(parts != null && parts.length > 0) {
result = parts[0];
}
}
return result;
return (String) properties.get(org.osgi.framework.Constants.OBJECTCLASS);
}

@Override
Expand All @@ -125,16 +168,12 @@ public boolean equals(Object o) {

EndpointDescription endpointDescription = (EndpointDescription) o;

if (id != null ? !id.equals(endpointDescription.id) : endpointDescription.id != null) {
return false;
}

return true;
return id != null ? id.equals(endpointDescription.id) : endpointDescription.id == null;
}

@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}

}
}
Loading