KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > xmlconfig > mapping > XMLMapping


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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 1022 2006-08-04 11:02:28Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.xmlconfig.mapping;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30
31 /**
32  * Mapping for a given name space.<br>
33  * It contains all classes mapping.
34  * @author Florent Benoit
35  */

36 public class XMLMapping {
37
38     /**
39      * Association between class name (and alias) and the given class mapping.
40      */

41     private Map JavaDoc<String JavaDoc, ClassMapping> classMappings = null;
42
43     /**
44      * Default constructor.
45      */

46     public XMLMapping() {
47         this.classMappings = new HashMap JavaDoc<String JavaDoc, ClassMapping>();
48     }
49
50     /**
51      * Add a given class mapping object.
52      * @param classMapping the given class.
53      */

54     public void addClassMapping(final ClassMapping classMapping) {
55         classMappings.put(classMapping.getName(), classMapping);
56         String JavaDoc alias = classMapping.getAlias();
57         if (alias != null) {
58             classMappings.put(alias, classMapping);
59         }
60     }
61
62     /**
63      * Gets the class mapping for the given class name.
64      * @param className the given className.
65      * @return the class mapping or null if not found.
66      */

67     public ClassMapping getClassMapping(final String JavaDoc className) {
68         return classMappings.get(className);
69     }
70
71     /**
72      * Returns a string representation of the object.
73      * @return string representation
74      */

75     @Override JavaDoc
76     public String JavaDoc toString() {
77         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
78         // classname
79
sb.append(this.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1));
80         sb.append("[classMappings=");
81         sb.append(classMappings);
82         sb.append("]");
83
84         return sb.toString();
85     }
86 }
87
Popular Tags