Revision 25587 branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/MyTransform.java

View differences:

MyTransform.java
14 14
import org.gvsig.tools.persistence.PersistentState;
15 15

  
16 16
/**
17
 * 
17
 *
18 18
 * This transform adds a new attribute of type Geometry to the
19
 * original store's default FeatureType. When applying the transform 
20
 * to a single feature this new attribute is assigned the value of a 
19
 * original store's default FeatureType. When applying the transform
20
 * to a single feature this new attribute is assigned the value of a
21 21
 * point whose coordinates proceed from two numeric attributes from the
22 22
 * store, called xname, yname.
23 23
 *
......
26 26

  
27 27
	private FeatureStore store;
28 28
	private String geomName;
29
	private String xname; 
29
	private String xname;
30 30
	private String yname;
31
	
31

  
32 32
	/**
33 33
	 * Empty default constructor
34 34
	 */
35 35
	public MyTransform() {
36 36
	}
37
	
37

  
38 38
	/**
39 39
	 * Initializes the transform by assigning the source store and the names of the necessary attributes.
40 40
	 *
41 41
	 * @param store
42 42
	 * 			source store.
43
	 * 
43
	 *
44 44
	 * @param geomName
45 45
	 * 			name of the geometry attribute in the default feature type from the source store.
46
	 * 
46
	 *
47 47
	 * @param xname
48 48
	 * 			name of the attribute containing the X coordinates
49
	 * 
49
	 *
50 50
	 * @param yname
51 51
	 * 			name of the attribute containing the Y coordinates
52
	 * 
52
	 *
53 53
	 * @throws DataException
54 54
	 */
55 55
	public void initialize(FeatureStore store, String geomName, String xname, String yname) throws DataException {
56
		
56

  
57 57
		// Initialize some data
58 58
		this.store = store;
59 59
		this.geomName = geomName;
60 60
		this.xname = xname;
61 61
		this.yname = yname;
62
		 
62

  
63 63
		// obtain the feature type, add the new attribute and keep a reference to the resulting feature type
64 64
		EditableFeatureType type = store.getDefaultFeatureType().getEditable();
65 65
		type.add(geomName, DataTypes.GEOMETRY);
66
		this.defaultFeatureType = type.getNotEditableCopy();		
66
		setDefaultFeatureType(type.getNotEditableCopy());
67 67
	}
68
	
68

  
69 69
	/**
70
	 * Applies this transform to a target editable feature, using data from the 
70
	 * Applies this transform to a target editable feature, using data from the
71 71
	 * source feature.
72 72
	 */
73 73
	public void applyTransform(Feature source, EditableFeature target)
74 74
			throws DataException {
75
	
75

  
76 76
		// copy source feature data over target feature
77 77
		target.copyFrom(source);
78
		
78

  
79 79
		// calculate and assign new attribute's value
80 80
		GeometryFactory geomFactory = GeometryManager.getInstance().getGeometryFactory();
81 81
		Geometry geom = geomFactory.createPoint2D(
82
			source.getDouble(xname), 
82
			source.getDouble(xname),
83 83
			source.getDouble(yname)
84 84
		);
85 85
		target.setGeometry(this.geomName, geom);
......
95 95

  
96 96
	public void setState(PersistentState state) throws PersistenceException {
97 97
	}
98
	
98

  
99 99
}

Also available in: Unified diff