|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.sixdml.xindice.xiSixdmlCollection
xiSixdmlCollection.java
An implementation of the SixdmlCollection interface which maps to a collection in
Xindice. This class is NOT thread safe.
| Field Summary | |
(package private) Collection |
collection
The underlying Xindice collection that this class uses to interact with the database. |
private String |
indexFile
The name of this Collection's index file. |
private boolean |
open
Flag indicates whether the collection is open or not. |
private HashMap |
properties
This is the table of properties for the needed by the Configurable interface. |
private String |
schemaName
The name of this Collection's schema file. |
| Fields inherited from interface org.sixdml.SixdmlConstants |
SIXDML_NS, SIXDML_VERSION |
| Constructor Summary | |
private |
xiSixdmlCollection()
Default constructor private because an instance of this class must always be instantiated with an underlying Xindice collection. |
(package private) |
xiSixdmlCollection(Collection collection)
Initializes this Collection by mapping it to a Xindice collection. |
| Method Summary | |
void |
addIndex(SixdmlIndex index)
Adds an index to apply to the collection. |
void |
close()
Releases all resources consumed by the Collection. |
String |
createId()
Creates a new unique ID within the context of the Collection. |
Resource |
createResource(String id,
String type)
Creates a new empty Resource with the provided id. |
private static URL |
createURL(String fileName)
Helper method to create a URL from a file name. |
Collection |
getChildCollection(String name)
Returns a Collection instance for the requested child collection if it exists. |
int |
getChildCollectionCount()
Returns the number of child collections under this Collection or 0 if no child collections exist. |
static String |
getContentsOfURL(URL source)
Helper Method: Obtains the contents at a particular URL and returns them as a string. |
SixdmlIndex[] |
getIndices()
Returns an array of SixdmlIndex objects that apply to this collection. |
String |
getName()
Returns the name associated with the Collection instance. |
Collection |
getParentCollection()
Returns the parent collection for this collection or null if no parent collection exists. |
String |
getProperty(String str)
Returns the value of the property identified by name. |
Resource |
getResource(String id)
Retrieves a Resource from the database. |
int |
getResourceCount()
Returns the number of XML resources in this Collection or 0 if no child collections exist. |
Service |
getService(String name,
String version)
Returns a Service instance for the requested service name and version. |
Service[] |
getServices()
Provides a list of all services known to the collection. |
private static void |
initializeParser(org.apache.xerces.parsers.DOMParser parser,
String targetNS,
String schemaLocation)
Helper Method: Initializes properties related to schema validation in parser. |
void |
insertDocument(String name,
String xmlString)
Adds an XML document created from the string argument to the collection. |
void |
insertDocument(String name,
URL documentSource)
Adds an XML document loaded from the specified URL to the collection. |
boolean |
isOpen()
Returns true if the Collection is open false otherwise. |
String[] |
listChildCollections()
Returns a list of collection names naming all child collections of the current collection. |
String[] |
listResources()
Returns a list of resource names naming all the resources in the current collection. |
static void |
main(String[] args)
Main used for testing class. |
void |
removeDocument(String name)
Removes an XML document from the collection. |
void |
removeIndex(String name)
Removes a particular index from the collection. |
void |
removeResource(Resource res)
Removes the Resource from the database. |
void |
setProperty(String name,
String value)
Sets the property name to have the value provided in value. |
void |
setSchema(URL schemaFile)
Sets the XML schema or DTD that will be used to constrain the documents in this collection. |
String |
showSchema()
Returns the contents of the schema for the collection as a string. |
void |
storeResource(Resource resource)
Stores the provided resource into the database. |
void |
unsetSchema()
Unsets the schema for this collection. |
private void |
validate(String xmlStr)
Helper Method: Validates an XML document against the collection's schema. |
private static File |
writeToFile(String file,
String contents,
boolean append)
Helper Method: Writes the contents of a string to a file. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private String indexFile
private String schemaName
private HashMap properties
Configurable interface.Configurableprivate boolean open
Collection collection
| Constructor Detail |
private xiSixdmlCollection()
xiSixdmlCollection(Collection collection)
throws XMLDBException
col - the collection that will be this object's interface to the database.XMLDBException - if a call to the getName() function of the Collection passed in
fails.Collection.getName()| Method Detail |
public void addIndex(SixdmlIndex index)
throws UnsupportedIndexTypeException,
IndexAlreadyExistsException,
XMLDBException
addIndex in interface SixdmlCollectionindex - the index to addUnsupportedIndexTypeException - if the index is of a type unsupported
by the database.IndexAlreadyExistsException - if an index with the same name already exists
for the collection.XMLDBException - if a database error occurs.
public void close()
throws XMLDBException
close in interface Collection
public String createId()
throws XMLDBException
createId in interface Collection
public Resource createResource(String id,
String type)
throws XMLDBException
createResource in interface Collectionid - the unique id to associate with the created Resource.type - the Resource type to create.XMLDBException - if the close method has been called on the Collection or the resource
type is unknown.ErrorMessages.COLLECTION_CLOSED,
ErrorMessages.UNKNOWN_RESOURCE_TYPE
public Collection getChildCollection(String name)
throws XMLDBException
getChildCollection in interface Collectionname - the name of the child collection to retrieve.XMLDBException - if the close method has been called on the CollectionErrorMessages.COLLECTION_CLOSED
public int getChildCollectionCount()
throws XMLDBException
getChildCollectionCount in interface CollectionXMLDBException - if the close method has been called on the CollectionErrorMessages.COLLECTION_CLOSED
public SixdmlIndex[] getIndices()
throws XMLDBException
getIndices in interface SixdmlCollectionXMLDBException - if a database error occurs.
public String getName()
throws XMLDBException
getName in interface Collection
public Collection getParentCollection()
throws XMLDBException
getParentCollection in interface CollectionXMLDBException - if the close method has been called on the CollectionErrorMessages.COLLECTION_CLOSED
public String getProperty(String str)
throws XMLDBException
getProperty in interface Configurable
public Resource getResource(String id)
throws XMLDBException
getResource in interface Collectionid - the unique id for the requested resource.XMLDBException - if the close method has been called on the Collection or the
user attempts to access the collection's schema.ErrorMessages.COLLECTION_CLOSED,
ErrorMessages.PERMISSION_DENIED_SCHEMA,
ErrorMessages.PERMISSION_DENIED_INDEX
public int getResourceCount()
throws XMLDBException
getResourceCount in interface CollectionXMLDBException - if the close method has been called on the CollectionErrorMessages.COLLECTION_CLOSED
public Service getService(String name,
String version)
throws XMLDBException
getService in interface Collectionname - the name of theservice to return.version - the version number of the service to return.
public Service[] getServices()
throws XMLDBException
getServices in interface Collection
public void insertDocument(String name,
String xmlString)
throws DocumentAlreadyExistsException,
InvalidCollectionDocumentException,
NonWellFormedXMLException,
XMLDBException
insertDocument in interface SixdmlCollectionname - the name of the document.xmlString - the string representation of a well-formed XML documentDocumentAlreadyExistsException - if there already exists a document with
the specified name in the database.InvalidCollectionDocumentException - if the document fails to validate against
the collection's schema.NonWellFormedXMLException - if the XML is not well formed.XMLDBException - if a database error occurs.
public void insertDocument(String name,
URL documentSource)
throws DocumentAlreadyExistsException,
IOException,
InvalidCollectionDocumentException,
NonWellFormedXMLException,
XMLDBException
insertDocument in interface SixdmlCollectionname - the name of the document.xmlString - the string representation of a well-formed XML documentDocumentAlreadyExistsException - if there already exists a document with
the specified name in the database.IOException - if an error occurs while trying to retrieve the file.InvalidCollectionDocumentException - if the document fails to validate against
the collection's schema.NonWellFormedXMLException - if the XML is not well formed.XMLDBException - if a database error occurs.
public boolean isOpen()
throws XMLDBException
isOpen in interface Collection
public String[] listChildCollections()
throws XMLDBException
listChildCollections in interface CollectionXMLDBException - if the close method has been called on the Collection
public String[] listResources()
throws XMLDBException
listResources in interface CollectionXMLDBException - if the close method has been called on the Collection
public void removeDocument(String name)
throws NonExistentDocumentException,
XMLDBException
removeDocument in interface SixdmlCollectionname - the name of the document.NonExistentDocumentException - if the document does not exist
in the collection.XMLDBException - if a database error occurs.
public void removeIndex(String name)
throws NonExistentIndexException,
XMLDBException
removeIndex in interface SixdmlCollectionindex - the index to addXMLDBException - if a database error occurs.
public void removeResource(Resource res)
throws XMLDBException
removeResource in interface Collectionres - the resource to remove.XMLDBException - if the close method has been called on the CollectionErrorMessages.COLLECTION_CLOSED,
ErrorMessages.NO_SUCH_RESOURCE,
ErrorMessages.PERMISSION_DENIED_SCHEMA,
ErrorMessages.PERMISSION_DENIED_INDEX
public void setProperty(String name,
String value)
throws XMLDBException
setProperty in interface Configurablename - the name of the property to set.value - the value to set for the property.
public void setSchema(URL schemaFile)
throws InvalidCollectionDocumentException,
IOException,
InvalidSchemaException,
XMLDBException
setSchema in interface SixdmlCollectionschemaFile - the location of the schema file either on the local file
system or over the internet.InvalidCollectionDocumentException - if an XML document in the
collection fails to be validated by the schema.IOException - if an error occurs while trying to retrieve the file.InvalidSchemaException - if the schema is invalid.XMLDBException - if a database error occurs.
public String showSchema()
throws XMLDBException
showSchema in interface SixdmlCollectionXMLDBException - if a database error occurs.
public void storeResource(Resource resource)
throws XMLDBException
storeResource in interface Collectionres - the resource to store in the database.XMLDBException - if the close method has been called on the Collection or the
document does validate against the collection's schema if any.ErrorMessages.COLLECTION_CLOSED,
ErrorMessages.WRONG_CONTENT_TYPE_STORE,
ErrorMessages.PERMISSION_DENIED_SCHEMA,
ErrorMessages.PERMISSION_DENIED_INDEX
public void unsetSchema()
throws XMLDBException
unsetSchema in interface SixdmlCollectionXMLDBException - if a database error occurs.
private void validate(String xmlStr)
throws Exception
xmlStr - the document to validate as a string.Exception - if anything goes wrong.
private static void initializeParser(org.apache.xerces.parsers.DOMParser parser,
String targetNS,
String schemaLocation)
throws SAXNotRecognizedException,
SAXNotSupportedException
parser - the DOM parser to initializetargetNS - the targetNamespace of the schema to use.schemaLocation - path to the schema. Only used if targetNS isn't null.
private static URL createURL(String fileName)
throws MalformedURLException
fileName - file to convert.
private static File writeToFile(String file,
String contents,
boolean append)
throws IOException
file - the file to write to.contents - the string to write to the file.append - boolean if true, then data will be written to the
end of the file rather than the beginning.IOException - if an error occurs in writing the file.
public static String getContentsOfURL(URL source)
throws IOException
source - the URL to obtaion the data from.IOException - if an error occurs while trying to retrieve the file.
public static void main(String[] args)
throws Exception
args - IGNORED
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||