Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FieldAdapter |
|
| 2.0;2 |
1 | package org.apache.fulcrum.intake.model; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import javax.xml.bind.annotation.adapters.XmlAdapter; | |
23 | ||
24 | import org.apache.fulcrum.intake.IntakeException; | |
25 | ||
26 | /** | |
27 | * Creates Field objects. | |
28 | * | |
29 | * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> | |
30 | * @version $Id: FieldFactory.java 1200653 2011-11-11 00:05:28Z tv $ | |
31 | */ | |
32 | 29 | public class FieldAdapter extends XmlAdapter<XmlField, Field<?>> |
33 | { | |
34 | /** | |
35 | * Creates a Field object appropriate for the type specified | |
36 | * in the xml file. | |
37 | * | |
38 | * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object) | |
39 | */ | |
40 | @Override | |
41 | public Field<?> unmarshal(XmlField xmlField) throws Exception | |
42 | { | |
43 | 28 | Field<?> field = null; |
44 | 28 | FieldType type = xmlField.getType(); |
45 | ||
46 | 28 | if (type == null) |
47 | { | |
48 | 0 | throw new IntakeException("An unsupported type has been specified for " + |
49 | 0 | xmlField.getName() + " in group " + xmlField.getGroup().getIntakeGroupName()); |
50 | } | |
51 | else | |
52 | { | |
53 | 28 | field = type.getInstance(xmlField, xmlField.getGroup()); |
54 | } | |
55 | ||
56 | 28 | return field; |
57 | } | |
58 | ||
59 | /** | |
60 | * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object) | |
61 | */ | |
62 | @Override | |
63 | public XmlField marshal(Field<?> field) throws Exception | |
64 | { | |
65 | // This is never used in this context | |
66 | 0 | return new XmlField(); |
67 | } | |
68 | } |