EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.service.impl]

COVERAGE SUMMARY FOR SOURCE FILE [ContributionObjectProvider.java]

nameclass, %method, %block, %line, %
ContributionObjectProvider.java100% (1/1)100% (2/2)78%  (69/89)87%  (20/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ContributionObjectProvider100% (1/1)100% (2/2)78%  (69/89)87%  (20/23)
provideObject (Module, Class, String, Location): Object 100% (1/1)77%  (66/86)86%  (19/22)
ContributionObjectProvider (): void 100% (1/1)100% (3/3)100% (1/1)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveutils.service.impl;
16 
17import java.util.Iterator;
18import java.util.List;
19import java.util.Map;
20import java.util.StringTokenizer;
21 
22import org.apache.hivemind.ApplicationRuntimeException;
23import org.apache.hivemind.HiveMind;
24import org.apache.hivemind.Location;
25import org.apache.hivemind.internal.Module;
26import org.apache.hivemind.service.ObjectProvider;
27import org.apache.hivemind.util.PropertyUtils;
28 
29/**
30 * An <code>org.apache.hivemind.service.ObjectProvider</code>
31 * that extracts a contribution item from a global configuration, referenced by
32 * a unique id. The translator string is of the form:
33 * <code>config-id:id-property:id-value</code>. The id-property name defines
34 * the name of a property of the contribution object that is supposed unique and
35 * will be used to find the required contribution.
36 *
37 * @author Jean-Francois Poilpret
38 */
39public class ContributionObjectProvider implements ObjectProvider
40{
41        public Object provideObject(Module                contributingModule,
42                                                                Class                propertyType,
43                                                                String                inputValue,
44                                                                Location        location)
45        {
46                if (HiveMind.isBlank(inputValue))
47                {
48                        return null;
49                }
50                StringTokenizer tokenizer = new StringTokenizer(inputValue, ":");
51 
52                if (tokenizer.countTokens() == NUM_TOKENS_CFG_PROP_ID)
53                {
54                        String idConfig = tokenizer.nextToken();
55                        String property = tokenizer.nextToken();
56                        String id = tokenizer.nextToken();
57                        List config = contributingModule.getConfiguration(idConfig);
58                        Iterator i = config.iterator();
59                        while (i.hasNext())
60                        {
61                                Object contrib = i.next();
62                                if (id.equals(PropertyUtils.read(contrib, property)))
63                                {
64                                        return contrib;
65                                }
66                        }
67                        return null;
68                }
69                else if (tokenizer.countTokens() == NUM_TOKENS_CFG_ID)
70                {
71                        String idConfig = tokenizer.nextToken();
72                        String id = tokenizer.nextToken();
73                        if (contributingModule.isConfigurationMappable(idConfig))
74                        {
75                                Map config = contributingModule.getConfigurationAsMap(idConfig);
76                                return config.get(id);
77                        }
78                }
79                throw new ApplicationRuntimeException(
80                                        "Bad input value <" + inputValue + ">", location, null);
81        }
82        
83        static final private int        NUM_TOKENS_CFG_PROP_ID        = 3;
84        static final private int        NUM_TOKENS_CFG_ID                = 2;
85}

[all classes][net.sourceforge.hiveutils.service.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov