Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
ElementMapping |
|
| 1.0;1 |
1 | /* |
|
2 | * Copyright 2001-2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.betwixt.io.read; |
|
17 | ||
18 | import org.apache.commons.betwixt.ElementDescriptor; |
|
19 | import org.xml.sax.Attributes; |
|
20 | ||
21 | /** |
|
22 | * Describes a mapping between an xml element and a betwixt element. |
|
23 | * |
|
24 | * @author Robert Burrell Donkin |
|
25 | * @since 0.5 |
|
26 | */ |
|
27 | public class ElementMapping { |
|
28 | ||
29 | /** Namespace of the xml element */ |
|
30 | private String namespace; |
|
31 | /** Name of the element */ |
|
32 | private String name; |
|
33 | /** Attributes associated with this element */ |
|
34 | private Attributes attributes; |
|
35 | /** The base type of the mapped bean */ |
|
36 | private Class type; |
|
37 | /** The mapped descriptor */ |
|
38 | private ElementDescriptor descriptor; |
|
39 | ||
40 | /** Base constructor */ |
|
41 | 3676 | public ElementMapping() {} |
42 | ||
43 | /** |
|
44 | * Gets the namespace URI or an empty string if the parser is not namespace aware |
|
45 | * or the element has no namespace. |
|
46 | * @return namespace possibly null |
|
47 | */ |
|
48 | public String getNamespace() { |
|
49 | 485 | return namespace; |
50 | } |
|
51 | ||
52 | /** |
|
53 | * Sets the namespace URI for this element |
|
54 | * @param namespace the namespace uri, possibly null |
|
55 | */ |
|
56 | public void setNamespace(String namespace) { |
|
57 | 3663 | this.namespace = namespace; |
58 | 3663 | } |
59 | ||
60 | /** |
|
61 | * Gets the local name if the parser is namespace aware, otherwise the name. |
|
62 | * @return the element name, possibly null |
|
63 | */ |
|
64 | public String getName() { |
|
65 | 4881 | return name; |
66 | } |
|
67 | ||
68 | /** |
|
69 | * Sets the local name for this element. |
|
70 | * @param name the element name, possibly null |
|
71 | */ |
|
72 | public void setName(String name) { |
|
73 | 3689 | this.name = name; |
74 | 3689 | } |
75 | ||
76 | /** |
|
77 | * Gets the element's attributes. |
|
78 | * @return the Attributes for this element, possibly null. |
|
79 | */ |
|
80 | public Attributes getAttributes() { |
|
81 | 6679 | return attributes; |
82 | } |
|
83 | ||
84 | /** |
|
85 | * Sets the element's attributes |
|
86 | * @param attributes the element's attributes, possibly null |
|
87 | */ |
|
88 | public void setAttributes(Attributes attributes) { |
|
89 | 3676 | this.attributes = attributes; |
90 | 3676 | } |
91 | ||
92 | /** |
|
93 | * Gets the base type for this element. |
|
94 | * The base type may - or may not - correspond to the created type. |
|
95 | * @return the Class of the base type for this element |
|
96 | */ |
|
97 | public Class getType() { |
|
98 | 3339 | return type; |
99 | } |
|
100 | ||
101 | /** |
|
102 | * Sets the base type for this element. |
|
103 | * The base type may - or may not - correspond to the created type. |
|
104 | * @param type the Class of the base type for this element |
|
105 | */ |
|
106 | public void setType(Class type) { |
|
107 | 3676 | this.type = type; |
108 | 3676 | } |
109 | ||
110 | /** |
|
111 | * Gets the mapped element descriptor. |
|
112 | * @return the mapped ElementDescriptor |
|
113 | */ |
|
114 | public ElementDescriptor getDescriptor() { |
|
115 | 4743 | return descriptor; |
116 | } |
|
117 | ||
118 | /** |
|
119 | * Sets the mapped element descriptor. |
|
120 | * @param descriptor set this descriptor |
|
121 | */ |
|
122 | public void setDescriptor(ElementDescriptor descriptor) { |
|
123 | 4375 | this.descriptor = descriptor; |
124 | 4375 | } |
125 | ||
126 | /** |
|
127 | * Returns something useful for logging. |
|
128 | */ |
|
129 | public String toString() { |
|
130 | 0 | StringBuffer buffer = new StringBuffer(); |
131 | 0 | buffer.append("ElementMapping["); |
132 | 0 | buffer.append(name); |
133 | 0 | buffer.append(" -> "); |
134 | 0 | buffer.append(type); |
135 | 0 | buffer.append("]"); |
136 | 0 | return buffer.toString(); |
137 | } |
|
138 | } |