KickJava   Java API By Example, From Geeks To Geeks.

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


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: ClassMapping.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  * Defines a mapping for a given class.
33  * @author Florent Benoit
34  */

35 public class ClassMapping extends AbsMapping {
36
37     /**
38      * Association between a name(or alias) and an attribute mapping.
39      */

40     private Map JavaDoc<String JavaDoc, AttributeMapping> attributesMapping = null;
41
42     /**
43      * Build a default class mapping.
44      */

45     public ClassMapping() {
46         super();
47         this.attributesMapping = new HashMap JavaDoc<String JavaDoc, AttributeMapping>();
48     }
49
50     /**
51      * Add a given attribute mapping object.
52      * @param attributeMapping the given attribute.
53      */

54     public void addAttributeMapping(final AttributeMapping attributeMapping) {
55         attributesMapping.put(attributeMapping.getName(), attributeMapping);
56         // store alias too (if any)
57
if (attributeMapping.getAlias() != null) {
58             attributesMapping.put(attributeMapping.getAlias(), attributeMapping);
59         }
60     }
61
62     /**
63      * Gets the attribute mapping for the given attribute name.
64      * @param attributeName the given attribute name.
65      * @return the attribute mapping or null if not found.
66      */

67     public AttributeMapping getAttributeMapping(final String JavaDoc attributeName) {
68         return attributesMapping.get(attributeName);
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("[");
81         sb.append(super.toString());
82         sb.append(", attributes=");
83         sb.append(attributesMapping);
84         sb.append("]");
85
86         return sb.toString();
87     }
88
89 }
90
Popular Tags