From 15f1da3dacc71aa0c53abe23045a90987b3190ed Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 15 Aug 2016 12:07:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20API:=20=D0=A0?= =?UTF-8?q?=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B0=D0=BD=D0=B4=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20Apache=20Felix=20Gogo=20Shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API/pom.xml | 10 +++++- API/src/main/java/asys/api/ASysUtils.java | 41 +++++++++++++++++++++++ API/src/main/java/asys/api/Command.java | 15 +++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 API/src/main/java/asys/api/ASysUtils.java create mode 100644 API/src/main/java/asys/api/Command.java diff --git a/API/pom.xml b/API/pom.xml index aa451d1..0854cd3 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -19,9 +19,17 @@ asys api - 0.2 + 0.3 bundle + + + org.osgi + org.osgi.core + 6.0.0 + + + ${project.groupId}.${project.artifactId}-${project.version} diff --git a/API/src/main/java/asys/api/ASysUtils.java b/API/src/main/java/asys/api/ASysUtils.java new file mode 100644 index 0000000..40650b4 --- /dev/null +++ b/API/src/main/java/asys/api/ASysUtils.java @@ -0,0 +1,41 @@ +/* + * DmitriyMX + * 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 getCommandListByAnnotationMethods(String scope, Class clazz) { + List listCommand = new Vector<>(); + + Method[] methods = clazz.getMethods(); + for(Method method : methods) { + if (method.isAnnotationPresent(Command.class)) { + listCommand.add(method.getName()); + } + } + + Dictionary 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; + } +} diff --git a/API/src/main/java/asys/api/Command.java b/API/src/main/java/asys/api/Command.java new file mode 100644 index 0000000..f6ff4b9 --- /dev/null +++ b/API/src/main/java/asys/api/Command.java @@ -0,0 +1,15 @@ +/* + * DmitriyMX + * 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 { +}