geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r703831 - in /geronimo/gshell/trunk/gshell-support/gshell-xstore: ./ src/main/java/org/apache/geronimo/gshell/xstore/ src/main/resources/META-INF/spring/
Date Sun, 12 Oct 2008 14:56:54 GMT
Author: jdillon
Date: Sun Oct 12 07:56:53 2008
New Revision: 703831

URL: http://svn.apache.org/viewvc?rev=703831&view=rev
Log:
Some basic xstore impl muck, using commons-vfs for backing

Added:
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
  (contents, props changed)
      - copied, changed from r703810, geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-support/gshell-xstore/pom.xml
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecord.java
    geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/resources/META-INF/spring/components.xml

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/pom.xml?rev=703831&r1=703830&r2=703831&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/pom.xml (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/pom.xml Sun Oct 12 07:56:53 2008
@@ -48,7 +48,12 @@
             <artifactId>slf4j-log4j12</artifactId>
             <scope>test</scope>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-vfs</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.geronimo.gshell.support</groupId>
             <artifactId>gshell-marshal</artifactId>

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java?rev=703831&r1=703830&r2=703831&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java
Sun Oct 12 07:56:53 2008
@@ -20,13 +20,11 @@
 package org.apache.geronimo.gshell.xstore;
 
 /**
- * ???
+ * Provides access to {@link XStoreRecord} instances..
  *
  * @version $Rev$ $Date$
  */
 public interface XStore
 {
     XStoreRecord resolveRecord(String path);
-
-    void close();
 }
\ No newline at end of file

Copied: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
(from r703810, geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java?p2=geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java&p1=geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java&r1=703810&r2=703831&rev=703831&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStore.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
Sun Oct 12 07:56:53 2008
@@ -19,14 +19,68 @@
 
 package org.apache.geronimo.gshell.xstore;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.geronimo.gshell.vfs.FileSystemAccess;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
- * ???
+ * {@link XStore} component.
  *
  * @version $Rev$ $Date$
  */
-public interface XStore
+public class XStoreImpl
+    implements XStore
 {
-    XStoreRecord resolveRecord(String path);
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private FileSystemAccess fileSystemAccess;
+
+    private String rootUri;
+
+    private FileSystem fileSystem;
+
+    public String getRootUri() {
+        if (rootUri == null) {
+            throw new IllegalStateException("Missing property: rootUri");
+        }
+        return rootUri;
+    }
+
+    public void setRootUri(final String rootUri) {
+        this.rootUri = rootUri;
+    }
+
+    private FileSystem getFileSystem() {
+        if (fileSystem == null) {
+            try {
+                FileObject file = fileSystemAccess.getManager().createVirtualFileSystem(getRootUri());
+                log.debug("Root file: {}", file);
+
+                fileSystem = file.getFileSystem();
+                log.debug("File system: {}", fileSystem);
+            }
+            catch (FileSystemException e) {
+                throw new XStoreException("Failed to create file-sysytem", e);
+            }
+        }
+
+        return fileSystem;
+    }
+
+    public XStoreRecord resolveRecord(final String path) {
+        assert path != null;
 
-    void close();
+        try {
+            FileObject file = getFileSystem().resolveFile(path);
+            return new XStoreRecordImpl(file);
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+    }
 }
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecord.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecord.java?rev=703831&r1=703830&r2=703831&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecord.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecord.java
Sun Oct 12 07:56:53 2008
@@ -22,7 +22,7 @@
 import java.util.Collection;
 
 /**
- * ???
+ * A record in an {@link XStore}.
  *
  * @version $Rev$ $Date$
  */
@@ -32,9 +32,9 @@
 
     boolean exists();
 
-    void set(Object object);
+    void set(Object value);
 
-    Object get();
+    <T> T get(Class<T> type);
 
     void close();
 

Added: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java?rev=703831&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
Sun Oct 12 07:56:53 2008
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.geronimo.gshell.xstore;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.geronimo.gshell.marshal.Marshaller;
+import org.apache.geronimo.gshell.marshal.MarshallerSupport;
+import org.codehaus.plexus.util.IOUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * {@link XStoreRecord} implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class XStoreRecordImpl
+    implements XStoreRecord
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final FileObject file;
+
+    public XStoreRecordImpl(final FileObject file) {
+        assert file != null;
+
+        this.file = file;
+    }
+    
+    public String getPath() {
+        return file.getName().getPath();
+    }
+
+    public boolean exists() {
+        try {
+            return file.exists();
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+    }
+
+    public void set(final Object value) {
+        assert value != null;
+
+        log.debug("Setting: {} -> {}", file.getName(), value);
+
+        BufferedOutputStream output = null;
+        try {
+            Marshaller marshaller = new MarshallerSupport(value.getClass());
+            output = new BufferedOutputStream(file.getContent().getOutputStream());
+            // noinspection unchecked
+            marshaller.marshal(value, output);
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+        finally {
+            IOUtil.close(output);
+        }
+    }
+
+    public <T> T get(final Class<T> type) {
+        assert type != null;
+
+        log.debug("Getting: {}", file);
+
+        BufferedInputStream input = null;
+
+        try {
+            Marshaller<T> marshaller = new MarshallerSupport<T>(type);
+            input = new BufferedInputStream(file.getContent().getInputStream());
+            T value = marshaller.unmarshal(input);
+            log.debug("Value: {}", value);
+            return value;
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+        finally {
+            IOUtil.close(input);
+        }
+    }
+
+    public void close() {
+        log.debug("Closing: {}", file);
+        
+        try {
+            file.close();
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+    }
+
+    public boolean delete() {
+        log.debug("Deleting: {}", file);
+
+        try {
+            return file.delete();
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+    }
+
+    public void refresh() {
+        log.debug("Refreshing: {}", file);
+
+        try {
+            file.refresh();
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+    }
+
+    public XStoreRecord getParent() {
+        FileObject parentFile;
+
+        try {
+            parentFile = file.getParent();
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+
+        if (parentFile != null) {
+            return new XStoreRecordImpl(parentFile);
+        }
+        return null;
+    }
+
+    public Collection<XStoreRecord> getChilden() {
+        FileObject[] files;
+
+        try {
+            files = file.getChildren();
+        }
+        catch (FileSystemException e) {
+            throw new XStoreException(e);
+        }
+
+        List<XStoreRecord> children = new ArrayList<XStoreRecord>(files.length);
+
+        for (FileObject file : files) {
+            children.add(new XStoreRecordImpl(file));
+        }
+
+        return children;
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/java/org/apache/geronimo/gshell/xstore/XStoreRecordImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/resources/META-INF/spring/components.xml?rev=703831&r1=703830&r2=703831&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-xstore/src/main/resources/META-INF/spring/components.xml
Sun Oct 12 07:56:53 2008
@@ -24,4 +24,8 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 
+    <bean id="xstore" class="org.apache.geronimo.gshell.xstore.XStoreImpl">
+
+    </bean>
+
 </beans>
\ No newline at end of file



Mime
View raw message