Add yang-data-jaxen OSGi activator 30/71830/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 7 May 2018 11:24:56 +0000 (13:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 May 2018 11:24:56 +0000 (13:24 +0200)
While we are providing a ServiceLoader definition, which can be
picked up by SPI Fly, provide an explicit OSGi activator, too.

Change-Id: Id7a221b34c10aeb4f492c9ab71b7af431840d718
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-jaxen/pom.xml
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/Activator.java [new file with mode: 0644]
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/package-info.java [new file with mode: 0644]

index d8191fdf109a2de13bbc45d0cb231d2598196c26..7e476036241275424be1dbe8a45a315413391408 100644 (file)
                 <configuration>
                     <instructions>
                         <Include-Resource>{META-INF/services=${project.build.directory}/classes/META-INF/services}</Include-Resource>
+                        <Bundle-Activator>org.opendaylight.yangtools.yang.data.jaxen.osgi.Activator</Bundle-Activator>
                     </instructions>
                 </configuration>
             </plugin>
diff --git a/yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/Activator.java b/yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/Activator.java
new file mode 100644 (file)
index 0000000..2b979a8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.jaxen.osgi;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathSchemaContextFactory;
+import org.opendaylight.yangtools.yang.data.jaxen.JaxenSchemaContextFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * YANG Jaxen XPath implementation activator. Publishes a {@link XPathSchemaContextFactory} implementation on bundle
+ * start.
+ *
+ * @author Robert Varga
+ */
+public final class Activator implements BundleActivator {
+    private ServiceRegistration<@NonNull XPathSchemaContextFactory> registration;
+
+    @Override
+    public void start(final BundleContext context) throws Exception {
+        registration = context.registerService(XPathSchemaContextFactory.class, new JaxenSchemaContextFactory(), null);
+    }
+
+    @Override
+    public void stop(final BundleContext context) throws Exception {
+        if (registration != null) {
+            registration.unregister();
+            registration = null;
+        }
+    }
+}
diff --git a/yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/package-info.java b/yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/osgi/package-info.java
new file mode 100644 (file)
index 0000000..1b3732a
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+/**
+ * OSGi-specific Jaxen XPath implementation code. Contains activators and similar.
+ */
+package org.opendaylight.yangtools.yang.data.jaxen.osgi;
\ No newline at end of file