001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.xbean.spring.generator;
018    
019    import java.util.Collections;
020    import java.util.HashMap;
021    import java.util.HashSet;
022    import java.util.Iterator;
023    import java.util.List;
024    import java.util.Map;
025    import java.util.Set;
026    import java.util.TreeSet;
027    
028    /**
029     * @author Dain Sundstrom
030     * @version $Id$
031     * @since 1.0
032     */
033    public class ElementMapping implements Comparable {
034        private final String namespace;
035        private final String elementName;
036        private final String className;
037        private final String description;
038        private final boolean rootElement;
039        private final String initMethod;
040        private final String destroyMethod;
041        private final String factoryMethod;
042        private final String contentProperty;
043        private final Set attributes;
044        private final Map attributesByName;
045        private final List constructors;
046        private final List flatProperties;
047        private final Map maps;
048        private final Map flatCollections;
049            private final List superClasses;
050            private final HashSet interfaces;
051        
052        public ElementMapping(String namespace, String elementName, String className, String description, 
053                boolean rootElement, String initMethod, String destroyMethod, String factoryMethod, 
054                String contentProperty, Set attributes, List constructors, List flatProperties, Map maps, 
055                Map flatCollections, List superClasses, HashSet interfaces) {
056            this.superClasses = superClasses;
057                    this.interfaces = interfaces;
058                    if (namespace == null) throw new NullPointerException("namespace");
059            if (elementName == null) throw new NullPointerException("elementName");
060            if (className == null) throw new NullPointerException("className");
061            if (attributes == null) throw new NullPointerException("attributes");
062            if (constructors == null) throw new NullPointerException("constructors");
063    
064            this.namespace = namespace;
065            this.elementName = elementName;
066            this.className = className;
067            this.description = description;
068            this.rootElement = rootElement;
069            this.initMethod = initMethod;
070            this.destroyMethod = destroyMethod;
071            this.factoryMethod = factoryMethod;
072            this.contentProperty = contentProperty;
073            this.constructors = constructors;
074            this.attributes = Collections.unmodifiableSet(new TreeSet(attributes));
075            this.maps = Collections.unmodifiableMap(maps);
076            this.flatProperties = Collections.unmodifiableList(flatProperties);
077            this.flatCollections = Collections.unmodifiableMap(flatCollections);
078            
079            Map attributesByName = new HashMap();
080            for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
081                AttributeMapping attribute = (AttributeMapping) iterator.next();
082                attributesByName.put(attribute.getAttributeName(), attribute);
083            }
084            this.attributesByName = Collections.unmodifiableMap(attributesByName);
085        }
086    
087        public String getNamespace() {
088            return namespace;
089        }
090    
091        public String getElementName() {
092            return elementName;
093        }
094    
095        public String getClassName() {
096            return className;
097        }
098    
099        public String getDescription() {
100            return description;
101        }
102    
103        public boolean isRootElement() {
104            return rootElement;
105        }
106    
107        public String getInitMethod() {
108            return initMethod;
109        }
110    
111        public String getDestroyMethod() {
112            return destroyMethod;
113        }
114    
115        public String getFactoryMethod() {
116            return factoryMethod;
117        }
118    
119        public String getContentProperty() {
120            return contentProperty;
121        }
122    
123        public Set getAttributes() {
124            return attributes;
125        }
126    
127        public AttributeMapping getAttribute(String attributeName) {
128            return (AttributeMapping) attributesByName.get(attributeName);
129        }
130    
131        public Map getMapMappings() {
132            return maps;
133        }
134    
135        public MapMapping getMapMapping(String name) {
136            return (MapMapping) maps.get(name);
137        }
138        
139        public Map getFlatCollections() {
140            return flatCollections;
141        }
142    
143        public List getFlatProperties() {
144            return flatProperties;
145        }
146    
147        public List getConstructors() {
148            return constructors;
149        }
150    
151        public int hashCode() {
152            return elementName.hashCode();
153        }
154    
155        public boolean equals(Object obj) {
156            if (obj instanceof ElementMapping) {
157                return elementName.equals(((ElementMapping) obj).elementName);
158            }
159            return false;
160        }
161    
162        public int compareTo(Object obj) {
163            return elementName.compareTo(((ElementMapping) obj).elementName);
164        }
165    
166            public HashSet getInterfaces() {
167                    return interfaces;
168            }
169    
170            public List getSuperClasses() {
171                    return superClasses;
172            }
173    }