View Javadoc

1   /*
2    * Copyright 2000-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.portals.graffito.jcr.mapper.model;
17  
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.portals.graffito.jcr.mapper.Mapper;
25  import org.apache.portals.graffito.jcr.mapper.impl.DigesterMapperImpl;
26  import org.apache.portals.graffito.jcr.persistence.PersistenceConstant;
27  
28  /***
29   * This class match to the complete xml mapping files.
30   * it contains mainly a collection of {@link ClassDescriptor}
31   *
32   * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
33   * @version $Id: Exp $
34   */
35  public class MappingDescriptor {
36  	
37  	private static final Log log = LogFactory.getLog(MappingDescriptor.class);
38      private HashMap classDescriptorsByClassName = new HashMap();
39      private HashMap classDescriptorsByNodeType = new HashMap();
40  
41      private Mapper mapper;
42  
43      privateong> String packageName;
44      
45      public void setPackage(String pckgName) {
46          this.packageName = pckgName;
47      }
48      
49      /***
50       * Add a new ClassDescriptor
51       *
52       * @param classDescriptor The class descriptor to add
53       */
54      public void addClassDescriptor(ClassDescriptor classDescriptor) {
55      	
56          log.debug("Adding the class descriptor for : " + classDescriptor.getClassName());	
57          if (null != this.packageName && !"".equals(this.packageName)) {
58              classDescriptor.setClassName(this.packageName + "." + classDescriptor.getClassName());
59  
60              if (null != classDescriptor.getExtend() && !"".equals(classDescriptor.getExtend())) {
61                  classDescriptor.setExtend(thisong>.packageName + "." + classDescriptor.getExtend());
62              }
63          }
64  
65          classDescriptorsByClassName.put(classDescriptor.getClassName(), classDescriptor);
66          
67          if (null != classDescriptor.getJcrNodeType() && !  "".equals(classDescriptor.getJcrNodeType()) && 
68          		 ! PersistenceConstant.NT_UNSTRUCTURED.equals(classDescriptor.getJcrNodeType()))
69          	 {
70               classDescriptorsByNodeType.put(classDescriptor.getJcrNodeType(), classDescriptor);	
71          	 }
72          classDescriptor.setMappingDescriptor(this);
73      }
74  
75      /***
76       * Get the classdescriptor to used for the class
77       * @param className the class name
78       * @return the class descriptor found or null
79       */
80      public ClassDescriptor getClassDescriptorByName(String className) {
81          return (ClassDescriptor) classDescriptorsByClassName.get(className);
82      }
83      
84      public ClassDescriptor getClassDescriptorByNodeType(String nodeType)
85      {
86          return (ClassDescriptor) classDescriptorsByNodeType.get(nodeType);	
87      }
88  
89      /***
90       * Get all class descriptors by class name
91       * @return all class descriptors found
92       */
93      public Map getClassDescriptorsByClassName() {
94          return classDescriptorsByClassName;
95      }
96      /***
97       * Get all class descriptors by class name
98       * @return all class descriptors found
99       */
100     public Map getClassDescriptorsByNodeType() {
101         return classDescriptorsByNodeType;
102     }
103     public Mapper getMapper() {
104         return this.mapper;
105     }
106 
107     public void setMapper(Mapper parentMapper) {
108         this.mapper = parentMapper;
109     }
110 }