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.core.test.converter;
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 SampleConverter extends AbstractBasicConverter implements
31: CompassConfigurable {
32:
33: private String seperator;
34:
35: public void configure(CompassSettings settings)
36: throws CompassException {
37: seperator = settings.getSetting("seperator", "XXX");
38: }
39:
40: protected String doToString(Object o,
41: ResourcePropertyMapping resourcePropertyMapping,
42: MarshallingContext context) {
43: A.TwoStringsValue value = (A.TwoStringsValue) o;
44: return value.getValue1() + seperator + value.getValue2();
45: }
46:
47: protected Object doFromString(String str,
48: ResourcePropertyMapping resourcePropertyMapping,
49: MarshallingContext context) throws ConversionException {
50: A.TwoStringsValue value = new A.TwoStringsValue();
51: value.setValue1(str.substring(0, str.indexOf(seperator)));
52: value.setValue2(str.substring(str.indexOf(seperator)
53: + seperator.length()));
54: return value;
55: }
56:
57: public String getSeperator() {
58: return seperator;
59: }
60:
61: public void setSeperator(String seperator) {
62: this.seperator = seperator;
63: }
64: }
|