001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.meta;
020:
021: import java.util.HashMap;
022:
023: import org.apache.commons.lang.StringUtils;
024:
025: public class XMLClassMetaData implements XMLMetaData {
026: private Class _type;
027: private int _code = JavaTypes.OBJECT;
028: private int _xmltype = XMLTYPE;
029: private String _name = null;
030: private String _xmlname = null;
031: private String _xmlnamespace = null;
032: private boolean _isXMLRootElement = false;
033: private HashMap _fieldMap = new HashMap();
034:
035: /**
036: * Constructor.
037: *
038: * @param type the class that contains XmlType annotation.
039: * @name the persistent field name that maps to xml column
040: */
041: public XMLClassMetaData(Class type, String name) {
042: _type = type;
043: _name = name;
044: }
045:
046: /**
047: * Constructor.
048: *
049: * @param type the class that contains XmlType annotation.
050: */
051: public XMLClassMetaData(Class type) {
052: _type = type;
053: }
054:
055: public void setName(String name) {
056: _name = name;
057: }
058:
059: public String getName() {
060: return _name;
061: }
062:
063: public void setXmlname(String name) {
064: _xmlname = name;
065: }
066:
067: public String getXmlname() {
068: return _isXMLRootElement ? null : _xmlname;
069: }
070:
071: public void setXmlnamespace(String name) {
072: // avoid JAXB XML bind default name
073: if (!StringUtils.equals(defaultName, name))
074: _xmlnamespace = name;
075: }
076:
077: public String getXmlnamespace() {
078: return _xmlnamespace;
079: }
080:
081: public void setXmlRootElement(boolean isXMLRootElement) {
082: _isXMLRootElement = isXMLRootElement;
083: }
084:
085: public boolean isXmlRootElement() {
086: return _isXMLRootElement;
087: }
088:
089: public boolean isXmlElement() {
090: return false;
091: }
092:
093: public boolean isXmlAttribute() {
094: return false;
095: }
096:
097: public XMLMetaData getFieldMapping(String name) {
098: return (XMLMetaData) _fieldMap.get(name);
099: }
100:
101: public void setType(Class type) {
102: _type = type;
103: }
104:
105: public Class getType() {
106: return _type;
107: }
108:
109: public int getTypeCode() {
110: return _code;
111: }
112:
113: public void setXmltype(int type) {
114: _xmltype = type;
115: }
116:
117: public int getXmltype() {
118: return _xmltype;
119: }
120:
121: public void addField(String name, XMLMetaData field) {
122: _fieldMap.put(name, field);
123: }
124: }
|