Archived
0

Новый API: Регистрация комманд для Apache Felix Gogo Shell

This commit is contained in:
2016-08-15 12:07:54 +03:00
parent ec2343feff
commit 15f1da3dac
3 changed files with 65 additions and 1 deletions

View File

@@ -19,9 +19,17 @@
<groupId>asys</groupId> <groupId>asys</groupId>
<artifactId>api</artifactId> <artifactId>api</artifactId>
<version>0.2</version> <version>0.3</version>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
</dependencies>
<build> <build>
<finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName> <finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
<plugins> <plugins>

View File

@@ -0,0 +1,41 @@
/*
* DmitriyMX <mail@dmitriymx.ru>
* 2016-08-15
*/
package asys.api;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import java.lang.reflect.Method;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
public class ASysUtils {
public static ServiceRegistration<?> RegisterCommands(BundleContext bundleContext, Object commnadsObject, String scope) {
return bundleContext.registerService(
commnadsObject.getClass().getName(),
commnadsObject,
getCommandListByAnnotationMethods(scope, commnadsObject.getClass()));
}
private static Dictionary<String, Object> getCommandListByAnnotationMethods(String scope, Class<?> clazz) {
List<String> listCommand = new Vector<>();
Method[] methods = clazz.getMethods();
for(Method method : methods) {
if (method.isAnnotationPresent(Command.class)) {
listCommand.add(method.getName());
}
}
Dictionary<String, Object> props = new Hashtable<>();
if (listCommand.size() > 0) {
props.put("osgi.command.scope", scope);
props.put("osgi.command.function", listCommand.toArray(new String[listCommand.size()]));
}
return props;
}
}

View File

@@ -0,0 +1,15 @@
/*
* DmitriyMX <mail@dmitriymx.ru>
* 2016-08-15
*/
package asys.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(value = ElementType.METHOD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Command {
}