Новый API: Регистрация комманд для Apache Felix Gogo Shell
This commit is contained in:
10
API/pom.xml
10
API/pom.xml
@@ -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>
|
||||||
|
|||||||
41
API/src/main/java/asys/api/ASysUtils.java
Normal file
41
API/src/main/java/asys/api/ASysUtils.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
API/src/main/java/asys/api/Command.java
Normal file
15
API/src/main/java/asys/api/Command.java
Normal 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 {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user