blob: 86b092a384ffe6871b7df4f99dc20f572352248c [file] [log] [blame]
Andreas Wundsam5204de22013-07-30 11:34:45 -07001//:: # Copyright 2013, Big Switch Networks, Inc.
2//:: #
3//:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4//:: # the following special exception:
5//:: #
6//:: # LOXI Exception
7//:: #
8//:: # As a special exception to the terms of the EPL, you may distribute libraries
9//:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10//:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11//:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12//:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13//:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14//:: #
15//:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16//:: #
17//:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18//:: # a copy of the EPL at:
19//:: #
20//:: # http::: #www.eclipse.org/legal/epl-v10.html
21//:: #
22//:: # Unless required by applicable law or agreed to in writing, software
23//:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24//:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25//:: # EPL for the specific language governing permissions and limitations
26//:: # under the EPL.
27//::
28//:: import itertools
29//:: import of_g
Yotam Harchola86e4252013-09-06 15:36:28 -070030//:: import re
Andreas Wundsam5204de22013-07-30 11:34:45 -070031//:: include('_copyright.java')
32
33//:: include('_autogen.java')
34
35package ${factory.package};
36
Yotam Harchola86e4252013-09-06 15:36:28 -070037import org.projectfloodlight.openflow.protocol.OFOxmList;
38
Andreas Wundsam5204de22013-07-30 11:34:45 -070039//:: include("_imports.java")
40
41public class ${factory.name} implements ${factory.interface.name} {
Andreas Wundsame0d52be2013-08-22 07:52:13 -070042 public final static ${factory.name} INSTANCE = new ${factory.name}();
43 private ${factory.name}() {}
44
45 //:: for name, clazz in factory.interface.sub_factories.items():
46 public ${clazz} ${name}() {
47 return ${clazz}Ver${factory.version.of_version}.INSTANCE;
48 }
49 //:: #endfor
50
Yotam Harchola86e4252013-09-06 15:36:28 -070051//:: general_get_match_func_written = False
Andreas Wundsam5204de22013-07-30 11:34:45 -070052//:: for i in factory.interface.members:
53 //:: if i.is_virtual:
54 //:: continue
55 //:: #endif
Yotam Harchola86e4252013-09-06 15:36:28 -070056 //:: is_match_object = re.match('OFMatch.*', i.name) # i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)) and i.versioned_class(factory.version).interface.parent_interface == 'Match'
57 //:: unsupported_match_object = is_match_object and not i.has_version(factory.version)
Andreas Wundsam5204de22013-07-30 11:34:45 -070058
Andreas Wundsame0d52be2013-08-22 07:52:13 -070059 //:: if len(i.writeable_members) > 0:
60 public ${i.name}.Builder ${factory.interface.method_name(i, builder=True)}() {
61 //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)):
Andreas Wundsam5204de22013-07-30 11:34:45 -070062 return new ${i.versioned_class(factory.version).name}.Builder();
Andreas Wundsame0d52be2013-08-22 07:52:13 -070063 //:: else:
Andreas Wundsam5204de22013-07-30 11:34:45 -070064 throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}");
Andreas Wundsame0d52be2013-08-22 07:52:13 -070065 //:: #endif
Andreas Wundsam5204de22013-07-30 11:34:45 -070066 }
Andreas Wundsame0d52be2013-08-22 07:52:13 -070067 //:: #endif
Yotam Harchola86e4252013-09-06 15:36:28 -070068 //:: if not general_get_match_func_written and is_match_object and not unsupported_match_object:
69 public Match.Builder buildMatch() {
70 return new ${i.versioned_class(factory.version).name}.Builder();
71 }
72 //:: general_get_match_func_written = True
73 //:: #endif
Andreas Wundsame0d52be2013-08-22 07:52:13 -070074 //:: if len(i.writeable_members) <= 2:
75 public ${i.name} ${factory.interface.method_name(i, builder=False)}(${", ".join("%s %s" % (p.java_type.public_type, p.name) for p in i.writeable_members)}) {
76 //:: if i.has_version(factory.version) and model.generate_class(i.versioned_class(factory.version)):
77 //:: if len(i.writeable_members) > 0:
78 return new ${i.versioned_class(factory.version).name}(
79 ${",\n ".join(
80 [ prop.name for prop in i.versioned_class(factory.version).data_members])}
81 );
82 //:: else:
83 return ${i.versioned_class(factory.version).name}.INSTANCE;
84 //:: #endif
85 //:: else:
86 throw new UnsupportedOperationException("${i.name} not supported in version ${factory.version}");
87 //:: #endif
88 }
89 //:: #endif
Andreas Wundsam5204de22013-07-30 11:34:45 -070090//:: #endfor
91
Andreas Wundsame0d52be2013-08-22 07:52:13 -070092 public OFMessageReader<${factory.base_class}> getReader() {
93//:: if factory.versioned_base_class:
94 return ${factory.versioned_base_class.name}.READER;
95//:: else:
96 throw new UnsupportedOperationException("Reader<${factory.base_class}> not supported in version ${factory.version}");
97//:: #endif
Andreas Wundsam3ad98162013-08-15 11:08:56 -070098 }
99
Yotam Harchol98af7752013-08-22 14:59:38 -0700100//:: if factory.interface.name == 'OFOxms':
101 @SuppressWarnings("unchecked")
102 public <F extends OFValueType<F>> OFOxm<F> fromValue(F value, MatchField<F> field) {
103 switch (field.id) {
104 //:: for oxm_name in model.oxm_map:
105 //:: type_name, value, masked = model.oxm_map[oxm_name]
106 //:: if masked:
107 //:: continue
108 //:: #endif
109 //:: method_name = oxm_name.replace('OFOxm', '')
110 //:: method_name = method_name[0].lower() + method_name[1:]
111 case ${value}:
Yotam Harcholbd1d7282013-08-22 20:10:31 -0700112 //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object
113 return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value)));
Yotam Harchol98af7752013-08-22 14:59:38 -0700114 //:: #endfor
115 default:
116 return null;
117 }
118 }
119
120 @SuppressWarnings("unchecked")
121 public <F extends OFValueType<F>> OFOxm<F> fromValueAndMask(F value, F mask, MatchField<F> field) {
122 switch (field.id) {
123 //:: for oxm_name in model.oxm_map:
124 //:: type_name, value, masked = model.oxm_map[oxm_name]
125 //:: if not masked:
126 //:: continue
127 //:: #endif
128 //:: method_name = oxm_name.replace('OFOxm', '')
129 //:: method_name = method_name[0].lower() + method_name[1:]
130 case ${value}:
Yotam Harcholbd1d7282013-08-22 20:10:31 -0700131 //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object
132 return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)value), (${type_name})((Object)mask)));
Yotam Harchol98af7752013-08-22 14:59:38 -0700133 //:: #endfor
134 default:
135 return null;
136 }
137 }
138
139 @SuppressWarnings("unchecked")
140 public <F extends OFValueType<F>> OFOxm<F> fromMasked(Masked<F> masked, MatchField<F> field) {
141 switch (field.id) {
142 //:: for oxm_name in model.oxm_map:
143 //:: type_name, value, masked = model.oxm_map[oxm_name]
144 //:: if not masked:
145 //:: continue
146 //:: #endif
147 //:: method_name = oxm_name.replace('OFOxm', '')
148 //:: method_name = method_name[0].lower() + method_name[1:]
149 case ${value}:
Yotam Harcholbd1d7282013-08-22 20:10:31 -0700150 //:: # The cast to Object is done to avoid some javac bug that in some versions cannot handle cast from generic type to other types but Object
151 return (OFOxm<F>)((Object)${method_name}((${type_name})((Object)(masked.getValue())), (${type_name})((Object)(masked.getMask()))));
Yotam Harchol98af7752013-08-22 14:59:38 -0700152 //:: #endfor
153 default:
154 return null;
155 }
156 }
157//:: #endif
158
Andreas Wundsam5204de22013-07-30 11:34:45 -0700159}