Revision 42602 trunk/org.gvsig.desktop/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

View differences:

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

  
......
32 31
import org.gvsig.tools.dynobject.DynClass;
33 32
import org.gvsig.tools.persistence.PersistenceManager;
34 33

  
35

  
36 34
public class FileResourceParameters extends AbstractResourceParameters {
37 35

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

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

  
42
	private DelegatedDynObject delegatedDynObject;
40
    private DelegatedDynObject delegatedDynObject;
43 41

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

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

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

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

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

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

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

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

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

  
91
	protected DelegatedDynObject getDelegatedDynObject() {
92
		return delegatedDynObject;
93
	}
90
    @Override
91
    protected DelegatedDynObject getDelegatedDynObject() {
92
        return delegatedDynObject;
93
    }
94 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
	 */
95
    /**
96
     * Added "static synchronized" because sometimes there is a
97
     * "DuplicateDynClassException" when user selects more than one file (SHP,
98
     * for example) to be added to the view. "definition" is null but then there
99
     * is an exception because in the meantime another thread has registered it
100
     * (I'm not sure this is the cause, but I cannot imagine another reason)
101
     */
104 102
    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
    		);
103
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
104
        DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME);
105
        if (definition == null) {
106
            definition = (DynClass) manager.addDefinition(
107
                    FileResourceParameters.class,
108
                    DYNCLASS_NAME,
109
                    DYNCLASS_NAME + " persistence definition",
110
                    null,
111
                    null
112
            );
115 113

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

Also available in: Unified diff