Fix checkstyle warnings in netconf-cli
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / queue / OFQueuePropertyType.java
1 /**
2  *
3  */
4 package org.openflow.protocol.queue;
5
6 import java.lang.reflect.Constructor;
7
8 import org.openflow.protocol.Instantiable;
9
10 /**
11  * List of OpenFlow Queue Property types and mappings to wire protocol value and
12  * derived classes
13  *
14  * @author David Erickson (daviderickson@cs.stanford.edu)
15  */
16 public class OFQueuePropertyType {
17     public static OFQueuePropertyType NONE = new OFQueuePropertyType(0, "NONE",
18             OFQueueProperty.class, new Instantiable<OFQueueProperty>() {
19                 @Override
20                 public OFQueueProperty instantiate() {
21                     return new OFQueueProperty();
22                 }
23             });
24
25     public static OFQueuePropertyType MIN_RATE = new OFQueuePropertyType(1, "MIN_RATE",
26             OFQueuePropertyMinRate.class, new Instantiable<OFQueueProperty>() {
27                 @Override
28                 public OFQueueProperty instantiate() {
29                     return new OFQueuePropertyMinRate();
30                 }
31             });
32
33     protected static OFQueuePropertyType[] mapping;
34
35     protected Class<? extends OFQueueProperty> clazz;
36     protected Constructor<? extends OFQueueProperty> constructor;
37     protected Instantiable<OFQueueProperty> instantiable;
38     protected int minLen;
39     protected String name;
40     protected short type;
41
42     /**
43      * Store some information about the OpenFlow Queue Property type, including wire
44      * protocol type number, length, and derived class
45      *
46      * @param type Wire protocol number associated with this OFQueuePropertyType
47      * @param name The name of this type
48      * @param clazz The Java class corresponding to this type of OpenFlow Queue Property
49      * @param instantiable the instantiable for the OFQueueProperty this type represents
50      */
51     OFQueuePropertyType(int type, String name, Class<? extends OFQueueProperty> clazz, Instantiable<OFQueueProperty> instantiable) {
52         this.type = (short) type;
53         this.name = name;
54         this.clazz = clazz;
55         this.instantiable = instantiable;
56         try {
57             this.constructor = clazz.getConstructor(new Class[]{});
58         } catch (Exception e) {
59             throw new RuntimeException(
60                     "Failure getting constructor for class: " + clazz, e);
61         }
62         OFQueuePropertyType.addMapping(this.type, this);
63     }
64
65     /**
66      * Adds a mapping from type value to OFQueuePropertyType enum
67      *
68      * @param i OpenFlow wire protocol Action type value
69      * @param t type
70      */
71     static public void addMapping(short i, OFQueuePropertyType t) {
72         if (mapping == null)
73             mapping = new OFQueuePropertyType[16];
74         OFQueuePropertyType.mapping[i] = t;
75     }
76
77     /**
78      * Given a wire protocol OpenFlow type number, return the OFType associated
79      * with it
80      *
81      * @param i wire protocol number
82      * @return OFType enum type
83      */
84
85     static public OFQueuePropertyType valueOf(short i) {
86         return OFQueuePropertyType.mapping[i];
87     }
88
89     /**
90      * @return Returns the wire protocol value corresponding to this
91      *         OFQueuePropertyType
92      */
93     public short getTypeValue() {
94         return this.type;
95     }
96
97     /**
98      * @return return the OFQueueProperty subclass corresponding to this OFQueuePropertyType
99      */
100     public Class<? extends OFQueueProperty> toClass() {
101         return clazz;
102     }
103
104     /**
105      * Returns the no-argument Constructor of the implementation class for
106      * this OFQueuePropertyType
107      * @return the constructor
108      */
109     public Constructor<? extends OFQueueProperty> getConstructor() {
110         return constructor;
111     }
112
113     /**
114      * Returns a new instance of the OFQueueProperty represented by this OFQueuePropertyType
115      * @return the new object
116      */
117     public OFQueueProperty newInstance() {
118         return instantiable.instantiate();
119     }
120
121     /**
122      * @return the instantiable
123      */
124     public Instantiable<OFQueueProperty> getInstantiable() {
125         return instantiable;
126     }
127
128     /**
129      * @param instantiable the instantiable to set
130      */
131     public void setInstantiable(Instantiable<OFQueueProperty> instantiable) {
132         this.instantiable = instantiable;
133     }
134
135     public String getName() {
136         return this.name;
137     }
138
139     @Override
140     public String toString() {
141         return this.name;
142     }
143 }