Revision 41170

View differences:

tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.DALFileLibrary
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/FileHelper.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal;
25

  
26
import java.io.InputStream;
27

  
28
import org.gvsig.metadata.MetadataLocator;
29
import org.gvsig.metadata.MetadataManager;
30
import org.gvsig.metadata.exceptions.MetadataException;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dynobject.DynObject;
33
import org.gvsig.tools.dynobject.DynStruct;
34
import org.gvsig.tools.exception.BaseRuntimeException;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
public class FileHelper {
40

  
41
	private static final Logger LOG = LoggerFactory.getLogger(FileHelper.class);
42

  
43
	private FileHelper() {
44
		// Do nothing
45
	}
46
	
47
	public static DynStruct registerParametersDefinition(String name, Class theClass, String filename) {
48
		DynStruct definition = null;
49
		
50
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
51
		definition = manager.getDefinition(name);
52
		if ( definition == null) {
53
			InputStream stream = theClass.getResourceAsStream(filename);
54
			if( stream == null ) {
55
				throw new DefinitionNotFoundException(theClass,filename);
56
			}
57
			definition = manager.addDefinition(
58
					theClass,
59
					name, 
60
					stream,
61
					theClass.getClassLoader(), 
62
					null, 
63
					null
64
			);
65
		}
66
		return definition;
67
	}
68
	
69
	public static DynStruct registerMetadataDefinition(String name, Class theClass, String filename) throws MetadataException {
70
		DynStruct definition = null;
71

  
72
		MetadataManager manager = MetadataLocator.getMetadataManager();
73
		definition = manager.getDefinition(name);
74
		if ( definition == null) {
75
			InputStream stream = theClass.getResourceAsStream(filename);
76
			if( stream == null ) {
77
				throw new DefinitionNotFoundException(theClass,filename);
78
			}
79
			definition = manager.addDefinition(
80
					name, 
81
					theClass.getResourceAsStream(filename),
82
					theClass.getClassLoader()
83
			);
84
		}
85
		return definition;
86
	}
87

  
88
	public static DynObject newParameters(String name) {
89
    	return ToolsLocator.getDynObjectManager()
90
			.createDynObject(
91
				ToolsLocator.getPersistenceManager().getDefinition(name)
92
			);
93
	}
94
	
95
	public static DynObject newMetadataContainer(String name) {
96
		try {
97
			MetadataManager manager = MetadataLocator.getMetadataManager();
98
			DynStruct definition = manager.getDefinition(name);
99
	    	return ToolsLocator.getDynObjectManager().createDynObject(definition);
100
		} catch(NullPointerException e) {
101
			throw new CantCreateMetadataException(name,e);
102
		}
103
	}
104

  
105
	private static class DefinitionNotFoundException extends BaseRuntimeException {
106
		
107
		/**
108
		 * 
109
		 */
110
		private static final long serialVersionUID = 7598155353307119897L;
111

  
112
		public DefinitionNotFoundException(Class theClass, String filename ) {
113
			super(
114
				"Can't open parameters definition '%(filename)' from class %(classname).",
115
				"_ResourceForParametersDefinitionNotFoundException",
116
				serialVersionUID
117
			);
118
			this.setValue("filename", filename);
119
			this.setValue("classname", theClass.getClass().getName());
120
		}
121
	}
122
	
123
	private static class CantCreateMetadataException extends RuntimeException {
124
		
125
		/**
126
		 * 
127
		 */
128
		private static final long serialVersionUID = -8373306339537106075L;
129

  
130
		CantCreateMetadataException(String name, Throwable cause) {
131
			super("Can't retrieve metadata definition for '"+name+"'.", cause);			
132
		}
133
	}
134
}
0 135

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/DALFileLocator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.fmap.dal;
26

  
27
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerManager;
28
import org.gvsig.tools.locator.AbstractLocator;
29
import org.gvsig.tools.locator.Locator;
30
import org.gvsig.tools.locator.LocatorException;
31

  
32
public class DALFileLocator extends AbstractLocator {
33

  
34

  
35
	private static final String LOCATOR_NAME = "DALFileLocator";
36

  
37
	/**
38
	 * DataManager name used by the locator to access the instance
39
	 */
40
	public static final String FILESYSTEMSERVEREXPLORERE_MANAGER_NAME = "FilesystemServerExplorereManager";
41

  
42
	private static final String FILESYSTEMSERVEREXPLORERE_MANAGER_DESCRIPTION = "FilesystemServerExplorereManager of gvSIG Data Access Library";
43

  
44
	/**
45
	 * Unique instance.
46
	 */
47
	private static final DALFileLocator instance = new DALFileLocator();
48

  
49
	/**
50
	 * Return the singleton instance.
51
	 *
52
	 * @return the singleton instance
53
	 */
54
	public static DALFileLocator getInstance() {
55
		return instance;
56
	}
57

  
58
	public String getLocatorName() {
59
		return LOCATOR_NAME;
60
	}
61

  
62
	/**
63
	 * Return a reference to FilesystemServerExplorerManager.
64
	 *
65
	 * @return a reference to FilesystemServerExplorerManager
66
	 * @throws LocatorException
67
	 *             if there is no access to the class or the class cannot be
68
	 *             instantiated
69
	 * @see Locator#get(String)
70
	 */
71
	public static FilesystemServerExplorerManager getFilesystemServerExplorerManager()
72
			throws LocatorException {
73
		return (FilesystemServerExplorerManager) getInstance().get(
74
				FILESYSTEMSERVEREXPLORERE_MANAGER_NAME);
75
	}
76

  
77
	/**
78
	 * Registers the Class implementing the FilesystemSeverExplorerManager
79
	 * interface.
80
	 * 
81
	 * @param clazz
82
	 *            implementing the FilesystemSeverExplorerManager interface
83
	 */
84
	public static void registerFilesystemSeverExplorerManager(Class clazz) {
85
		getInstance().register(FILESYSTEMSERVEREXPLORERE_MANAGER_NAME,
86
				FILESYSTEMSERVEREXPLORERE_MANAGER_DESCRIPTION,
87
				clazz);
88
	}
89

  
90
}
0 91

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/DALFileLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25

  
26
package org.gvsig.fmap.dal;
27

  
28
import org.gvsig.fmap.dal.resource.file.FileResource;
29
import org.gvsig.fmap.dal.resource.file.FileResourceParameters;
30
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
31
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
32
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
33
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.DefaultFilesystemServerExplorer;
34
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.DefaultFilesystemServerExplorerManager;
35
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
36
import org.gvsig.tools.library.AbstractLibrary;
37
import org.gvsig.tools.library.LibraryException;
38

  
39

  
40
public class DALFileLibrary extends AbstractLibrary {
41

  
42
    public void doRegistration() {
43
        registerAsServiceOf(DALLibrary.class);
44
    }
45

  
46
	protected void doInitialize() throws LibraryException {
47
	}
48

  
49
	protected void doPostInitialize() throws LibraryException {
50
    	DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
51

  
52
    	ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator.getResourceManager();
53

  
54
    	if (!resman.getResourceProviders().contains(FileResource.NAME)) {
55
			resman.register(FileResource.NAME, FileResource.DESCRIPTION,
56
					FileResource.class, FileResourceParameters.class);
57
		}
58

  
59
    	if (!dataman.getExplorerProviders().contains(FilesystemServerExplorer.NAME)) {
60
			dataman.registerExplorerProvider(FilesystemServerExplorer.NAME,
61
					DefaultFilesystemServerExplorer.class,
62
					FilesystemServerExplorerParameters.class);
63
			DALFileLocator
64
					.registerFilesystemSeverExplorerManager(DefaultFilesystemServerExplorerManager.class);
65
    	}
66
	}
67
}
0 68

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/resource/file/FileResource.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.resource.file;
25

  
26
import java.io.File;
27
import java.io.FileInputStream;
28
import java.io.FileNotFoundException;
29
import java.text.MessageFormat;
30

  
31
import org.gvsig.fmap.dal.exception.InitializeException;
32
import org.gvsig.fmap.dal.resource.ResourceParameters;
33
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
34
import org.gvsig.fmap.dal.resource.exception.PrepareResourceException;
35
import org.gvsig.fmap.dal.resource.exception.ResourceException;
36
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException;
37
import org.gvsig.fmap.dal.resource.spi.AbstractResource;
38

  
39
/**
40
 * @author jmvivo
41
 *
42
 */
43
public class FileResource extends AbstractResource {
44

  
45
	final public static String NAME = "file";
46
	final public static String DESCRIPTION = "File of filesystem";
47

  
48
	private File file;
49

  
50
	public FileResource(FileResourceParameters params)
51
			throws InitializeException {
52
		super(params);
53
		file = null;
54
	}
55

  
56
	public Object get() throws AccessResourceException {
57
		return getFile();
58
	}
59

  
60
	public String getFileName() throws AccessResourceException {
61
		return (String) getFile().getPath();
62
	}
63

  
64
	public File getFile() throws AccessResourceException {
65

  
66
		try {
67
			prepare();
68
		} catch (PrepareResourceException e) {
69
			throw new AccessResourceException(this, e);
70
		}
71
		return ((FileResourceParameters)getParameters()).getFile();
72
	}
73

  
74
	// TODO ???
75
	public FileInputStream getFileInputStream() throws AccessResourceException,
76
			FileNotFoundException {
77
		FileInputStream fis = new FileInputStream(getFile());
78
		try {
79
			notifyOpen();
80
		} catch (ResourceNotifyOpenException e) {
81
			throw new AccessResourceException(this, e);
82
		}
83
		return fis;
84
	}
85

  
86
	public String getName() throws AccessResourceException {
87
		return MessageFormat.format("FileResource({0})",
88
				new Object[] { getFileName() });
89
	}
90

  
91
	public boolean isThis(ResourceParameters parameters)
92
			throws ResourceException {
93
		if (!(parameters instanceof FileResourceParameters)) {
94
			return false;
95
		}
96
		FileResourceParameters params;
97
		params = (FileResourceParameters) parameters.getCopy();
98
		prepare(params);
99
		return params.getFileName().equals(this.getFileName());
100

  
101
	}
102

  
103
}
104

  
0 105

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/resource/file/FileResourceParameters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.resource.file;
25

  
26
import java.io.File;
27

  
28
import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.dataTypes.DataTypes;
31
import org.gvsig.tools.dynobject.DelegatedDynObject;
32
import org.gvsig.tools.dynobject.DynClass;
33
import org.gvsig.tools.persistence.PersistenceManager;
34

  
35

  
36
public class FileResourceParameters extends AbstractResourceParameters {
37

  
38
    public static final String DYNCLASS_NAME = "FileResourceParameters";
39

  
40
    private static final String DYNFIELDNAME_FILE = "file";
41

  
42
	private DelegatedDynObject delegatedDynObject;
43

  
44
    public FileResourceParameters() {
45
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
46
				.getDynObjectManager()
47
				.createDynObject(registerDynClass());
48
	}
49

  
50
	public FileResourceParameters(Object[] params) {
51
		this();
52
		// XXX puede que sobre
53
        setDynValue(DYNFIELDNAME_FILE, params[0]);
54
	}
55

  
56
	public FileResourceParameters(String name) {
57
		this();
58
		setDynValue(DYNFIELDNAME_FILE, name);
59
	}
60

  
61
	public String getFileName() {
62
		if( this.getFile()== null ) {
63
			return null;
64
		}
65
		return this.getFile().getPath();
66
	}
67

  
68
	public FileResourceParameters setFileName(String fileName) {
69
		this.setDynValue(DYNFIELDNAME_FILE, fileName);
70
		return this;
71
	}
72

  
73
	public File getFile() {
74
		return (File) this.getDynValue(DYNFIELDNAME_FILE);
75
	}
76

  
77
	public FileResourceParameters setFile(File file) {
78
		this.setDynValue(DYNFIELDNAME_FILE, file);
79
		return this;
80
	}
81

  
82
	public FileResourceParameters setFile(String fileName) {
83
		this.setDynValue(DYNFIELDNAME_FILE, fileName);
84
		return this;
85
	}
86

  
87
	public String getTypeName() {
88
		return FileResource.NAME;
89
	}
90

  
91
	protected DelegatedDynObject getDelegatedDynObject() {
92
		return delegatedDynObject;
93
	}
94

  
95
	/**
96
	 * Added "static synchronized" because sometimes
97
	 * there is a "DuplicateDynClassException" when user
98
	 * selects more than one file (SHP, for example) to be
99
	 * added to the view. "definition" is null but then there is
100
	 * an exception because in the meantime another thread has registered it
101
	 * (I'm not sure this is the cause, but I cannot imagine another
102
	 * reason)
103
	 */
104
    private static synchronized DynClass registerDynClass() {
105
    	PersistenceManager manager = ToolsLocator.getPersistenceManager();
106
    	DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME);
107
    	if( definition == null ) {
108
    		definition = (DynClass) manager.addDefinition(
109
    				FileResourceParameters.class,
110
    				DYNCLASS_NAME, 
111
    				DYNCLASS_NAME+" persistence definition", 
112
    				null, 
113
    				null
114
    		);
115

  
116
			definition.addDynField(DYNFIELDNAME_FILE).setType(DataTypes.FILE)
117
					.setDescription("The file");
118
        }
119
        return definition;
120
    }
121
}
0 122

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/FilesystemFileFilter.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.serverexplorer.filesystem;
25

  
26
import java.io.FileFilter;
27

  
28
public interface FilesystemFileFilter extends FileFilter {
29

  
30
	public String getDataStoreProviderName();
31
	public String getDescription();
32

  
33
}
0 34

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/AbsolutePathRequiredException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.serverexplorer.filesystem;
25

  
26
import org.gvsig.fmap.dal.exception.CreateException;
27

  
28
public class AbsolutePathRequiredException extends CreateException {
29

  
30
	private static final long serialVersionUID = 8723525042950358334L;
31
	private final static String MESSAGE_FORMAT = "Absolute path required creating '%(resource)'.";
32
	private final static String MESSAGE_KEY = "_AbsolutePathRequiredException";
33

  
34
	public AbsolutePathRequiredException(String resource) {
35
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
36
		setValue("resource", resource);
37
	}
38

  
39
}
40

  
0 41

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/spi/FilesystemServerExplorerManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.fmap.dal.serverexplorer.filesystem.spi;
26

  
27
import java.util.Iterator;
28

  
29
public interface FilesystemServerExplorerManager {
30
	final public static String FILE_FILTER_EPSNAME = "FilesystemExplorerFilters";
31
	final public String FILE_FILTER_EPSDESCRIPTION = "Registro de filtros asociados al explorador del sistema de ficheros.";
32

  
33
	public void registerProvider(String name, String description,
34
			Class filesystemServerProvicerClass);
35

  
36
	public Iterator getRegisteredProviders();
37

  
38
}
0 39

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/spi/FilesystemServerExplorerProvider.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.serverexplorer.filesystem.spi;
25

  
26
import org.gvsig.fmap.dal.DataStore;
27
import org.gvsig.fmap.dal.DataStoreParameters;
28
import org.gvsig.fmap.dal.NewDataStoreParameters;
29
import org.gvsig.fmap.dal.exception.CreateException;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.exception.RemoveException;
32
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter;
33

  
34
/**
35
 * @author jmvivo
36
 *
37
 */
38
public interface FilesystemServerExplorerProvider extends FilesystemFileFilter {
39

  
40
	public void initialize(FilesystemServerExplorerProviderServices serverExplorer);
41

  
42
	public boolean canCreate();
43

  
44
	public void create(NewDataStoreParameters parameters, boolean overwrite)
45
			throws CreateException;
46

  
47
	public NewDataStoreParameters getCreateParameters() throws DataException;
48

  
49
	public void remove(DataStoreParameters parameters) throws RemoveException;
50

  
51
	public boolean canCreate(NewDataStoreParameters parameters);
52
	
53
	public String getResourceRootPathName(DataStore dataStore);
54
	
55
	public int getMode();
56

  
57
	/**
58
	 * Return true if any mode in the parameter is supported.
59
	 * 
60
	 * @param mode
61
	 * @return
62
	 */
63
	public boolean isMode(int mode);
64
}
0 65

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/spi/FilesystemServerExplorerProviderServices.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.fmap.dal.serverexplorer.filesystem.spi;
26

  
27
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
28
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
29

  
30
public interface FilesystemServerExplorerProviderServices extends
31
		DataServerExplorerProvider, FilesystemServerExplorer {
32

  
33
}
0 34

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/FilesystemServerExplorer.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.fmap.dal.serverexplorer.filesystem;
26

  
27
import java.io.File;
28
import java.util.Iterator;
29
import java.util.List;
30

  
31
import org.gvsig.fmap.dal.DataServerExplorer;
32
import org.gvsig.fmap.dal.DataStore;
33
import org.gvsig.fmap.dal.DataStoreParameters;
34
import org.gvsig.fmap.dal.NewDataStoreParameters;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.exception.FileNotFoundException;
37

  
38
public interface FilesystemServerExplorer extends DataServerExplorer {
39

  
40
	public static final String NAME = "FilesystemExplorer";
41

  
42
	public void setCurrentPath(File path) throws FileNotFoundException;
43

  
44
	public File getCurrentPath();
45

  
46
	public File getRoot();
47
	
48
	public List getProviderNameList(File file);
49

  
50
	public String getProviderName(File file);
51
	
52
	public NewDataStoreParameters getAddParameters(File file)
53
			throws DataException;
54

  
55
	public DataStoreParameters createStoreParameters(File file)
56
			throws DataException;
57
	public DataStoreParameters createStoreParameters(File file, String providerName) 
58
			throws DataException;
59

  
60
//	public DataStore open(File file) throws DataException,
61
//			ValidateDataParametersException;
62

  
63
	public Iterator getFilters();
64

  
65
	public Iterator getFilters(int mode);
66
	
67
	public FilesystemFileFilter getFilter(int mode, String description);
68
	
69
	public FilesystemFileFilter getGenericFilter();
70
	
71
	public File getResourcePath(DataStore dataStore, String resourceName) throws DataException;
72

  
73
}
0 74

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/FilesystemServerExplorerParameters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.serverexplorer.filesystem;
25

  
26
import org.gvsig.fmap.dal.DataServerExplorerParameters;
27
import org.gvsig.fmap.dal.DataTypes;
28
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.dynobject.DelegatedDynObject;
31
import org.gvsig.tools.dynobject.DynClass;
32
import org.gvsig.tools.dynobject.DynField;
33
import org.gvsig.tools.dynobject.DynObjectManager;
34

  
35
public class FilesystemServerExplorerParameters extends AbstractDataParameters
36
		implements DataServerExplorerParameters {
37

  
38
    public static final String DYNCLASS_NAME = "FilesystemServerExplorerParameters";
39

  
40
    private static final String FIELD_ROOT = "root";
41

  
42
	private DelegatedDynObject delegatedDynObject;
43

  
44
	public FilesystemServerExplorerParameters() {
45
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
46
				.getDynObjectManager()
47
				.createDynObject(this.registerDynClass());
48
	}
49

  
50
	private DynClass registerDynClass() {
51
	   	DynObjectManager dynman = ToolsLocator.getDynObjectManager();
52
    	DynClass dynClass = dynman.get(DYNCLASS_NAME);
53
    	DynField field;
54
    	if (dynClass == null) {
55
    		dynClass = dynman.add(DYNCLASS_NAME);
56

  
57
    		field = dynClass.addDynField(FIELD_ROOT);
58
    		field.setType(DataTypes.STRING);
59
    		field.setDescription("Root directory path of the explorer");
60
    		field.setTheTypeOfAvailableValues(DynField.ANY);
61

  
62

  
63
    		field = dynClass.addDynField("initialpath");
64
			field.setType(DataTypes.STRING);
65
			field.setDescription("Initial path of the explorer");
66
			field.setTheTypeOfAvailableValues(DynField.ANY);
67

  
68
    	}
69
    	return dynClass;
70
	}
71

  
72
	public void setRoot(String path) {
73
		this.setDynValue(FIELD_ROOT, path);
74
	}
75

  
76
	public String getRoot() {
77
		return (String) this.getDynValue(FIELD_ROOT);
78
	}
79

  
80
	public void setInitialpath(String path) {
81
		this.setDynValue("initialpath", path);
82
	}
83

  
84
	public String getInitialpath() {
85
		return (String) this.getDynValue("initialpath");
86
	}
87

  
88
	public String getExplorerName() {
89
		return FilesystemServerExplorer.NAME;
90
	}
91

  
92
	protected DelegatedDynObject getDelegatedDynObject() {
93
		return delegatedDynObject;
94
	}
95
}
0 96

  
tags/org.gvsig.desktop-2.0.26/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/impl/DefaultFilesystemServerExplorer.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.serverexplorer.filesystem.impl;
25

  
26
import java.io.File;
27
import java.util.ArrayList;
28
import java.util.HashSet;
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.Set;
32

  
33
import org.gvsig.fmap.dal.DALFileLocator;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataManager;
36
import org.gvsig.fmap.dal.DataServerExplorerParameters;
37
import org.gvsig.fmap.dal.DataStore;
38
import org.gvsig.fmap.dal.DataStoreParameters;
39
import org.gvsig.fmap.dal.NewDataStoreParameters;
40
import org.gvsig.fmap.dal.exception.DataException;
41
import org.gvsig.fmap.dal.exception.FileNotFoundException;
42
import org.gvsig.fmap.dal.exception.InitializeException;
43
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
44
import org.gvsig.fmap.dal.exception.RemoveException;
45
import org.gvsig.fmap.dal.exception.ServerExplorerAddException;
46
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
47
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter;
48
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
49
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
50
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
51
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
52
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
53
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
54
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
55
import org.gvsig.tools.dispose.impl.AbstractDisposable;
56
import org.gvsig.tools.exception.BaseException;
57
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
58

  
59
public class DefaultFilesystemServerExplorer extends AbstractDisposable
60
		implements FilesystemServerExplorerProviderServices,
61
		FilesystemFileFilter {
62

  
63
	FilesystemServerExplorerParameters parameters;
64

  
65
	private File root;
66

  
67
	private File current; // Current path
68

  
69
	private DataServerExplorerProviderServices providerServices;
70

  
71
	private List serverProviders;
72

  
73
	public DefaultFilesystemServerExplorer(
74
			FilesystemServerExplorerParameters parameters,
75
			DataServerExplorerProviderServices services)
76
			throws InitializeException {
77
		this.parameters = parameters;
78
		this.providerServices = services;
79
		if (this.parameters.getRoot() != null) {
80
			this.root = new File(this.parameters.getRoot());
81
		}
82
		if (this.parameters.getInitialpath() != null) {
83
			this.current = new File(this.parameters.getInitialpath());
84
		}
85
		if (this.root == null && this.current == null) {
86
			// throw new InitializeException(this.getName(),
87
			// new IllegalArgumentException());
88
		} else if (this.current == null) {
89
			this.current = new File(this.parameters.getRoot());
90
		}
91
	}
92

  
93
	public DataServerExplorerParameters getParameters() {
94
		return parameters;
95
	}
96

  
97
	protected void doDispose() throws BaseException {
98
		this.parameters = null;
99
		this.root = null;
100
	}
101

  
102
	public List list(int mode) throws DataException {
103
		if (this.current == null) {
104
			throw new IllegalStateException();
105
		}
106
		if (!this.current.exists()) {
107
			new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current);
108
		}
109

  
110
		if (!this.current.isDirectory()) {
111
			new IllegalArgumentException(this.getProviderName()
112
					+ ": Path not a directory '" + this.current + "'");
113
		}
114

  
115
		List files = new ArrayList(); // return files
116
		List providers = this.getProviders(mode); 
117
		String allfiles[] = this.current.list();
118

  
119
		for (int i = 0; i < allfiles.length; i++) {
120
			File file = new File(this.root, allfiles[i]);
121
			Iterator providersit = providers.iterator();
122
			while (providersit.hasNext()) {
123
				FilesystemServerExplorerProvider provider = (FilesystemServerExplorerProvider) providersit
124
						.next();
125
				if( provider.accept(file)) {
126
					DataStoreParameters dsp = this.createStoreParameters(file);
127
					if (dsp != null) {
128
						files.add(dsp);
129
					}
130
					break;
131
				}
132
			}
133
		}
134
		return files;
135
	}
136

  
137
	public List list() throws DataException {
138
		if (this.current == null) {
139
			throw new IllegalStateException(); // FIXME
140
		}
141
		if (!this.current.exists()) {
142
			// TODO crear excepcion de Data??
143
			new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current);
144
		}
145

  
146
		if (!this.current.isDirectory()) {
147
			new IllegalArgumentException(this.getProviderName()
148
					+ ": Path not a directory '" + this.current + "'");
149
		}
150

  
151
		String files[] = this.current.list();
152
		int i;
153
		File theFile;
154
		ArrayList list = new ArrayList();
155
		DataStoreParameters dsp = null;
156

  
157
		for (i = 0; i < files.length; i++) {
158
			theFile = new File(this.root, files[i]);
159
			dsp = this.createStoreParameters(theFile);
160
			if (dsp != null) {
161
				list.add(dsp);
162
			}
163
		}
164
		return list;
165
	}
166

  
167
	public void setCurrentPath(File path) throws FileNotFoundException {
168
		// FIXME Comprobar si es un directorio existente
169
		if (!path.exists()) {
170
			throw new FileNotFoundException(path);
171
		}
172
		if (!path.isDirectory()) {
173
			throw new IllegalArgumentException(path.getPath()
174
					+ " is not a directory");
175
		}
176
		if (!isFromRoot(path)) {
177
			throw new IllegalArgumentException(path.getPath()
178
					+ " is not from root");
179

  
180
		}
181

  
182
		this.current = path;
183
	}
184

  
185
	public File getCurrentPath() {
186
		return this.current;
187
	}
188

  
189
	public File getRoot() {
190
		return this.root;
191
	}
192

  
193
	public void remove(DataStoreParameters dsp) throws RemoveException {
194
		String providerName = dsp.getDataStoreName();
195
		try {
196
			this.checkIsMine(dsp);
197
			FilesystemServerExplorerProvider provider = this
198
					.getProvider(providerName);
199

  
200
			provider.remove(dsp);
201
		} catch (DataException e) {
202
			throw new RemoveException(this.getProviderName(), e);
203
		}
204
	}
205

  
206
	public boolean add(String providerName, NewDataStoreParameters ndsp,
207
			boolean overwrite) throws DataException {
208

  
209
		try {
210
			this.checkIsMine(ndsp);
211
			FilesystemServerExplorerProvider provider = this
212
					.getProvider(providerName);
213

  
214
			ndsp.validate();
215
			provider.create(ndsp, overwrite);
216
			return true; 
217
		} catch (DataException e) {
218
			throw new ServerExplorerAddException(this.getProviderName(), e);
219
		} catch (ValidateDataParametersException e) {
220
			throw new ServerExplorerAddException(this.getProviderName(), e);
221
		}
222
	}
223

  
224
	public boolean canAdd() {
225
		return this.root.canWrite();
226
	}
227

  
228
	public String getProviderName() {
229
		return FilesystemServerExplorer.NAME;
230
	}
231

  
232
	public NewDataStoreParameters getAddParameters(String storeName)
233
			throws DataException {
234
		FilesystemServerExplorerProvider provider = this.getProvider(storeName);
235
		if (provider == null) {
236
			throw new IllegalArgumentException(
237
					"Not registered in this explorer"); // FIXME
238
		}
239

  
240
		NewDataStoreParameters nParams = provider.getCreateParameters();
241
		// nParams.setAttribute("path", this.getCurrentPath().getPath());
242
		return nParams;
243
	}
244

  
245
	public boolean canAdd(String storeName) throws DataException {
246
		if (storeName == null) {
247
			return false;// CanAdd with genericFilter
248
		}
249
		FilesystemServerExplorerProvider provider = this.getProvider(storeName);
250
		if (provider == null) {
251
			throw new IllegalArgumentException(
252
					"Not registered in this explorer"); // FIXME
253
		}
254

  
255
		return provider.canCreate();
256

  
257
	}
258

  
259
	// ==========================================
260

  
261
	private FilesystemServerExplorerProvider getProvider(String storeName)
262
			throws InitializeException, ProviderNotRegisteredException {
263
		Iterator providers = getProviders(FilesystemServerExplorer.MODE_ALL).iterator();
264
		FilesystemServerExplorerProvider provider;
265
		while (providers.hasNext()) {
266
			provider = (FilesystemServerExplorerProvider) providers.next();
267
			if (provider.getDataStoreProviderName().equals(storeName)) {
268
				return provider;
269
			}
270
		}
271
		return null;
272
	}
273

  
274
	private DataManagerProviderServices getManager() {
275
		return (DataManagerProviderServices) DALLocator.getDataManager();
276
	}
277
	
278
	public DataStoreParameters createStoreParameters(File file, String providerName) throws DataException {
279

  
280
		return this.getParametersFor(file, providerName, true);
281
	}
282

  
283
	public DataStoreParameters createStoreParameters(File file) throws DataException {
284

  
285
		return this.getParametersFor(file, null, true);
286
	}
287
	
288
	public DataStoreParameters getParametersFor(File file, String providerName, boolean checksExist) throws DataException {
289
		
290
		if (checksExist) {
291
			if (!file.exists()) {
292
				return null;
293
			}
294
			if (!file.isFile()) {
295
				return null;
296
			}
297
			if (!file.canRead()) {
298
				return null;
299
			}
300
			if (file.isHidden()) { // XXX ???
301
				return null;
302
			}
303
		}
304
		if(providerName == null)
305
			providerName = this.getProviderName(file);
306
		if (providerName != null) {
307
			DataStoreParameters params = this.getManager()
308
			.createStoreParameters(providerName);
309
			((FilesystemStoreParameters) params).setFile(file);
310
			return params;
311

  
312
		}
313
		return null;
314
	}
315
	
316
	public List getProviderNameList(File file) {
317
		Iterator filters = getFilters();
318
		List list = new ArrayList();
319
		while (filters.hasNext()) {
320
			FilesystemFileFilter filter = (FilesystemFileFilter) filters.next();
321
			if (filter.accept(file)) {
322
				list.add(filter.getDataStoreProviderName());
323
			}
324
		}
325
		return list;
326
	}
327

  
328
	public String getProviderName(File file) {
329
		Iterator filters = getFilters();
330
		while (filters.hasNext()) {
331
			FilesystemFileFilter filter = (FilesystemFileFilter) filters.next();
332
			if (filter.accept(file)) {
333
				return filter.getDataStoreProviderName();
334
			}
335
		}
336
		return null;
337
	}
338

  
339
	public List getDataStoreProviderNames() {
340
		Set names = new HashSet();
341
		
342
		Iterator filters = getFilters();
343
		while (filters.hasNext()) {
344
			FilesystemFileFilter filter = (FilesystemFileFilter) filters.next();
345
			names.add(filter.getDataStoreProviderName());
346
		}
347
		return new ArrayList(names);	
348
	}
349

  
350
	private void checkIsMine(DataStoreParameters dsp)
351
			throws IllegalArgumentException, DataException {
352
		// FIXME Exception ???
353
		if (!(dsp instanceof FilesystemStoreParameters)) {
354
			new IllegalArgumentException(
355
					"not instance of FilesystemStoreParameters");
356
		}
357
		Iterator filters = getFilters();
358
		File file = ((FilesystemStoreParameters) dsp).getFile();
359
		if (!this.isFromRoot(file)) {
360
			throw new IllegalArgumentException("worng explorer");
361
		}
362
		FilesystemFileFilter filter;
363
		while (filters.hasNext()) {
364
			filter = (FilesystemFileFilter) filters.next();
365
			if (dsp.getDataStoreName()
366
					.equals(filter.getDataStoreProviderName())) {
367
				return;
368
			}
369
		}
370
		throw new IllegalArgumentException("worng explorer");
371
	}
372

  
373
	private boolean isFromRoot(File file) {
374
		if (this.root == null) {
375
			return true;
376
		}
377
		return file.getAbsolutePath().startsWith(this.root.getAbsolutePath());
378
	}
379

  
380
	public List getProviders() {
381
		if (this.serverProviders == null) {
382
			Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
383
					.getRegisteredProviders();
384
			this.serverProviders = new ArrayList();
385
			Extension ext;
386
			FilesystemServerExplorerProvider provider;
387
			while (iter.hasNext()) {
388
				ext = (Extension) iter.next();
389
				try {
390
					provider = (FilesystemServerExplorerProvider) ext.create();
391
				} catch (Exception e) {
392
					throw new RuntimeException(e);// FIXME !!!
393
				}
394
				provider.initialize(this);
395
				this.serverProviders.add(provider);
396
			}
397
		}
398
		return this.serverProviders;
399
	}
400

  
401
	public List getProviders(int mode) {
402
		Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
403
				.getRegisteredProviders();
404
		List providers = new ArrayList();
405
		Extension ext;
406
		FilesystemServerExplorerProvider provider;
407
		while (iter.hasNext()) {
408
			ext = (Extension) iter.next();
409
			try {
410
				provider = (FilesystemServerExplorerProvider) ext.create();
411
			} catch (Exception e) {
412
				throw new RuntimeException(e);// FIXME !!!
413
			}
414
			if (provider.isMode(mode)) {
415
				provider.initialize(this);
416
				providers.add(provider);
417
			}
418
		}
419
		return providers;
420
	}
421

  
422
	public Iterator getFilters(int mode) {
423
		return this.getProviders(mode).iterator();
424
	}
425
	
426
	public Iterator getFilters() {
427
		return this.getProviders().iterator();
428
	}
429

  
430
	public FilesystemFileFilter getFilter(int mode, final String description ) {
431
		
432
		final List filters = new ArrayList();
433
		Iterator it = this.getFilters(mode);
434
		while( it.hasNext() ) {
435
			filters.add( it.next() );
436
		}
437
		FilesystemFileFilter filter = new FilesystemFileFilter() {
438
			
439
			public boolean accept(File f) {
440
				if (f.isDirectory()) {
441
					return true;
442
				}
443
				for(int i=0; i<filters.size(); i++) {
444
					if( ((FilesystemFileFilter)filters.get(i)).accept(f) ) {
445
						return true;
446
					}
447
				}
448
				return false;
449
			}
450
			
451
			public String getDescription() {
452
				return description;
453
			}
454
			
455
			public String getDataStoreProviderName() {
456
				return null;
457
			}
458
		};
459
		return filter;
460
	}
461

  
462
	public FilesystemFileFilter getGenericFilter() {
463
		// FIXME: Este metodo, getGenericFilter, no tengo claro que deba existir (jjdc)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff