Define APIs to determine how to translate an intent.

It's a part of ONOS-1654.

- IntentResolver handles translation of an intent
- IIntentRuntimeService supports to register/unregister IntentResolver

Change-Id: I9367fddf29eb55c3d7ed206e1fbf8635454f2e36
diff --git a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
index 2b8774b..6750595 100644
--- a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
+++ b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
@@ -67,6 +67,23 @@
     boolean executeBatch(BatchOperation<Intent> ops);
 
     /**
+     * Adds an IntentResolver associated with a given intent type.
+     *
+     * @param type the class instance of the intent type.
+     * @param resolver the resolver of the given intent type.
+     * @param <T> the type of the intent.
+     */
+    public <T extends Intent> void addResolver(Class<T> type, IntentResolver<T> resolver);
+
+    /**
+     * Removes the IntentResolver associated with the intent type.
+     *
+     * @param type the class instance of the intent type.
+     * @param <T> the type of the intent.
+     */
+    public <T extends Intent> void removeResolver(Class<T> type);
+
+    /**
      * Gets IFlow objects managed by the specified intent.
      *
      * @param intentId ID of the target Intent.
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentResolutionException.java b/src/main/java/net/onrc/onos/api/intent/IntentResolutionException.java
new file mode 100644
index 0000000..5b90f27
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/IntentResolutionException.java
@@ -0,0 +1,7 @@
+package net.onrc.onos.api.intent;
+
+/**
+ * The base class of an exception thrown during intent resolution.
+ */
+public class IntentResolutionException extends Exception {
+}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentResolver.java b/src/main/java/net/onrc/onos/api/intent/IntentResolver.java
new file mode 100644
index 0000000..1f13cdc
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/IntentResolver.java
@@ -0,0 +1,24 @@
+package net.onrc.onos.api.intent;
+
+import java.util.List;
+
+/**
+ * An interface to translate an intent to lower level intents.
+ *
+ * IntentResolvers are registered to {@link IIntentRuntimeService} to handle translations of intents
+ * (we call it intent resolution).
+ *
+ * @param <T> the type of intent this resolver translates
+ */
+public interface IntentResolver<T extends Intent> {
+    /**
+     * Returns lower level intents, into which the given intent is translated.
+     *
+     * This method is invoked by the Intent Framework when the framework find an unresolved intent.
+     *
+     * @param intent the intent to be translated.
+     * @return lower level intents, into which the given intent is translated.
+     * @throws IntentResolutionException if this method can't resolve the intent.
+     */
+    public List<Intent> resolve(T intent) throws IntentResolutionException;
+}
diff --git a/src/main/java/net/onrc/onos/core/newintent/IntentRuntimeModule.java b/src/main/java/net/onrc/onos/core/newintent/IntentRuntimeModule.java
index 8410400..8da30e8 100644
--- a/src/main/java/net/onrc/onos/core/newintent/IntentRuntimeModule.java
+++ b/src/main/java/net/onrc/onos/core/newintent/IntentRuntimeModule.java
@@ -9,6 +9,7 @@
 import net.onrc.onos.api.intent.IIntentRuntimeService;
 import net.onrc.onos.api.intent.Intent;
 import net.onrc.onos.api.intent.IntentId;
+import net.onrc.onos.api.intent.IntentResolver;
 
 /**
  * Implementation of Intent-Runtime Service.
@@ -64,6 +65,16 @@
     }
 
     @Override
+    public <T extends Intent> void addResolver(Class<T> type, IntentResolver<T> resolver) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public <T extends Intent> void removeResolver(Class<T> type) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
     public Collection<IFlow> getFlows(String intentId) {
         // TODO Auto-generated method stub
         return null;