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: * $Header:$
18: */
19:
20: package org.apache.beehive.controls.system.jdbc;
21:
22: import org.apache.beehive.controls.api.ControlException;
23: import org.apache.beehive.controls.api.context.ControlBeanContext;
24: import org.apache.beehive.controls.system.jdbc.JdbcControl.SQL;
25:
26: import java.lang.reflect.Method;
27: import java.sql.ResultSet;
28: import java.sql.SQLException;
29: import java.util.Calendar;
30:
31: /**
32: * Default ResultSetMapper implementation for XmlObjects.
33: */
34: public class DefaultXmlObjectResultSetMapper extends
35: DefaultObjectResultSetMapper {
36:
37: /**
38: * Map a ResultSet to an XmlObject. Object type is defined by the return type of the method.
39: *
40: * @param context A ControlBeanContext instance.
41: * @param m Method associated with this call.
42: * @param resultSet Result set to map.
43: * @param cal A Calendar instance for resolving date/time values.
44: * @return An XmlObject
45: */
46: public Object mapToResultType(ControlBeanContext context, Method m,
47: ResultSet resultSet, Calendar cal) {
48:
49: final Class returnType = m.getReturnType();
50: final boolean isArray = returnType.isArray();
51:
52: try {
53: if (isArray) {
54: final SQL methodSQL = (SQL) context
55: .getMethodPropertySet(m, SQL.class);
56: return arrayFromResultSet(resultSet, methodSQL
57: .arrayMaxLength(), returnType, cal);
58: } else {
59:
60: if (!resultSet.next()) {
61: return _tmf.fixNull(m.getReturnType());
62: }
63:
64: return RowMapperFactory.getRowMapper(resultSet,
65: returnType, cal).mapRowToReturnType();
66: }
67: } catch (SQLException e) {
68: throw new ControlException(e.getMessage(), e);
69: }
70: }
71: }
|