5530223ba32cc22e9f3b4329992a7ed1ce2c59a7
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronTrunk.java
1 /*
2  * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.neutron.spi;
10
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 @XmlRootElement(name = "trunk")
20 @XmlAccessorType(XmlAccessType.NONE)
21 public final class NeutronTrunk extends NeutronAdminAttributes<NeutronTrunk> implements Serializable {
22     private static final long serialVersionUID = 1L;
23
24     @XmlElement(name = "port_id")
25     String portId;
26
27     @XmlElement(name = "sub_ports")
28     List<NeutronTrunkSubPort> subPorts;
29
30     public NeutronTrunk() {
31     }
32
33     @Override
34     public void initDefaults() {
35         // In order to override super.initDefaults()
36         // status needs to be checked before calling super.initDefaults()
37         if (status == null) {
38             status = "DOWN";
39         }
40         super.initDefaults();
41         if (subPorts == null) {
42             subPorts = new ArrayList<>();
43         }
44     }
45
46     public String getPortId() {
47         return portId;
48     }
49
50     public void setPortId(String portId) {
51         this.portId = portId;
52     }
53
54     public List<NeutronTrunkSubPort> getSubPorts() {
55         return subPorts;
56     }
57
58     public void setSubPorts(List<NeutronTrunkSubPort> subPorts) {
59         this.subPorts = subPorts;
60     }
61
62     @Override
63     protected boolean extractField(String field, NeutronTrunk ans) {
64         switch (field) {
65             case "port_id":
66                 ans.setPortId(this.getPortId());
67                 break;
68             case "sub_ports":
69                 List<NeutronTrunkSubPort> subPortList = new ArrayList<>();
70                 subPortList.addAll(this.getSubPorts());
71                 ans.setSubPorts(subPortList);
72                 break;
73             default:
74                 return super.extractField(field, ans);
75         }
76         return true;
77     }
78
79     @Override
80     public String toString() {
81         return "NeutronTrunk{" + "trunkUUID='" + uuid + '\'' + ", trunkName='" + name + '\''
82                 + ", tenantID='" + tenantID + '\'' + ", adminStateUp='" + adminStateUp + '\''
83                 + ", status='" + status + '\'' + ", portId='" + portId + '\''
84                 + ", subPorts='" + subPorts + '\'' + '}';
85     }
86 }