01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.datatype.convertor;
18:
19: import java.util.Locale;
20:
21: /**
22: * The purpose of a Convertor is to convert between Object and String
23: * representations of the same thing. For example, convert
24: * {@link Long}s or {@link java.util.Date Date}s to strings, and vice
25: * versa. The behaviour of this conversion process can depend on the
26: * user's Locale.
27: *
28: * <p>If you need to do mass conversion of a lot of values, it may be
29: * beneficial to pass a {@link FormatCache} object to the convert methods.
30: * Some convertors need to build and configure parser or formatting objects,
31: * which can be expensive if it needs to be done repeatedly.
32: *
33: * @version CVS $Id: Convertor.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public interface Convertor {
36:
37: /**
38: * Converts string representation into the object of convertor's type.
39: * Returns null if conversion fails.
40: *
41: * @param formatCache can be null if not needed
42: */
43: Object convertFromString(String value, Locale locale,
44: FormatCache formatCache);
45:
46: String convertToString(Object value, Locale locale,
47: FormatCache formatCache);
48:
49: Class getTypeClass();
50:
51: public interface FormatCache {
52: public Object get();
53:
54: public void store(Object object);
55: }
56: }
|