Hi Michael 

   Can you just provide us with the steps so that we can just start writing
slide stores. I want to map the database objects in webdav as web folder. I
need to
   implement it via store. please help. Can you please tell some basic steps
to follow the same

Regards,
Gaurav Handa
9281



-----Original Message-----
From: Oliver Zeigermann [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 22, 2004 1:46 AM
To: Slide Developers Mailing List
Subject: Re: cvs commit:
jakarta-slide/src/stores/org/apache/slide/store/mem
AbstractTransientStore.java TransientContentStore.java
TransientDescriptorsStore.java TransientDescriptorStore.java
TransientLockStore.java TransientNodeStore.java TransientSecurityStore.


That's great stuff! I was just wondering about the XAResource 
implementation. Why not using the AbstractXAResource from commons 
transaction? Works fine and leaves a single source to modify for the XA 
methods...

Oliver

[EMAIL PROTECTED] wrote:

> luetzkendorf    2004/07/21 10:36:29
> 
>   Added:       src/stores/org/apache/slide/store/mem
>                         AbstractTransientStore.java
>                         TransientContentStore.java
>                         TransientDescriptorsStore.java
>                         TransientDescriptorStore.java
>                         TransientLockStore.java TransientNodeStore.java
>                         TransientSecurityStore.java VersionedUriKey.java
>   Log:
>   first versions of transient utility stores added
>   (they are successfully tested with the transaction package
>   checked out 20040721 but not with the version currently checked in)
>   this is WORK IN PROGRESS
>   
>   Revision  Changes    Path
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/AbstractTransientStore.j
ava
>   
>   Index: AbstractTransientStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/AbstractTransi
entStore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import java.lang.reflect.Constructor;
>   import java.lang.reflect.InvocationTargetException;
>   import java.text.MessageFormat;
>   import java.util.Collections;
>   import java.util.Enumeration;
>   import java.util.HashMap;
>   import java.util.Hashtable;
>   import java.util.Iterator;
>   import java.util.Map;
>   import java.util.NoSuchElementException;
>   
>   import javax.transaction.xa.XAException;
>   import javax.transaction.xa.XAResource;
>   import javax.transaction.xa.Xid;
>   
>   import org.apache.commons.transaction.memory.ConflictException;
>   import org.apache.commons.transaction.memory.TransactionalMapWrapper;
>   import org.apache.commons.transaction.memory.jca.MapXAResource;
>   import org.apache.commons.transaction.util.xa.XidWrapper;
>   
>   import org.apache.slide.common.AbstractServiceBase;
>   import org.apache.slide.common.NamespaceAccessToken;
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.ServiceConnectionFailedException;
>   import org.apache.slide.common.ServiceDisconnectionFailedException;
>   import org.apache.slide.common.ServiceInitializationFailedException;
>   import org.apache.slide.common.ServiceParameterErrorException;
>   import org.apache.slide.common.ServiceParameterMissingException;
>   import org.apache.slide.common.ServiceResetFailedException;
>   import org.apache.slide.util.logger.Logger;
>   
>   
>   /**
>    * @author Stefan L�tzkendorf
>    */
>   public abstract class AbstractTransientStore extends AbstractServiceBase
{
>      
>      static final String MAP_IMPL_PARAMETER = "map-classname";
>      static final String MAP_IMPL_PARAMETER_DEFAULT = 
>         "org.apache.commons.transaction.memory.OptimisticMapWrapper";
>      
>      private Map parameters = null;
>      private boolean isConnected = false;
>      
>      /**
>       * The map containing the stored content.
>       */
>      private TransactionalMapWrapper store = null;
>   
>      /**
>       * The XAResource to delegate all XA requests.
>       */
>      private MapXAResource xaResource = null; 
>   
>      private Map suspendedContexts = Collections.synchronizedMap(new
HashMap());
>   
>      public AbstractTransientStore() {
>         
>      }
>      
>      // ----------------------------------------------------- XAResource
Mathods
>      
>      public void start(Xid xid, int flags)
>         throws XAException 
>      {
>         debug("start {0} {1}", xid, Integer.toString(flags));
>         this.xaResource.start(xid, flags);
>         // >>
>         if (flags == XAResource.TMRESUME) {
>            Xid key = XidWrapper.wrap(xid);
>            TransactionalMapWrapper.TxContext txContext = 
>
(TransactionalMapWrapper.TxContext)suspendedContexts.get(key);
>            if (txContext != null) {
>               this.store.resumeTransaction(txContext);
>               this.suspendedContexts.remove(key);
>            } else {
>               throw new XAException("no such suspended txn");
>            }
>         } else {
>            this.store.startTransaction();
>         }
>         // <<
>      }
>      
>      public void commit(Xid xid, boolean onePhase)
>         throws XAException 
>      {
>         debug("commit {0} {1}", xid, Boolean.valueOf(onePhase));
>         try {
>            this.xaResource.commit(xid, onePhase);
>         }
>         catch (ConflictException e) {
>            this.xaResource.rollback(xid);
>            // TODO it would be great if we could if we could throw
something
>            // that would (on the webdav layer) leads to a 409 Conflict
>            // instead of 500 Internal Server Erroe
>            throw new XAException(XAException.XA_RBOTHER); // ??
>         }
>      }
>      
>      public int prepare(Xid xid)
>         throws XAException 
>      {
>         debug("prepare {0}", xid);
>         // >>
>         // resume if suspended, because the transactional map throws an
exception
>         // if we call prepare on suspended txns
>         Xid key = XidWrapper.wrap(xid);
>         TransactionalMapWrapper.TxContext txContext = 
>
(TransactionalMapWrapper.TxContext)this.suspendedContexts.get(key);
>         if (txContext != null) {
>            this.store.resumeTransaction(txContext);
>            this.suspendedContexts.remove(key);
>         }
>         // <<
>         return this.xaResource.prepare(xid);   
>      }
>   
>      public void end(Xid xid, int flags)
>          throws XAException 
>      {
>         debug("end {0} {1}", xid, Integer.toString(flags));
>         this.xaResource.end(xid, flags);
>         // >>
>         if (flags == XAResource.TMSUSPEND) {
>            TransactionalMapWrapper.TxContext txContext = 
>               this.store.suspendTransaction();
>            this.suspendedContexts.put(XidWrapper.wrap(xid), txContext);
>         }
>         // <<
>      }
>      
>      public void rollback(Xid xid)
>          throws XAException 
>      {
>         debug("rollback {0}", xid);
>         // >>
>         // resume if suspended, because the transactional map throws an
exception
>         // if we call prepare on suspended txns
>         Xid key = XidWrapper.wrap(xid);
>         TransactionalMapWrapper.TxContext txContext = 
>
(TransactionalMapWrapper.TxContext)this.suspendedContexts.get(key);
>         if (txContext != null) {
>            this.store.resumeTransaction(txContext);
>            this.suspendedContexts.remove(key);
>         }
>         // <<
>         this.xaResource.rollback(xid);
>      }
>      
>      public Xid[] recover(int flag)
>         throws XAException 
>      {
>         debug("recover {0}", Integer.toString(flag));
>         return this.xaResource.recover(flag);
>      }
>   
>      public void forget(Xid xid)
>          throws XAException 
>      {
>          debug("forget {0}", xid);
>          this.xaResource.forget(xid);
>      }
>      
>      public int getTransactionTimeout()
>          throws XAException 
>      {
>          return this.xaResource.getTransactionTimeout();
>      }
>   
>      public boolean setTransactionTimeout(int seconds)
>          throws XAException
>      {
>          return this.xaResource.setTransactionTimeout(seconds);
>      }
>      
>      public boolean isSameRM(XAResource xares)
>          throws XAException 
>      {
>         return this == xares;
>      }
>      
>      
>      
>   
>      // ------------------------------------- Store accessors for
implementations
>   
>      protected void put(Object key, Object value) {
>         this.store.put(key, value);
>      }
>      
>      protected Object get(Object key) {
>         return this.store.get(key);
>      }
>      
>      protected Object remove(Object key) {
>         return this.store.remove(key);
>      }
>      
>      // ------------------------------------------------ ContextTuple
InnerClass
>      
>      public void setParameters(Hashtable parameters)
>            throws ServiceParameterErrorException,
>                   ServiceParameterMissingException 
>      {
>         this.parameters = new HashMap(parameters);
>      }
>      
>      protected String getParameter(String name) {
>         if (this.parameters != null) {
>            return (String)this.parameters.get(name);
>         } else {
>            throw new IllegalStateException("Parameter not yet set!");
>         }
>      }
>      public void initialize(NamespaceAccessToken token)
>         throws ServiceInitializationFailedException
>      {
>         super.initialize(token);
>         
>         String param = (String)this.parameters.get(MAP_IMPL_PARAMETER);
>         if (param == null) {
>            param = MAP_IMPL_PARAMETER_DEFAULT;
>         }
>         try {
>            info("Initializing {0} using {1}.", getClass().getName(),
param);
>            Map toBeWrapped = new HashMap();
>            Class mapClass = Class.forName(param);
>            Class[] ctorFormalArgs = { Map.class };
>            Constructor ctor = mapClass.getConstructor(ctorFormalArgs);
>            Object[] ctorArgs = { toBeWrapped };
>            this.store =
(TransactionalMapWrapper)ctor.newInstance(ctorArgs);
>         } 
>         catch (ClassNotFoundException e) {
>            throw new ServiceInitializationFailedException(this, e);
>         } 
>         catch (InstantiationException e) {
>            throw new ServiceInitializationFailedException(this, e);
>         } 
>         catch (IllegalAccessException e) {
>            throw new ServiceInitializationFailedException(this, e);
>         }
>         catch (NoSuchMethodException e) {
>            throw new ServiceInitializationFailedException(this, e);
>         }
>         catch (InvocationTargetException e) {
>            throw new ServiceInitializationFailedException(this, e);
>         }
>         catch (ClassCastException e) {
>            throw new ServiceInitializationFailedException(this, 
>                  "class in parameter '" + MAP_IMPL_PARAMETER + "' must " +
>                        "be derived from TransactionalMapWrapper");
>         }
>         
>         this.xaResource = new MapXAResource(this.store);
>         // FIXME logging
>      }
>   
>      public void connect() throws ServiceConnectionFailedException {
>         this.isConnected = true;
>      }
>      public void disconnect() throws ServiceDisconnectionFailedException {
>         this.isConnected = false;
>      }
>      public void reset() throws ServiceResetFailedException {
>      }
>      public boolean isConnected() throws ServiceAccessException {
>         return this.isConnected;
>      }
>      
>   
>      //
-------------------------------------------------------------------
>   
>      
>      protected String LogChannel() {  
>         return LOG_CHANNEL;
>      }
>      protected void debug(String msg, Object o) {
>        if (this.getLogger().isEnabled(Logger.DEBUG)) {
>           Object[] args = { o };
>           this.getLogger().log(MessageFormat.format(msg, args), 
>                                LogChannel(), Logger.DEBUG);
>        }
>      }
>      protected void debug(String msg, Object o1, Object o2) {
>        if (this.getLogger().isEnabled(Logger.DEBUG)) {
>           Object[] args = { o1, o2 };
>           this.getLogger().log(MessageFormat.format(msg, args), 
>                                LogChannel(), Logger.DEBUG);
>        }
>      }
>      private void info(String msg, Object o1, Object o2) {
>         if (this.getLogger().isEnabled(Logger.INFO)) {
>            Object[] args = { o1, o2 };
>            this.getLogger().log(MessageFormat.format(msg, args), 
>                                 LogChannel(), Logger.INFO);
>         }
>      }
>      
>      /**
>       * Empty enumeration.
>       */
>      protected static Enumeration EMPTY_ENUM = new Enumeration() {
>         public boolean hasMoreElements() {
>            return false;
>         }
>         public Object nextElement() {
>            throw new NoSuchElementException();
>         }
>      };
>      
>      /**
>       * Enumeration wrapper for an Iterator. 
>       */
>      protected static class IteratorEnum implements Enumeration {
>         private Iterator iterator;
>         public IteratorEnum(Iterator iterator){
>            this.iterator = iterator;
>         }
>         public boolean hasMoreElements() {
>            return this.iterator.hasNext();
>         }
>         public Object nextElement() {
>            return this.iterator.next();
>         }
>      }
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/TransientContentStore.ja
va
>   
>   Index: TransientContentStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientConte
ntStore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.content.NodeRevisionContent;
>   import org.apache.slide.content.NodeRevisionDescriptor;
>   import org.apache.slide.content.RevisionAlreadyExistException;
>   import org.apache.slide.content.RevisionNotFoundException;
>   import org.apache.slide.store.ContentStore;
>   
>   
>   /**
>    * @author Stefan L�tzkendorf
>    */
>   public class TransientContentStore extends AbstractTransientStore
implements
>         ContentStore
>   {
>      // FIXME: should we clone the content byte array?
>   
>      public NodeRevisionContent retrieveRevisionContent(Uri uri,
>            NodeRevisionDescriptor revisionDescriptor)
>            throws ServiceAccessException, RevisionNotFoundException
>      {
>         VersionedUriKey key = new VersionedUriKey(uri, 
>               revisionDescriptor.getRevisionNumber());
>         debug("retrieveRevisionContent {0}", key);
>         
>         byte[] content = (byte[])get(key);
>         if (content != null) {
>            NodeRevisionContent revisionContent = new
NodeRevisionContent();
>            revisionContent.setContent(content);
>            return revisionContent;
>         } else {
>            throw new RevisionNotFoundException(uri.toString(), 
>                  revisionDescriptor.getRevisionNumber());
>         }
>      }
>   
>      public void createRevisionContent(Uri uri,
>            NodeRevisionDescriptor revisionDescriptor,
>            NodeRevisionContent revisionContent) throws
ServiceAccessException,
>            RevisionAlreadyExistException
>      {
>         VersionedUriKey key = new VersionedUriKey(uri, 
>               revisionDescriptor.getRevisionNumber());
>         debug("createRevisionContent {0}", key);
>         
>         byte[] content = (byte[])get(key);
>         if (content == null) {
>            put(key, revisionContent.getContentBytes());
>         } else {
>            throw new RevisionAlreadyExistException(uri.toString(), 
>                  revisionDescriptor.getRevisionNumber());
>         }
>      }
>      
>      public void storeRevisionContent(Uri uri,
>            NodeRevisionDescriptor revisionDescriptor,
>            NodeRevisionContent revisionContent) throws
ServiceAccessException,
>            RevisionNotFoundException
>      {
>         VersionedUriKey key = new VersionedUriKey(uri, 
>               revisionDescriptor.getRevisionNumber());
>         debug("storeRevisionContent {0}", key);
>        
>         byte[] content = (byte[])get(key);
>         if (content != null) {
>            put(key, revisionContent.getContentBytes());
>         } else {
>            throw new RevisionNotFoundException(uri.toString(), 
>                  revisionDescriptor.getRevisionNumber());
>         }
>      }
>   
>      public void removeRevisionContent(Uri uri,
>            NodeRevisionDescriptor revisionDescriptor)
>            throws ServiceAccessException
>      {
>         VersionedUriKey key = new VersionedUriKey(uri, 
>               revisionDescriptor.getRevisionNumber());
>         debug("storeRevisionContent {0}", key);
>         
>         remove(key);
>      }
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/TransientDescriptorsStor
e.java
>   
>   Index: TransientDescriptorsStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientDescr
iptorsStore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.content.NodeRevisionDescriptors;
>   import org.apache.slide.content.RevisionDescriptorNotFoundException;
>   import org.apache.slide.store.RevisionDescriptorsStore;
>   
>   
>   /**
>    * @author Stefan L�tzkendorf
>    */
>   public class TransientDescriptorsStore extends AbstractTransientStore
implements
>         RevisionDescriptorsStore
>   {
>      // Note: cloning is done by the ExtendedStore
>      
>      public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
>            throws ServiceAccessException,
RevisionDescriptorNotFoundException
>      {
>         NodeRevisionDescriptors descriptors = 
>               (NodeRevisionDescriptors)get(uri.toString());
>         if (descriptors != null) {
>            return descriptors;
>         } else {
>            throw new RevisionDescriptorNotFoundException(uri.toString());
>         }
>      }
>   
>      public void createRevisionDescriptors(Uri uri,
>            NodeRevisionDescriptors revisionDescriptors)
>            throws ServiceAccessException
>      {
>         put(uri.toString(), revisionDescriptors);
>      }
>   
>      public void storeRevisionDescriptors(Uri uri,
>            NodeRevisionDescriptors revisionDescriptors)
>            throws ServiceAccessException,
RevisionDescriptorNotFoundException
>      {
>         NodeRevisionDescriptors descriptors = 
>               (NodeRevisionDescriptors)get(uri.toString());
>         if (descriptors != null) {
>            put(uri.toString(), revisionDescriptors);
>         } else {
>            throw new RevisionDescriptorNotFoundException(uri.toString());
>         }
>      }
>   
>      public void removeRevisionDescriptors(Uri uri) throws
ServiceAccessException
>      {
>         remove(uri.toString());
>      }
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/TransientDescriptorStore
.java
>   
>   Index: TransientDescriptorStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientDescr
iptorStore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.content.NodeRevisionDescriptor;
>   import org.apache.slide.content.NodeRevisionNumber;
>   import org.apache.slide.content.RevisionDescriptorNotFoundException;
>   import org.apache.slide.store.RevisionDescriptorStore;
>   
>   
>   /**
>    * @author Stefan L�tzkendorf
>    */
>   public class TransientDescriptorStore extends AbstractTransientStore
implements
>         RevisionDescriptorStore
>   {
>      // Note: we don't clone the descriptors because ExtendedStore does
>   
>      public NodeRevisionDescriptor retrieveRevisionDescriptor(Uri uri,
>            NodeRevisionNumber revisionNumber) throws
ServiceAccessException,
>            RevisionDescriptorNotFoundException
>      {
>         NodeRevisionDescriptor descriptor = 
>            (NodeRevisionDescriptor)get(new VersionedUriKey(uri,
revisionNumber));
>         if (descriptor != null) {
>            return descriptor;
>         } else {
>            throw new RevisionDescriptorNotFoundException(uri.toString());
>         }
>      }
>   
>      public void createRevisionDescriptor(Uri uri,
>            NodeRevisionDescriptor revisionDescriptor)
>            throws ServiceAccessException
>      {
>         put(new VersionedUriKey(uri,
revisionDescriptor.getRevisionNumber()), 
>               revisionDescriptor);
>      }
>   
>      public void storeRevisionDescriptor(Uri uri,
>            NodeRevisionDescriptor revisionDescriptor)
>            throws ServiceAccessException,
RevisionDescriptorNotFoundException
>      {
>         VersionedUriKey key = new VersionedUriKey(uri, 
>               revisionDescriptor.getRevisionNumber());
>         NodeRevisionDescriptor descriptor =
(NodeRevisionDescriptor)get(key);
>         if (descriptor != null) {
>            put(key, revisionDescriptor);
>         } else {
>            throw new RevisionDescriptorNotFoundException(uri.toString());
>         }
>      }
>   
>      public void removeRevisionDescriptor(Uri uri,
>            NodeRevisionNumber revisionNumber) throws
ServiceAccessException
>      {
>         remove(new VersionedUriKey(uri, revisionNumber));
>      }
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/TransientLockStore.java
>   
>   Index: TransientLockStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientLockS
tore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import java.util.ArrayList;
>   import java.util.Enumeration;
>   import java.util.List;
>   
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.lock.LockTokenNotFoundException;
>   import org.apache.slide.lock.NodeLock;
>   import org.apache.slide.store.LockStore;
>   
>   
>   /**
>    * @author Stefan L�tzkendorf
>    */
>   public class TransientLockStore extends AbstractTransientStore 
>      implements LockStore 
>   {
>      // Note: we don't clone Locks because ExtendedStore clones
>   
>      public void putLock(Uri uri, NodeLock lock) throws
ServiceAccessException {
>         debug("putLock {0} {1}", uri, lock.getLockId());
>         List list = (List)get(uri.toString());
>         if (list != null) {
>            list = new ArrayList(list);
>         } else {
>            list = new ArrayList();
>         }
>         list.add(lock);
>         put(uri.toString(), list);
>      }
>      
>      public void renewLock(Uri uri, NodeLock lock)
>         throws ServiceAccessException, LockTokenNotFoundException 
>      {
>         debug("renewLock {0} {1}", uri, lock.getLockId());
>         List list = (List)get(uri.toString());
>         if (list == null || !list.contains(lock)) {
>            throw new LockTokenNotFoundException(lock);
>         }
>         list = new ArrayList(list);
>         list.remove(lock);
>         list.add(lock);
>         put(uri.toString(), list);
>      }
>   
>      public void removeLock(Uri uri, NodeLock lock)
>         throws ServiceAccessException, LockTokenNotFoundException 
>      {
>         debug("removeLock {0} {1}", uri, lock.getLockId());
>         List list = (List)get(uri.toString());
>         if (list == null) {
>            throw new LockTokenNotFoundException(lock);
>         }
>         if (!list.contains(lock)) {
>            throw new LockTokenNotFoundException(lock);
>         } else {
>            if (list.size() == 1) {
>               remove(uri.toString());
>            } else {
>               list = new ArrayList(list);
>               list.remove(lock);
>               put(uri.toString(), list);
>            }
>         }
>      }
>      
>      public void killLock(Uri uri, NodeLock lock)
>         throws ServiceAccessException, LockTokenNotFoundException 
>      {
>         debug("killLock {0} {1}", uri, lock.getLockId());
>         removeLock(uri, lock);
>      }
>   
>      public Enumeration enumerateLocks(Uri uri) throws
ServiceAccessException 
>      {
>         debug("enumerateLocks {0}", uri);
>   
>         List list = (List)get(uri.toString());
>         if (list != null) {
>            return new IteratorEnum(list.iterator());
>         } else {
>            return EMPTY_ENUM;
>         }
>      }
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/TransientNodeStore.java
>   
>   Index: TransientNodeStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientNodeS
tore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.store.NodeStore;
>   import org.apache.slide.structure.ObjectAlreadyExistsException;
>   import org.apache.slide.structure.ObjectNode;
>   import org.apache.slide.structure.ObjectNotFoundException;
>   
>   
>   /**
>    * NodeStore that stores ObjectNodes in transient memory. 
>    * 
>    * @author Stefan L�tzkendorf
>    */
>   public class TransientNodeStore extends AbstractTransientStore
implements
>         NodeStore
>   {
>      // Note: we don't clone ObjectNodes because ExtendedStore clones
>   
>      public ObjectNode retrieveObject(Uri uri) throws
ServiceAccessException,
>            ObjectNotFoundException
>      {
>         ObjectNode node = (ObjectNode)get(uri.toString());
>         if (node != null) {
>            return node;
>         } else {
>            throw new ObjectNotFoundException(uri);
>         }
>      }
>   
>      public void storeObject(Uri uri, ObjectNode object)
>            throws ServiceAccessException, ObjectNotFoundException
>      {
>         ObjectNode node = (ObjectNode)get(uri.toString());
>         if (node != null) {
>            put(uri.toString(), object);
>         } else {
>            throw new ObjectNotFoundException(uri);
>         }
>      }
>   
>      public void createObject(Uri uri, ObjectNode object)
>            throws ServiceAccessException, ObjectAlreadyExistsException
>      {
>         ObjectNode node = (ObjectNode)get(uri.toString());
>         if (node == null) {
>            put(uri.toString(), object); 
>         } else {
>            throw new ObjectAlreadyExistsException(uri.toString());
>         }
>      }
>   
>      public void removeObject(Uri uri, ObjectNode object)
>            throws ServiceAccessException, ObjectNotFoundException
>      {
>         ObjectNode node = (ObjectNode)get(uri.toString());
>         if (node != null) {
>            remove(uri.toString());
>         } else {
>            throw new ObjectNotFoundException(uri);
>         }
>      }
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/TransientSecurityStore.j
ava
>   
>   Index: TransientSecurityStore.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/TransientSecur
ityStore.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import java.util.ArrayList;
>   import java.util.Enumeration;
>   import java.util.List;
>   
>   import org.apache.slide.common.ServiceAccessException;
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.security.NodePermission;
>   import org.apache.slide.store.SecurityStore;
>   
>   
>   /**
>    * @author Stefan L�tzkendorf
>    */
>   public class TransientSecurityStore extends AbstractTransientStore
implements
>         SecurityStore
>   {
>      // ExtendendStore always caches, so we don't
>      
>      public void grantPermission(Uri uri, NodePermission permission)
>            throws ServiceAccessException
>      {
>         List list = (List)get(uri.toString());
>         if (list != null) {
>            list = new ArrayList(list);
>         } else {
>            list = new ArrayList();
>         }
>         list.add(permission);
>         put(uri.toString(), list);
>      }
>   
>      public void revokePermission(Uri uri, NodePermission permission)
>            throws ServiceAccessException
>      {
>         List list = (List)get(uri.toString());
>         if (list != null) {
>            list = new ArrayList(list);
>            if (list.remove(permission)) {
>               if (list.size() > 0) {
>                  put(uri.toString(), list);
>               } else {
>                  remove(uri.toString());
>               }
>            } 
>         }
>      }
>   
>      public void revokePermissions(Uri uri) throws ServiceAccessException
>      {
>         List list = (List)get(uri.toString());
>         if (list != null) {
>            remove(uri.toString());
>         }
>      }
>   
>      public Enumeration enumeratePermissions(Uri uri)
>            throws ServiceAccessException
>      {
>         List list = (List)get(uri.toString());
>         if (list != null) {
>            return new IteratorEnum(list.iterator());
>         } else {
>            return EMPTY_ENUM;
>         }
>      }
>   
>   }
>   
>   
>   
>   1.1
jakarta-slide/src/stores/org/apache/slide/store/mem/VersionedUriKey.java
>   
>   Index: VersionedUriKey.java
>   ===================================================================
>   /*
>    * $Header:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/mem/VersionedUriKe
y.java,v 1.1 2004/07/21 17:36:29 luetzkendorf Exp $
>    * $Revision: 1.1 $
>    * $Date: 2004/07/21 17:36:29 $
>    *
>    * ====================================================================
>    *
>    * Copyright 1999-2002 The Apache Software Foundation
>    *
>    * Licensed under the Apache License, Version 2.0 (the "License");
>    * you may not use this file except in compliance with the License.
>    * You may obtain a copy of the License at
>    *
>    *     http://www.apache.org/licenses/LICENSE-2.0
>    *
>    * Unless required by applicable law or agreed to in writing, software
>    * distributed under the License is distributed on an "AS IS" BASIS,
>    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
>    * See the License for the specific language governing permissions and
>    * limitations under the License.
>    *
>    */
>   package org.apache.slide.store.mem;
>   
>   import org.apache.slide.common.Uri;
>   import org.apache.slide.content.NodeRevisionNumber;
>   
>   
>   /**
>    * Class to hold an URI and a version number to be used as key in maps.
>    * 
>    * @author Stefan L�tzkendorf
>    */
>   class VersionedUriKey {
>      private String uri;
>      private String version;
>      VersionedUriKey(Uri uri, NodeRevisionNumber number) 
>      {
>         this.uri = uri.toString();
>         this.version = number.toString();
>      }
>      public boolean equals(Object obj)
>      {
>         if (obj == this) return true;
>         if (obj instanceof VersionedUriKey) {
>            VersionedUriKey that = (VersionedUriKey)obj;
>            return this.uri.equals(that.uri) &&
this.version.equals(that.version);
>         }
>         return false;
>      }
>      public int hashCode()
>      {
>         return (uri.hashCode() + version.hashCode());
>      }
>      public String toString()
>      {
>         return uri + " - " + version;
>      }
>   }
>   
>   
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to