Added cubby-holes for new projects.
diff --git a/utils/osgi/pom.xml b/utils/osgi/pom.xml
new file mode 100644
index 0000000..ccf3385
--- /dev/null
+++ b/utils/osgi/pom.xml
@@ -0,0 +1,26 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-utils-osgi</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>OSGI utilities</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
new file mode 100644
index 0000000..b53b5fa
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
@@ -0,0 +1,19 @@
+package org.onlab.osgi;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * Default implementation of the service directory using OSGi framework utilities.
+ */
+public class DefaultServiceDirectory implements ServiceDirectory {
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
+ T impl = bc.getService(bc.getServiceReference(serviceClass));
+ if (impl == null) {
+ throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
+ }
+ return impl;
+ }
+}
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/ServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/ServiceDirectory.java
new file mode 100644
index 0000000..ee33fa2
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/ServiceDirectory.java
@@ -0,0 +1,18 @@
+package org.onlab.osgi;
+
+/**
+ * Simple abstraction of a service directory where service implementations can
+ * be found by the class name of the interfaces they provide.
+ */
+public interface ServiceDirectory {
+
+ /**
+ * Returns implementation of the specified service class.
+ * @param serviceClass service class
+ * @param <T> type of service
+ * @return implementation class
+ * @throws ServiceNotFoundException if no implementation found
+ */
+ <T> T get(Class<T> serviceClass);
+
+}
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/ServiceNotFoundException.java b/utils/osgi/src/main/java/org/onlab/osgi/ServiceNotFoundException.java
new file mode 100644
index 0000000..4a79622
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/ServiceNotFoundException.java
@@ -0,0 +1,31 @@
+package org.onlab.osgi;
+
+/**
+ * Represents condition where some service is not found or not available.
+ */
+public class ServiceNotFoundException extends RuntimeException {
+
+ /**
+ * Creates a new exception with no message.
+ */
+ public ServiceNotFoundException() {
+ }
+
+ /**
+ * Creates a new exception with the supplied message.
+ * @param message error message
+ */
+ public ServiceNotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new exception with the supplied message and cause.
+ * @param message error message
+ * @param cause cause of the error
+ */
+ public ServiceNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/TestServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/TestServiceDirectory.java
new file mode 100644
index 0000000..2915d4b
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/TestServiceDirectory.java
@@ -0,0 +1,30 @@
+package org.onlab.osgi;
+
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.MutableClassToInstanceMap;
+
+/**
+ * Service directory implementation suitable for testing.
+ */
+public class TestServiceDirectory implements ServiceDirectory {
+
+ private ClassToInstanceMap<Object> services = MutableClassToInstanceMap.create();
+
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ return services.getInstance(serviceClass);
+ }
+
+ /**
+ * Adds a new service to the directory.
+ *
+ * @param serviceClass service class
+ * @param service service instance
+ * @return self
+ */
+ public TestServiceDirectory add(Class serviceClass, Object service) {
+ services.putInstance(serviceClass, service);
+ return this;
+ }
+
+}
diff --git a/utils/osgi/src/main/javadoc/org/onlab/osgi/package.html b/utils/osgi/src/main/javadoc/org/onlab/osgi/package.html
new file mode 100644
index 0000000..b833050
--- /dev/null
+++ b/utils/osgi/src/main/javadoc/org/onlab/osgi/package.html
@@ -0,0 +1,3 @@
+<body>
+Facilities for building testable components in OSGi independent fashion.
+</body>
\ No newline at end of file
diff --git a/utils/pom.xml b/utils/pom.xml
new file mode 100644
index 0000000..60cd862
--- /dev/null
+++ b/utils/pom.xml
@@ -0,0 +1,41 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-utils</artifactId>
+ <packaging>pom</packaging>
+
+ <description>Domain agnostic utilities</description>
+
+ <modules>
+ <module>osgi</module>
+ <module>rest</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/utils/rest/pom.xml b/utils/rest/pom.xml
new file mode 100644
index 0000000..52988cf
--- /dev/null
+++ b/utils/rest/pom.xml
@@ -0,0 +1,44 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-utils-rest</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>JAX-RS utilities</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <version>1.18.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-grizzly2</artifactId>
+ <version>1.18.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onlab.onos</groupId>
+ <artifactId>onos-utils-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/utils/rest/src/main/java/org/onlab/rest/BaseResource.java b/utils/rest/src/main/java/org/onlab/rest/BaseResource.java
new file mode 100644
index 0000000..78fa031
--- /dev/null
+++ b/utils/rest/src/main/java/org/onlab/rest/BaseResource.java
@@ -0,0 +1,36 @@
+package org.onlab.rest;
+
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onlab.osgi.ServiceDirectory;
+
+/**
+ * Base abstraction of a JAX-RS resource.
+ */
+public abstract class BaseResource {
+
+ private static ServiceDirectory services = new DefaultServiceDirectory();
+
+ /**
+ * Sets alternate service directory to be used for lookups.
+ * <p>
+ * Intended to ease unit testing and not intended for use in production.
+ * </p>
+ *
+ * @param serviceDirectory alternate service directory
+ */
+ public static void setServiceDirectory(ServiceDirectory serviceDirectory) {
+ services = serviceDirectory;
+ }
+
+ /**
+ * Returns reference to the specified service implementation.
+ *
+ * @param service service class
+ * @param <T> type of service
+ * @return service implementation
+ */
+ protected static <T> T get(Class<T> service) {
+ return services.get(service);
+ }
+
+}
diff --git a/utils/rest/src/main/javadoc/org/onlab/rest/package.html b/utils/rest/src/main/javadoc/org/onlab/rest/package.html
new file mode 100644
index 0000000..09b098f
--- /dev/null
+++ b/utils/rest/src/main/javadoc/org/onlab/rest/package.html
@@ -0,0 +1,3 @@
+<body>
+Facilities for building JAX-RS web resources.
+</body>
\ No newline at end of file