KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > schema > rules > ConfigurationTranslator


1 // Copyright 2004, 2005 The Apache Software Foundation
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

15 package org.apache.hivemind.schema.rules;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.hivemind.HiveMind;
22 import org.apache.hivemind.Location;
23 import org.apache.hivemind.internal.Module;
24 import org.apache.hivemind.schema.Translator;
25
26 /**
27  * Interprets a string as an extension point id, and provides the elements for that extension point.
28  * Depending on the target property type the elements will be provided as a List or as a Map.
29  *
30  * @author Howard Lewis Ship
31  */

32 public class ConfigurationTranslator implements Translator
33 {
34     public Object JavaDoc translate(Module contributingModule, Class JavaDoc propertyType, String JavaDoc inputValue,
35             Location location)
36     {
37         if (HiveMind.isBlank(inputValue))
38             return null;
39
40         // For backward compatibility allow configuratin of type map be assigned to
41
// properties of type List. Drawback: Lazy construction of the configuration
42
// gets lost. The configuration is constructed right here during the conversion
43
Object JavaDoc configuration = contributingModule.getConfiguration(inputValue);
44         if (configuration instanceof Map JavaDoc && propertyType.equals(List JavaDoc.class)) {
45             configuration = new ArrayList JavaDoc(((Map JavaDoc) configuration).values());
46         }
47         
48         return configuration;
49     }
50 }
Popular Tags