Bump upstreams for Silicon
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronObject.java
index 451774b1169a50aa577b34e8402380aa4bc5c5ee..255ff47b1af470c7ab3a1ed3ce69bc59a8e4109f 100644 (file)
@@ -9,8 +9,6 @@
 
 package org.opendaylight.neutron.spi;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import java.io.Serializable;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.List;
@@ -18,23 +16,23 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-public abstract class NeutronObject<T extends NeutronObject> extends NeutronID
-        implements Serializable, INeutronObject<T> {
+public abstract class NeutronObject<T extends NeutronObject<T>> extends NeutronID implements INeutronObject<T> {
     // T extends NeutronObject as 0th type argument. Used by extractFields()
     private static final int NEUTRON_OBJECT_CLASS_TYPE_INDEX = 0;
 
-    private static final Logger LOG = LoggerFactory.getLogger(NeutronFirewallRule.class);
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronObject.class);
 
     private static final long serialVersionUID = 1L;
 
-    @XmlElement(name = "tenant_id")
-    String tenantID;
+    private String tenantID;
 
     @XmlElement(name = "project_id")
     String projectID;
@@ -43,33 +41,31 @@ public abstract class NeutronObject<T extends NeutronObject> extends NeutronID
     Long revisionNumber;
 
     public NeutronObject() {
-        super();
     }
 
     @Override
+    @XmlElement(name = "tenant_id")
+    @XmlJavaTypeAdapter(EmptyStringAsNullAdapter.class)
     public String getTenantID() {
-        if (tenantID != null && tenantID.isEmpty()) {
-            // Bug 4775 - Treat empty string tenantId as null, so no attempt is made
-            //            to turn it into a uuid.
-            return null;
-        }
         return tenantID;
     }
 
     @Override
+    @XmlElement(name = "tenant_id")
+    @XmlJavaTypeAdapter(EmptyStringAsNullAdapter.class)
     public void setTenantID(String tenantID) {
         this.tenantID = tenantID;
     }
 
     @Override
-    @JsonIgnore
+    @XmlTransient
     public void setTenantID(Uuid tenantID) {
         this.tenantID = tenantID.getValue().replace("-", "");
     }
 
     @Override
     public String toString() {
-        return "NeutronObject [id=" + uuid + ", tenantID=" + tenantID + "]";
+        return "NeutronObject [id=" + uuid + ", tenantID=" + getTenantID() + "]";
     }
 
     @Override
@@ -94,11 +90,11 @@ public abstract class NeutronObject<T extends NeutronObject> extends NeutronID
 
     @Override
     public void initDefaults() {
-        if (projectID != null && tenantID == null) {
-            tenantID = projectID;
+        if (projectID != null && getTenantID() == null) {
+            setTenantID(projectID);
         }
-        if (projectID == null && tenantID != null) {
-            projectID = tenantID;
+        if (projectID == null && getTenantID() != null) {
+            projectID = getTenantID();
         }
     }
 
@@ -120,8 +116,8 @@ public abstract class NeutronObject<T extends NeutronObject> extends NeutronID
         Class<T> cls = (Class<T>) types[NEUTRON_OBJECT_CLASS_TYPE_INDEX];
         T ans;
         try {
-            ans = cls.newInstance();
-        } catch (IllegalAccessException | InstantiationException e) {
+            ans = cls.getDeclaredConstructor().newInstance();
+        } catch (ReflectiveOperationException e) {
             // should not happen.
             throw new IllegalStateException(e);
         }