Package org.xmldb.api.base

Examples of org.xmldb.api.base.XMLDBException


     *  <code>ErrorCodes.COLLECTION_CLOSED</code> if the <code>close</code>
     *  method has been called on the <code>Collection</code><br />
     */
    public void storeResource(Resource res) throws XMLDBException {
        if (res.getContent() == null) {
            throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
                                     "No resource data");
        }

        checkOpen();

        if (res instanceof BinaryResource) {
            Object content = res.getContent();
            byte[] bytes;
            if (content instanceof byte[]) {
                bytes = (byte[]) content;
            } else {
                throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
                                         "The contents of a binary resource must have type byte[].");
            }

            try {
                if (res.getId() != null) {
                    col.setBinary(res.getId(), bytes);
                } else {
                    String name = col.insertBinary(bytes).toString();
                    ((BinaryResourceImpl) res).setId(name);
                }
            } catch (Exception e) {
                throw FaultCodes.createXMLDBException(ErrorCodes.INVALID_RESOURCE,
                                                      "Invalid resource:" + res.getId(), e);
            }

        } else if (res instanceof XMLResource) {
            try {
                Node content = ((XMLResourceImpl) res).getContentAsDOM();
                if (content != null && content instanceof Document) {
                    if (res.getId() != null) {
                        col.setDocument(res.getId(), (Document) content);
                    } else {
                        String name = col.insertDocument((Document) content).toString();
                        ((XMLResourceImpl) res).setId(name);
                    }
                } else {
                    throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
                                             "A resource must be a document in order to be stored.");
                }
            } catch (Exception e) {
                throw FaultCodes.createXMLDBException(ErrorCodes.INVALID_RESOURCE,
                                                      "Invalid resource: " + res.getId(), e);
            }

        } else {
            throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
                                     "Only XMLResource and BinaryResource supported");
        }
    }
View Full Code Here


     *  method has been called on the <code>Collection</code><br />
     */
    public org.xmldb.api.base.Collection getChildCollection(String name) throws XMLDBException {

        if (name.indexOf('/') != -1) {
            throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                                     "Invalid collection: " + name);
        }

        try {
            return new CollectionImpl(db, getCanonicalName() + "/" + name);
View Full Code Here

     */
    public void removeResource(Resource res) throws XMLDBException {

        if (res == null || res.getId() == null || res.getId().length() == 0) {
            // Query result resource will have null ID
            throw new XMLDBException(ErrorCodes.INVALID_RESOURCE,
                                     "Resource passed is null or its ID is empty.");
        }

        checkOpen();
        try {
View Full Code Here

    /* see superclass for documentation */
    public void removeCollection(String childName) throws XMLDBException {

        if (null == childName || childName.length() == 0) {
            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
                                     FaultCodes.COL_COLLECTION_NOT_FOUND,
                                     "Cannot remove child collection '" + childName + "': Name is empty");
        }

        checkOpen();
View Full Code Here

                colName = name.substring(colIndex + 1);
            }

            Database db = Database.getDatabase(dbName);
            if (db == null) {
                throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
                                         "Database '" + dbName + "' could not be found");
            }

            Collection col = db.getCollection(colName);
            if (col == null) {
                throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
                                         "Collection '" + colName + "' could not be found");
            }

            return col;
        } else {
            throw new XMLDBException(ErrorCodes.INVALID_URI,
                                     "Collection name must begin with a '/'");
        }
    }
View Full Code Here

                    log.debug("Using URL: '" + xmlRpcURL + "'");
                }
                try {
                    cfg.setServerURL(new URL(xmlRpcURL));
                } catch (MalformedURLException e) {
                    throw new XMLDBException(ErrorCodes.INVALID_URI, e);
                }

                /*
                 * Determine basic authentication parameters
                 */
 
View Full Code Here

     */
    public Collection getCollection(String uri, String userName, String password) throws XMLDBException {
        /* TODO: introduce authentication some day */

        if (!acceptsURI(uri)) {
            throw new XMLDBException(ErrorCodes.INVALID_URI,
                                     "Invalid URL: " + uri);
        }

        /* Chop off driver prefix, and '://' */
        uri = uri.substring(getName().length() + 3);

        /* Extract host name & port, if present */
        int firstSlash = uri.indexOf('/');
        if (firstSlash == -1) {
            throw new XMLDBException(ErrorCodes.INVALID_URI,
                                     "Invalid URL (must have '/'): " + uri);
        }

        /* Extract collection name */
        String collPath = uri.substring(firstSlash);
        if (!collPath.startsWith("/")) {
            throw new XMLDBException(ErrorCodes.INVALID_URI,
                                     "Invalid URL (collection name must start with '/'): " + uri);
        }

        String hostPort = uri.substring(0, firstSlash);

View Full Code Here

                final XObject xobject = xp.execute(xpc, n, pfx);
        switch (xobject.getType()) {
                    // case XObject.CLASS_RTREEEFRAG :
                    default :
                        throw new XMLDBException(ErrorCodes.NOT_IMPLEMENTED,
                                                 "Unsupported result type: " + xobject.getTypeString());

                    case XObject.CLASS_NODESET:
                        ni = xobject.nodeset();
                        node = ni.nextNode();
View Full Code Here

    private void addNamespaces(XPathQueryService service, String namespacesString) throws XMLDBException {
        if (namespacesString != null && namespacesString.length() > 0) {
            StringTokenizer st = new StringTokenizer(namespacesString, "=;");
            if (st.countTokens() % 2 != 0) {
                throw new XMLDBException(0, "mismatched namespace prefixes and uris in '" + namespacesString + "'");
            }
            while (st.hasMoreTokens()) {
                service.setNamespace(st.nextToken(), st.nextToken());
            }
        }
View Full Code Here

     *
     * @exception XMLDBException thrown if collection is closed
     */
    protected void checkOpen() throws XMLDBException {
        if (!isOpen()) {
            throw new XMLDBException(ErrorCodes.COLLECTION_CLOSED);
        }
    }
View Full Code Here

TOP

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

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.