Package com.dbxml.db.client.xmlrpc

Source Code of com.dbxml.db.client.xmlrpc.ContentClientImpl

package com.dbxml.db.client.xmlrpc;

/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: ContentClientImpl.java,v 1.5 2006/02/02 18:53:47 bradford Exp $
*/

import com.dbxml.db.client.CollectionClient;
import com.dbxml.db.client.ContentClient;
import com.dbxml.db.server.labrador.ContentProxy;
import com.dbxml.util.dbXMLException;
import com.dbxml.xml.dom.DOMHelper;
import com.dbxml.xml.dom.TextWriter;
import java.util.Map;
import org.w3c.dom.Document;

/**
* ContentClientImpl
*/

public final class ContentClientImpl extends ConnectionManager implements ContentClient {
   private dbXMLClientImpl dbxmlClient;
   private CollectionClientImpl parent;
   private String document;
   private byte[] value;

   private String key;
   private String colName;
   private String canonicalName;
   private int type = -1;

   public ContentClientImpl(dbXMLClientImpl dbxmlClient, CollectionClientImpl parent, String path) throws dbXMLException {
      super(dbxmlClient);
      this.dbxmlClient = dbxmlClient;
      this.parent = parent;
      setClientPath(path);
      init();
   }

   public ContentClientImpl(dbXMLClientImpl dbxmlClient, String path) throws dbXMLException {
      super(dbxmlClient);
      this.dbxmlClient = dbxmlClient;
      setClientPath(path);
      init();
   }

   private void init() throws dbXMLException {
      Map info = executeMap("getInformation", null);
      key = (String)info.get(ContentProxy.NAME);
      colName = (String)info.get(ContentProxy.COL_NAME);
      canonicalName = (String)info.get(ContentProxy.CANONICAL_NAME);
      Integer i = (Integer)info.get(ContentProxy.CONTENT_TYPE);
      if ( i != null )
         type = i.intValue();
      else
         throw new dbXMLException("This path does not point to a Document");

   }

   public int getContentType() throws dbXMLException {
      return type;
   }

   public String getKey() throws dbXMLException {
      return key;
   }

   public String getCanonicalName() throws dbXMLException {
      return canonicalName;
   }

   public CollectionClient getCollection() throws dbXMLException {
      if ( parent == null ) {
         try {
            parent = new CollectionClientImpl(dbxmlClient, colName);
         }
         catch ( Exception e ) {
            throw new dbXMLException(e);
         }
      }
      return parent;
   }

   public String getDocumentAsText() throws dbXMLException {
      if ( document == null )
         document = executeString("getDocument", null);
      return document;
   }

   public Document getDocument() throws dbXMLException {
      try {
         return DOMHelper.parseText(getDocumentAsText());
      }
      catch ( dbXMLException e ) {
         throw e;
      }
      catch ( Exception e ) {
         throw new dbXMLException(e);
      }
   }

   public byte[] getValue() throws dbXMLException {
      if ( value == null )
         value = executeBinary("getValue", null);
      return value;
   }

   public void setDocumentAsText(String document) throws dbXMLException {
      execute("setDocument", new Object[]{document});
      this.document = document;
   }

   public void setDocument(Document document) throws dbXMLException {
      try {
         String doc = TextWriter.toString(document);
         setDocumentAsText(doc);
         this.document = doc;
      }
      catch ( dbXMLException e ) {
         throw e;
      }
      catch ( Exception e ) {
         throw new dbXMLException(e);
      }
   }

   public void setValue(byte[] value) throws dbXMLException {
      execute("setValue", new Object[]{value});
      this.value = value;
   }
}
TOP

Related Classes of com.dbxml.db.client.xmlrpc.ContentClientImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.