Package org.xmldb.api.base

Examples of org.xmldb.api.base.Collection


        collection.removeResource(newResource);
    }

  public void testRemove() throws Exception {
    Collection collection = client.getCollection(TEST_COLLECTION_PATH);
    if (collection == null) {
      throw new Exception("getCollection(" + TEST_COLLECTION_PATH + ") returned null");
    }

    /*
     * Create a binary resource, save it in the 'current' collection,
     * then remove it and verify that it was indeed removed.
     */

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
    collection.storeResource(newResource);
    String id = newResource.getId();

    Resource foundResource = collection.getResource(id);
    assertNotNull("It should be in there", foundResource);

        collection.removeResource(foundResource);
        foundResource = collection.getResource(id);
        assertNull("It should not be in there anymore", foundResource);
  }
View Full Code Here


* Simple XML:DB API example to list collections.
*/
public class ListCollections extends AbstractExample {

    public static void main(String[] args) throws Exception {
        Collection collection = null;
        try {

            collection = getCollection("xmldb:xindice://localhost:8888/db/");
            //collection = getCollection("xmldb:xindice-embed:///db/");

            String[] childCollections = collection.listChildCollections();
            System.out.println("Children of collection [" + collection.getName() + "]");
            for (int i = 0; i < childCollections.length; i++) {

                System.out.println("\t" + (i + 1) + ". " + childCollections[i]);
            }
        } catch (XMLDBException e) {
            System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            System.err.println("Exception occured " + e);
            e.printStackTrace();
        } finally {
            if (collection != null) {
                collection.close();
            }
        }
    }
View Full Code Here

* Simple XML:DB API example to query the database.
*/
public class Example1 extends AbstractExample {
 
  public static void main(String[] args) throws Exception {
    Collection collection = null;
    try {

      collection = getCollection("xmldb:xindice:///db/addressbook");

      String xpath = "//person[fname='John']";
      XPathQueryService service = (XPathQueryService) collection.getService("XPathQueryService", "1.0");
      ResourceSet resourceSet = service.query(xpath);
      ResourceIterator resourceIterator = resourceSet.getIterator();

      while (resourceIterator.hasMoreResources()) {
        Resource resource = resourceIterator.nextResource();
        System.out.println((String) resource.getContent());
      }
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
    }
    finally {
      if (collection != null) {
        collection.close();
      }
    }
  }
View Full Code Here

* Simple XML:DB API Example to insert a new document into the database.
*/
public class AddDocument  extends AbstractExample {
 
  public static void main(String[] args) throws Exception {
    Collection collection = null;
    try {

      collection = getCollection("xmldb:xindice:///db/addressbook");
     
      String data = readFileFromDisk(args[0]);

      XMLResource document = (XMLResource) collection.createResource(null, "XMLResource");
      document.setContent(data);
      collection.storeResource(document);
      System.out.println("Document " + args[0] + " inserted as " + document.getId());
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
    }
    finally {
      if (collection != null) {
        collection.close();
      }
    }
  }
View Full Code Here

    public String getDriver() {
        return driver;
    }

    public String getName(String path) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        return col.getName();
    }
View Full Code Here

                "</collection>";
        return createCollection(parent, path, DOMParser.toDocument(config));
    }

    public Collection createCollection(String parent, String path, Document configuration) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + parent);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + parent + ") returned null");
        }
        CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0");
        return service.createCollection(path, configuration);
    }
View Full Code Here

    public Collection getCollection(String path) throws Exception {
        return DatabaseManager.getCollection(driver + "/" + path);
    }

    public void dropCollection(String path, String name) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);

        if (col != null) {
            CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0");
            service.dropCollection(name);
        }
    }
View Full Code Here

            service.dropCollection(name);
        }
    }

    public String[] listCollections(String path) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        return col.listChildCollections();
    }
View Full Code Here

        }
        return col.listChildCollections();
    }

    public int countCollections(String path) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        return col.getChildCollectionCount();
    }
View Full Code Here

        }
        return col.getChildCollectionCount();
    }

    public void createIndexer(String path, String name, String indexdef) throws Exception {
        Collection col = DatabaseManager.getCollection(driver + "/" + path);
        if (col == null) {
            throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
        }
        CollectionManager service = (CollectionManager) col.getService("CollectionManager", "1.0");

        service.createIndexer(DOMParser.toDocument(indexdef));
    }
View Full Code Here

TOP

Related Classes of org.xmldb.api.base.Collection

Copyright © 2018 www.massapicom. 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.