1 22 23 28 package org.xquark.mapper.storage; 29 30 import java.io.IOException ; 31 import java.util.Date ; 32 33 import org.xml.sax.SAXException ; 34 import org.xquark.mapper.RepositoryDocument; 35 import org.xquark.mapper.RepositoryException; 36 import org.xquark.mapper.metadata.DocumentInfo; 37 import org.xquark.xml.xdbc.XMLDBCException; 38 import org.xquark.xml.xdbc.XMLDBCNotSupportedException; 39 import org.xquark.xquery.xdbc.AbstractXMLDocument; 40 41 45 public class RepositoryDocumentImpl extends AbstractXMLDocument 46 implements RepositoryDocument 47 { 48 private static final String RCSRevision = "$Revision: 1.1 $"; 49 private static final String RCSName = "$Name: $"; 50 51 private DocumentInfo docInfo; 52 53 56 public RepositoryDocumentImpl(String Id, XMLCollectionImpl collection) 57 { 58 super(Id, collection); 59 } 60 61 64 public RepositoryDocumentImpl ( 65 DocumentInfo docInfo, 66 XMLCollectionImpl collection 67 ) 68 { 69 this(docInfo.docID, collection); 70 setDocumentInfo(docInfo); 71 } 72 73 public void setDocumentInfo(DocumentInfo docInfo) 74 { 75 this.docInfo = docInfo; 76 } 77 78 public void setIdentifier(String identifier) throws XMLDBCException, XMLDBCNotSupportedException 82 { 83 super.setIdentifier(identifier); 84 getCollection().renameDocument(getIdentifier(), identifier); } 86 87 public void remove() throws XMLDBCException, XMLDBCNotSupportedException 88 { 89 getCollection().removeDocument(getIdentifier()); 90 } 91 92 public void getAsSAX() throws XMLDBCException, SAXException 93 { 94 _RepositoryCollection collection = (_RepositoryCollection)getCollection(); 95 RepositoryReader reader = collection.getReader(); 96 plugHandlers(reader); 97 try 98 { 99 reader.parse(getIdentifier()); 100 } 101 catch (IOException e) 102 { 103 throw new RepositoryException(RepositoryException.DB_ERROR, "IOException while reading document."); 105 } 106 collection.releaseReader(reader); 107 } 108 109 public int getAverageNodeDataLength() throws XMLDBCException 113 { 114 if (docInfo == null) 115 getDocumentInfo(); 116 return docInfo.avgNodeLen; 117 } 118 119 public Date getCreationDate() throws XMLDBCException 120 { 121 if (docInfo == null) 122 getDocumentInfo(); 123 return docInfo.creationDate; 124 } 125 126 public long getEstimatedDocumentLength() throws XMLDBCException 127 { 128 if (docInfo == null) 129 getDocumentInfo(); 130 return docInfo.getEstimatedDocumentLength(); 131 } 132 133 public long getNodeCount() throws XMLDBCException 134 { 135 if (docInfo == null) 136 getDocumentInfo(); 137 return docInfo.nodeCount; 138 } 139 140 private void getDocumentInfo() throws RepositoryException 144 { 145 docInfo = ((_RepositoryCollection)getCollection()).getMetadata().getDocumentInfo(getIdentifier()); 146 } 147 } 148 | Popular Tags |