geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r701647 - in /geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main: java/org/apache/geronimo/gshell/vfs/provider/meta/ resources/META-INF/spring/
Date Sat, 04 Oct 2008 14:51:18 GMT
Author: jdillon
Date: Sat Oct  4 07:51:18 2008
New Revision: 701647

URL: http://svn.apache.org/viewvc?rev=701647&view=rev
Log:
Mostly functional meta file-system muck

Added:
    geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
  (with props)
    geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/resources/META-INF/spring/components.xml

Added: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java?rev=701647&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
Sat Oct  4 07:51:18 2008
@@ -0,0 +1,150 @@
+/*
+ * 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.vfs.provider.meta;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Meta file data.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MetaFileData
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final FileName name;
+
+    private FileType type = FileType.IMAGINARY;
+
+    private long lastModified = -1;
+
+    private final Map<String,Object> attributes = Collections.synchronizedMap(new HashMap<String,Object>());
+
+    private final Collection<MetaFileData> children = Collections.synchronizedCollection(new
ArrayList<MetaFileData>());
+
+    public MetaFileData(final FileName name) {
+        assert name != null;
+
+        this.name = name;
+    }
+
+    public FileName getName() {
+        return name;
+    }
+
+    public FileType getType() {
+        return type;
+    }
+
+    public void setType(final FileType type) {
+        assert type != null;
+
+        this.type = type;
+    }
+
+    public void updateLastModified() {
+        lastModified = System.currentTimeMillis();
+    }
+
+    public long getLastModified() {
+        return lastModified;
+    }
+
+    public void setLastModified(long lastModified) {
+        this.lastModified = lastModified;
+    }
+
+    public Map<String,Object> getAttributes() {
+        return attributes;
+    }
+
+    public Collection<MetaFileData> getChildren() {
+        return children;
+    }
+
+    public void addChild(final MetaFileData data) throws FileSystemException {
+        assert data != null;
+
+        if (!getType().hasChildren()) {
+            throw new FileSystemException("A child can only be added in a folder");
+        }
+        if (hasChild(data)) {
+            throw new FileSystemException("Child already exists: " + data);
+        }
+
+        log.debug("Adding child: {}", data);
+
+        getChildren().add(data);
+        updateLastModified();
+    }
+
+    public void removeChild(final MetaFileData data) throws FileSystemException{
+        assert data != null;
+
+        if (!getType().hasChildren()) {
+            throw new FileSystemException("A child can only be removed from a folder");
+        }
+        if (!hasChild(data)) {
+            throw new FileSystemException("Child not found: " + data);
+        }
+
+        log.debug("Removing child: {}", data);
+        
+        getChildren().remove(data);
+        updateLastModified();
+    }
+
+    public boolean hasChild(final MetaFileData data) {
+        assert data != null;
+
+        return getChildren().contains(data);
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) return true;
+        if (obj == null || getClass() != obj.getClass()) return false;
+
+        MetaFileData that = (MetaFileData) obj;
+        return !(name != null ? !name.equals(that.name) : that.name != null);
+
+    }
+
+    @Override
+    public int hashCode() {
+        return getName().hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return getName().toString();
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java?rev=701647&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
Sat Oct  4 07:51:18 2008
@@ -0,0 +1,134 @@
+/*
+ * 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.vfs.provider.meta;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.provider.AbstractFileObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.util.Map;
+
+/**
+ * Meta file object.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MetaFileObject
+    extends AbstractFileObject
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final MetaFileSystem fileSystem;
+
+    private MetaFileData data;
+
+    public MetaFileObject(final FileName fileName, final MetaFileSystem fileSystem) {
+        super(fileName, fileSystem);
+
+        // Save for uncasted typed access
+        this.fileSystem = fileSystem;
+    }
+
+    MetaFileData getData() {
+        assert data != null;
+        
+        return data;
+    }
+
+    void setData(final MetaFileData data) {
+        assert data != null;
+        
+        this.data = data;
+    }
+
+
+    @Override
+    protected FileType doGetType() throws Exception {
+        return getData().getType();
+    }
+
+    @Override
+    protected long doGetLastModifiedTime() throws Exception {
+        return getData().getLastModified();
+    }
+
+    @Override
+    protected long doGetContentSize() throws Exception {
+        // Meta file is always empty
+        return 0;
+    }
+
+    @Override
+    protected InputStream doGetInputStream() throws Exception {
+        // No contents thus no input stream
+        return null;
+    }
+
+    @Override
+    protected Map<String,Object> doGetAttributes() {
+        return getData().getAttributes();
+    }
+
+    @Override
+    protected void doSetAttribute(final String name, final Object value) {
+        getData().getAttributes().put(name, value);
+    }
+
+    protected void doRemoveAttribute(final String name) {
+        getData().getAttributes().remove(name);
+    }
+
+    @Override
+    protected String[] doListChildren() throws Exception {
+        return fileSystem.listChildren(getName());
+    }
+
+    @Override
+    protected void doDelete() throws Exception {
+        fileSystem.delete(this);
+    }
+
+    @Override
+    protected void doCreateFolder() throws Exception {
+        injectType(FileType.FOLDER);
+        fileSystem.save(this);
+    }
+
+    @Override
+    protected void doAttach() throws Exception {
+        fileSystem.attach(this);
+    }
+
+    @Override
+    protected void doDetach() throws Exception {
+        data = null;
+    }
+
+    @Override
+    protected void injectType(final FileType type) {
+        assert type != null;
+
+        getData().setType(type);
+        super.injectType(type);
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileObject.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java?rev=701647&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
Sat Oct  4 07:51:18 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.vfs.provider.meta;
+
+import org.apache.commons.vfs.Capability;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * Meta file provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MetaFileProvider
+    extends AbstractOriginatingFileProvider
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public static final Collection<Capability> CAPABILITIES = Collections.unmodifiableCollection(Arrays.asList(
+        Capability.ATTRIBUTES,
+        Capability.CREATE,
+        Capability.DELETE,
+        Capability.GET_TYPE,
+        Capability.GET_LAST_MODIFIED,
+        Capability.LAST_MODIFIED,
+        Capability.LIST_CHILDREN,
+        Capability.URI
+    ));
+
+    public Collection getCapabilities() {
+        return CAPABILITIES;
+    }
+
+    protected FileSystem doCreateFileSystem(final FileName fileName, final FileSystemOptions
options) throws FileSystemException {
+        MetaFileSystem fs = new MetaFileSystem(fileName, options);
+
+        log.debug("Created file system: {}", fs);
+
+        return fs;
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java?rev=701647&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
(added)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
Sat Oct  4 07:51:18 2008
@@ -0,0 +1,157 @@
+/*
+ * 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.vfs.provider.meta;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.provider.AbstractFileSystem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Meta file system.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MetaFileSystem
+    extends AbstractFileSystem
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final Map<FileName,MetaFileData> nodes = Collections.synchronizedMap(new
HashMap<FileName,MetaFileData>());
+
+    public MetaFileSystem(final FileName rootName, final FileSystemOptions options) {
+        super(rootName, null, options);
+
+        // Setup the root file's data
+        MetaFileData data = new MetaFileData(rootName);
+        data.setType(FileType.FOLDER);
+        data.updateLastModified();
+        nodes.put(rootName, data);
+    }
+
+    protected FileObject createFile(final FileName fileName) throws Exception {
+        MetaFileObject file = new MetaFileObject(fileName, this);
+
+        log.debug("Created file: {}", file);
+
+        return file;
+    }
+
+    protected void addCapabilities(final Collection capabilities) {
+        assert capabilities != null;
+
+        // noinspection unchecked
+        capabilities.addAll(MetaFileProvider.CAPABILITIES);
+    }
+
+    @Override
+    public void close() {
+        nodes.clear();
+        super.close();
+    }
+
+    //
+    // Internal bits invoked from MetaFileObject
+    //
+
+    void save(final MetaFileObject file) throws FileSystemException {
+        assert file != null;
+
+        log.debug("Saving: {}", file);
+
+        FileName name = file.getName();
+        MetaFileData data = file.getData();
+
+        if (name.getDepth() > 0) {
+            MetaFileData parentData = nodes.get(file.getParent().getName());
+
+            if (!parentData.hasChild(data)) {
+                MetaFileObject parent = (MetaFileObject)file.getParent();
+                parent.getData().addChild(data);
+                parent.close();
+            }
+        }
+
+        nodes.put(name, data);
+        file.getData().updateLastModified();
+        file.close();
+    }
+
+    void attach(final MetaFileObject file) throws FileSystemException {
+        assert file != null;
+
+        log.debug("Attaching: {}", file);
+
+        FileName name = file.getName();
+        assert name != null;
+
+        MetaFileData data = nodes.get(name);
+        if (data == null) {
+            data = new MetaFileData(name);
+        }
+
+        file.setData(data);
+    }
+
+    void delete(final MetaFileObject file) throws FileSystemException {
+        assert file != null;
+
+        log.debug("Deleting: {}", file);
+
+        if (file.getParent() == null) {
+            throw new FileSystemException("Can not delete file-system root");
+        }
+
+        nodes.remove(file.getName());
+
+        MetaFileObject parent = (MetaFileObject) resolveFile(file.getParent().getName());
+        parent.getData().removeChild(file.getData());
+        parent.close();
+
+        file.close();
+    }
+
+    String[] listChildren(final FileName name) throws FileSystemException {
+        assert name != null;
+
+        log.debug("Listing children: {}", name);
+
+        MetaFileData data = nodes.get(name);
+        Collection<MetaFileData> children = data.getChildren();
+
+        List<String> names = new ArrayList<String>(children.size());
+        for (MetaFileData child : children) {
+            names.add(child.getName().getBaseName());
+        }
+
+        return names.toArray(new String[names.size()]);
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/java/org/apache/geronimo/gshell/vfs/provider/meta/MetaFileSystem.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/resources/META-INF/spring/components.xml?rev=701647&r1=701646&r2=701647&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs-meta/src/main/resources/META-INF/spring/components.xml
Sat Oct  4 07:51:18 2008
@@ -24,13 +24,11 @@
        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 class="org.apache.geronimo.gshell.vfs.config.FileProviderConfigurer">
-        <property name="scheme" value="file"/>
+        <property name="scheme" value="meta"/>
         <property name="provider">
-            <bean class="org.apache.geronimo.gshell.vfs.provider.local.LocalFileProvider"/>
+            <bean class="org.apache.geronimo.gshell.vfs.provider.meta.MetaFileProvider"/>
         </property>
     </bean>
-    -->
 
 </beans>
\ No newline at end of file



Mime
View raw message