01: // Copyright 2004, 2005 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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;
16:
17: import org.apache.hivemind.Location;
18: import org.apache.hivemind.internal.Module;
19:
20: /**
21: * Object which can translate a string into an object value. This is used to
22: * translate attribute values (or element content) from strings into
23: * numbers, booleans or other constructs before assigning the final value
24: * to a propery. Translation occurs after symbol substitution.
25: *
26: * <p>
27: * Translator classes should have a public constructor that takes no
28: * arguments. They may optionally have a second constructor
29: * that takes a single string as a parameter. When the
30: * {@link org.apache.hivemind.parse.DescriptorParser} encounters
31: * a <code>translator</code> of the form
32: * "<code><i>translator-id</i>,<i>initialization-string</i></code>"
33: * (example: "int,min=0") it will use the second constructor, passing
34: * the initialization string.
35: *
36: * <p>
37: * Generally, initializion strings are of the form
38: * <code><i>key</i>=<i>value</i>[,<i>key</i>=<i>value</i>]*</code>.
39: * Each initializer has a set of keys it recognizes, other keys are simply
40: * ignored.
41: *
42: * @author Howard Lewis Ship
43: */
44: public interface Translator {
45: /**
46: * Invoked by a {@link org.apache.hivemind.schema.Rule}
47: * to translate an inputValue into an appropriate object.
48: * Substitution symbols will already have been expanded before this method is
49: * invoked.
50: *
51: * @param contributingModule the module from which the input value originates
52: * @param propertyType the type of the property to be assigned by this translator; smart translators may
53: * be able to automatically convert from string to the correct type
54: * @param inputValue the value to be translated, either an attribute value or the content of the element
55: * @param location the location of the inputValue; used to set the location of created objects,
56: * or when reporting errors
57: */
58: public Object translate(Module contributingModule,
59: Class propertyType, String inputValue, Location location);
60: }
|