model.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-3.5.0).
03  * Copyright (c) 2007-2016 Franz Wilhelmstötter
04  *
05  * Licensed under the Apache License, Version 2.0 (the "License");
06  * you may not use this file except in compliance with the License.
07  * You may obtain a copy of the License at
08  *
09  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Author:
18  *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19  */
20 package org.jenetics.internal.util;
21 
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAttribute;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import javax.xml.bind.annotation.XmlType;
28 import javax.xml.bind.annotation.XmlValue;
29 import javax.xml.bind.annotation.adapters.XmlAdapter;
30 
31 /**
32  * This object contains models not defined as native XML type.
33  *
34  * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
35  * @version 1.6
36  * @since 2.0
37  */
38 public final class model {
39     private model() {require.noInstance();}
40 
41     @XmlRootElement(name = "char")
42     @XmlType(name = "char")
43     @XmlAccessorType(XmlAccessType.FIELD)
44     public static final class CharacterModel {
45 
46         @XmlValue
47         public String value;
48 
49         public static final class Adapter
50             extends XmlAdapter<CharacterModel, Character>
51         {
52             @Override
53             public CharacterModel marshal(final Character value) {
54                 final CharacterModel model = new CharacterModel();
55                 model.value = value.toString();
56                 return model;
57             }
58 
59             @Override
60             public Character unmarshal(final CharacterModel model) {
61                 return model.value.charAt(0);
62             }
63         }
64 
65         public static final Adapter ADAPTER = new Adapter();
66 
67     }
68 
69     @XmlRootElement(name = "indexed-object")
70     @XmlType(name = "org.jenetics.IndexedObject")
71     @XmlAccessorType(XmlAccessType.FIELD)
72     public static final class IndexedObject {
73 
74         @XmlAttribute(required = true)
75         public int index;
76 
77         @XmlElement(name = "value", required = true, nillable = false)
78         public Object value;
79 
80     }
81 
82 }