svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.buffer.impl / src / main / java / org / gvsig / raster / lib / buffer / impl / operations / median / MedianOperationFactory.java @ 44831
History | View | Annotate | Download (4.9 KB)
1 | 44831 | jjdelcerro | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2017 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.raster.lib.buffer.impl.operations.median; |
||
24 | |||
25 | import java.io.IOException; |
||
26 | import java.io.InputStream; |
||
27 | import java.util.Map; |
||
28 | |||
29 | import org.xmlpull.v1.XmlPullParserException; |
||
30 | |||
31 | import org.gvsig.raster.lib.buffer.api.Buffer; |
||
32 | import org.gvsig.raster.lib.buffer.api.operations.Operation; |
||
33 | import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
||
34 | import org.gvsig.tools.ToolsLocator; |
||
35 | import org.gvsig.tools.dynobject.DynObject; |
||
36 | import org.gvsig.tools.dynobject.DynObjectManager; |
||
37 | import org.gvsig.tools.dynobject.DynStruct; |
||
38 | |||
39 | |||
40 | /**
|
||
41 | * @author fdiaz
|
||
42 | *
|
||
43 | */
|
||
44 | public class MedianOperationFactory implements OperationFactory { |
||
45 | public static String NAME="Median"; |
||
46 | public static String DESCRIPTION="Median operation";//FIXME: |
||
47 | private DynStruct definition;
|
||
48 | |||
49 | /**
|
||
50 | *
|
||
51 | */
|
||
52 | public MedianOperationFactory() {
|
||
53 | // TODO Auto-generated constructor stub
|
||
54 | } |
||
55 | |||
56 | /* (non-Javadoc)
|
||
57 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#createParameters()
|
||
58 | */
|
||
59 | @Override
|
||
60 | public DynObject createParameters() {
|
||
61 | DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
||
62 | if (definition == null) { |
||
63 | definition = createParametersDefinition(); |
||
64 | } |
||
65 | DynObject parameters = manager.createDynObject(definition); |
||
66 | return parameters;
|
||
67 | } |
||
68 | |||
69 | /* (non-Javadoc)
|
||
70 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#create()
|
||
71 | */
|
||
72 | @Override
|
||
73 | public Operation create() { |
||
74 | return new MedianOperation(this); |
||
75 | } |
||
76 | |||
77 | /* (non-Javadoc)
|
||
78 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#createParametersDefinition()
|
||
79 | */
|
||
80 | @Override
|
||
81 | public DynStruct createParametersDefinition() {
|
||
82 | return registerParametersDefinition("MedianOperationParameters", "/org/gvsig/raster/lib/buffer/impl/operations/median/MedianOperationParameters.xml"); |
||
83 | } |
||
84 | |||
85 | /* (non-Javadoc)
|
||
86 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#getName()
|
||
87 | */
|
||
88 | @Override
|
||
89 | public String getName() { |
||
90 | return NAME;
|
||
91 | } |
||
92 | |||
93 | /* (non-Javadoc)
|
||
94 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#getDescription()
|
||
95 | */
|
||
96 | @Override
|
||
97 | public String getDescription() { |
||
98 | return DESCRIPTION;
|
||
99 | } |
||
100 | |||
101 | /* (non-Javadoc)
|
||
102 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#isApplicable(org.gvsig.raster.lib.buffer.api.Buffer)
|
||
103 | */
|
||
104 | @Override
|
||
105 | public Applicable isApplicable(Buffer buffer) { |
||
106 | return Applicable.YES;
|
||
107 | } |
||
108 | |||
109 | /* (non-Javadoc)
|
||
110 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#isApplicable(org.gvsig.raster.lib.buffer.api.operations.Operation)
|
||
111 | */
|
||
112 | @Override
|
||
113 | public Applicable isApplicable(Operation operation) { |
||
114 | return Applicable.YES;
|
||
115 | } |
||
116 | |||
117 | protected DynStruct registerParametersDefinition(String name, String filename) { |
||
118 | DynStruct definition = null;
|
||
119 | |||
120 | DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
||
121 | definition = manager.get(name); |
||
122 | if ( definition == null) { |
||
123 | InputStream stream = this.getClass().getResourceAsStream(filename); |
||
124 | if( stream == null ) { |
||
125 | throw new IllegalArgumentException("File '"+filename+"' not found"); |
||
126 | } |
||
127 | Map<String, DynStruct> definitions = null; |
||
128 | try {
|
||
129 | definitions = manager.importDynClassDefinitions(stream, this.getClass().getClassLoader());
|
||
130 | } catch (XmlPullParserException e) {
|
||
131 | throw new IllegalArgumentException("DynClass '"+name+"' can't parse file '"+filename+"'",e); |
||
132 | } catch (IOException e) { |
||
133 | throw new IllegalArgumentException("DynClass '"+name+"' can't parse file '"+filename+"'",e); |
||
134 | } |
||
135 | definition = definitions.get(name); |
||
136 | if ( definition == null) { |
||
137 | throw new IllegalArgumentException("DynClass '"+name+"' not found in file '"+filename+"'"); |
||
138 | } |
||
139 | } |
||
140 | return definition;
|
||
141 | } |
||
142 | |||
143 | } |