001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: JdbcConfigDeserializer.java 9395 2007-09-30 02:00:31Z lzheng $
023: */
024: package com.bostechcorp.cbesb.runtime.component.jdbc.wsdl;
025:
026: import javax.wsdl.Definition;
027: import javax.wsdl.WSDLException;
028: import javax.wsdl.extensions.ExtensibilityElement;
029: import javax.wsdl.extensions.ExtensionDeserializer;
030: import javax.wsdl.extensions.ExtensionRegistry;
031: import javax.xml.namespace.QName;
032:
033: import org.w3c.dom.Element;
034:
035: import com.bostechcorp.cbesb.common.util.ErrorUtil;
036: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
037: import com.bostechcorp.cbesb.runtime.component.util.wsdl.BaseCommonAttributeDeserializer;
038: import com.ibm.wsdl.util.xml.DOMUtils;
039:
040: public class JdbcConfigDeserializer extends
041: BaseCommonAttributeDeserializer implements
042: ExtensionDeserializer {
043:
044: public ExtensibilityElement unmarshall(Class parentType,
045: QName elementType, Element el, Definition def,
046: ExtensionRegistry extReg) throws WSDLException {
047:
048: JdbcConfig jdbcConfig = (JdbcConfig) super .unmarshall(
049: parentType, elementType, el, def, extReg);
050:
051: jdbcConfig.setDriver(MacroUtil.resolveUserMacro(DOMUtils
052: .getAttribute(el, JdbcExtension.DRIVER)));
053: jdbcConfig.setUrl(MacroUtil.resolveUserMacro(DOMUtils
054: .getAttribute(el, JdbcExtension.URL)));
055: jdbcConfig.setUser(MacroUtil.resolveUserMacro(DOMUtils
056: .getAttribute(el, JdbcExtension.USER)));
057: jdbcConfig.setPassword(MacroUtil.resolveUserMacro(DOMUtils
058: .getAttribute(el, JdbcExtension.PASSWORD)));
059: jdbcConfig.setRequestHandler(MacroUtil
060: .resolveUserMacro(DOMUtils.getAttribute(el,
061: JdbcExtension.REQUEST_HANDLER)));
062: jdbcConfig.setExecHandler(MacroUtil.resolveUserMacro(DOMUtils
063: .getAttribute(el, JdbcExtension.EXEC_HANDLER)));
064: String autoCommit = DOMUtils.getAttribute(el,
065: JdbcExtension.AUTO_COMMIT);
066: if (autoCommit != null && autoCommit.equalsIgnoreCase("true")) {
067: if (autoCommit.equalsIgnoreCase("true")) {
068: jdbcConfig.setAutoCommit(true);
069: } else {
070: jdbcConfig.setAutoCommit(false);
071: }
072: }
073: String connectionRetries = DOMUtils.getAttribute(el,
074: JdbcExtension.CONNECTION_RETRIES);
075: if (connectionRetries != null) {
076: try {
077: int value = Integer.parseInt(connectionRetries);
078: jdbcConfig.setConnectionRetries(value);
079: } catch (NumberFormatException e) {
080:
081: ErrorUtil
082: .printError("Invalid value for attribute: ", e);
083: throw new WSDLException(WSDLException.PARSER_ERROR,
084: "Invalid value for attribute: "
085: + JdbcExtension.CONNECTION_RETRIES);
086: }
087: }
088: String connectionInterval = DOMUtils.getAttribute(el,
089: JdbcExtension.CONNECTION_INTERVAL);
090: if (connectionInterval != null) {
091: try {
092: int value = Integer.parseInt(connectionInterval);
093: jdbcConfig.setConnectionInterval(value);
094: } catch (NumberFormatException e) {
095:
096: ErrorUtil
097: .printError("Invalid value for attribute: ", e);
098: throw new WSDLException(WSDLException.PARSER_ERROR,
099: "Invalid value for attribute: "
100: + JdbcExtension.CONNECTION_INTERVAL);
101: }
102: }
103: String transactionTimeout = DOMUtils.getAttribute(el,
104: JdbcExtension.TRANSACTION_TIMEOUT);
105: if (transactionTimeout != null) {
106: try {
107: int value = Integer.parseInt(transactionTimeout);
108: jdbcConfig.setTransactionTimeout(value);
109: } catch (NumberFormatException e) {
110:
111: ErrorUtil
112: .printError("Invalid value for attribute: ", e);
113: throw new WSDLException(WSDLException.PARSER_ERROR,
114: "Invalid value for attribute: "
115: + JdbcExtension.TRANSACTION_TIMEOUT);
116: }
117: }
118: String defaultPageSize = DOMUtils.getAttribute(el,
119: JdbcExtension.DEFAULT_PAGE_SIZE);
120: if (defaultPageSize != null) {
121: try {
122: int value = Integer.parseInt(defaultPageSize);
123: jdbcConfig.setDefaultPageSize(value);
124: } catch (NumberFormatException e) {
125: ErrorUtil
126: .printError("Invalid value for attribute: ", e);
127: throw new WSDLException(WSDLException.PARSER_ERROR,
128: "Invalid value for attribute: "
129: + JdbcExtension.DEFAULT_PAGE_SIZE);
130: }
131: }
132:
133: return jdbcConfig;
134: }
135:
136: }
|