Revision 44669
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/coercion/CoerceToDate.java | ||
---|---|---|
1 | 1 |
package org.gvsig.timesupport.impl.coercion; |
2 | 2 |
|
3 |
import java.util.Locale;
|
|
3 |
import java.util.Date;
|
|
4 | 4 |
import org.gvsig.timesupport.RelativeInstant; |
5 | 5 |
import org.gvsig.timesupport.RelativeInterval; |
6 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
6 | 7 |
import org.gvsig.tools.dataTypes.CoercionException; |
7 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
8 |
import org.gvsig.tools.dataTypes.DataTypesManager.CoercionWithLocale; |
|
8 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
9 | 9 |
|
10 | 10 |
/** |
11 | 11 |
* |
12 | 12 |
* @author jjdelcerro |
13 | 13 |
*/ |
14 |
public class CoerceToDate implements CoercionWithLocale{
|
|
14 |
public class CoerceToDate extends AbstractCoercion {
|
|
15 | 15 |
|
16 |
|
|
17 |
public CoerceToDate() { |
|
18 |
} |
|
16 |
public CoerceToDate() { |
|
17 |
} |
|
19 | 18 |
|
20 |
@Override |
|
21 |
public Object coerce(Object o) throws CoercionException { |
|
22 |
return this.coerce(o, null); |
|
19 |
@Override |
|
20 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
21 |
if (value == null || value instanceof Date) { |
|
22 |
return value; |
|
23 | 23 |
} |
24 |
|
|
25 |
@Override |
|
26 |
public Object coerce(Object o, Locale locale) throws CoercionException { |
|
27 |
if( o instanceof RelativeInstant ) { |
|
28 |
return ((RelativeInstant) o).toDate(); |
|
29 |
} |
|
30 |
if( o instanceof RelativeInterval ) { |
|
31 |
return ((RelativeInterval) o).getStart().toDate(); |
|
32 |
} |
|
33 |
throw new CoercionException("Can't convert object to date"); |
|
24 |
if (value instanceof RelativeInstant) { |
|
25 |
return ((RelativeInstant) value).toDate(); |
|
34 | 26 |
} |
35 |
|
|
27 |
if (value instanceof RelativeInterval) { |
|
28 |
return ((RelativeInterval) value).getStart().toDate(); |
|
29 |
} |
|
30 |
throw new CoercionException("Can't convert object to date"); |
|
31 |
} |
|
32 |
|
|
36 | 33 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/coercion/CoerceToInstant.java | ||
---|---|---|
3 | 3 |
import java.text.DateFormat; |
4 | 4 |
import java.text.ParseException; |
5 | 5 |
import java.util.Date; |
6 |
import java.util.Locale; |
|
7 | 6 |
import org.apache.commons.lang3.math.NumberUtils; |
8 | 7 |
import org.gvsig.timesupport.RelativeInstant; |
9 | 8 |
import org.gvsig.timesupport.TimeSupportLocator; |
10 | 9 |
import org.gvsig.timesupport.TimeSupportManager; |
10 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
11 | 11 |
import org.gvsig.tools.dataTypes.CoercionException; |
12 |
import org.gvsig.tools.dataTypes.DataTypesManager.CoercionWithLocale; |
|
12 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
|
13 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
14 |
import org.gvsig.tools.dataTypes.CoercionContextLocale; |
|
13 | 15 |
|
14 | 16 |
/** |
15 | 17 |
* |
16 | 18 |
* @author jjdelcerro |
17 | 19 |
*/ |
18 |
public class CoerceToInstant implements CoercionWithLocale {
|
|
20 |
public class CoerceToInstant extends AbstractCoercion {
|
|
19 | 21 |
|
20 |
public CoerceToInstant() { |
|
21 |
|
|
22 |
public CoerceToInstant() { |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
28 |
if (value == null || value instanceof RelativeInstant) { |
|
29 |
return value; |
|
22 | 30 |
} |
23 |
|
|
24 |
@Override
|
|
25 |
public Object coerce(Object o) throws CoercionException {
|
|
26 |
return this.coerce(o, null);
|
|
31 |
TimeSupportManager manager = TimeSupportLocator.getManager(); |
|
32 |
if (value instanceof Date) {
|
|
33 |
RelativeInstant instant = manager.createRelativeInstant((Date) value);
|
|
34 |
return instant;
|
|
27 | 35 |
} |
28 |
|
|
29 |
public Object coerce(Object o, Locale locale) throws CoercionException { |
|
30 |
if( o == null ) { |
|
31 |
return null; |
|
32 |
} |
|
33 |
if( o instanceof RelativeInstant ) { |
|
34 |
return o; |
|
35 |
} |
|
36 |
TimeSupportManager manager = TimeSupportLocator.getManager(); |
|
37 |
if( o instanceof Date ) { |
|
38 |
RelativeInstant instant = manager.createRelativeInstant((Date)o); |
|
39 |
return instant; |
|
40 |
} |
|
41 |
if( o instanceof Number ) { |
|
42 |
RelativeInstant instant = manager.createRelativeInstant( ((Number)o).longValue()); |
|
43 |
return instant; |
|
44 |
} |
|
45 |
if( o instanceof String ) { |
|
46 |
long milis_l = NumberUtils.toLong((String) o, Long.MIN_VALUE); |
|
47 |
if( milis_l != Long.MIN_VALUE ) { |
|
48 |
RelativeInstant instant = manager.createRelativeInstant(milis_l); |
|
49 |
return instant; |
|
50 |
} |
|
51 |
double milis_d = NumberUtils.toDouble((String) o, Double.NaN); |
|
52 |
if( milis_d != Double.NaN ) { |
|
53 |
RelativeInstant instant = manager.createRelativeInstant((long)milis_d); |
|
54 |
return instant; |
|
55 |
} |
|
56 |
DateFormat df = DateFormat.getDateTimeInstance( |
|
57 |
DateFormat.DEFAULT, |
|
58 |
DateFormat.DEFAULT, |
|
59 |
locale==null? Locale.getDefault():locale |
|
60 |
); |
|
61 |
try { |
|
62 |
Date date = df.parse((String) o); |
|
63 |
RelativeInstant instant = manager.createRelativeInstant(date); |
|
64 |
return instant; |
|
65 |
} catch (ParseException ex) { |
|
66 |
} |
|
67 |
} |
|
68 |
throw new CoercionException("Can't coerce ("+o.getClass().getSimpleName()+") '"+o.toString()+"' to Instant."); |
|
36 |
if (value instanceof Number) { |
|
37 |
RelativeInstant instant = manager.createRelativeInstant(((Number) value).longValue()); |
|
38 |
return instant; |
|
69 | 39 |
} |
40 |
if (value instanceof String) { |
|
41 |
long milis_l = NumberUtils.toLong((String) value, Long.MIN_VALUE); |
|
42 |
if (milis_l != Long.MIN_VALUE) { |
|
43 |
RelativeInstant instant = manager.createRelativeInstant(milis_l); |
|
44 |
return instant; |
|
45 |
} |
|
46 |
double milis_d = NumberUtils.toDouble((String) value, Double.NaN); |
|
47 |
if (milis_d != Double.NaN) { |
|
48 |
RelativeInstant instant = manager.createRelativeInstant((long) milis_d); |
|
49 |
return instant; |
|
50 |
} |
|
51 |
CoercionContextLocale theContext; |
|
52 |
if (context instanceof CoercionContextLocale) { |
|
53 |
theContext = (CoercionContextLocale) context; |
|
54 |
} else { |
|
55 |
theContext = DataTypeUtils.coerceContextDefaultLocale(); |
|
56 |
} |
|
57 |
DateFormat df = DateFormat.getDateTimeInstance( |
|
58 |
DateFormat.DEFAULT, |
|
59 |
DateFormat.DEFAULT, |
|
60 |
theContext.locale() |
|
61 |
); |
|
62 |
try { |
|
63 |
Date date = df.parse((String) value); |
|
64 |
RelativeInstant instant = manager.createRelativeInstant(date); |
|
65 |
return instant; |
|
66 |
} catch (ParseException ex) { |
|
67 |
} |
|
68 |
} |
|
69 |
throw new CoercionException("Can't coerce (" + value.getClass().getSimpleName() + ") '" + value.toString() + "' to Instant."); |
|
70 |
} |
|
70 | 71 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/coercion/CoerceToInterval.java | ||
---|---|---|
3 | 3 |
import java.text.DateFormat; |
4 | 4 |
import java.text.ParseException; |
5 | 5 |
import java.util.Date; |
6 |
import java.util.Locale; |
|
7 | 6 |
import org.apache.commons.lang3.math.NumberUtils; |
8 | 7 |
import org.gvsig.timesupport.RelativeInstant; |
9 | 8 |
import org.gvsig.timesupport.RelativeInterval; |
10 | 9 |
import org.gvsig.timesupport.TimeSupportLocator; |
11 | 10 |
import org.gvsig.timesupport.TimeSupportManager; |
11 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
12 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
12 | 13 |
import org.gvsig.tools.dataTypes.CoercionException; |
13 |
import org.gvsig.tools.dataTypes.DataTypesManager.CoercionWithLocale; |
|
14 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
|
15 |
import org.gvsig.tools.dataTypes.CoercionContextLocale; |
|
14 | 16 |
|
15 | 17 |
/** |
16 | 18 |
* |
17 | 19 |
* @author jjdelcerro |
18 | 20 |
*/ |
19 |
public class CoerceToInterval implements CoercionWithLocale {
|
|
21 |
public class CoerceToInterval extends AbstractCoercion {
|
|
20 | 22 |
|
21 |
public CoerceToInterval() { |
|
22 |
|
|
23 |
public CoerceToInterval() { |
|
24 |
|
|
25 |
} |
|
26 |
|
|
27 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
28 |
if (value == null || value instanceof RelativeInterval) { |
|
29 |
return value; |
|
23 | 30 |
} |
24 |
|
|
25 |
@Override
|
|
26 |
public Object coerce(Object o) throws CoercionException {
|
|
27 |
return this.coerce(o, null);
|
|
31 |
TimeSupportManager manager = TimeSupportLocator.getManager(); |
|
32 |
if (value instanceof RelativeInstant) {
|
|
33 |
RelativeInterval interval = manager.createRelativeInterval(((RelativeInstant) value), ((RelativeInstant) value));
|
|
34 |
return interval;
|
|
28 | 35 |
} |
29 |
|
|
30 |
public Object coerce(Object o, Locale locale) throws CoercionException { |
|
31 |
if( o == null ) { |
|
32 |
return null; |
|
33 |
} |
|
34 |
if( o instanceof RelativeInterval ) { |
|
35 |
return o; |
|
36 |
} |
|
37 |
TimeSupportManager manager = TimeSupportLocator.getManager(); |
|
38 |
if( o instanceof RelativeInstant ) { |
|
39 |
RelativeInterval interval = manager.createRelativeInterval(((RelativeInstant) o), ((RelativeInstant) o)); |
|
40 |
return interval; |
|
41 |
} |
|
42 |
if( o instanceof Date ) { |
|
43 |
RelativeInterval interval = manager.createRelativeInterval(((Date) o).getTime(), ((Date) o).getTime()); |
|
44 |
return interval; |
|
45 |
} |
|
46 |
if( o instanceof Number ) { |
|
47 |
RelativeInterval interval = manager.createRelativeInterval(((Number)o).longValue(), ((Number)o).longValue()); |
|
48 |
return interval; |
|
49 |
} |
|
50 |
if( o instanceof String ) { |
|
51 |
long milis_l = NumberUtils.toLong((String) o, Long.MIN_VALUE); |
|
52 |
if( milis_l != Long.MIN_VALUE ) { |
|
53 |
RelativeInterval interval = manager.createRelativeInterval(milis_l, milis_l); |
|
54 |
return interval; |
|
55 |
} |
|
56 |
double milis_d = NumberUtils.toDouble((String) o, Double.NaN); |
|
57 |
if( milis_d != Double.NaN ) { |
|
58 |
RelativeInterval interval = manager.createRelativeInterval((long)milis_d, (long)milis_d); |
|
59 |
return interval; |
|
60 |
} |
|
61 |
DateFormat df = DateFormat.getDateTimeInstance( |
|
62 |
DateFormat.DEFAULT, |
|
63 |
DateFormat.DEFAULT, |
|
64 |
locale==null? Locale.getDefault():locale |
|
65 |
); |
|
66 |
try { |
|
67 |
Date date = df.parse((String) o); |
|
68 |
RelativeInterval interval = manager.createRelativeInterval(date.getTime(), date.getTime()); |
|
69 |
return interval; |
|
70 |
} catch (ParseException ex) { |
|
71 |
} |
|
72 |
} |
|
73 |
throw new CoercionException("Can't coerce ("+o.getClass().getSimpleName()+") '"+o.toString()+"' to Interval."); |
|
36 |
if (value instanceof Date) { |
|
37 |
RelativeInterval interval = manager.createRelativeInterval(((Date) value).getTime(), ((Date) value).getTime()); |
|
38 |
return interval; |
|
74 | 39 |
} |
40 |
if (value instanceof Number) { |
|
41 |
RelativeInterval interval = manager.createRelativeInterval(((Number) value).longValue(), ((Number) value).longValue()); |
|
42 |
return interval; |
|
43 |
} |
|
44 |
if (value instanceof String) { |
|
45 |
long milis_l = NumberUtils.toLong((String) value, Long.MIN_VALUE); |
|
46 |
if (milis_l != Long.MIN_VALUE) { |
|
47 |
RelativeInterval interval = manager.createRelativeInterval(milis_l, milis_l); |
|
48 |
return interval; |
|
49 |
} |
|
50 |
double milis_d = NumberUtils.toDouble((String) value, Double.NaN); |
|
51 |
if (milis_d != Double.NaN) { |
|
52 |
RelativeInterval interval = manager.createRelativeInterval((long) milis_d, (long) milis_d); |
|
53 |
return interval; |
|
54 |
} |
|
55 |
CoercionContextLocale theContext; |
|
56 |
if (context instanceof CoercionContextLocale) { |
|
57 |
theContext = (CoercionContextLocale) context; |
|
58 |
} else { |
|
59 |
theContext = DataTypeUtils.coerceContextDefaultLocale(); |
|
60 |
} |
|
61 |
DateFormat df = DateFormat.getDateTimeInstance( |
|
62 |
DateFormat.DEFAULT, |
|
63 |
DateFormat.DEFAULT, |
|
64 |
theContext.locale() |
|
65 |
); |
|
66 |
try { |
|
67 |
Date date = df.parse((String) value); |
|
68 |
RelativeInterval interval = manager.createRelativeInterval(date.getTime(), date.getTime()); |
|
69 |
return interval; |
|
70 |
} catch (ParseException ex) { |
|
71 |
} |
|
72 |
} |
|
73 |
throw new CoercionException("Can't coerce (" + value.getClass().getSimpleName() + ") '" + value.toString() + "' to Interval."); |
|
74 |
} |
|
75 | 75 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/TimeSupportDefaultImplLibrary.java | ||
---|---|---|
58 | 58 |
protected void doPostInitialize() throws LibraryException { |
59 | 59 |
//Register the types |
60 | 60 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
61 |
dataTypesManager.setCoercion(DataTypes.INSTANT, new CoerceToInstant());
|
|
62 |
dataTypesManager.setCoercion(DataTypes.INTERVAL, new CoerceToInterval());
|
|
61 |
dataTypesManager.addCoercion(DataTypes.INSTANT, new CoerceToInstant());
|
|
62 |
dataTypesManager.addCoercion(DataTypes.INTERVAL, new CoerceToInterval());
|
|
63 | 63 |
dataTypesManager.addCoercion(DataTypes.DATE, new CoerceToDate()); |
64 | 64 |
|
65 | 65 |
TimeSupportManager timeSupportManager = TimeSupportLocator.getManager(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.time/org.gvsig.expressionevaluator.time.lib/org.gvsig.expressionevaluator.time.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/date/RelativeInstantFunction.java | ||
---|---|---|
11 | 11 |
import org.gvsig.timesupport.RelativeInstant; |
12 | 12 |
import org.gvsig.timesupport.TimeSupportLocator; |
13 | 13 |
import org.gvsig.tools.ToolsLocator; |
14 |
import org.gvsig.tools.dataTypes.Coercion; |
|
14 | 15 |
import org.gvsig.tools.dataTypes.CoercionException; |
15 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
16 | 16 |
|
17 | 17 |
public class RelativeInstantFunction extends AbstractFunction { |
18 | 18 |
|
19 |
private final DataTypesManager.Coercion toInstant;
|
|
19 |
private final Coercion toInstant; |
|
20 | 20 |
|
21 | 21 |
public RelativeInstantFunction() { |
22 | 22 |
super("Date", "RelativeInstant",Range.is(1), |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.time/org.gvsig.expressionevaluator.time.lib/org.gvsig.expressionevaluator.time.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/date/RelativeIntervalFunction.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl.function.date; |
2 | 2 |
|
3 |
import java.text.ParseException; |
|
4 |
import java.text.SimpleDateFormat; |
|
5 |
import java.util.Date; |
|
6 | 3 |
import java.util.Objects; |
7 | 4 |
import org.apache.commons.lang3.Range; |
8 | 5 |
import org.gvsig.expressionevaluator.Interpreter; |
9 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 | 7 |
import org.gvsig.timesupport.DataTypes; |
11 |
import org.gvsig.timesupport.Instant; |
|
12 | 8 |
import org.gvsig.timesupport.RelativeInstant; |
13 | 9 |
import org.gvsig.timesupport.RelativeInterval; |
14 | 10 |
import org.gvsig.timesupport.TimeSupportLocator; |
15 | 11 |
import org.gvsig.tools.ToolsLocator; |
12 |
import org.gvsig.tools.dataTypes.Coercion; |
|
16 | 13 |
import org.gvsig.tools.dataTypes.CoercionException; |
17 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
18 | 14 |
|
19 | 15 |
public class RelativeIntervalFunction extends AbstractFunction { |
20 | 16 |
|
21 |
private final DataTypesManager.Coercion toInstant;
|
|
17 |
private final Coercion toInstant; |
|
22 | 18 |
|
23 | 19 |
public RelativeIntervalFunction() { |
24 | 20 |
super("Date", "RelativeInterval",Range.is(2), |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CaseFunction.java | ||
---|---|---|
7 | 7 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
8 | 8 |
import org.gvsig.tools.ToolsLocator; |
9 | 9 |
import org.gvsig.tools.dataTypes.DataTypes; |
10 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
10 |
import org.gvsig.tools.dataTypes.Coercion; |
|
11 | 11 |
|
12 | 12 |
public class CaseFunction extends AbstractFunction { |
13 | 13 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/typeconversion/ToLongFunction.java | ||
---|---|---|
6 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 7 |
import org.gvsig.tools.ToolsLocator; |
8 | 8 |
import org.gvsig.tools.dataTypes.DataTypes; |
9 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
9 |
import org.gvsig.tools.dataTypes.Coercion; |
|
10 | 10 |
|
11 | 11 |
public class ToLongFunction extends AbstractFunction { |
12 | 12 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/typeconversion/ToFloatFunction.java | ||
---|---|---|
6 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 7 |
import org.gvsig.tools.ToolsLocator; |
8 | 8 |
import org.gvsig.tools.dataTypes.DataTypes; |
9 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
9 |
import org.gvsig.tools.dataTypes.Coercion; |
|
10 | 10 |
|
11 | 11 |
public class ToFloatFunction extends AbstractFunction { |
12 | 12 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/typeconversion/CastFunction.java | ||
---|---|---|
10 | 10 |
import org.gvsig.tools.dataTypes.DataType; |
11 | 11 |
import org.gvsig.tools.dataTypes.DataTypes; |
12 | 12 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
13 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
13 |
import org.gvsig.tools.dataTypes.Coercion; |
|
14 | 14 |
|
15 | 15 |
public class CastFunction extends AbstractFunction { |
16 | 16 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/typeconversion/ToStrFunction.java | ||
---|---|---|
6 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 7 |
import org.gvsig.tools.ToolsLocator; |
8 | 8 |
import org.gvsig.tools.dataTypes.DataTypes; |
9 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
9 |
import org.gvsig.tools.dataTypes.Coercion; |
|
10 | 10 |
|
11 | 11 |
public class ToStrFunction extends AbstractFunction { |
12 | 12 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/typeconversion/ToDoubleFunction.java | ||
---|---|---|
6 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 7 |
import org.gvsig.tools.ToolsLocator; |
8 | 8 |
import org.gvsig.tools.dataTypes.DataTypes; |
9 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
9 |
import org.gvsig.tools.dataTypes.Coercion; |
|
10 | 10 |
|
11 | 11 |
public class ToDoubleFunction extends AbstractFunction { |
12 | 12 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/typeconversion/ToIntegerFunction.java | ||
---|---|---|
6 | 6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 7 |
import org.gvsig.tools.ToolsLocator; |
8 | 8 |
import org.gvsig.tools.dataTypes.DataTypes; |
9 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
9 |
import org.gvsig.tools.dataTypes.Coercion; |
|
10 | 10 |
|
11 | 11 |
public class ToIntegerFunction extends AbstractFunction { |
12 | 12 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/coercion/CoerceToString.java | ||
---|---|---|
24 | 24 |
package org.gvsig.expressionevaluator.impl.coercion; |
25 | 25 |
|
26 | 26 |
import org.gvsig.expressionevaluator.Expression; |
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
27 | 28 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
29 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
29 | 30 |
|
30 | 31 |
/** |
31 | 32 |
* Convert a Expression to String. |
32 | 33 |
* |
33 | 34 |
*/ |
34 |
public class CoerceToString implements Coercion {
|
|
35 |
public class CoerceToString extends AbstractCoercion {
|
|
35 | 36 |
|
36 |
public CoerceToString() {
|
|
37 |
// Do nothing
|
|
38 |
}
|
|
37 |
public CoerceToString() { |
|
38 |
// Do nothing |
|
39 |
} |
|
39 | 40 |
|
40 |
@Override |
|
41 |
public Object coerce(Object value) throws CoercionException { |
|
42 |
try { |
|
43 |
if (value == null || value instanceof String) { |
|
44 |
return value; |
|
45 |
} |
|
46 |
if (value instanceof Expression) { |
|
47 |
return ((Expression) value).getPhrase(); |
|
48 |
} |
|
49 |
} catch (Exception e) { |
|
50 |
throw new CoercionException(e); |
|
51 |
} |
|
52 |
throw new CoercionException(); |
|
41 |
@Override |
|
42 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
43 |
if (value == null || value instanceof String) { |
|
44 |
return value; |
|
53 | 45 |
} |
46 |
try { |
|
47 |
if (value instanceof Expression) { |
|
48 |
return ((Expression) value).getPhrase(); |
|
49 |
} |
|
50 |
} catch (Exception e) { |
|
51 |
throw new CoercionException(e); |
|
52 |
} |
|
53 |
throw new CoercionException(); |
|
54 |
} |
|
54 | 55 |
|
55 | 56 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/coercion/CoerceToExpression.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.expressionevaluator.Expression; |
27 | 27 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
28 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
28 | 29 |
import org.gvsig.tools.dataTypes.CoercionException; |
29 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
30 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
30 | 31 |
|
31 | 32 |
/** |
32 | 33 |
* Convert a object to Expression. |
33 | 34 |
* |
34 | 35 |
*/ |
35 |
public class CoerceToExpression implements Coercion { |
|
36 |
@SuppressWarnings("UseSpecificCatch") |
|
37 |
public class CoerceToExpression extends AbstractCoercion { |
|
36 | 38 |
|
37 |
@Override |
|
38 |
public Object coerce(Object value) throws CoercionException { |
|
39 |
try { |
|
40 |
if (value == null || value instanceof Expression) { |
|
41 |
return value; |
|
42 |
} |
|
43 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
44 |
expression.setPhrase(value.toString()); |
|
45 |
return expression; |
|
46 |
} catch (Exception e) { |
|
47 |
throw new CoercionException(e); |
|
48 |
} |
|
49 |
|
|
39 |
@Override |
|
40 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
41 |
if (value == null || value instanceof Expression) { |
|
42 |
return value; |
|
50 | 43 |
} |
44 |
try { |
|
45 |
Expression expression = ExpressionEvaluatorLocator.getManager().createExpression(); |
|
46 |
expression.setPhrase(value.toString()); |
|
47 |
return expression; |
|
48 |
} catch (Exception e) { |
|
49 |
throw new CoercionException(e); |
|
50 |
} |
|
51 | 51 |
|
52 |
} |
|
53 |
|
|
52 | 54 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/ExpressionEvaluatorImplLibrary.java | ||
---|---|---|
51 | 51 |
|
52 | 52 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
53 | 53 |
|
54 |
dataTypesManager.setCoercion(DataTypes.EXPRESSION, new CoerceToExpression());
|
|
54 |
dataTypesManager.addCoercion(DataTypes.EXPRESSION, new CoerceToExpression());
|
|
55 | 55 |
dataTypesManager.addCoercion(DataTypes.STRING,new CoerceToString()); |
56 | 56 |
|
57 | 57 |
ToolsLocator.registerScriptManager(DefaultExpressionEvaluatorManager.class); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/DefaultExpressionPickerController.java | ||
---|---|---|
29 | 29 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
30 | 30 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
31 | 31 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
32 |
import org.gvsig.tools.dataTypes.Coercion; |
|
32 | 33 |
import org.gvsig.tools.i18n.I18nManager; |
33 | 34 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
34 | 35 |
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue; |
... | ... | |
211 | 212 |
@Override |
212 | 213 |
public void coerceAndSet(Object value) { |
213 | 214 |
try { |
214 |
DataTypesManager.Coercion toExpression = ToolsLocator.getDataTypesManager().getCoercion(DataTypes.EXPRESSION);
|
|
215 |
Coercion toExpression = ToolsLocator.getDataTypesManager().getCoercion(DataTypes.EXPRESSION); |
|
215 | 216 |
this.set((Expression) toExpression.coerce(value)); |
216 | 217 |
} catch (CoercionException ex) { |
217 | 218 |
throw new IllegalArgumentException("Can't converto to color", ex); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.shape/src/main/java/org/gvsig/export/shape/service/ExportShapeService.java | ||
---|---|---|
47 | 47 |
import org.gvsig.fmap.geom.primitive.Surface; |
48 | 48 |
import org.gvsig.fmap.geom.type.GeometryType; |
49 | 49 |
import org.gvsig.tools.ToolsLocator; |
50 |
import org.gvsig.tools.dataTypes.Coercion; |
|
50 | 51 |
import org.gvsig.tools.dataTypes.CoercionException; |
51 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
52 | 52 |
import org.gvsig.tools.dispose.DisposableIterator; |
53 | 53 |
import org.gvsig.tools.dispose.DisposeUtils; |
54 | 54 |
import org.gvsig.tools.util.HasAFile; |
... | ... | |
272 | 272 |
|
273 | 273 |
List<Geometry> extracted; |
274 | 274 |
Geometry gitem; |
275 |
DataTypesManager.Coercion toGeometry = ToolsLocator.getDataTypesManager() |
|
276 |
.get(DataTypes.GEOMETRY).getCoercion(); |
|
275 |
Coercion toGeometry = ToolsLocator.getDataTypesManager().getCoercion(DataTypes.GEOMETRY); |
|
277 | 276 |
|
278 | 277 |
//Usefull for reproject |
279 | 278 |
ExportServiceManager serviceManager = ExportLocator.getServiceManager(); |
... | ... | |
415 | 414 |
efad.setType(att.getDataType()); |
416 | 415 |
efad.setSize(att.getSize()); |
417 | 416 |
efad.setPrecision(att.getPrecision()); |
417 |
efad.setScale(att.getScale()); |
|
418 | 418 |
|
419 | 419 |
if (att.getDataType().getType() == DataTypes.GEOMETRY) { |
420 | 420 |
efad.setGeometryType(att.getGeomType()); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.newlayer/org.gvsig.newlayer.lib/org.gvsig.newlayer.lib.impl/src/main/java/org/gvsig/newlayer/impl/FeatureTypePanel.java | ||
---|---|---|
860 | 860 |
// TODO Improve this? |
861 | 861 |
// Half of the size dedicated |
862 | 862 |
// to precision (at least 1) |
863 |
efad1.setPrecision(Math.max(1, fieldLength/2)); |
|
863 |
efad1.setPrecision(fieldLength); |
|
864 |
efad1.setScale(Math.max(1, fieldLength/2)); |
|
864 | 865 |
} |
865 | 866 |
|
866 | 867 |
if (dataType.getType() == DataTypes.GEOMETRY) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/spatialindex/AbstractSpatialIndex.java | ||
---|---|---|
34 | 34 |
import org.gvsig.tools.ToolsLocator; |
35 | 35 |
import org.gvsig.tools.dataTypes.CoercionException; |
36 | 36 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
37 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
37 |
import org.gvsig.tools.dataTypes.Coercion; |
|
38 | 38 |
import org.gvsig.tools.dynobject.DynObject; |
39 | 39 |
import org.gvsig.tools.service.Manager; |
40 | 40 |
import org.gvsig.tools.visitor.Visitor; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/coerce/CoerceToString.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.geom.jts.coerce; |
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
27 | 28 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
29 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
29 | 30 |
|
30 | 31 |
/** |
31 | 32 |
* Convert a Geometry to String encoded as WKT. |
32 |
*
|
|
33 |
*
|
|
33 |
* |
|
34 |
* |
|
34 | 35 |
* @author gvSIG Team |
35 | 36 |
* @version $Id$ |
36 |
*
|
|
37 |
* |
|
37 | 38 |
*/ |
38 |
public class CoerceToString implements Coercion { |
|
39 |
@SuppressWarnings("UseSpecificCatch") |
|
40 |
public class CoerceToString extends AbstractCoercion { |
|
39 | 41 |
|
40 |
Coercion previous = null; |
|
41 |
|
|
42 |
public CoerceToString() { |
|
43 |
// Do nothing |
|
44 |
} |
|
45 |
|
|
46 |
public CoerceToString(Coercion previous) { |
|
47 |
this.previous = previous; |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
public Object coerce(Object value) throws CoercionException { |
|
52 |
try { |
|
53 |
if( value == null || value instanceof String ) { |
|
54 |
return value; |
|
55 |
} |
|
56 |
if( value instanceof Geometry ) { |
|
57 |
return ((Geometry)value).convertToWKT(); |
|
58 |
} |
|
59 |
if( previous != null ) { |
|
60 |
return previous.coerce(value); |
|
61 |
} |
|
62 |
} catch (Exception e) { |
|
63 |
throw new CoercionException(e); |
|
64 |
} |
|
65 |
throw new CoercionException(); |
|
66 |
} |
|
42 |
public CoerceToString() { |
|
43 |
// Do nothing |
|
44 |
} |
|
67 | 45 |
|
46 |
@Override |
|
47 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
48 |
if (value == null || value instanceof String) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
try { |
|
52 |
if (value instanceof Geometry) { |
|
53 |
return ((Geometry) value).convertToWKT(); |
|
54 |
} |
|
55 |
} catch (Exception e) { |
|
56 |
throw new CoercionException(e); |
|
57 |
} |
|
58 |
throw new CoercionException(); |
|
59 |
} |
|
60 |
|
|
68 | 61 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/coerce/CoerceToGeometry.java | ||
---|---|---|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.fmap.geom.GeometryLocator; |
28 | 28 |
import org.gvsig.fmap.geom.GeometryManager; |
29 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
29 | 30 |
import org.gvsig.tools.dataTypes.CoercionException; |
30 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
31 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
31 | 32 |
|
32 | 33 |
/** |
33 | 34 |
* Convert a object to Geometry. |
... | ... | |
41 | 42 |
* |
42 | 43 |
*/ |
43 | 44 |
@SuppressWarnings("UseSpecificCatch") |
44 |
public class CoerceToGeometry implements Coercion {
|
|
45 |
public class CoerceToGeometry extends AbstractCoercion {
|
|
45 | 46 |
|
46 |
public Object coerce(Object value) throws CoercionException { |
|
47 |
try { |
|
48 |
if (value == null || value instanceof Geometry) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
Geometry geom; |
|
52 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
53 |
if (value instanceof byte[]) { |
|
54 |
geom = manager.createFrom((byte[]) value); |
|
55 |
} else { |
|
56 |
// Si no puede pasear el WKT devuelbe null y no lanza una |
|
57 |
// excepcion. |
|
58 |
geom = manager.createFrom(value.toString()); |
|
59 |
} |
|
60 |
if (geom == null) { |
|
61 |
throw new CoercionException(); |
|
62 |
} |
|
63 |
return geom; |
|
64 |
} catch (Exception e) { |
|
65 |
throw new CoercionException(e); |
|
66 |
} |
|
67 |
|
|
47 |
@Override |
|
48 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
49 |
if (value == null || value instanceof Geometry) { |
|
50 |
return value; |
|
68 | 51 |
} |
52 |
try { |
|
53 |
Geometry geom; |
|
54 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
55 |
if (value instanceof byte[]) { |
|
56 |
geom = manager.createFrom((byte[]) value); |
|
57 |
} else { |
|
58 |
// Si no puede pasear el WKT devuelbe null y no lanza una |
|
59 |
// excepcion. |
|
60 |
geom = manager.createFrom(value.toString()); |
|
61 |
} |
|
62 |
if (geom == null) { |
|
63 |
throw new CoercionException(); |
|
64 |
} |
|
65 |
return geom; |
|
66 |
} catch (Exception e) { |
|
67 |
throw new CoercionException(e); |
|
68 |
} |
|
69 | 69 |
|
70 |
} |
|
71 |
|
|
70 | 72 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/coerce/CoerceToEnvelope.java | ||
---|---|---|
27 | 27 |
import org.gvsig.fmap.geom.GeometryLocator; |
28 | 28 |
import org.gvsig.fmap.geom.GeometryManager; |
29 | 29 |
import org.gvsig.fmap.geom.primitive.Envelope; |
30 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
30 | 31 |
import org.gvsig.tools.dataTypes.CoercionException; |
31 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
32 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
32 | 33 |
|
33 | 34 |
/** |
34 | 35 |
* Convert a object to Envelope. |
... | ... | |
42 | 43 |
* |
43 | 44 |
*/ |
44 | 45 |
@SuppressWarnings("UseSpecificCatch") |
45 |
public class CoerceToEnvelope implements Coercion {
|
|
46 |
public class CoerceToEnvelope extends AbstractCoercion {
|
|
46 | 47 |
|
47 |
@Override |
|
48 |
public Object coerce(Object value) throws CoercionException { |
|
49 |
try { |
|
50 |
if (value == null || value instanceof Envelope) { |
|
51 |
return value; |
|
52 |
} |
|
53 |
if (value instanceof Geometry) { |
|
54 |
return ((Geometry) value).getEnvelope(); |
|
55 |
} |
|
56 |
Geometry geom; |
|
57 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
58 |
if (value instanceof byte[]) { |
|
59 |
geom = manager.createFrom((byte[]) value); |
|
60 |
} else { |
|
61 |
geom = manager.createFrom(value.toString()); |
|
62 |
} |
|
63 |
if (geom == null) { |
|
64 |
throw new CoercionException(); |
|
65 |
} |
|
66 |
return geom.getEnvelope(); |
|
67 |
} catch (Exception e) { |
|
68 |
throw new CoercionException(e); |
|
69 |
} |
|
70 |
|
|
48 |
@Override |
|
49 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
50 |
if (value == null || value instanceof Envelope) { |
|
51 |
return value; |
|
71 | 52 |
} |
53 |
try { |
|
54 |
if (value instanceof Geometry) { |
|
55 |
return ((Geometry) value).getEnvelope(); |
|
56 |
} |
|
57 |
Geometry geom; |
|
58 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
59 |
if (value instanceof byte[]) { |
|
60 |
geom = manager.createFrom((byte[]) value); |
|
61 |
} else { |
|
62 |
geom = manager.createFrom(value.toString()); |
|
63 |
} |
|
64 |
if (geom == null) { |
|
65 |
throw new CoercionException(); |
|
66 |
} |
|
67 |
return geom.getEnvelope(); |
|
68 |
} catch (Exception e) { |
|
69 |
throw new CoercionException(e); |
|
70 |
} |
|
72 | 71 |
|
72 |
} |
|
73 |
|
|
73 | 74 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/coerce/CoerceToByteArray.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.geom.jts.coerce; |
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
28 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
27 | 29 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
30 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
29 | 31 |
|
30 | 32 |
/** |
31 | 33 |
* Convert a Geometry to Byte Array encoded as WKB. |
... | ... | |
34 | 36 |
* @version $Id$ |
35 | 37 |
* |
36 | 38 |
*/ |
37 |
public class CoerceToByteArray implements Coercion { |
|
39 |
@SuppressWarnings("UseSpecificCatch") |
|
40 |
public class CoerceToByteArray extends AbstractCoercion { |
|
38 | 41 |
|
39 |
Coercion previous = null; |
|
42 |
public CoerceToByteArray() { |
|
43 |
// Do nothing |
|
44 |
} |
|
40 | 45 |
|
41 |
public CoerceToByteArray() { |
|
42 |
// Do nothing |
|
43 |
} |
|
46 |
@Override |
|
47 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
48 |
if (value == null || value instanceof Byte[]) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
try { |
|
52 |
if (value instanceof Geometry) { |
|
53 |
return ((Geometry) value).convertToWKB(); |
|
54 |
} |
|
55 |
} catch (Exception e) { |
|
56 |
throw new CoercionException(e); |
|
57 |
} |
|
58 |
throw new CoercionException(); |
|
59 |
} |
|
44 | 60 |
|
45 |
public CoerceToByteArray(Coercion previous) { |
|
46 |
this.previous = previous; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
public Object coerce(Object value) throws CoercionException { |
|
51 |
try { |
|
52 |
if( value == null || value instanceof byte[] ) { |
|
53 |
return value; |
|
54 |
} |
|
55 |
if( value instanceof Geometry ) { |
|
56 |
return ((Geometry)value).convertToWKB(); |
|
57 |
} |
|
58 |
if( previous != null ) { |
|
59 |
return previous.coerce(value); |
|
60 |
} |
|
61 |
} catch (Exception e) { |
|
62 |
throw new CoercionException(e); |
|
63 |
} |
|
64 |
throw new CoercionException(); |
|
65 |
} |
|
66 |
|
|
67 | 61 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/DefaultGeometryLibrary.java | ||
---|---|---|
134 | 134 |
|
135 | 135 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
136 | 136 |
|
137 |
dataTypesManager.setCoercion(DataTypes.GEOMETRY, new CoerceToGeometry()); |
|
138 |
dataTypesManager.setCoercion(DataTypes.ENVELOPE, new CoerceToEnvelope()); |
|
139 |
dataTypesManager.setCoercion(DataTypes.STRING, |
|
140 |
new CoerceToString(dataTypesManager.getCoercion(DataTypes.STRING))); |
|
141 |
dataTypesManager.setCoercion(DataTypes.BYTEARRAY, |
|
142 |
new CoerceToByteArray(dataTypesManager.getCoercion(DataTypes.BYTEARRAY))); |
|
137 |
dataTypesManager.addCoercion(DataTypes.GEOMETRY, new CoerceToGeometry()); |
|
138 |
dataTypesManager.addCoercion(DataTypes.ENVELOPE, new CoerceToEnvelope()); |
|
139 |
dataTypesManager.addCoercion(DataTypes.STRING, new CoerceToString()); |
|
140 |
dataTypesManager.addCoercion(DataTypes.BYTEARRAY,new CoerceToByteArray()); |
|
143 | 141 |
|
144 | 142 |
GeometryOperation.OPERATION_INTERSECTS_CODE = |
145 | 143 |
geometryManager.getGeometryOperationCode(GeometryOperation.OPERATION_INTERSECTS_NAME); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.api/pom.xml | ||
---|---|---|
41 | 41 |
<type>test-jar</type> |
42 | 42 |
<scope>test</scope> |
43 | 43 |
</dependency> |
44 |
|
|
44 | 45 |
<dependency> |
45 | 46 |
<groupId>org.gvsig</groupId> |
46 | 47 |
<artifactId>org.gvsig.tools.util.api</artifactId> |
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/feature/spi/simpleprovider/AutomaticDetectionOfTypes.java | ||
---|---|---|
8 | 8 |
import java.util.Objects; |
9 | 9 |
import org.gvsig.fmap.dal.DataTypes; |
10 | 10 |
import org.gvsig.tools.ToolsLocator; |
11 |
import org.gvsig.tools.dataTypes.Coercion; |
|
12 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
13 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
|
11 | 14 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
12 | 15 |
|
13 | 16 |
/** |
... | ... | |
25 | 28 |
public boolean possibleInt = true; |
26 | 29 |
public boolean possibleFloat = true; |
27 | 30 |
public boolean possibleDouble = true; |
31 |
public boolean possibleDecimal = true; |
|
28 | 32 |
public boolean possibleLong = true; |
29 | 33 |
public boolean possibleURL = true; |
30 | 34 |
public boolean possibleDate = true; |
... | ... | |
64 | 68 |
locale = Locale.getDefault(); |
65 | 69 |
} |
66 | 70 |
DataTypesManager typeManager = ToolsLocator.getDataTypesManager(); |
67 |
DataTypesManager.CoercionWithLocale toDouble = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.DOUBLE); |
|
68 |
DataTypesManager.CoercionWithLocale toFloat = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.FLOAT); |
|
69 |
DataTypesManager.CoercionWithLocale toDate = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.DATE); |
|
70 |
DataTypesManager.CoercionWithLocale toInt = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.INT); |
|
71 |
DataTypesManager.CoercionWithLocale toLong = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.LONG); |
|
72 |
DataTypesManager.Coercion toGeom = typeManager.getCoercion(DataTypes.GEOMETRY); |
|
73 |
|
|
71 |
Coercion toDecimal = typeManager.getCoercion(DataTypes.DECIMAL); |
|
72 |
Coercion toDouble = typeManager.getCoercion(DataTypes.DOUBLE); |
|
73 |
Coercion toFloat = typeManager.getCoercion(DataTypes.FLOAT); |
|
74 |
Coercion toDate = typeManager.getCoercion(DataTypes.DATE); |
|
75 |
Coercion toInt = typeManager.getCoercion(DataTypes.INT); |
|
76 |
Coercion toLong = typeManager.getCoercion(DataTypes.LONG); |
|
77 |
Coercion toGeom = typeManager.getCoercion(DataTypes.GEOMETRY); |
|
78 |
CoercionContext coercionContext = DataTypeUtils.coerceContextLocale(locale); |
|
79 |
|
|
74 | 80 |
List<Object> row = rows.read(); |
75 | 81 |
lineno++; |
76 | 82 |
|
... | ... | |
81 | 87 |
} |
82 | 88 |
String rawvalue = Objects.toString(row.get(i),null); |
83 | 89 |
PossibleDataType possibleDataType = possibleDataTypes.get(i); |
90 |
if (possibleDataType.possibleDecimal) { |
|
91 |
try { |
|
92 |
toDecimal.coerce(rawvalue, coercionContext); |
|
93 |
possibleDataType.possibleDecimal = true; |
|
94 |
} catch (Exception ex) { |
|
95 |
possibleDataType.possibleDecimal = false; |
|
96 |
} |
|
97 |
} |
|
84 | 98 |
if (possibleDataType.possibleDouble) { |
85 | 99 |
try { |
86 |
toDouble.coerce(rawvalue, locale);
|
|
100 |
toDouble.coerce(rawvalue, coercionContext);
|
|
87 | 101 |
possibleDataType.possibleDouble = true; |
88 | 102 |
} catch (Exception ex) { |
89 | 103 |
possibleDataType.possibleDouble = false; |
... | ... | |
91 | 105 |
} |
92 | 106 |
if (possibleDataType.possibleFloat) { |
93 | 107 |
try { |
94 |
toFloat.coerce(rawvalue, locale);
|
|
108 |
toFloat.coerce(rawvalue, coercionContext);
|
|
95 | 109 |
possibleDataType.possibleFloat = true; |
96 | 110 |
} catch (Exception ex) { |
97 | 111 |
possibleDataType.possibleFloat = false; |
... | ... | |
105 | 119 |
} |
106 | 120 |
if (possibleDataType.possibleDate) { |
107 | 121 |
try { |
108 |
toDate.coerce(rawvalue, locale);
|
|
122 |
toDate.coerce(rawvalue, coercionContext);
|
|
109 | 123 |
possibleDataType.possibleDate = true; |
110 | 124 |
} catch (Exception ex) { |
111 | 125 |
possibleDataType.possibleDate = false; |
... | ... | |
141 | 155 |
types[n++] = DataTypes.LONG; |
142 | 156 |
continue; |
143 | 157 |
} |
158 |
if (possibleDataType.possibleDecimal) { |
|
159 |
types[n++] = DataTypes.DECIMAL; |
|
160 |
continue; |
|
161 |
} |
|
144 | 162 |
if (possibleDataType.possibleFloat) { |
145 | 163 |
// Forzamos los float a double para evitar perder precision |
146 | 164 |
types[n++] = DataTypes.DOUBLE; |
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/feature/spi/simpleprovider/SimpleSequentialReaderStoreProvider.java | ||
---|---|---|
79 | 79 |
import org.gvsig.fmap.geom.primitive.Point; |
80 | 80 |
import org.gvsig.fmap.geom.type.GeometryType; |
81 | 81 |
import org.gvsig.tools.ToolsLocator; |
82 |
import org.gvsig.tools.dataTypes.Coercion; |
|
83 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
82 | 84 |
import org.gvsig.tools.dataTypes.CoercionException; |
83 | 85 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
84 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
85 |
import org.gvsig.tools.dataTypes.DataTypesManager.CoercionWithLocale; |
|
86 | 86 |
import org.gvsig.tools.dispose.Disposable; |
87 | 87 |
import org.gvsig.tools.dispose.DisposeUtils; |
88 | 88 |
import org.gvsig.tools.dynobject.Tags; |
... | ... | |
1109 | 1109 |
readerData.setFeatureTypes(ftypes, ftype); |
1110 | 1110 |
|
1111 | 1111 |
Coercion coercion[] = new Coercion[ftype.size()]; |
1112 |
CoercionContext coercionContext[] = new CoercionContext[ftype.size()]; |
|
1112 | 1113 |
int sizes[] = new int[ftype.size()]; |
1113 | 1114 |
for ( int i = 0; i < ftype.size(); i++ ) { |
1114 | 1115 |
sizes[i] = -1; |
1115 | 1116 |
FeatureAttributeDescriptor ad = ftype.getAttributeDescriptor(i); |
1116 |
coercion[i] = ad.getDataType().getCoercion(); |
|
1117 |
coercion[i] = ad.getCoercion(); |
|
1118 |
coercionContext[i] = ad.getCoercionContext(); |
|
1117 | 1119 |
if ( ad.getDataType().getType() == DataTypes.STRING ) { |
1118 | 1120 |
if ( ad.getSize() == 0 ) { |
1119 | 1121 |
// Es un string y no tiene un size asignado. |
... | ... | |
1154 | 1156 |
if( rawvalue instanceof String && StringUtils.isBlank((String)rawvalue) ) { |
1155 | 1157 |
rawvalue = null; |
1156 | 1158 |
} |
1157 |
Object value; |
|
1158 |
if ( locale != null && coercion[i] instanceof CoercionWithLocale ) { |
|
1159 |
value = ((CoercionWithLocale) (coercion[i])).coerce(rawvalue, locale); |
|
1160 |
} else { |
|
1161 |
value = coercion[i].coerce(rawvalue); |
|
1162 |
} |
|
1159 |
Object value = coercion[i].coerce(rawvalue, coercionContext[i]); |
|
1163 | 1160 |
feature.set(i, value); |
1164 | 1161 |
if ( sizes[i] >= 0 && value != null ) { |
1165 | 1162 |
int x = ((String) value).length(); |
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/serverexplorer/filesystem/FilesystemServerExplorer.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
public interface FilesystemServerExplorer extends DataServerExplorer { |
38 | 38 |
|
39 |
public static final String NAME = "FilesystemExplorer";
|
|
39 |
public static final String NAME = FILESYSTEM_SERVER_EXPLORER_NAME;
|
|
40 | 40 |
|
41 | 41 |
public void setCurrentPath(File path) throws FileNotFoundException; |
42 | 42 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPStoreParameters.java | ||
---|---|---|
43 | 43 |
|
44 | 44 |
private static final String SHXFILE_PARAMTER_NAME = "shxfile"; |
45 | 45 |
/* friend */ static final String SHPFILE_PARAMTER_NAME = "shpfile"; |
46 |
private static final String CRS_PARAMTER_NAME = "CRS"; |
|
46 |
// private static final String CRS_PARAMTER_NAME = "CRS";
|
|
47 | 47 |
private static final String USE_NULLGEOMETRY_PARAMTER_NAME = "useNullGeometry"; |
48 | 48 |
private static final String ALLOW_INCONSISTENCIES_IN_GEOMETRY_TYPE = "allowInconsistenciesInGeometryType"; |
49 | 49 |
private static final String LOAD_CORRUPT_GEOMETRIES_AS_NULL = "loadCorruptGeometriesAsNull"; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPLibrary.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import java.util.ArrayList; |
28 | 28 |
import java.util.List; |
29 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
|
29 | 30 |
|
30 | 31 |
import org.gvsig.fmap.dal.DALFileLibrary; |
31 | 32 |
import org.gvsig.fmap.dal.DALFileLocator; |
... | ... | |
34 | 35 |
import org.gvsig.fmap.dal.FileHelper; |
35 | 36 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
36 | 37 |
import org.gvsig.fmap.dal.store.dbf.DBFLibrary; |
37 |
import org.gvsig.metadata.MetadataLocator;
|
|
38 |
import org.gvsig.fmap.geom.GeometryLibrary;
|
|
38 | 39 |
import org.gvsig.metadata.exceptions.MetadataException; |
39 |
import org.gvsig.tools.ToolsLocator; |
|
40 | 40 |
import org.gvsig.tools.dynobject.DynClass; |
41 | 41 |
import org.gvsig.tools.library.AbstractLibrary; |
42 | 42 |
import org.gvsig.tools.library.LibraryException; |
... | ... | |
48 | 48 |
registerAsServiceOf(DALLibrary.class); |
49 | 49 |
require(DALFileLibrary.class); |
50 | 50 |
require(DBFLibrary.class); |
51 |
require(GeometryLibrary.class); |
|
52 |
require(ExpressionEvaluatorLibrary.class); |
|
51 | 53 |
} |
52 | 54 |
|
53 | 55 |
@Override |
54 | 56 |
protected void doPostInitialize() throws LibraryException { |
55 |
List<Throwable> exs = new ArrayList<Throwable>();
|
|
57 |
List<Throwable> exs = new ArrayList<>(); |
|
56 | 58 |
DynClass metadataDefinition; |
57 | 59 |
|
58 | 60 |
FileHelper.registerParametersDefinition( |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPFilesystemServerProvider.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.io.File; |
27 | 27 |
import java.io.IOException; |
28 |
import javax.xml.datatype.DatatypeConfigurationException; |
|
29 | 28 |
|
30 | 29 |
import org.gvsig.fmap.dal.DALLocator; |
31 | 30 |
import org.gvsig.fmap.dal.DataManager; |
... | ... | |
39 | 38 |
import org.gvsig.fmap.dal.exception.RemoveException; |
40 | 39 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
41 | 40 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
42 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
43 | 41 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
44 | 42 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyChangesException; |
45 | 43 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
... | ... | |
47 | 45 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
48 | 46 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.AbsolutePathRequiredException; |
49 | 47 |
import org.gvsig.fmap.dal.store.dbf.DBFFilesystemServerProvider; |
50 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
51 | 48 |
|
52 | 49 |
/** |
53 | 50 |
* @author jmvivo |
... | ... | |
143 | 140 |
final SHPNewStoreParameters params = (SHPNewStoreParameters) parameters; |
144 | 141 |
final EditableFeatureType fType = params.getDefaultFeatureType(); |
145 | 142 |
|
146 |
// Parche para crear con el tama?o que tocan los campos del DBF |
|
147 |
// Asumo que el dbfFtype se va a destruir tras crear el dbf. |
|
148 |
final EditableFeatureType dbfFtype = fixFeatureType(fType); |
|
149 |
|
|
150 |
SHPStoreProvider.removeGeometryColumn(dbfFtype); |
|
151 |
|
|
152 |
EditableFeatureAttributeDescriptor efad = SHPStoreProvider.addGeometryColumn((EditableFeatureType) fType); |
|
153 |
// efad.setGeometryType(params.getGeometryType()); |
|
154 |
|
|
155 | 143 |
File dbfFile = params.getDBFFile(); |
156 | 144 |
File shpFile = params.getSHPFile(); |
157 | 145 |
File shxFile = params.getSHXFile(); |
... | ... | |
213 | 201 |
SHPFeatureWriter writer = |
214 | 202 |
new SHPFeatureWriter(getDataStoreProviderName()); |
215 | 203 |
|
216 |
writer.begin(params, fType, dbfFtype, 0);
|
|
204 |
writer.begin(params, fType, 0); |
|
217 | 205 |
|
218 | 206 |
writer.end(); |
219 | 207 |
return null; |
... | ... | |
299 | 287 |
DataManager manager = DALLocator.getDataManager(); |
300 | 288 |
SHPStoreParameters params = |
301 | 289 |
(SHPStoreParameters) manager.createStoreParameters(this.getDataStoreProviderName()); |
302 |
params.setSHPFile(file.getPath()); |
|
290 |
params.setSHPFile(file.getPath());
|
|
303 | 291 |
return params; |
304 | 292 |
|
305 | 293 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import org.apache.commons.io.FileUtils; |
32 | 32 |
import org.apache.commons.io.FilenameUtils; |
33 |
import org.cresques.cts.ICRSFactory; |
|
34 | 33 |
import org.cresques.cts.IProjection; |
35 | 34 |
import org.slf4j.Logger; |
36 | 35 |
import org.slf4j.LoggerFactory; |
37 | 36 |
|
38 | 37 |
import org.gvsig.fmap.dal.DataStore; |
39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
40 | 38 |
import org.gvsig.fmap.dal.DataTypes; |
41 | 39 |
import org.gvsig.fmap.dal.FileHelper; |
42 | 40 |
import org.gvsig.fmap.dal.exception.CloseException; |
43 | 41 |
import org.gvsig.fmap.dal.exception.DataException; |
44 | 42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
45 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
46 | 43 |
import org.gvsig.fmap.dal.exception.ReadException; |
47 | 44 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
48 | 45 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
49 | 46 |
import org.gvsig.fmap.dal.feature.Feature; |
50 | 47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
51 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
52 | 48 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
53 | 49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
54 | 50 |
import org.gvsig.fmap.dal.feature.FeatureType; |
55 | 51 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
56 | 52 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
57 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
58 | 53 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
59 | 54 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
60 | 55 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
... | ... | |
85 | 80 |
*/ |
86 | 81 |
public class SHPStoreProvider extends DBFStoreProvider { |
87 | 82 |
|
88 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
89 |
private static final Logger logger = LoggerFactory.getLogger(SHPStoreProvider.class); |
|
90 |
public static String NAME = "Shape"; |
|
83 |
private static final GeometryManager GEOM_MANAGER = GeometryLocator.getGeometryManager(); |
|
84 |
private static final Logger LOGGER = LoggerFactory.getLogger(SHPStoreProvider.class); |
|
85 |
|
|
86 |
public static String NAME = DataStore.SHAPE_PROVIDER_NAME; |
|
91 | 87 |
public static String DESCRIPTION = "Shape file"; |
92 | 88 |
private ISHPFile shpFile; |
93 | 89 |
|
94 | 90 |
private MultiResource resource; |
95 | 91 |
|
96 |
protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY";
|
|
92 |
public static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY";
|
|
97 | 93 |
|
98 | 94 |
public static final String METADATA_DEFINITION_NAME = NAME; |
99 | 95 |
|
... | ... | |
229 | 225 |
|
230 | 226 |
attr.setObjectClass(Geometry.class); |
231 | 227 |
attr.setAllowNull(true); |
232 |
fType.setDefaultGeometryAttributeName(attr.getName()); |
|
228 |
// fType.setDefaultGeometryAttributeName(attr.getName());
|
|
233 | 229 |
return attr; |
234 | 230 |
|
235 | 231 |
} |
... | ... | |
249 | 245 |
return candidate; |
250 | 246 |
} |
251 | 247 |
|
252 |
protected static FeatureType removeGeometryColumn(EditableFeatureType fType) { |
|
253 |
Iterator<?> iter = fType.iterator(); |
|
254 |
FeatureAttributeDescriptor attr; |
|
255 |
while (iter.hasNext()) { |
|
256 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
257 |
if (attr.getType() == DataTypes.GEOMETRY) { |
|
258 |
iter.remove(); |
|
259 |
} |
|
248 |
protected EditableFeatureType getTheFeatureType() throws InitializeException{ |
|
249 |
try { |
|
250 |
this.open(); |
|
251 |
} catch (DataException e) { |
|
252 |
throw new InitializeException(this.getProviderName(), e); |
|
260 | 253 |
} |
261 |
fType.setDefaultGeometryAttributeName(null); |
|
262 |
return fType.getNotEditableCopy(); |
|
263 |
} |
|
264 |
|
|
265 |
protected EditableFeatureType getTheFeatureType() throws InitializeException, OpenException { |
|
266 | 254 |
final EditableFeatureType fType = super.getTheFeatureType(); |
267 |
this.open(); |
|
268 | 255 |
try { |
269 | 256 |
getResource().execute(new ResourceAction() { |
270 | 257 |
|
271 | 258 |
public Object run() throws Exception { |
272 | 259 |
EditableFeatureAttributeDescriptor attr = addGeometryColumn(fType); |
273 | 260 |
|
274 |
attr.setGeometryType(geomManager.getGeometryType(
|
|
261 |
attr.setGeometryType(GEOM_MANAGER.getGeometryType(
|
|
275 | 262 |
shpFile.getGeometryType(), |
276 | 263 |
shpFile.getGeometrySubType() |
277 | 264 |
)); |
... | ... | |
460 | 447 |
} catch (DataException e) { |
461 | 448 |
throw new PerformEditingException(this.getProviderName(), e); |
462 | 449 |
} |
463 |
// TODO Comprobar el campo de geometria |
|
464 |
|
|
465 |
final EditableFeatureType dbfFtype = fType.getEditable(); |
|
466 |
|
|
467 |
removeGeometryColumn(dbfFtype); |
|
468 |
|
|
469 | 450 |
try { |
470 | 451 |
// TODO repasar el concepto de enUso de un recurso. |
471 | 452 |
loTengoEnUso = true; |
... | ... | |
490 | 471 |
tmpParams.setSHPFile(str_base + ".shp"); |
491 | 472 |
tmpParams.setSHXFile(str_base + ".shx"); |
492 | 473 |
|
493 |
writer.begin(tmpParams, fType, dbfFtype, set.getSize());
|
|
474 |
writer.begin(tmpParams, fType, set.getSize()); |
|
494 | 475 |
|
495 | 476 |
iter = set.fastIterator(); |
496 | 477 |
while (iter.hasNext()) { |
... | ... | |
504 | 485 |
|
505 | 486 |
|
506 | 487 |
if (!shpParams.getDBFFile().delete()) { |
507 |
logger.debug("Can't delete dbf file '" + shpParams.getDBFFile() + "'.");
|
|
488 |
LOGGER.debug("Can't delete dbf file '" + shpParams.getDBFFile() + "'.");
|
|
508 | 489 |
throw new IOException("Can't delete dbf '" |
509 | 490 |
+ FilenameUtils.getBaseName(shpParams.getDBFFileName()) |
510 | 491 |
+ "' file to replace with the new dbf.\nThe new dbf is in temporary file '" + str_base |
511 | 492 |
+ "'"); |
512 | 493 |
} |
513 | 494 |
if (!shpParams.getSHPFile().delete()) { |
514 |
logger.debug("Can't delete dbf file '" + shpParams.getSHPFile() + "'.");
|
|
495 |
LOGGER.debug("Can't delete dbf file '" + shpParams.getSHPFile() + "'.");
|
|
515 | 496 |
throw new IOException("Can't delete shp '" |
516 | 497 |
+ FilenameUtils.getBaseName(shpParams.getSHPFileName()) |
517 | 498 |
+ "' file to replace with the new shp.\nThe new shp is in temporary file '" + str_base |
518 | 499 |
+ "'"); |
519 | 500 |
} |
520 | 501 |
if (!shpParams.getSHXFile().delete()) { |
521 |
logger.debug("Can't delete dbf file '" + shpParams.getSHXFile() + "'.");
|
|
502 |
LOGGER.debug("Can't delete dbf file '" + shpParams.getSHXFile() + "'.");
|
|
522 | 503 |
throw new IOException("Can't delete shx '" |
523 | 504 |
+ FilenameUtils.getBaseName(shpParams.getSHXFileName()) |
524 | 505 |
+ "' file to replace with the new shx.\nThe new shx is in temporary file '" + str_base |
525 | 506 |
+ "'"); |
526 | 507 |
} |
527 | 508 |
if (shpParams.getCPGFile().exists() && !shpParams.getCPGFile().delete()) { |
528 |
logger.debug("Can't delete cpg file '" + shpParams.getCPGFile() + "'.");
|
|
509 |
LOGGER.debug("Can't delete cpg file '" + shpParams.getCPGFile() + "'.");
|
|
529 | 510 |
throw new IOException("Can't delete cpg '" |
530 | 511 |
+ FilenameUtils.getBaseName(shpParams.getCPGFileName()) |
531 | 512 |
+ "' file to replace with the new cpg.\nThe new cpg is in temporary file '" + str_base |
... | ... | |
535 | 516 |
File prjFile = SHP.getPrjFile(shpParams.getSHPFile()); |
536 | 517 |
if (prjFile.exists()) { |
537 | 518 |
if (!prjFile.delete()) { |
538 |
logger.debug("Can't delete prj file '" + prjFile + "'.");
|
|
519 |
LOGGER.debug("Can't delete prj file '" + prjFile + "'.");
|
|
539 | 520 |
throw new IOException("Can't delete shx '" |
540 | 521 |
+ FilenameUtils.getBaseName(prjFile.getPath()) |
541 | 522 |
+ "' file to replace with the new shx.\nThe new shx is in temporary file '" |
... | ... | |
595 | 576 |
FeatureStore store = getFeatureStore(); |
596 | 577 |
FeatureType fType = store.getDefaultFeatureType(); |
597 | 578 |
|
598 |
// TODO Comprobar el campo de geometria |
|
599 |
EditableFeatureType dbfFtype = fType.getEditable(); |
|
600 |
|
|
601 |
removeGeometryColumn(dbfFtype); |
|
602 |
FeatureSet set = store.getFeatureSet(); |
|
603 |
|
|
604 | 579 |
writer = new SHPFeatureWriter(getProviderName()); |
605 |
|
|
606 |
writer.begin(getShpParameters(), fType, dbfFtype, set.getSize()); |
|
580 |
writer.begin(getShpParameters(), fType, store.getFeatureCount()); |
|
607 | 581 |
return null; |
608 | 582 |
} |
609 | 583 |
}); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPFeatureWriter.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 | 35 |
import org.gvsig.fmap.dal.exception.WriteException; |
36 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
36 | 37 |
import org.gvsig.fmap.dal.feature.Feature; |
37 | 38 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
38 | 39 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
50 | 51 |
|
51 | 52 |
public class SHPFeatureWriter extends DBFFeatureWriter { |
52 | 53 |
|
53 |
private static final GeometryManager geomManager = GeometryLocator |
|
54 |
.getGeometryManager(); |
|
55 |
private static final Logger logger = LoggerFactory |
|
56 |
.getLogger(GeometryManager.class); |
|
54 |
private static final GeometryManager GEOM_MANAGER = GeometryLocator.getGeometryManager(); |
|
55 |
private static final Logger LOGGER = LoggerFactory.getLogger(SHPFeatureWriter.class); |
|
57 | 56 |
|
58 | 57 |
private SHPFileWrite shpWrite; |
59 | 58 |
private Envelope envelope = null; |
... | ... | |
65 | 64 |
super(name); |
66 | 65 |
} |
67 | 66 |
|
68 |
public void begin(DBFStoreParameters dbfParameters, |
|
69 |
FeatureType featureType, FeatureType dbfFeatureType, long numRows) |
|
67 |
public void begin(DBFStoreParameters dbfParameters, FeatureType featureType, long numRows) |
|
70 | 68 |
throws DataException { |
71 | 69 |
SHPStoreParameters shpParameters = (SHPStoreParameters) dbfParameters; |
72 | 70 |
File shpFile = shpParameters.getSHPFile(); |
... | ... | |
88 | 86 |
int shapeType = getShapeTypeAndSetSupportedGeometries(featureType); |
89 | 87 |
try { |
90 | 88 |
shpWrite.writeHeaders( |
91 |
geomManager.createEnvelope(0, 0, 0, 0, featureType.getDefaultGeometryAttribute().getGeomType().getSubType()),
|
|
89 |
GEOM_MANAGER.createEnvelope(0, 0, 0, 0, featureType.getDefaultGeometryAttribute().getGeomType().getSubType()),
|
|
92 | 90 |
shapeType, 0, 0); |
93 | 91 |
} catch (CreateEnvelopeException e) { |
94 |
logger.error("Error creating the envelope", e);
|
|
92 |
LOGGER.warn("Error creating the envelope", e);
|
|
95 | 93 |
} |
96 | 94 |
|
97 | 95 |
this.shpFeatureType = featureType; |
98 |
super.begin(dbfParameters, dbfFeatureType, numRows); |
|
99 | 96 |
|
97 |
EditableFeatureType efType = featureType.getEditable(); |
|
98 |
efType.remove(efType.getDefaultGeometryAttributeIndex()); |
|
99 |
efType.setDefaultGeometryAttributeName(null); |
|
100 |
super.begin(dbfParameters, efType, numRows); |
|
101 |
|
|
100 | 102 |
} |
101 | 103 |
|
102 | 104 |
private int getShapeTypeAndSetSupportedGeometries(FeatureType featureType) { |
103 | 105 |
|
104 |
FeatureAttributeDescriptor geometryAttr = |
|
105 |
featureType.getAttributeDescriptor(featureType |
|
106 |
.getDefaultGeometryAttributeIndex()); |
Also available in: Unified diff