001 /*
002 * Java Genetic Algorithm Library (jenetics-1.6.0).
003 * Copyright (c) 2007-2014 Franz Wilhelmstötter
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 * Author:
018 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
019 */
020 package org.jenetics.internal.util;
021
022 import static java.lang.annotation.ElementType.TYPE;
023 import static java.lang.annotation.RetentionPolicy.RUNTIME;
024
025 import java.lang.annotation.Retention;
026 import java.lang.annotation.Target;
027
028 import javax.xml.bind.annotation.XmlAccessType;
029 import javax.xml.bind.annotation.XmlAccessorType;
030 import javax.xml.bind.annotation.XmlAttribute;
031 import javax.xml.bind.annotation.XmlRootElement;
032 import javax.xml.bind.annotation.XmlType;
033 import javax.xml.bind.annotation.adapters.XmlAdapter;
034
035 import org.jscience.mathematics.number.Float64;
036 import org.jscience.mathematics.number.Integer64;
037
038 import org.jenetics.util.Function;
039 import org.jenetics.util.StaticObject;
040
041 /**
042 * This object contains models for the java primitive/basic types and the
043 * integer and float types of the JScience library.
044 *
045 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
046 * @version 1.6 — <em>$Date: 2014-02-02 $</em>
047 * @since 1.6
048 */
049 public final class model extends StaticObject {
050 private model() {}
051
052 @Retention(RUNTIME)
053 @Target(TYPE)
054 public @interface ValueType {
055 Class<?> value();
056 }
057
058 @Retention(RUNTIME)
059 @Target(TYPE)
060 public @interface ModelType {
061 Class<?> value();
062 }
063
064 /* ************************************************************************
065 * Java primitive type models.
066 **************************************************************************/
067
068 @XmlRootElement(name = "java.lang.Boolean")
069 @XmlType(name = "java.lang.Boolean")
070 @XmlAccessorType(XmlAccessType.FIELD)
071 public static final class BooleanModel {
072
073 @XmlAttribute
074 public boolean value;
075
076 @ValueType(Boolean.class)
077 @ModelType(BooleanModel.class)
078 public static final class Adapter
079 extends XmlAdapter<BooleanModel, Boolean>
080 {
081 @Override
082 public BooleanModel marshal(final Boolean value) {
083 final BooleanModel model = new BooleanModel();
084 model.value = value;
085 return model;
086 }
087
088 @Override
089 public Boolean unmarshal(final BooleanModel model) {
090 return model.value;
091 }
092 }
093
094 public static final Adapter Adapter = new Adapter();
095
096 }
097
098 @XmlRootElement(name = "java.lang.Byte")
099 @XmlType(name = "java.lang.Byte")
100 @XmlAccessorType(XmlAccessType.FIELD)
101 public static final class ByteModel {
102
103 @XmlAttribute
104 public byte value;
105
106 @ValueType(Byte.class)
107 @ModelType(ByteModel.class)
108 public static final class Adapter
109 extends XmlAdapter<ByteModel, Byte>
110 {
111 @Override
112 public ByteModel marshal(final Byte value) {
113 final ByteModel model = new ByteModel();
114 model.value = value;
115 return model;
116 }
117
118 @Override
119 public Byte unmarshal(final ByteModel model) {
120 return model.value;
121 }
122 }
123
124 public static final Adapter Adapter = new Adapter();
125
126 }
127
128 @XmlRootElement(name = "java.lang.Character")
129 @XmlType(name = "java.lang.Character")
130 @XmlAccessorType(XmlAccessType.FIELD)
131 public static final class CharacterModel {
132
133 @XmlAttribute
134 public String value;
135
136 @ValueType(Character.class)
137 @ModelType(CharacterModel.class)
138 public static final class Adapter
139 extends XmlAdapter<CharacterModel, Character>
140 {
141 @Override
142 public CharacterModel marshal(final Character value) {
143 final CharacterModel model = new CharacterModel();
144 model.value = value.toString();
145 return model;
146 }
147
148 @Override
149 public Character unmarshal(final CharacterModel model) {
150 return model.value.charAt(0);
151 }
152 }
153
154 public static final Adapter Adapter = new Adapter();
155
156 }
157
158 @XmlRootElement(name = "java.lang.Short")
159 @XmlType(name = "java.lang.Short")
160 @XmlAccessorType(XmlAccessType.FIELD)
161 public static final class ShortModel {
162
163 @XmlAttribute
164 public short value;
165
166 @ValueType(Short.class)
167 @ModelType(ShortModel.class)
168 public static final class Adapter
169 extends XmlAdapter<ShortModel, Short>
170 {
171 @Override
172 public ShortModel marshal(final Short value) {
173 final ShortModel model = new ShortModel();
174 model.value = value;
175 return model;
176 }
177
178 @Override
179 public Short unmarshal(final ShortModel model) {
180 return model.value;
181 }
182 }
183
184 public static final Adapter Adapter = new Adapter();
185
186 }
187
188 @XmlRootElement(name = "java.lang.Integer")
189 @XmlType(name = "java.lang.Integer")
190 @XmlAccessorType(XmlAccessType.FIELD)
191 public static final class IntegerModel {
192
193 @XmlAttribute
194 public int value;
195
196 @ValueType(Integer.class)
197 @ModelType(IntegerModel.class)
198 public static final class Adapter
199 extends XmlAdapter<IntegerModel, Integer>
200 {
201 @Override
202 public IntegerModel marshal(final Integer value) {
203 final IntegerModel model = new IntegerModel();
204 model.value = value;
205 return model;
206 }
207
208 @Override
209 public Integer unmarshal(final IntegerModel model) {
210 return model.value;
211 }
212 }
213
214 public static final Adapter Adapter = new Adapter();
215
216 }
217
218 @XmlRootElement(name = "java.lang.Long")
219 @XmlType(name = "java.lang.Long")
220 @XmlAccessorType(XmlAccessType.FIELD)
221 public static final class LongModel {
222
223 @XmlAttribute
224 public long value;
225
226 @ValueType(Long.class)
227 @ModelType(LongModel.class)
228 public static final class Adapter
229 extends XmlAdapter<LongModel, Long>
230 {
231 @Override
232 public LongModel marshal(final Long value) {
233 final LongModel model = new LongModel();
234 model.value = value;
235 return model;
236 }
237
238 @Override
239 public Long unmarshal(final LongModel model) {
240 return model.value;
241 }
242 }
243
244 public static final Adapter Adapter = new Adapter();
245
246 }
247
248 @XmlRootElement(name = "java.lang.Float")
249 @XmlType(name = "java.lang.Float")
250 @XmlAccessorType(XmlAccessType.FIELD)
251 public static final class FloatModel {
252
253 @XmlAttribute
254 public float value;
255
256 @ValueType(Float.class)
257 @ModelType(FloatModel.class)
258 public static final class Adapter
259 extends XmlAdapter<FloatModel, Float>
260 {
261 @Override
262 public FloatModel marshal(final Float value) {
263 final FloatModel model = new FloatModel();
264 model.value = value;
265 return model;
266 }
267
268 @Override
269 public Float unmarshal(final FloatModel model) {
270 return model.value;
271 }
272 }
273
274 public static final Adapter Adapter = new Adapter();
275
276
277 }
278
279 @XmlRootElement(name = "java.lang.Double")
280 @XmlType(name = "java.lang.Double")
281 @XmlAccessorType(XmlAccessType.FIELD)
282 public static final class DoubleModel {
283
284 @XmlAttribute
285 public double value;
286
287 @ValueType(Double.class)
288 @ModelType(DoubleModel.class)
289 public static final class Adapter
290 extends XmlAdapter<DoubleModel, Double>
291 {
292 @Override
293 public DoubleModel marshal(final Double value) {
294 final DoubleModel model = new DoubleModel();
295 model.value = value;
296 return model;
297 }
298
299 @Override
300 public Double unmarshal(final DoubleModel model) {
301 return model.value;
302 }
303 }
304
305 public static final Adapter Adapter = new Adapter();
306
307 }
308
309 @XmlRootElement(name = "java.lang.String")
310 @XmlType(name = "java.lang.String")
311 @XmlAccessorType(XmlAccessType.FIELD)
312 public static final class StringModel {
313
314 @XmlAttribute
315 public String value;
316
317 @ValueType(String.class)
318 @ModelType(StringModel.class)
319 public static final class Adapter
320 extends XmlAdapter<StringModel, String>
321 {
322 @Override
323 public StringModel marshal(final String value) {
324 final StringModel model = new StringModel();
325 model.value = value;
326 return model;
327 }
328
329 @Override
330 public String unmarshal(final StringModel model) {
331 return model.value;
332 }
333 }
334
335 public static final Adapter Adapter = new Adapter();
336
337 }
338
339
340 /* ************************************************************************
341 * JScience primitive type models.
342 **************************************************************************/
343
344 @XmlRootElement(name = "org.jscience.mathematics.number.Integer64")
345 @XmlType(name = "org.jscience.mathematics.number.Integer64")
346 @XmlAccessorType(XmlAccessType.FIELD)
347 public static final class Integer64Model {
348
349 @XmlAttribute
350 public long value;
351
352 @ValueType(Integer64.class)
353 @ModelType(Integer64Model.class)
354 public static final class Adapter
355 extends XmlAdapter<Integer64Model, Integer64>
356 {
357 @Override
358 public Integer64Model marshal(final Integer64 value) {
359 final Integer64Model model = new Integer64Model();
360 model.value = value.longValue();
361 return model;
362 }
363
364 @Override
365 public Integer64 unmarshal(final Integer64Model model) {
366 return Integer64.valueOf(model.value);
367 }
368 }
369
370 public static final Adapter Adapter = new Adapter();
371
372 public static final Function<Integer64, Integer64Model>
373 Marshaller = jaxb.Marshaller(Adapter);
374
375 public static final Function<Integer64Model, Integer64>
376 Unmarshaller = jaxb.Unmarshaller(Adapter);
377
378 }
379
380 @XmlRootElement(name = "org.jscience.mathematics.number.Float64")
381 @XmlType(name = "org.jscience.mathematics.number.Float64")
382 @XmlAccessorType(XmlAccessType.FIELD)
383 public static final class Float64Model {
384
385 @XmlAttribute
386 public double value;
387
388 @ValueType(Float64.class)
389 @ModelType(Float64Model.class)
390 public static final class Adapter
391 extends XmlAdapter<Float64Model, Float64>
392 {
393 @Override
394 public Float64Model marshal(final Float64 value) {
395 final Float64Model model = new Float64Model();
396 model.value = value.doubleValue();
397 return model;
398 }
399
400 @Override
401 public Float64 unmarshal(final Float64Model model) {
402 return Float64.valueOf(model.value);
403 }
404 }
405
406 public static final Adapter Adapter = new Adapter();
407
408 public static final Function<Float64, Float64Model> Marshaller =
409 jaxb.Marshaller(Adapter);
410
411 public static final Function<Float64Model, Float64> Unmarshaller =
412 jaxb.Unmarshaller(Adapter);
413
414 }
415
416 }
|