1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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 package org.apache.commons.betwixt.io.read; 18 19 import org.apache.commons.betwixt.ElementDescriptor; 20 import org.xml.sax.Attributes; 21 22 /** 23 * Describes a mapping between an xml element and a betwixt element. 24 * 25 * @author Robert Burrell Donkin 26 * @since 0.5 27 */ 28 public class ElementMapping { 29 30 /** Namespace of the xml element */ 31 private String namespace; 32 /** Name of the element */ 33 private String name; 34 /** Attributes associated with this element */ 35 private Attributes attributes; 36 /** The base type of the mapped bean */ 37 private Class type; 38 /** The mapped descriptor */ 39 private ElementDescriptor descriptor; 40 41 /** Base constructor */ 42 public ElementMapping() {} 43 44 /** 45 * Gets the namespace URI or an empty string if the parser is not namespace aware 46 * or the element has no namespace. 47 * @return namespace possibly null 48 */ 49 public String getNamespace() { 50 return namespace; 51 } 52 53 /** 54 * Sets the namespace URI for this element 55 * @param namespace the namespace uri, possibly null 56 */ 57 public void setNamespace(String namespace) { 58 this.namespace = namespace; 59 } 60 61 /** 62 * Gets the local name if the parser is namespace aware, otherwise the name. 63 * @return the element name, possibly null 64 */ 65 public String getName() { 66 return name; 67 } 68 69 /** 70 * Sets the local name for this element. 71 * @param name the element name, possibly null 72 */ 73 public void setName(String name) { 74 this.name = name; 75 } 76 77 /** 78 * Gets the element's attributes. 79 * @return the Attributes for this element, possibly null. 80 */ 81 public Attributes getAttributes() { 82 return attributes; 83 } 84 85 /** 86 * Sets the element's attributes 87 * @param attributes the element's attributes, possibly null 88 */ 89 public void setAttributes(Attributes attributes) { 90 this.attributes = attributes; 91 } 92 93 /** 94 * Gets the base type for this element. 95 * The base type may - or may not - correspond to the created type. 96 * @return the Class of the base type for this element 97 */ 98 public Class getType() { 99 return type; 100 } 101 102 /** 103 * Sets the base type for this element. 104 * The base type may - or may not - correspond to the created type. 105 * @param type the Class of the base type for this element 106 */ 107 public void setType(Class type) { 108 this.type = type; 109 } 110 111 /** 112 * Gets the mapped element descriptor. 113 * @return the mapped ElementDescriptor 114 */ 115 public ElementDescriptor getDescriptor() { 116 return descriptor; 117 } 118 119 /** 120 * Sets the mapped element descriptor. 121 * @param descriptor set this descriptor 122 */ 123 public void setDescriptor(ElementDescriptor descriptor) { 124 this.descriptor = descriptor; 125 } 126 127 /** 128 * Returns something useful for logging. 129 * @since 0.8 130 */ 131 public String toString() { 132 StringBuffer buffer = new StringBuffer(); 133 buffer.append("ElementMapping["); 134 buffer.append(name); 135 buffer.append(" -> "); 136 buffer.append(type); 137 buffer.append("]"); 138 return buffer.toString(); 139 } 140 }