Merge "Clean up code issues caused by transcriber refactoring"
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronFirewallInterface.java
index 5f5e1349f785c1a1601b344703f1a14c4073510a..ea9d2de395de4c07230a6e0bed9b1f05e9b8fb74 100644 (file)
@@ -13,10 +13,12 @@ import org.opendaylight.neutron.spi.INeutronFirewallCRUD;
 import org.opendaylight.neutron.spi.NeutronFirewall;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -25,16 +27,9 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-/**
- * Deprecated as all Neutron FWaaS is experimental and so doesn't meet
- * the scope of neutron northbound
- *
- * @deprecated
- */
-
 public class NeutronFirewallInterface extends AbstractNeutronInterface implements INeutronFirewallCRUD {
 
-    private static final Logger logger = LoggerFactory.getLogger(NeutronFirewallInterface.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(NeutronFirewallInterface.class);
 
     private ConcurrentMap<String, NeutronFirewall> firewallDB  = new ConcurrentHashMap<String, NeutronFirewall>();
 
@@ -43,33 +38,6 @@ public class NeutronFirewallInterface extends AbstractNeutronInterface implement
         super(providerContext);
     }
 
-    // this method uses reflection to update an object from it's delta.
-
-    private boolean overwrite(Object target, Object delta) {
-        Method[] methods = target.getClass().getMethods();
-
-        for (Method toMethod : methods) {
-            if (toMethod.getDeclaringClass().equals(target.getClass())
-                    && toMethod.getName().startsWith("set")) {
-
-                String toName = toMethod.getName();
-                String fromName = toName.replace("set", "get");
-
-                try {
-                    Method fromMethod = delta.getClass().getMethod(fromName);
-                    Object value = fromMethod.invoke(delta, (Object[]) null);
-                    if (value != null) {
-                        toMethod.invoke(target, value);
-                    }
-                } catch (Exception e) {
-                    logger.error(e.getMessage());
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
     @Override
     public boolean neutronFirewallExists(String uuid) {
         return firewallDB.containsKey(uuid);
@@ -78,7 +46,7 @@ public class NeutronFirewallInterface extends AbstractNeutronInterface implement
     @Override
     public NeutronFirewall getNeutronFirewall(String uuid) {
         if (!neutronFirewallExists(uuid)) {
-            logger.debug("No Firewall Have Been Defined");
+            LOGGER.debug("No Firewall Have Been Defined");
             return null;
         }
         return firewallDB.get(uuid);
@@ -91,7 +59,7 @@ public class NeutronFirewallInterface extends AbstractNeutronInterface implement
             NeutronFirewall firewall = entry.getValue();
             allFirewalls.add(firewall);
         }
-        logger.debug("Exiting getFirewalls, Found {} OpenStackFirewall", allFirewalls.size());
+        LOGGER.debug("Exiting getFirewalls, Found {} OpenStackFirewall", allFirewalls.size());
         List<NeutronFirewall> ans = new ArrayList<NeutronFirewall>();
         ans.addAll(allFirewalls);
         return ans;
@@ -147,5 +115,13 @@ public class NeutronFirewallInterface extends AbstractNeutronInterface implement
         return null;
     }
 
-
+    public static void registerNewInterface(BundleContext context,
+                                            ProviderContext providerContext,
+                                            List<ServiceRegistration<?>> registrations) {
+        NeutronFirewallInterface neutronFirewallInterface = new NeutronFirewallInterface(providerContext);
+        ServiceRegistration<INeutronFirewallCRUD> neutronFirewallInterfaceRegistration = context.registerService(INeutronFirewallCRUD.class, neutronFirewallInterface, null);
+        if(neutronFirewallInterfaceRegistration != null) {
+            registrations.add(neutronFirewallInterfaceRegistration);
+        }
+    }
 }