ozeigermann 2004/02/26 05:40:54
Modified: src/stores/org/apache/slide/store/txfile
XMLResourceDescriptor.java
TxXMLFileDescriptorsStore.java
src/doc changelog.xml
Removed: src/stores/slidestore/file UriProperties.java
AbstractUriProperties.java
Log:
Refactored and cleaned up XMLResourceDescriptor
to be standalone and removed now obsolete classes
from filestore package.
Revision Changes Path
1.8 +710 -121
jakarta-slide/src/stores/org/apache/slide/store/txfile/XMLResourceDescriptor.java
Index: XMLResourceDescriptor.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/txfile/XMLResourceDescriptor.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XMLResourceDescriptor.java 20 Feb 2004 09:46:41 -0000 1.7
+++ XMLResourceDescriptor.java 26 Feb 2004 13:40:54 -0000 1.8
@@ -26,13 +26,19 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.apache.slide.common.*;
+import org.apache.slide.lock.LockTokenNotFoundException;
import org.apache.slide.lock.NodeLock;
+import org.apache.slide.security.NodePermission;
import org.apache.slide.structure.*;
import org.apache.slide.content.*;
@@ -44,28 +50,30 @@
import org.apache.slide.store.txfile.rm.impl.FileResourceManager;
import org.apache.slide.util.logger.*;
-import slidestore.file.UriProperties;
-
-import java.io.File;
-
/**
- * XML descriptor as a resource in a [EMAIL PROTECTED] FileResourceManager}. Copies
code from
- * UriProperties, that's why Marc is listed as author as well.
+ * XML descriptor as a resource in a [EMAIL PROTECTED] FileResourceManager}. Takes
over very much code from
+ * UriProperties and AbstractUriProperties, that's why Marc is listed as author as
well.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Oliver Zeigermann</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc D�cugis</a>
* @see FileResourceManager
*/
-public class XMLResourceDescriptor extends UriProperties {
+public class XMLResourceDescriptor {
- private static String tmpDir;
- static {
- try {
- tmpDir = File.createTempFile("xyz", null).getParent();
- } catch (IOException e) {
- tmpDir = null;
- }
- }
+ /** Stored object.*/
+ protected ObjectNode object;
+
+ /** Permissions vector. */
+ protected Vector permissions;
+
+ /** Locks vector.*/
+ protected Vector locks;
+
+ /** Revision descriptors.*/
+ protected NodeRevisionDescriptors revisionDescriptors;
+
+ /** Revision descriptor hashtable.*/
+ protected Hashtable descriptor;
protected static final String PATH_EXTENSION = ".def.xml";
protected final FileResourceManager rm;
@@ -77,6 +85,177 @@
protected StoreLogger logger;
+ protected SimpleDateFormat dateFormat;
+
+ protected static String booleanToString(boolean aBoolean) {
+ return aBoolean ? "true" : "false";
+ }
+
+ protected static Element createBindings(String aParent, String aChild,
Enumeration aEnum) {
+ Element aElement = new Element(aParent);
+ Element childNode;
+ ObjectNode.Binding binding;
+ while (aEnum.hasMoreElements()) {
+ binding = (ObjectNode.Binding) aEnum.nextElement();
+ childNode = new Element(aChild);
+ childNode.setAttribute(new Attribute("name", binding.getName()));
+ childNode.setAttribute(new Attribute("uuri", binding.getUuri()));
+ aElement.addContent(childNode);
+ }
+ return aElement;
+ }
+
+ protected static Element createElements(String aParent, String aChild,
Enumeration aEnum) {
+ Element aElement = new Element(aParent);
+ while (aEnum.hasMoreElements()) {
+ Object aObject = aEnum.nextElement();
+ Element aItem = new Element(aChild);
+ aItem.setAttribute("val", aObject.toString());
+ aElement.addContent(aItem);
+ }
+ return aElement;
+ }
+
+ protected static NodePermission decodePermission(Element aElement, String aUri)
{
+ String aRevisionNumber = aElement.getAttributeValue("revisionNumber");
+ String aSubject = aElement.getAttributeValue("subjectUri");
+ String aAction = aElement.getAttributeValue("actionUri");
+ boolean aInheritable = new
Boolean(aElement.getAttributeValue("inheritable")).booleanValue();
+ boolean aNegative = new
Boolean(aElement.getAttributeValue("negative")).booleanValue();
+ return new NodePermission(aUri, aRevisionNumber, aSubject, aAction,
aInheritable, aNegative);
+
+ }
+
+ protected static Element encodeNodePermission(NodePermission aPermission) {
+ Element aElementPermission = new Element("permission");
+ NodeRevisionNumber aRevisionNumber = aPermission.getRevisionNumber();
+ if (aRevisionNumber != null) {
+ aElementPermission.setAttribute("revisionNumber",
encodeRevisionNumber(aRevisionNumber));
+ }
+ aElementPermission.setAttribute("subjectUri", aPermission.getSubjectUri());
+ aElementPermission.setAttribute("actionUri", aPermission.getActionUri());
+ aElementPermission.setAttribute("inheritable",
booleanToString(aPermission.isInheritable()));
+ aElementPermission.setAttribute("negative",
booleanToString(aPermission.isNegative()));
+ return aElementPermission;
+ }
+
+ protected static Element encodeRevisionDescriptor(NodeRevisionDescriptor
aDescriptor) {
+ Element aRevisions = new Element("revisions");
+ aRevisions.setAttribute("branchName", aDescriptor.getBranchName());
+ aRevisions.setAttribute("number",
encodeRevisionNumber(aDescriptor.getRevisionNumber()));
+ aRevisions.addContent(createElements("labels", "label",
aDescriptor.enumerateLabels()));
+ Element aProperties = new Element("properties");
+
+ for (Enumeration aEnum = aDescriptor.enumerateProperties();
aEnum.hasMoreElements();) {
+ Object aObject = aEnum.nextElement();
+ // System.out.println("---------- encodeRevisionDescriptor
aObject="+aObject+" "+aObject.getClass().getName());
+ NodeProperty aProp = (NodeProperty) aObject;
+ aProperties.addContent(encodeNodeProperty(aProp));
+ }
+ aRevisions.addContent(aProperties);
+ return aRevisions;
+ }
+
+ protected static Element encodeNodeProperty(NodeProperty aProp) {
+ Element aElement = new Element("property");
+ aElement.setAttribute("name", aProp.getName());
+ aElement.setAttribute("namespace", aProp.getNamespace());
+ aElement.setAttribute("value", aProp.getValue().toString());
+ aElement.setAttribute("type", aProp.getType());
+ aElement.setAttribute("protected", booleanToString(aProp.isProtected()));
+ Element aPermissions = new Element("permissions");
+
+ for (Enumeration aEnum = aProp.enumeratePermissions();
aEnum.hasMoreElements();) {
+ NodePermission aPermission = (NodePermission) aEnum.nextElement();
+ aPermissions.addContent(encodeNodePermission(aPermission));
+ }
+ aElement.addContent(aPermissions);
+ return aElement;
+ }
+
+ protected static Vector createVector(Element aElement, String aParentName,
String aChildName) {
+ Element aParent = aElement.getChild(aParentName);
+ Vector aRet = new Vector();
+ // System.out.println("--------- createVector aParentName="+aParentName+"
aChildName="+aChildName);
+ List aList = aParent.getChildren(aChildName);
+ // System.out.println("--------- createVector aList="+aList);
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ aRet.addElement(aChild.getAttributeValue("val"));
+ }
+ return aRet;
+ }
+
+ protected static Vector createBindingVector(
+ Element aElement,
+ String aParentName,
+ String aChildName,
+ boolean parentBindings) {
+ Element aParent = aElement.getChild(aParentName);
+ Vector aRet = new Vector();
+ // System.out.println("--------- createVector aParentName="+aParentName+"
aChildName="+aChildName);
+ Iterator it = aParent.getChildren().iterator();
+ while (it.hasNext()) {
+ Element aChild = (Element) it.next();
+ String name = aChild.getAttributeValue("name");
+ String uuri = aChild.getAttributeValue("uuri");
+ if (parentBindings) {
+ aRet.add(new ObjectNode.ParentBinding(name, uuri));
+ } else {
+ aRet.add(new ObjectNode.Binding(name, uuri));
+ }
+ }
+ return aRet;
+ }
+
+ protected static String encodeRevisionNumber(NodeRevisionNumber
aRevisionNumber) {
+ return aRevisionNumber.getMajor() + "." + aRevisionNumber.getMinor();
+ }
+
+ protected static Object createObject(String aNomClasse, Class aTypes[], Object
aArgs[])
+ throws UnknownObjectClassException {
+ Class aClasse = null;
+ try {
+ // First, load the object's class
+ aClasse = Class.forName(aNomClasse);
+ Constructor aConstructor = aClasse.getConstructor(aTypes);
+ if (aConstructor == null)
+ aConstructor = aClasse.getSuperclass().getConstructor(aTypes);
+ return aConstructor.newInstance(aArgs);
+
+ } catch (Exception e) {
+ throw new UnknownObjectClassException(aNomClasse);
+ }
+ }
+
+ protected static NodeRevisionNumber decodeRevisionNumber(Element aElement) {
+ Element aElementRevision = aElement.getChild("revision");
+ return new NodeRevisionNumber(
+ Integer.parseInt(aElementRevision.getAttributeValue("major")),
+ Integer.parseInt(aElementRevision.getAttributeValue("minor")));
+ }
+
+ protected static NodeRevisionNumber decodeRevisionNumber(String aStr) {
+ return (aStr == null ? null : new NodeRevisionNumber(aStr));
+ }
+
+ protected static NodeProperty decodeNodeProperty(Element aElement, String aUri)
{
+ String aName = aElement.getAttributeValue("name");
+ String aValue = aElement.getAttributeValue("value");
+ String aNamespace = aElement.getAttributeValue("namespace");
+ String aType = aElement.getAttributeValue("type");
+ boolean aProtected = new
Boolean(aElement.getAttributeValue("protected")).booleanValue();
+
+ Element aPermisionsElement = aElement.getChild("permissions");
+ List aList = aPermisionsElement.getChildren();
+ Vector aPermission = new Vector();
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ aPermission.addElement(decodePermission(aChild, aUri));
+ }
+ return new NodeProperty(aName, aValue, aNamespace, aType, aProtected);
+ }
+
/**
* Creates an XML descriptor resource.
*
@@ -94,10 +273,8 @@
Object txId,
String characterEncoding)
throws ServiceAccessException, ObjectNotFoundException {
- // XXX super class tries to create folders, no way to stop it:
- // at least let it create folders in a place where it can do no harm
- super(tmpDir, uri);
+ dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
logger =
rm.getLogger().cloneWithNewLogChannel(XMLResourceDescriptor.class.getName());
this.rm = rm;
@@ -114,13 +291,303 @@
load();
}
+ // -------------- PART TAKE OVER FROM AbstractUriProperties START
--------------
+
+ /**
+ * Retrive an object from the Descriptors Store.
+ *
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ * @exception ObjectNotFoundException The object to retrieve was not found
+ */
+ public ObjectNode retrieveObject() throws ServiceAccessException,
ObjectNotFoundException {
+ if (object == null) {
+ throw new ObjectNotFoundException(uri);
+ }
+ return object.cloneObject();
+ }
+
+ /**
+ * Store an object in the Descriptors Store.
+ *
+ * @param object Object to update
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ * @exception ObjectNotFoundException The object to update was not found
+ */
+ public void storeObject(ObjectNode aObject) throws ServiceAccessException,
ObjectNotFoundException {
+ object = aObject.cloneObject();
+ save();
+ }
+
+ /**
+ * Create a new object in the Descriptors Store.
+ *
+ * @param object SlideObject
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ * @exception ObjectAlreadyExistsException An object already exists
+ * at this Uri
+ */
+ public void createObject(ObjectNode aObject) throws ServiceAccessException,
ObjectAlreadyExistsException {
+ try {
+ if (object.getUri().equals(uri.toString())) {
+ throw new ObjectAlreadyExistsException(uri.toString());
+ }
+ storeObject(aObject);
+ } catch (ObjectNotFoundException e) {
+ // Never happens
+ }
+ }
+
+ /**
+ * Remove an object from the Descriptors Store.
+ *
+ * @param object Object to remove
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ * @exception ObjectNotFoundException The object to remove was not found
+ */
+ public void removeObject(ObjectNode aObject) throws ServiceAccessException,
ObjectNotFoundException {
+ object = null;
+ }
+
+ /**
+ * Store an object permissions in the Descriptors Store.
+ *
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ */
+ public void grantPermission(NodePermission permission) throws
ObjectNotFoundException, ServiceAccessException {
+ if (permissions == null)
+ permissions = new Vector();
+ permissions.addElement(permission.cloneObject());
+ save();
+ }
+
+ /**
+ * Store an object permissions in the Descriptors Store.
+ *
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ */
+ public void revokePermission(NodePermission permission) throws
ObjectNotFoundException, ServiceAccessException {
+ if (permissions != null)
+ permissions.removeElement(permission);
+ save();
+ }
+
+ /**
+ * Revoke all the permissions on the object .
+ *
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ */
+ public void revokePermissions() throws ObjectNotFoundException,
ServiceAccessException {
+ if (permissions != null)
+ permissions.removeAllElements();
+ save();
+ }
+
+ /**
+ * Store an object permissions in the Descriptors Store.
+ *
+ * @param permission Permission we want to create
+ * @exception ServiceAccessException Error accessing the Descriptors Store
+ */
+ public Enumeration enumeratePermissions() throws ServiceAccessException {
+ if (permissions == null)
+ permissions = new Vector();
+ return permissions.elements();
+ }
+
+ /**
+ * Puts a lock on a subject.
+ *
+ * @param lock Lock token
+ * @exception ServiceAccessException Service access error
+ */
+ public void putLock(NodeLock lock) throws ObjectNotFoundException,
ServiceAccessException {
+ if (locks == null)
+ locks = new Vector();
+ locks.addElement(lock.cloneObject());
+ save();
+ }
+
+ /**
+ * Renews a lock.
+ *
+ * @param lock Token to renew
+ * @exception ServiceAccessException Service access error
+ * @exception LockTokenNotFoundException Lock token was not found
+ */
+ public void renewLock(NodeLock lock) throws LockTokenNotFoundException,
ObjectNotFoundException, ServiceAccessException {
+ if (locks == null)
+ locks = new Vector();
+ boolean wasPresent = locks.removeElement(lock);
+ if (!wasPresent) {
+ throw new LockTokenNotFoundException(lock);
+ }
+ locks.addElement(lock.cloneObject());
+ save();
+ }
+
+ /**
+ * Removes (cancels) a lock.
+ *
+ * @param lock Token to remove
+ * @exception ServiceAccessException Service access error
+ * @exception LockTokenNotFoundException Lock token was not found
+ */
+ public void removeLock(NodeLock lock) throws LockTokenNotFoundException,
ObjectNotFoundException, ServiceAccessException {
+
+ if (locks == null) {
+ throw new LockTokenNotFoundException(lock);
+ }
+ boolean wasPresent = locks.removeElement(lock);
+ if (!wasPresent) {
+ throw new LockTokenNotFoundException(lock);
+ }
+ save();
+ }
+
+ /**
+ * Returns the list of locks put on a subject.
+ *
+ * @param subject Subject
+ * @return Enumeration List of locks which have been put on the subject
+ * @exception ServiceAccessException Service access error
+ */
+ public Enumeration enumerateLocks() throws ServiceAccessException {
+ if (locks == null)
+ locks = new Vector();
+ return locks.elements();
+ }
+
+ /**
+ * Retrieve a revision descriptors.
+ *
+ * @exception ServiceAccessException Service access error
+ * @exception RevisionDescriptorNotFoundException Revision descriptor
+ * was not found
+ */
+ public NodeRevisionDescriptors retrieveRevisionDescriptors()
+ throws ServiceAccessException, RevisionDescriptorNotFoundException {
+ if (revisionDescriptors == null) {
+ throw new RevisionDescriptorNotFoundException(uri.toString());
+ }
+ return revisionDescriptors.cloneObject();
+ }
+
+ /**
+ * Create new revision descriptors.
+ *
+ * @param revisionDescriptors Node revision descriptors
+ * @exception ServiceAccessException Service access error
+ */
+ public void createRevisionDescriptors(NodeRevisionDescriptors
aRevisionDescriptors)
+ throws ObjectNotFoundException, ServiceAccessException {
+ revisionDescriptors = aRevisionDescriptors.cloneObject();
+ save();
+ }
+
+ /**
+ * Update revision descriptors.
+ *
+ * @param revisionDescriptors Node revision descriptors
+ * @exception ServiceAccessException Service access error
+ * @exception RevisionDescriptorNotFoundException Revision descriptor
+ * was not found
+ */
+ public void storeRevisionDescriptors(NodeRevisionDescriptors
aRevisionDescriptors)
+ throws RevisionDescriptorNotFoundException, ObjectNotFoundException,
ServiceAccessException {
+ if (!revisionDescriptors.getUri().equals(uri.toString())) {
+ throw new RevisionDescriptorNotFoundException(uri.toString());
+ }
+ revisionDescriptors = aRevisionDescriptors.cloneObject();
+ save();
+ }
+
+ /**
+ * Remove revision descriptors.
+ *
+ * @exception ServiceAccessException Service access error
+ */
+ public void removeRevisionDescriptors() throws ObjectNotFoundException,
ServiceAccessException {
+ revisionDescriptors = null;
+ save();
+ }
+
+ /**
+ * Retrieve revision descriptor.
+ *
+ * @param revisionNumber Node revision number
+ */
+ public NodeRevisionDescriptor retrieveRevisionDescriptor(NodeRevisionNumber
revisionNumber)
+ throws ServiceAccessException, RevisionDescriptorNotFoundException {
+ Object result = null;
+
+ if (descriptor != null && revisionNumber != null)
+ result = descriptor.get(revisionNumber.toString());
+
+ if (result == null) {
+ throw new RevisionDescriptorNotFoundException(uri.toString());
+ }
+ return ((NodeRevisionDescriptor) result).cloneObject();
+ }
+
+ /**
+ * Create new revision descriptor.
+ *
+ * @param revisionDescriptor Node revision descriptor
+ * @exception ServiceAccessException Service access error
+ */
+ public void createRevisionDescriptor(NodeRevisionDescriptor aRevisionDescriptor)
+ throws ObjectNotFoundException, ServiceAccessException {
+ if (descriptor == null)
+ descriptor = new Hashtable();
+
+ descriptor.put(aRevisionDescriptor.getRevisionNumber().toString(),
aRevisionDescriptor.cloneObject());
+ save();
+ }
+
+ /**
+ * Update revision descriptor.
+ *
+ * @param revisionDescriptors Node revision descriptor
+ * @exception ServiceAccessException Service access error
+ * @exception RevisionDescriptorNotFoundException Revision descriptor
+ * was not found
+ */
+ public void storeRevisionDescriptor(NodeRevisionDescriptor aRevisionDescriptor)
+ throws RevisionDescriptorNotFoundException, ObjectNotFoundException,
ServiceAccessException {
+ String key = aRevisionDescriptor.getRevisionNumber().toString();
+ if (descriptor == null || !descriptor.containsKey(key)) {
+ throw new RevisionDescriptorNotFoundException(uri.toString());
+ }
+ descriptor.put(key, aRevisionDescriptor.cloneObject());
+ save();
+ }
+
+ /**
+ * Remove revision descriptor.
+ *
+ * @param revisionNumber Revision number
+ * @exception ServiceAccessException Service access error
+ */
+ public void removeRevisionDescriptor(NodeRevisionNumber number) throws
ObjectNotFoundException, ServiceAccessException {
+ if (descriptor == null)
+ return;
+
+ descriptor.remove(number.toString());
+ save();
+ }
+
+ // -------------- PART TAKE OVER FROM AbstractUriProperties END --------------
+
/**
* Stores this descriptor to the resource manager.
*
* @throws ServiceAccessException if anything goes wrong at system level
* @throws ObjectNotFoundException if the descriptor has not been created
before
*/
- public synchronized void save() throws ServiceAccessException,
ObjectNotFoundException {
+ public void save() throws ServiceAccessException, ObjectNotFoundException {
if (txId == null) {
store.throwInternalError("Not inside tx");
}
@@ -152,7 +619,7 @@
* @throws ServiceAccessException if anything goes wrong at system level
* @throws ObjectAlreadyExistsException if the descriptor already exists
*/
- public synchronized void create() throws ServiceAccessException,
ObjectAlreadyExistsException {
+ public void create() throws ServiceAccessException,
ObjectAlreadyExistsException {
logger.logFiner("Tx " + txId + " creates " + loadPath);
if (txId == null) {
store.throwInternalError("Not inside tx");
@@ -175,7 +642,7 @@
* @throws ServiceAccessException if anything goes wrong at system level
* @throws ObjectNotFoundException if the descriptor does not exist
*/
- public synchronized void delete() throws ServiceAccessException,
ObjectNotFoundException {
+ public void delete() throws ServiceAccessException, ObjectNotFoundException {
logger.logFiner("Tx " + txId + " deletes " + loadPath);
if (txId == null) {
store.throwInternalError("Not inside tx");
@@ -193,49 +660,6 @@
}
/**
- * Loads this descriptor from the resource manager.
- *
- * @throws ServiceAccessException if anything goes wrong at system level
- * @throws ObjectNotFoundException if the descriptor does not exist
- */
- public synchronized void load() throws ServiceAccessException,
ObjectNotFoundException {
- logger.logFiner("Tx " + txId + " loads data for " + loadPath);
-
- InputStream is = null;
- try {
- logger.logFinest("Faking read access from outside tx for " + loadPath);
- if (txId != null) {
- if (rm.resourceExists(txId, loadPath)) {
- is = rm.readResource(txId, loadPath);
- load(is);
- } else {
- init();
- }
- } else {
- if (rm.resourceExists(loadPath)) {
- is = rm.readResource(loadPath);
- load(is);
- } else {
- init();
- }
- }
- } catch (ResourceManagerException e) {
- if (e.getStatus() == ResourceManagerException.ERR_NO_SUCH_RESOURCE) {
- throw new ObjectNotFoundException(uri);
- } else {
- store.throwInternalError(e, uri);
- }
- } finally {
- try {
- if (is != null) {
- is.close();
- }
- } catch (IOException e) {
- }
- }
- }
-
- /**
* Gets the URI of this descriptor.
*
* @return the URI
@@ -260,7 +684,7 @@
* @param o object to compare this descriptor to
* @return <code>true</code> if object is equal as described above
*/
- public synchronized boolean equals(Object o) {
+ public boolean equals(Object o) {
return (
this == o
|| (o != null
@@ -269,11 +693,11 @@
&& ((XMLResourceDescriptor) o).txId.equals(txId)));
}
- public synchronized String toString() {
+ public String toString() {
return txId + ": " + uri;
}
- protected synchronized void save(OutputStream os) throws ServiceAccessException
{
+ protected void save(OutputStream os) throws ServiceAccessException {
Element aRoot = encode();
Document aDocument = new Document(aRoot);
@@ -290,25 +714,226 @@
}
}
- public synchronized Element encodeObject() {
+ /**
+ * Loads this descriptor from the resource manager.
+ *
+ * @throws ServiceAccessException if anything goes wrong at system level
+ * @throws ObjectNotFoundException if the descriptor does not exist
+ */
+ protected void load() throws ServiceAccessException, ObjectNotFoundException {
+ logger.logFiner("Tx " + txId + " loads data for " + loadPath);
+
+ InputStream is = null;
+ try {
+ logger.logFinest("Faking read access from outside tx for " + loadPath);
+ if (txId != null) {
+ if (rm.resourceExists(txId, loadPath)) {
+ is = rm.readResource(txId, loadPath);
+ load(is);
+ } else {
+ init();
+ }
+ } else {
+ if (rm.resourceExists(loadPath)) {
+ is = rm.readResource(loadPath);
+ load(is);
+ } else {
+ init();
+ }
+ }
+ } catch (ResourceManagerException e) {
+ if (e.getStatus() == ResourceManagerException.ERR_NO_SUCH_RESOURCE) {
+ throw new ObjectNotFoundException(uri);
+ } else {
+ store.throwInternalError(e, uri);
+ }
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ protected void load(InputStream is) throws ServiceAccessException {
+ SAXBuilder aBuilder = new SAXBuilder();
+ try {
+ Document aDocument = aBuilder.build(is);
+ decode(aDocument.getRootElement());
+ } catch (JDOMException e) {
+ store.throwInternalError(e);
+ } catch (IOException e) {
+ store.throwInternalError(e);
+ }
+ }
+
+ protected void init() throws ServiceAccessException {
+ // need to set this null, as AbstractUriProperties.retrieveObject relies on
it
+ object = null;
+ permissions = new Vector();
+ locks = new Vector();
+ revisionDescriptors = new NodeRevisionDescriptors();
+ descriptor = new Hashtable();
+ }
+
+ protected Element encode() throws ServiceAccessException {
+ Element aRoot = new Element("data");
+ aRoot.addContent(encodeObject());
+ aRoot.addContent(encodePermissions());
+ aRoot.addContent(encodeLocks());
+ aRoot.addContent(encodeRevisionDescriptors());
+ aRoot.addContent(encodeRevisionDescriptor());
+ return aRoot;
+ }
+
+ protected Element encodeObject() {
+ Element aElementObjectNode = new Element("objectnode");
if (object != null) {
- return super.encodeObject();
+ aElementObjectNode.setAttribute("classname",
object.getClass().getName());
+ aElementObjectNode.setAttribute("uri", object.getUri());
+ if (object instanceof LinkNode) {
+ aElementObjectNode.setAttribute("linkTo", ((LinkNode)
object).getLinkedUri());
+ }
} else {
- Element aElementObjectNode = new Element("objectnode");
// for null locks
aElementObjectNode.setAttribute("classname", "null");
aElementObjectNode.setAttribute("uri", uri.toString());
- aElementObjectNode.addContent(new Element("childs"));
- aElementObjectNode.addContent(new Element("links"));
- return aElementObjectNode;
}
+ aElementObjectNode.addContent(createBindings("children", "child",
object.enumerateBindings()));
+ aElementObjectNode.addContent(createBindings("parents", "parent",
object.enumerateParentBindings()));
+ aElementObjectNode.addContent(createElements("links", "link",
object.enumerateLinks()));
+ return aElementObjectNode;
+ }
+
+ protected Element encodePermissions() {
+ Element aPermissions = new Element("permissions");
+ if (permissions == null)
+ return aPermissions;
+
+ for (int aSize = permissions.size(), i = 0; i < aSize; i++) {
+ NodePermission aPermission = (NodePermission) permissions.elementAt(i);
+ aPermissions.addContent(encodeNodePermission(aPermission));
+ }
+ return aPermissions;
+ }
+
+ protected Element encodeLocks() {
+ Element aElementLocks = new Element("locks");
+ if (locks == null)
+ return aElementLocks;
+
+ for (int aSize = locks.size(), i = 0; i < aSize; i++) {
+ NodeLock aLock = (NodeLock) locks.elementAt(i);
+ Element aElementLock = new Element("lock");
+ aElementLock.setAttribute("subjectUri", aLock.getSubjectUri());
+ aElementLock.setAttribute("typeUri", aLock.getTypeUri());
+ aElementLock.setAttribute("date",
dateFormat.format(aLock.getExpirationDate()));
+ aElementLock.setAttribute("inheritance",
booleanToString(aLock.isInheritable()));
+ aElementLock.setAttribute("exclusive",
booleanToString(aLock.isExclusive()));
+ aElementLock.setAttribute("lockId", aLock.getLockId());
+ aElementLock.setAttribute("owner", aLock.getOwnerInfo());
+ aElementLocks.addContent(aElementLock);
+ }
+ return aElementLocks;
+ }
+
+ protected Element encodeRevisionDescriptors() {
+
+ Element aRevisionsHistory = new Element("revisionsHistory");
+ if (revisionDescriptors == null)
+ return aRevisionsHistory;
+
+ aRevisionsHistory.setAttribute(
+ "initialRevision",
+ encodeRevisionNumber(revisionDescriptors.getInitialRevision()));
+ aRevisionsHistory.setAttribute("useVersioning",
booleanToString(revisionDescriptors.isVersioned()));
+
+ // System.out.println("---------- encodeRevisionDescriptors
getLatestRevision="+
+ // revisionDescriptors.getLatestRevision());
+
+ Element aBranchesElement = new Element("branches");
+ Enumeration aBranches = revisionDescriptors.enumerateBranchNames();
+ while (aBranches.hasMoreElements()) {
+ String aBranchName = (String) aBranches.nextElement();
+ Element aElementBranch = new Element("branch");
+ aElementBranch.setAttribute("name", aBranchName);
+ NodeRevisionNumber aRevisionNumber =
revisionDescriptors.getLatestRevision(aBranchName);
+ aElementBranch.setAttribute("lastestRevision",
encodeRevisionNumber(aRevisionNumber));
+ aBranchesElement.addContent(aElementBranch);
+ }
+ aRevisionsHistory.addContent(aBranchesElement);
+
+ Element aRevisionsElement = new Element("revisions");
+ Enumeration aRevisions = revisionDescriptors.enumerateRevisionNumbers();
+ while (aRevisions.hasMoreElements()) {
+ NodeRevisionNumber aRevisionNumber = (NodeRevisionNumber)
aRevisions.nextElement();
+ Element aRevisionElement = new Element("branch");
+ aRevisionElement.setAttribute("start",
encodeRevisionNumber(aRevisionNumber));
+
+ Enumeration aSuccessors =
revisionDescriptors.getSuccessors(aRevisionNumber);
+ while (aSuccessors.hasMoreElements()) {
+ NodeRevisionNumber aSuccessorRevisionNumber = (NodeRevisionNumber)
aSuccessors.nextElement();
+ Element aSuccessorRevisionElement = new Element("revision");
+ aSuccessorRevisionElement.setAttribute("number",
encodeRevisionNumber(aSuccessorRevisionNumber));
+ aRevisionElement.addContent(aSuccessorRevisionElement);
+ }
+ aRevisionsElement.addContent(aRevisionElement);
+ }
+ aRevisionsHistory.addContent(aRevisionsElement);
+
+ return aRevisionsHistory;
+ }
+
+ protected Element encodeRevisionDescriptor() {
+ Element aRet = new Element("descriptor");
+ if (descriptor == null)
+ return aRet;
+
+ for (Enumeration aEnum = descriptor.elements(); aEnum.hasMoreElements();) {
+ NodeRevisionDescriptor aRevisionDescriptor = (NodeRevisionDescriptor)
aEnum.nextElement();
+ aRet.addContent(encodeRevisionDescriptor(aRevisionDescriptor));
+ }
+ return aRet;
}
- public synchronized void decodeObject(Element aElement) throws
ServiceAccessException {
+ protected void decode(Element aRoot) throws ServiceAccessException {
+ decodeObject(aRoot);
+ decodePermissions(aRoot);
+ decodeLocks(aRoot);
+ decodeRevisionDescriptors(aRoot);
+ decodeRevisionDescriptor(aRoot);
+ }
+
+ protected void decodeObject(Element aElement) throws ServiceAccessException {
Element aElementObjectNode = aElement.getChild("objectnode");
String aClasseName = aElementObjectNode.getAttributeValue("classname");
if (!"null".equals(aClasseName)) {
- super.decodeObject(aElement);
+ try {
+ String aUri = aElementObjectNode.getAttributeValue("uri");
+ Vector aChilds = createBindingVector(aElementObjectNode,
"children", "child", false);
+ Vector aParents = createBindingVector(aElementObjectNode,
"parents", "parent", true);
+ Vector aLinks = createVector(aElementObjectNode, "links", "link");
+ // System.out.println("--------- decodeObject aChilds="+aChilds);
+ // System.out.println("--------- decodeObject aLinks="+aLinks);
+ Class aTypes[] = null;
+ Object aArgs[] = null;
+
+ if (aClasseName.equals(LinkNode.class.getName())) {
+ String aLinkTo = aElementObjectNode.getAttributeValue("linkTo");
+ aTypes = new Class[] { String.class, Vector.class,
Vector.class, String.class };
+ aArgs = new Object[] { aUri, aChilds, aLinks, aLinkTo };
+ } else {
+ aTypes = new Class[] { String.class, Vector.class,
Vector.class, Vector.class };
+ aArgs = new Object[] { aUri, aChilds, aParents, aLinks };
+ }
+ object = (ObjectNode) createObject(aClasseName, aTypes, aArgs);
+ object.setUri(object.getUuri());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(null, e);
+ }
uri = object.getUri();
} else {
object = null;
@@ -316,7 +941,7 @@
}
}
- public synchronized void decodePermissions(Element aElement) {
+ protected void decodePermissions(Element aElement) {
permissions = new Vector();
Element aPermissions = aElement.getChild("permissions");
List aList = aPermissions.getChildren();
@@ -326,7 +951,7 @@
}
}
- public synchronized void decodeLocks(Element aElement) throws
ServiceAccessException {
+ protected void decodeLocks(Element aElement) throws ServiceAccessException {
try {
locks = new Vector();
Element aElementLocks = aElement.getChild("locks");
@@ -342,7 +967,8 @@
String aLockId = aChild.getAttributeValue("lockId");
String ownerInfo = aChild.getAttributeValue("owner");
- locks.addElement(new NodeLock(aLockId, uri, aSubject, aType,
aDateExpiration, aInheritable, aNegative, ownerInfo));
+ locks.addElement(
+ new NodeLock(aLockId, uri, aSubject, aType, aDateExpiration,
aInheritable, aNegative, ownerInfo));
}
} catch (Exception e) {
e.printStackTrace();
@@ -351,7 +977,7 @@
}
- public synchronized void decodeRevisionDescriptors(Element aElement) {
+ protected void decodeRevisionDescriptors(Element aElement) {
Element aRevisionsHistory = aElement.getChild("revisionsHistory");
NodeRevisionNumber aInitialRevision =
@@ -404,7 +1030,7 @@
aUseVersionning);
}
- public synchronized void decodeRevisionDescriptor(Element aParent) {
+ protected void decodeRevisionDescriptor(Element aParent) {
descriptor = new Hashtable();
Element aElement = aParent.getChild("descriptor");
@@ -441,41 +1067,4 @@
}
}
- protected synchronized void load(InputStream is) throws ServiceAccessException {
- SAXBuilder aBuilder = new SAXBuilder();
- try {
- Document aDocument = aBuilder.build(is);
- decode(aDocument.getRootElement());
- } catch (JDOMException e) {
- store.throwInternalError(e);
- } catch (IOException e) {
- store.throwInternalError(e);
- }
- }
-
- protected synchronized void init() throws ServiceAccessException {
- // need to set this null, as AbstractUriProperties.retrieveObject relies on
it
- object = null;
- permissions = new Vector();
- locks = new Vector();
- revisionDescriptors = new NodeRevisionDescriptors();
- descriptor = new Hashtable();
- }
-
- protected synchronized void save(Uri uri) throws ServiceAccessException {
- if (txId == null) {
- store.throwInternalError("Not inside tx");
- }
- // null objects must be saveable, as it is possible to have nulllocks
-
- // if (object == null) {
- // store.throwInternalError("Resource '" + uri + "' not
initialized");
- // }
- try {
- save();
- } catch (ObjectNotFoundException e) {
- store.throwInternalError(e);
- }
- }
-
-}
\ No newline at end of file
+}
1.7 +20 -20
jakarta-slide/src/stores/org/apache/slide/store/txfile/TxXMLFileDescriptorsStore.java
Index: TxXMLFileDescriptorsStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/txfile/TxXMLFileDescriptorsStore.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TxXMLFileDescriptorsStore.java 25 Feb 2004 15:14:27 -0000 1.6
+++ TxXMLFileDescriptorsStore.java 26 Feb 2004 13:40:54 -0000 1.7
@@ -73,20 +73,20 @@
public ObjectNode retrieveObject(Uri uri) throws ServiceAccessException,
ObjectNotFoundException {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- ObjectNode object = xfd.retrieveObject(uri);
+ ObjectNode object = xfd.retrieveObject();
return object;
}
public void storeObject(Uri uri, ObjectNode object) throws
ServiceAccessException, ObjectNotFoundException {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.storeObject(uri, object);
+ xfd.storeObject(object);
}
public void createObject(Uri uri, ObjectNode object) throws
ServiceAccessException, ObjectAlreadyExistsException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
xfd.create();
- xfd.storeObject(uri, object);
+ xfd.storeObject(object);
} catch (ObjectNotFoundException e) {
// should not happen, if it does, it is an error inside this store:
throwInternalError("Newly created file vanished");
@@ -107,7 +107,7 @@
public void grantPermission(Uri uri, NodePermission permission) throws
ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.grantPermission(uri, permission);
+ xfd.grantPermission(permission);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -116,7 +116,7 @@
public void revokePermission(Uri uri, NodePermission permission) throws
ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.revokePermission(uri, permission);
+ xfd.revokePermission(permission);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -125,7 +125,7 @@
public void revokePermissions(Uri uri) throws ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.revokePermissions(uri);
+ xfd.revokePermissions();
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -150,7 +150,7 @@
public void putLock(Uri uri, NodeLock lock) throws ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.putLock(uri, lock);
+ xfd.putLock(lock);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -159,7 +159,7 @@
public void renewLock(Uri uri, NodeLock lock) throws ServiceAccessException,
LockTokenNotFoundException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.renewLock(uri, lock);
+ xfd.renewLock(lock);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -168,7 +168,7 @@
public void removeLock(Uri uri, NodeLock lock) throws ServiceAccessException,
LockTokenNotFoundException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.removeLock(uri, lock);
+ xfd.removeLock(lock);
} catch (ObjectNotFoundException e) {
throw new LockTokenNotFoundException(lock);
}
@@ -198,7 +198,7 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- return xfd.retrieveRevisionDescriptors(uri);
+ return xfd.retrieveRevisionDescriptors();
} catch (ObjectNotFoundException e) {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
@@ -208,7 +208,7 @@
throws ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.createRevisionDescriptors(uri, revisionDescriptors);
+ xfd.createRevisionDescriptors(revisionDescriptors);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -218,7 +218,7 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.storeRevisionDescriptors(uri, revisionDescriptors);
+ xfd.storeRevisionDescriptors(revisionDescriptors);
} catch (ObjectNotFoundException e) {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
@@ -227,7 +227,7 @@
public void removeRevisionDescriptors(Uri uri) throws ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.removeRevisionDescriptors(uri);
+ xfd.removeRevisionDescriptors();
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -243,7 +243,7 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- return xfd.retrieveRevisionDescriptor(uri, revisionNumber);
+ return xfd.retrieveRevisionDescriptor(revisionNumber);
} catch (ObjectNotFoundException e) {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
@@ -253,7 +253,7 @@
throws ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.createRevisionDescriptor(uri, revisionDescriptor);
+ xfd.createRevisionDescriptor(revisionDescriptor);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
@@ -263,7 +263,7 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.storeRevisionDescriptor(uri, revisionDescriptor);
+ xfd.storeRevisionDescriptor(revisionDescriptor);
} catch (ObjectNotFoundException e) {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
@@ -272,7 +272,7 @@
public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber number) throws
ServiceAccessException {
try {
XMLResourceDescriptor xfd = getFileDescriptor(uri);
- xfd.removeRevisionDescriptor(uri, number);
+ xfd.removeRevisionDescriptor(number);
} catch (ObjectNotFoundException e) {
throwInternalError(e);
}
1.88 +1 -0 jakarta-slide/src/doc/changelog.xml
Index: changelog.xml
===================================================================
RCS file: /home/cvs/jakarta-slide/src/doc/changelog.xml,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- changelog.xml 11 Feb 2004 11:30:10 -0000 1.87
+++ changelog.xml 26 Feb 2004 13:40:54 -0000 1.88
@@ -15,6 +15,7 @@
release.
<changelog>
+ <update date="February 26, 2004" author="ozeigermann">Refactored and
cleaned up XMLResourceDescriptor to be standalone and removed now obsolete classes
from filestore package.</fix>
<fix date="February 02, 2004" author="mholz">Handle unknown actions in
SecurityImpl.</fix>
<add date="February 01, 2004" author="mholz">Added JDBC adapter, which
provides backward compatibility with Slide 1.x JDBC store.</add>
<fix date="January 29, 2004" author="ozeigermann">SQL Server now
allows for unicode in all strings. Patched contributed by Jacob Lund.</fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]