KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > types > ExtendedTypeDecorator


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.access.types;
20
21 import java.sql.CallableStatement JavaDoc;
22 import java.sql.PreparedStatement JavaDoc;
23 import java.sql.ResultSet JavaDoc;
24
25 import org.apache.cayenne.map.DbAttribute;
26 import org.apache.cayenne.validation.ValidationResult;
27
28 /**
29  * Decorates another ExtendedType, converting objects to other Java types.
30  *
31  * @since 3.0
32  * @author Andrus Adamchik
33  */

34 abstract class ExtendedTypeDecorator implements ExtendedType {
35
36     private ExtendedType decorated;
37
38     ExtendedTypeDecorator(ExtendedType decorated) {
39         this.decorated = decorated;
40     }
41
42     abstract Object JavaDoc toJavaObject(Object JavaDoc object);
43
44     abstract Object JavaDoc fromJavaObject(Object JavaDoc object);
45
46     public abstract String JavaDoc getClassName();
47
48     public Object JavaDoc materializeObject(CallableStatement JavaDoc rs, int index, int type)
49             throws Exception JavaDoc {
50         return toJavaObject(decorated.materializeObject(rs, index, type));
51     }
52
53     public Object JavaDoc materializeObject(ResultSet JavaDoc rs, int index, int type) throws Exception JavaDoc {
54         return toJavaObject(decorated.materializeObject(rs, index, type));
55     }
56
57     public void setJdbcObject(
58             PreparedStatement JavaDoc statement,
59             Object JavaDoc value,
60             int pos,
61             int type,
62             int precision) throws Exception JavaDoc {
63         decorated.setJdbcObject(statement, fromJavaObject(value), pos, type, precision);
64     }
65
66     /**
67      * @deprecated since 3.0 as validation should not be done at the DataNode level.
68      */

69     public boolean validateProperty(
70             Object JavaDoc source,
71             String JavaDoc property,
72             Object JavaDoc value,
73             DbAttribute dbAttribute,
74             ValidationResult validationResult) {
75         
76         return decorated.validateProperty(
77                 source,
78                 property,
79                 value,
80                 dbAttribute,
81                 validationResult);
82     }
83 }
84
Popular Tags