Package org.xmldb.api.base

Examples of org.xmldb.api.base.XMLDBException


     */
    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 {
            // TODO: Test BinaryResource workings
            Hashtable params = new Hashtable();
            params.put(RPCDefaultMessage.COLLECTION, collPath);
            params.put(RPCDefaultMessage.NAME, res.getId());
            runRemoteCommand("RemoveDocument", params);
        } catch (XMLDBException x) {

            throw x;  // propagate any xmldb exception.
        } catch (Exception e) {
            throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE, e);
        }
    }
View Full Code Here


        } catch (XMLDBException x) {

            throw x;  // propagate any xmldb exception.
        } catch (Exception e) {

            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
        }
    }
View Full Code Here

        } catch (XMLDBException x) {

            throw x;  // propagate any xmldb exception.
        } catch (Exception e) {
            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
        }
    }
View Full Code Here

        } catch (XMLDBException x) {

            throw x;  // propagate any xmldb exception.
        } catch (Exception e) {

            throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
        }
    }
View Full Code Here

            return col.getChildCollection(path);
        } catch (XMLDBException x) {

            throw x;  // propagate any xmldb exception.
        } catch (Exception e) {
            throw new XMLDBException(ErrorCodes.INVALID_COLLECTION, "Cannot create child collection", e);
        }
    }
View Full Code Here

         **/
        String count = null;
        try {
            count = doc.getDocumentElement().getFirstChild().getNodeValue();
        } catch (Exception e) {
            throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "Unable to retrieve <src:modified> element content from server result", e);
        }
        try {

            return Long.parseLong(count);
        } catch (Exception e) {

            throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "<src:modified> in server result did not contain a valid count", e);
        }
    }
View Full Code Here

            params.put(RPCDefaultMessage.COLLECTION, collPath);
            params.put(RPCDefaultMessage.NAME, childName);
            String result = (String) runRemoteCommand("RemoveCollection", params);

            if (!result.equals("yes")) {
                throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                                         "Cannot remove child collection[" + childName + "]");
            }
        } catch (XMLDBException x) {
            throw x;  // propagate any xmldb exception.
        } catch (Exception e) {
            throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
                                     "Cannot remove child collection[" + childName + "]", e);
        }
    }
View Full Code Here

            throw FaultCodes.createXMLDBException(ErrorCodes.INVALID_COLLECTION,
                                                  "Collection not available: " + collPath, e);
        }

        if (this.col == null) {
            throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION,
                                     "Collection not found: " + collPath);
        }
    }
View Full Code Here

                                           doc.getDataBytes());

            } else if (entry instanceof byte[]) {
                return new BinaryResourceImpl(id, this, (byte[])entry);
            } else {
                throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE,
                                         "Internal error: Unexpected resource type " + entry.getClass().getName());
            }
        } catch (Exception e) {
            throw FaultCodes.createXMLDBException("Resource not available: " + id, e);
        }
View Full Code Here

     *  <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.insertBinary(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 {
                String name = "";
                Node content = ((XMLResourceImpl) res).getContentAsDOM();
                if (content != null && content instanceof Document) {
                    if (res.getId() != null) {
                        col.insertDocument(res.getId(), (Document) content);
                    } else {
                        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

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.