Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.algorithm / src / main / java / org / gvsig / raster / algorithm / RasterBaseAlgorithmLibrary.java @ 2443

History | View | Annotate | Download (4.92 KB)

1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 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 2
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.raster.algorithm;
25

    
26
import java.util.List;
27

    
28
import org.gvsig.i18n.Messages;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.extensionpoint.ExtensionPoint;
31
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
32
import org.gvsig.tools.library.AbstractLibrary;
33
import org.gvsig.tools.library.LibraryException;
34

    
35
/**
36
 * Initialization of RasterBaseAlgorithmLibrary library.
37
 * 
38
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
39
 */
40
public class RasterBaseAlgorithmLibrary extends AbstractLibrary {
41
        public static final String         REGISTER_PROCESS_LABEL             = "DataProcess";
42
        public static final String         REGISTER_INPUT_PARAMETERS_LABEL    = "DataProcessInputParameters";
43
        public static final String         REGISTER_OUTPUT_PARAMETERS_LABEL   = "DataProcessOutputParameters";
44

    
45
        /**
46
         * Registers a raster process
47
         */
48
        public static void register(String processLabel, Class<?> process) {
49
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
50
                ExtensionPoint point = extensionPoints.add(REGISTER_PROCESS_LABEL);
51
                point.append(processLabel, "", process);
52
        }
53
        
54
        /**
55
         * Gets the process name 
56
         * @param process
57
         * @return
58
         */
59
        @SuppressWarnings("unchecked")
60
        public static String getProcessName(Class<?> process) {
61
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
62
                ExtensionPoint point = extensionPoints.add(REGISTER_PROCESS_LABEL);
63
                List<String> it = point.getNames();
64
                for (int i = 0; i < it.size(); i++) {
65
                        Class<?> value = point.get(it.get(i)).getExtension();
66
                        if(value == process)
67
                                return it.get(i);
68
                } 
69
                return null;
70
        }
71
        
72
        /**
73
         *  Registers input parameters of a raster process
74
         *  @deprecated Uses ProcessParamsManagement register
75
         */
76
        public static String registerInputParameter(String parameterLabel, Class<?> parameterClass) {
77
                return registerParameter(parameterLabel, parameterClass, REGISTER_INPUT_PARAMETERS_LABEL);
78
        }
79
        
80
        /**
81
         *  Registers output parameters of a raster process
82
         *  @deprecated Uses ProcessParamsManagement register
83
         */
84
        public static String registerOutputParameter(String parameterLabel, Class<?> parameterClass) {
85
                return registerParameter(parameterLabel, parameterClass, REGISTER_OUTPUT_PARAMETERS_LABEL);
86
        }
87
        
88
        /**
89
         * Registers a raster process
90
         * @deprecated Uses ProcessParamsManagement register
91
         */
92
        private static String registerParameter(String parameterLabel, Class<?> parameterClass, String type) {
93
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
94
                ExtensionPoint point = extensionPoints.add(type);
95
                int i = 0;
96
                
97
                //Si no hay un par?metro registrado con ese nombre se registra
98
                if(point.get(parameterLabel) == null) {
99
                        point.append(parameterLabel, "", parameterClass);
100
                        return parameterLabel;
101
                } else {
102
                        //Si hay un par?metro registrado con ese nombre pero los tipos son iguales no se hace nada
103
                        if(point.get(parameterLabel).getExtension() == parameterClass)
104
                                return parameterLabel;
105
                        
106
                        //Buscamos un nombre no registrado para el par?metro a?adiendo sufijos
107
                        String newName = parameterLabel + "_" + i;
108
                        while (point.get(newName) != null && point.get(newName).getExtension() != parameterClass) {
109
                                i++;
110
                                newName = parameterLabel + "_" + i;
111
                        }
112
                        point.append(parameterLabel + "_" + i, "", parameterClass);
113
                }
114
                return parameterLabel + "_" + i;
115
        }
116
        
117
    @Override
118
    protected void doInitialize() throws LibraryException {
119
        // Nothing to do
120
    }
121

    
122
    @Override
123
    protected void doPostInitialize() throws LibraryException {
124
        Messages.addResourceFamily(
125
            "org.gvsig.raster.algorithm.i18n.text", 
126
            RasterBaseAlgorithmLibrary.class.getClassLoader(), 
127
            RasterBaseAlgorithmLibrary.class.getClass().getName());
128
        //registerGeoProcess(new RasterReprojectAlgorithmLibrary());
129
    }
130

    
131
    /**
132
     * Returns the instance of the manager
133
     * @return
134
     */
135
    public static RasterBaseAlgorithmManager getManager() {
136
            return RasterBaseAlgorithmManager.getInstance();
137
    }
138
}