Remove the usages of @XmlSeeAlso annotation. 52/1952/3
authorPrasanth Pallamreddy <ppallamr@cisco.com>
Wed, 16 Oct 2013 18:48:56 +0000 (11:48 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 17 Oct 2013 12:00:55 +0000 (12:00 +0000)
- The @XmlSeeAlso annotations are unnecessary now that the bundle
  scanner can detect them automatically.
- minor fix to the bundle scanner to allow annotated classes to be
  loaded from a proper classloader

Change-Id: I4445ddbdb5b2f2f8edce34f0c056e3da61f916d5
Signed-off-by: Prasanth Pallamreddy <ppallamr@cisco.com>
opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleInfo.java
opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java
opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/JacksonJsonProcessingExceptionMapper.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Property.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/DataLinkAddress.java

index a10893110cac02ca76d2e43b5c09472ee1fda7e5..4e94c5f84549344613ffe168386312f01a5de269 100644 (file)
@@ -69,7 +69,7 @@ import org.slf4j.LoggerFactory;
                 result.add(entry.getKey());
             }
         }
-        return BundleScanner.loadClasses(bundle, result);
+        return BundleScanner.loadClasses(result, bundle);
     }
 
     private boolean matches(Pattern pattern, Set<String> values) {
@@ -81,13 +81,22 @@ import org.slf4j.LoggerFactory;
         return false;
     }
 
+    /**
+     * Get classes with annotations matching a pattern
+     *
+     * @param allbundles - all bundles
+     * @param pattern - annotation pattern to match
+     * @param initBundle - the bundle which initiated this call
+     *
+     * @return list of annotated classes matching the pattern
+     */
     public List<Class<?>> getAnnotatedClasses(
             Collection<BundleInfo> allbundles,
-            Pattern pattern)
+            Pattern pattern, Bundle initBundle)
     {
         List<Class<?>> classes = getAnnotatedClasses(pattern);
         processAnnotatedClassesInternal(this, allbundles, pattern,
-                new HashSet<BundleInfo>(), classes);
+                new HashSet<BundleInfo>(), classes, initBundle);
         return classes;
     }
 
@@ -115,17 +124,18 @@ import org.slf4j.LoggerFactory;
             Collection<BundleInfo> bundlesToScan,
             Pattern pattern,
             Collection<BundleInfo> visited,
-            List<Class<?>> classes)
+            List<Class<?>> classes,
+            Bundle initBundle)
     {
         for (BundleInfo other : bundlesToScan) {
             if (other.getId() == target.getId()) continue;
             if (target.isDependantOn(other)) {
                 if (!visited.contains(other)) {
-                    classes.addAll(BundleScanner.loadClasses(other.getBundle(),
-                            other.getExportedAnnotatedClasses(pattern)));
+                    classes.addAll(BundleScanner.loadClasses(
+                            other.getExportedAnnotatedClasses(pattern), initBundle));
                     visited.add(other);
                     processAnnotatedClassesInternal(other, bundlesToScan,
-                            pattern, visited, classes);
+                            pattern, visited, classes, initBundle);
                 }
             }
         }
index 3e517e9a1f717e3b9a8c889c5b34b2f3bf3d7351..a5a2073a610886d0aed68044ca70f40c44146556 100644 (file)
@@ -73,7 +73,8 @@ import org.slf4j.LoggerFactory;
         Pattern pattern = mergePatterns(annotations, false);
         List<Class<?>> result = null;
         if (includeDependentBundleClasses) {
-            result = info.getAnnotatedClasses(bundleAnnotations.values(), pattern);
+            result = info.getAnnotatedClasses(bundleAnnotations.values(),
+                    pattern, context.getBundle());
         } else {
             result = info.getAnnotatedClasses(pattern);
         }
@@ -237,17 +238,23 @@ import org.slf4j.LoggerFactory;
         // find bundle dependencies
     }
 
-    public static List<Class<?>> loadClasses(Bundle bundle,
-            Collection<String> annotatedClasses)
+    public static List<Class<?>> loadClasses(
+            Collection<String> annotatedClasses,
+            Bundle initBundle)
     {
         List<Class<?>> result = new ArrayList<Class<?>>();
+        StringBuilder errors = new StringBuilder();
         for (String name : annotatedClasses) {
             try {
-                result.add(bundle.loadClass(name));
-            } catch (Exception e) {
-                LOGGER.error("Unable to load class: {}", name, e);
+                result.add(initBundle.loadClass(name));
+            } catch (ClassNotFoundException e) {
+                errors.append(name).append(", ");
             }
         }
+        if (LOGGER.isDebugEnabled() && errors.length() > 0) {
+            LOGGER.debug("Bundle: {} could not load classes: {}",
+                    initBundle.getSymbolicName(), errors.toString());
+        }
         return result;
     }
 
index ca0d1b7caee1a3a67aab852f1415e4ae98bf34b8..5e5dee3279a2642b2719316b110804bed0c716fb 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.controller.northbound.commons;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.Produces;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
@@ -22,7 +21,7 @@ import org.codehaus.jackson.JsonProcessingException;
  * A custom exception mapper for handling Jackson JsonProcessingException types
  */
 @Provider
-@Consumes({MediaType.APPLICATION_JSON, "text/json"})
+@Consumes({MediaType.APPLICATION_JSON})
 public class JacksonJsonProcessingExceptionMapper
     implements ExceptionMapper<JsonProcessingException>
 {
index cd3e45492da523534342dcb98514d5addd628bfc..6076293fbc5bf604b7300c136977ac58bf633d62 100644 (file)
@@ -20,10 +20,6 @@ import java.io.Serializable;
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-@XmlSeeAlso({ Controller.class, Drop.class, Flood.class, FloodAll.class, HwPath.class, Loopback.class, Output.class,
-    PopVlan.class, PushVlan.class, SetDlDst.class, SetDlSrc.class, SetDlType.class, SetNwDst.class, SetNwSrc.class,
-    SetNwTos.class, SetTpDst.class, SetTpSrc.class, SetVlanCfi.class, SetVlanId.class, SetVlanPcp.class,
-    SwPath.class })
 public abstract class Action implements Serializable {
     private static final long serialVersionUID = 1L;
     private static final Logger logger = LoggerFactory.getLogger(Action.class);
index 9dc00d0dcd8415bac697b4d9839da226a2e34598..c36ac92cef0f74dac996666045d2692be7478537 100644 (file)
@@ -31,11 +31,6 @@ import javax.xml.bind.annotation.XmlSeeAlso;
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-@XmlSeeAlso({ Config.class, Name.class, State.class, TimeStamp.class,
-    Latency.class, Bandwidth.class, Tier.class, Actions.class,
-    AdvertisedBandwidth.class, Buffers.class, Capabilities.class,
-    MacAddress.class, PeerBandwidth.class, SupportedBandwidth.class,
-    Tables.class, Description.class, ForwardingMode.class })
 abstract public class Property implements Serializable, Cloneable {
     private static final long serialVersionUID = 1L;
     private final String name;
index 96a992b3c366c23d993197755d13c984298580c9..fbf8a0d1b1c81db99e491ebe5c2c743991e31c13 100644 (file)
@@ -26,7 +26,6 @@ import javax.xml.bind.annotation.XmlSeeAlso;
  *
  */
 @XmlRootElement
-@XmlSeeAlso( { EthernetAddress.class })
 abstract public class DataLinkAddress implements Serializable {
     private static final long serialVersionUID = 1L;
     private String name;
@@ -53,6 +52,7 @@ abstract public class DataLinkAddress implements Serializable {
      *
      * @return A clone of this DataLinkAddress
      */
+    @Override
     abstract public DataLinkAddress clone();
 
     /**