Beispiel #1
0
        /**
         * Delete the specified instance from the WITSML server.
         *
         * @param instance  Instance to delete. Non-null.
         * @throws ArgumentException If instance is null.
         * @throws WitsmlServerException  If the server access failed for some reason.
         */
        public void delete(WitsmlObject instance)
        { //throws WitsmlServerException {
            if (instance == null)
            {
                throw new ArgumentException("instance cannot be null");
            }

            String wsdlFunction = "WMLS_DeleteFromStore";

            long requestTime = DateTime.Now.Ticks;// System.currentTimeMillis();

            String queryXml    = "";
            String responseXml = null;

            String type = instance.getWitsmlType();
            //Class<? extends WitsmlObject>
            var actualClass = getActualClass(version, type);

            String id       = instance.getId();
            String parentId = instance.getParentId() != null?instance.getParentId() : "";

            try
            {
                // Find the getQuery() method
                // Method getQueryMethod = instance.getClass().getDeclaredMethod("getQuery",
                //                                                             String.class,
                //                                                           String[].class);
                MethodInfo getQueryMethod = instance.GetType().GetMethod("getQuery"); //
                //getQueryMethod.setAccessible(true);

                // This is the complete query for the class
                queryXml = (String)getQueryMethod.Invoke(null, new Object[] { id, parentId });// (null, id, new String[] {parentId});

                // Filter the ID part only
                WitsmlQuery query = new WitsmlQuery();
                query.includeElement("name");
                queryXml = query.apply(queryXml);

                Console.WriteLine(queryXml); // System.out.println(queryXml);

                // Send the query to the WITSML server and pick the response
                WitsmlResponse response = accessor.delete(type, queryXml);

                notify(wsdlFunction, type, requestTime, queryXml, null,
                       response.getStatusCode(),
                       response.getServerMessage(),
                       null);
            }
            catch (MissingMethodException exception)
            { // NoSuchMethodException exception) {
              // Programmer error
              //Debug.Assert(false : "Method not found: " + instance;
            }
            catch (AccessViolationException exception)
            {// IllegalAccessException exception) {
             // Programmer error
             //Debug.Assert(false : "Unable to invoke: " + instance;
            }
            catch (TargetInvocationException exception)
            { // InvocationTargetException exception) {
                // Wrapped exception from the invocation such as WitsmlParseException
                notify(wsdlFunction, type, requestTime, queryXml, null, null, null,
                       exception.InnerException);                                   //.getCause());
                String message = "Exception thrown by " + actualClass + ".newInstance()";
                throw new WitsmlServerException(message, exception.InnerException); //.getCause());
            }
            //catch (RemoteException exception) {
            //    // Connection problems.
            //    notify(wsdlFunction, type, requestTime, queryXml, null, null, null,
            //           exception);
            //    String message = "Unable to connect to WITSML server: " + this;
            //    throw new WitsmlServerException(message, exception);
            //}
            catch (IOException exception)
            {
                // Unable to read response XML
                notify(wsdlFunction, type, requestTime, queryXml, null, null, null,
                       exception);
                String message = "Unable to read response XML: " + responseXml;
                throw new WitsmlServerException(message, exception);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Update the specified WITSML instance by making a new fetch from the server.
        /// </summary>
        /// <param name="witsmlObject">Instance to update. Non-null.</param>
        /// <param name="witsmlQuery"> Query to apply. Non-null.</param>
        public void update(WitsmlObject witsmlObject, WitsmlQuery witsmlQuery)
        {
            if (witsmlObject == null)
            {
                throw new ArgumentException("witsmlObject cannot be null");
            }

            if (witsmlQuery == null)
            {
                throw new ArgumentException("witsmlQuery cannot be null");
            }

            String wsdlFunction = "WMLS_GetFromStore";
            long   requestTime  = DateTime.Now.Ticks;
            String witsmlType   = witsmlObject.getWitsmlType();

            String queryXml    = null;
            String responseXml = null;

            try
            {
                // Find the getQuery() method
                //Method getQueryMethod = witsmlObject.getClass().getDeclaredMethod("getQuery",
                //                                                                  String.class,
                //                                                                  String[].class);
                //getQueryMethod.setAccessible(true);
                MethodInfo getQueryMethod = witsmlObject.GetType().GetMethod("getQuery");

                // This is the complete query for the class
                //        String id = witsmlObject.getId() != null ? witsmlObject.getId() : "";
                //queryXml = (String) getQueryMethod.invoke(null, id,
                //                                          new String[] {witsmlObject.getParentId()});
                queryXml = getQueryMethod.Invoke(null, new object[] { witsmlObject.getParentId() }) as string;

                // Apply nodifications as specified by the WitsmlQuery instance
                queryXml = witsmlQuery.apply(queryXml);

                // Call server and capture the response
                WitsmlResponse response = accessor.get(witsmlType, queryXml);
                responseXml = response.getResponse();

                notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml,
                       response.getStatusCode(),
                       response.getServerMessage(),
                       null);


                //
                // Build DOM document from response
                //
                //SAXBuilder builder = new SAXBuilder();
                //Document document = XDocument.Load(new StringReader(responseXml));
                XDocument document = XDocument.Load(new StringReader(responseXml));

                XElement root    = document.Root;                                                    //.getRootElement();
                XElement element = root.Element(root.Name.Namespace + witsmlObject.getWitsmlType()); //.Element(witsmlObject.getWitsmlType(),
                //root.getNamespace());

                //
                // Find the update() method on the target class
                //
                if (element != null)
                {
                    MethodInfo updateMethod = witsmlObject.GetType().GetMethod("update");//.getClass().getDeclaredMethod("update",

                    //Element.class);
                    //updateMethod.setAccessible(true);

                    // Call update on the instance
                    updateMethod.Invoke(witsmlObject, new object[] { element });
                }
            }
            catch (MissingMethodException exception)
            { // NoSuchMethodException exception) {
                // Programming error
                // exception.printStackTrace();
                Console.Write(exception.StackTrace);
                //Debug.Assert(false : "update() not found: " + witsmlObject.getClass();
            }
            catch (AccessViolationException exception)
            {// IllegalAccessException exception) {
                // Programming error
                //exception.printStackTrace();
                Console.Write(exception.StackTrace);
                //Debug.Assert(false : "Unable to invoke update(): " + witsmlObject.getClass();
            }
            catch (TargetInvocationException exception)
            { // InvocationTargetException exception) {
                // Wrapped exception from the invocation such as WitsmlParseException
                notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
                       exception);
                String message = "Exception thrown on reflective call on: " + witsmlObject;
                throw new WitsmlServerException(message, exception.InnerException); //.getCause());
            }
            //catch (RemoteException exception) {
            //    // Connection problems.
            //    notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
            //           exception);
            //    String message = "Unable to connect to WITSML server at " + getUrl();
            //    throw new WitsmlServerException(message, exception);
            //}
            catch (IOException exception)
            {
                // Unable to read response XML
                notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
                       exception);
                String message = "Unable to read response XML: " + responseXml;
                throw new WitsmlServerException(message, exception);
            }
            //catch (JDOMException exception) {
            //    // Unable to parse response XML
            //    notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
            //           exception);
            //    String message = "Unable to parse response XML: " + responseXml;
            //    throw new WitsmlServerException(message, exception);
            //}
        }