001: package net.sourceforge.squirrel_sql.plugins.sqlval;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell and Olof Edlund
005: * colbell@users.sourceforge.net
006: *
007: * This code is based on the example web service client code originally written
008: * by Olof Edlund.
009: *
010: * This library is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public
012: * License as published by the Free Software Foundation; either
013: * version 2.1 of the License, or (at your option) any later version.
014: *
015: * This library is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: * Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public
021: * License along with this library; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023: */
024: import java.rmi.RemoteException;
025:
026: import javax.xml.namespace.QName;
027: import javax.xml.rpc.ParameterMode;
028: import javax.xml.rpc.ServiceException;
029:
030: import org.apache.axis.client.Call;
031: import org.apache.axis.client.Service;
032: import org.apache.axis.encoding.XMLType;
033:
034: import com.mimer.ws.validateSQL.ValidatorResult;
035:
036: public class WebServiceValidator {
037: /** The session that this validator is connected to. */
038: private final WebServiceSession _webServiceSession;
039:
040: /** Preferences. */
041: private final WebServiceSessionProperties _prefs;
042:
043: /**
044: * Ctor specifying the session.
045: *
046: * @param webServiceSession The session to the web service that this
047: * will use.
048: * @param perfs Preferences
049: *
050: * @throws IllegalArgumentException
051: * Thrown if null WebServiceSession or null WebServicePreferences
052: * objects passed.
053: */
054: public WebServiceValidator(WebServiceSession webServiceSession,
055: WebServiceSessionProperties prefs) {
056: super ();
057: if (webServiceSession == null) {
058: throw new IllegalArgumentException(
059: "WebServiceSession == null");
060: }
061: if (prefs == null) {
062: throw new IllegalArgumentException(
063: "WebServicePreferences == null");
064: }
065: _webServiceSession = webServiceSession;
066: _prefs = prefs;
067: }
068:
069: public ValidatorResult validate(String sql)
070: throws ServiceException, RemoteException {
071: Service l_service = new Service();
072: Call l_call = (Call) l_service.createCall();
073:
074: //Set the target server and name space
075: l_call.setTargetEndpointAddress(_webServiceSession
076: .getTargetURL());
077: l_call.setOperationName(new QName("SQL99Validator",
078: "validateSQL"));
079:
080: //Add the parameter names and types
081: //Use the session Id you got from the openSession call here
082: l_call.addParameter("a_sessionId", XMLType.XSD_INT,
083: ParameterMode.IN);
084:
085: //Use the session key you got from the openSession call here
086: l_call.addParameter("a_sessionKey", XMLType.XSD_INT,
087: ParameterMode.IN);
088:
089: //The SQL statement to be validated against the standard
090: l_call.addParameter("a_sqlStatement", XMLType.XSD_STRING,
091: ParameterMode.IN);
092:
093: //The format of the result. This must be "text" or "html".
094: //Hopefully some type of XML format will be available as well
095: l_call.addParameter("a_resultType", XMLType.XSD_STRING,
096: ParameterMode.IN);
097:
098: QName l_qn = new QName(IWebServiceURL.REQUEST_URL,
099: "ValidatorResult");
100:
101: l_call
102: .registerTypeMapping(
103: ValidatorResult.class,
104: l_qn,
105: new org.apache.axis.encoding.ser.BeanSerializerFactory(
106: ValidatorResult.class, l_qn),
107: new org.apache.axis.encoding.ser.BeanDeserializerFactory(
108: ValidatorResult.class, l_qn));
109:
110: //Set the return type
111: l_call.setReturnType(l_qn);
112:
113: // Parameters for call.
114: final Object[] parms = new Object[] {
115: Integer.valueOf(_webServiceSession.getSessionID()),
116: Integer.valueOf(_webServiceSession.getSessionKey()),
117: sql, "text" };
118:
119: // Execute validator and return results.
120: return (ValidatorResult) l_call.invoke(parms);
121: }
122: }
|