01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: XMLMapping.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.xmlconfig.mapping;
25:
26: import java.util.HashMap;
27: import java.util.Map;
28:
29: /**
30: * Mapping for a given name space.<br>
31: * It contains all classes mapping.
32: * @author Florent Benoit
33: */
34: public class XMLMapping {
35:
36: /**
37: * Association between class name (and alias) and the given class mapping.
38: */
39: private Map<String, ClassMapping> classMappings = null;
40:
41: /**
42: * Default constructor.
43: */
44: public XMLMapping() {
45: this .classMappings = new HashMap<String, ClassMapping>();
46: }
47:
48: /**
49: * Add a given class mapping object.
50: * @param classMapping the given class.
51: */
52: public void addClassMapping(final ClassMapping classMapping) {
53: classMappings.put(classMapping.getName(), classMapping);
54: String alias = classMapping.getAlias();
55: if (alias != null) {
56: classMappings.put(alias, classMapping);
57: }
58: }
59:
60: /**
61: * Gets the class mapping for the given class name.
62: * @param className the given className.
63: * @return the class mapping or null if not found.
64: */
65: public ClassMapping getClassMapping(final String className) {
66: return classMappings.get(className);
67: }
68:
69: /**
70: * Returns a string representation of the object.
71: * @return string representation
72: */
73: @Override
74: public String toString() {
75: StringBuilder sb = new StringBuilder();
76: // classname
77: sb.append(this .getClass().getName().substring(
78: this .getClass().getPackage().getName().length() + 1));
79: sb.append("[classMappings=");
80: sb.append(classMappings);
81: sb.append("]");
82:
83: return sb.toString();
84: }
85: }
|