KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > system > jdbc > DefaultXmlObjectResultSetMapper


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  * $Header:$
17  */

18
19 package org.apache.beehive.controls.system.jdbc;
20
21 import org.apache.beehive.controls.api.ControlException;
22 import org.apache.beehive.controls.api.context.ControlBeanContext;
23 import org.apache.beehive.controls.system.jdbc.JdbcControl.SQL;
24
25 import java.lang.reflect.Method JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.util.Calendar JavaDoc;
29
30 /**
31  * Default ResultSetMapper implementation for XmlObjects.
32  */

33 public class DefaultXmlObjectResultSetMapper extends DefaultObjectResultSetMapper {
34
35     /**
36      * Map a ResultSet to an XmlObject. Object type is defined by the return type of the method.
37      *
38      * @param context A ControlBeanContext instance.
39      * @param m Method associated with this call.
40      * @param resultSet Result set to map.
41      * @param cal A Calendar instance for resolving date/time values.
42      * @return An XmlObject
43      */

44     public Object JavaDoc mapToResultType(ControlBeanContext context, Method JavaDoc m, ResultSet JavaDoc resultSet, Calendar JavaDoc cal) {
45
46         final Class JavaDoc returnType = m.getReturnType();
47         final boolean isArray = returnType.isArray();
48
49         try {
50             if (isArray) {
51                 final SQL methodSQL = (SQL) context.getMethodPropertySet(m, SQL.class);
52                 return arrayFromResultSet(resultSet, methodSQL.arrayMaxLength(), returnType, cal);
53             } else {
54
55                 if (!resultSet.next()) {
56                     return _tmf.fixNull(m.getReturnType());
57                 }
58
59                 return RowMapperFactory.getRowMapper(resultSet, returnType, cal).mapRowToReturnType();
60             }
61         } catch (SQLException JavaDoc e) {
62             throw new ControlException(e.getMessage(), e);
63         }
64     }
65 }
66
Popular Tags