01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.annotations.test;
18:
19: import org.compass.core.CompassException;
20: import org.compass.core.config.CompassConfigurable;
21: import org.compass.core.config.CompassSettings;
22: import org.compass.core.converter.ConversionException;
23: import org.compass.core.converter.basic.AbstractBasicConverter;
24: import org.compass.core.mapping.ResourcePropertyMapping;
25: import org.compass.core.marshall.MarshallingContext;
26:
27: /**
28: * @author kimchy
29: */
30: public class ConvertedConverter extends AbstractBasicConverter
31: implements CompassConfigurable {
32:
33: private String separator;
34:
35: public void configure(CompassSettings settings)
36: throws CompassException {
37: separator = settings.getSetting("separator", "/");
38: }
39:
40: protected Object doFromString(String str,
41: ResourcePropertyMapping resourcePropertyMapping,
42: MarshallingContext context) throws ConversionException {
43: Converted converted = new Converted();
44: converted.value1 = str.substring(0, str.indexOf(separator));
45: converted.value2 = str.substring(str.indexOf(separator)
46: + separator.length());
47: return converted;
48: }
49:
50: protected String doToString(Object o,
51: ResourcePropertyMapping resourcePropertyMapping,
52: MarshallingContext context) {
53: Converted converted = (Converted) o;
54: return converted.value1 + separator + converted.value2;
55: }
56:
57: }
|