Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / extensionPointsOld / ExtensionBuilder.java @ 40561

History | View | Annotate | Download (3.8 KB)

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.utils.extensionPointsOld;
25

    
26
import java.lang.reflect.Constructor;
27
import java.lang.reflect.InvocationTargetException;
28
import java.util.Map;
29

    
30
/**
31
 * Clase de utilidad usada para crear las extensiones.
32
 * 
33
 * Esta clase presenta un par de metodos estaticos para permitir crear un objeto
34
 * a partir de una clase.
35
 * 
36
 * @author jjdelcerro
37
 * @deprecated @see org.gvsig.tools.extensionPoint.ExtensionBuilder
38
 */
39
public abstract class ExtensionBuilder implements IExtensionBuilder {
40

    
41
        /**
42
         * Crea un objeto de la clase indicada.
43
         * 
44
         * @param cls Clase de la que crear la instancia
45
         * @return
46
         * 
47
         * @throws InstantiationException
48
         * @throws IllegalAccessException
49
         */
50
        public static Object create(Class cls) throws InstantiationException, IllegalAccessException {
51
                Object obj = null;
52

    
53
                if( cls == null ) {
54
                        return null;
55
                }
56
                obj = cls.newInstance();
57
                return obj;
58
        }
59
        
60
        /**
61
         * Crea un objeto de la clase indicada.
62
         * 
63
         * Crea un objeto de la clase indicada pasandole al constructor
64
         * los argumentos indicados en <i>args</i>.
65
         * <br>
66
         * @param cls Clase de la que crear la instancia
67
         * @param args Argumentos que pasar al constructor.
68
         * @return
69
         * 
70
         * @throws SecurityException
71
         * @throws NoSuchMethodException
72
         * @throws IllegalArgumentException
73
         * @throws InstantiationException
74
         * @throws IllegalAccessException
75
         * @throws InvocationTargetException
76
         */
77
        public static Object create(Class cls, Object [] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
78
                Object obj = null;
79
                Constructor create = null;
80
                Class [] types = new Class[args.length];
81
                
82
                if( cls == null ) {
83
                        return null;
84
                }
85
                for( int n=0 ; n<args.length ; n++ ) {
86
                        Object arg = args[n]; 
87
                        types[n] = arg.getClass();
88
                }
89
                create = cls.getConstructor(types);
90
                obj = create.newInstance(args);
91
                return obj;
92
        }
93
        /**
94
         * Crea un objeto de la clase indicada.
95
         * 
96
         * Crea un objeto de la clase indicada pasandole al constructor
97
         * un como argumento un Map..
98
         * <br>
99
         * @param cls Clase de la que crear la instancia
100
         * @param args Map a pasar como argumento al constructor.
101
         * @return
102
         * 
103
         * @throws SecurityException
104
         * @throws NoSuchMethodException
105
         * @throws IllegalArgumentException
106
         * @throws InstantiationException
107
         * @throws IllegalAccessException
108
         * @throws InvocationTargetException
109
         */
110
        public static Object create(Class cls, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
111
                Object obj = null;
112
                Constructor create = null;
113
                Class [] types = new Class[1];
114
                Object [] argsx = new Object[1];
115
                
116
                if( cls == null ) {
117
                        return null;
118
                }
119
                types[0] = Map.class;
120
                argsx[0] = args;
121
                create = cls.getConstructor(types);
122
                obj = create.newInstance(argsx);
123
                return obj;
124
        }
125
}