KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > config > DefaultLookupAlgorithm


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.config;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.config.evaluator.Evaluator;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26  * The default algorithm used to determine whether a section applies to the object being looked up
27  *
28  * @author gavinc
29  */

30 public class DefaultLookupAlgorithm implements ConfigLookupAlgorithm
31 {
32    private static final Log logger = LogFactory.getLog(DefaultLookupAlgorithm.class);
33    
34    /**
35     * @see org.alfresco.config.ConfigLookupAlgorithm#process(org.alfresco.config.ConfigSection, org.alfresco.config.evaluator.Evaluator, java.lang.Object, org.alfresco.config.Config)
36     */

37    public void process(ConfigSection section, Evaluator evaluator, Object JavaDoc object, Config results)
38    {
39       // if the config section applies to the given object extract all the
40
// config elements inside and add them to the Config object
41
if (evaluator.applies(object, section.getCondition()))
42       {
43          if (logger.isDebugEnabled())
44             logger.debug(section + " matches");
45
46          List JavaDoc<ConfigElement> sectionConfigElements = section.getConfigElements();
47          for (ConfigElement newConfigElement : sectionConfigElements)
48          {
49             // if the config element being added already exists we need to combine it or replace it
50
String JavaDoc name = newConfigElement.getName();
51             ConfigElement existingConfigElement = (ConfigElement)results.getConfigElements().get(name);
52             if (existingConfigElement != null)
53             {
54                if (section.isReplace())
55                {
56                   // if the section has been marked as 'replace' and a config element
57
// with this name has already been found, replace it
58
results.getConfigElements().put(name, newConfigElement);
59                   
60                   if (logger.isDebugEnabled())
61                      logger.debug("Replaced " + existingConfigElement + " with " + newConfigElement);
62                }
63                else
64                {
65                   // combine this config element with the previous one found with the same name
66
ConfigElement combinedConfigElement = existingConfigElement.combine(newConfigElement);
67                   results.getConfigElements().put(name, combinedConfigElement);
68                
69                   if (logger.isDebugEnabled())
70                   {
71                      logger.debug("Combined " + newConfigElement + " with " + existingConfigElement +
72                                   " to create " + combinedConfigElement);
73                   }
74                }
75             }
76             else
77             {
78                results.getConfigElements().put(name, newConfigElement);
79             }
80          }
81       }
82    }
83 }
84
Popular Tags