Revision 32880 branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/persistence/Point2DPersistenceFactory.java

View differences:

Point2DPersistenceFactory.java
26 26
 */
27 27
package org.gvsig.fmap.mapcontext.tools.persistence;
28 28

  
29
import java.awt.Color;
30 29
import java.awt.geom.Point2D;
31 30

  
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DynObjectManager;
34 31
import org.gvsig.tools.dynobject.DynStruct;
35
import org.gvsig.tools.persistence.AbstractHierarchyPersistenceFactory;
36
import org.gvsig.tools.persistence.PersistenceException;
32
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
37 33
import org.gvsig.tools.persistence.PersistentState;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
38 35

  
39 36
/**
40 37
 * Factory to manage the persistence of {@link Point2D} objects.
41 38
 * 
42 39
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
40
 * @author 2010- <a href="jjdelcerro@gvsig.org">Joaquin Jose del Cerro</a> -
41
 *         gvSIG team
43 42
 */
44
public class Point2DPersistenceFactory extends
45
		AbstractHierarchyPersistenceFactory {
43
public class Point2DPersistenceFactory extends AbstractSinglePersistenceFactory {
46 44

  
47 45
	static final String FIELD_X = "x";
48

  
49 46
	static final String FIELD_Y = "y";
50 47

  
51
	private static final String POINT2D_DYNCLASS_NAME = "Point2D";
48
	private static final String DYNCLASS_NAME = "Point2D";
49
	private static final String DYNCLASS_DESCRIPTION = "Point2D";
52 50

  
53
	private static final String POINT2D_DYNCLASS_DESCRIPTION = "Point2D";
54

  
55
	private DynStruct pointDefinition;
56

  
57 51
	/**
58 52
	 * Creates a new {@link Point2DPersistenceFactory} with the
59
	 * {@link DynStruct} definition for the {@link Color} objects.
53
	 * {@link DynStruct} definition for the {@link Point2D} objects.
60 54
	 */
61 55
	public Point2DPersistenceFactory() {
56
		super(Point2D.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null);
62 57

  
63
		// Create the DynStruct related to the Point2D objects persisted
64
		// data, which will be its X and X values.
65
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
58
		DynStruct definition = this.getDefinition();
66 59

  
67
		pointDefinition = dynman.add(POINT2D_DYNCLASS_NAME,
68
				POINT2D_DYNCLASS_DESCRIPTION);
69

  
70
		pointDefinition.addDynFieldDouble(FIELD_X).setMandatory(true);
71
		pointDefinition.addDynFieldDouble(FIELD_Y).setMandatory(true);
60
		definition.addDynFieldDouble(FIELD_X).setMandatory(true);
61
		definition.addDynFieldDouble(FIELD_Y).setMandatory(true);
72 62
	}
73 63

  
74
	protected Class getParentClass() {
75
		return Point2D.class;
76
	}
77

  
78
	protected DynStruct getParentClassDefinition() {
79
		return pointDefinition;
80
	}
81

  
82
	public Object createFromState(PersistentState state, Class classToUse)
64
	public Object createFromState(PersistentState state)
83 65
			throws PersistenceException {
84 66
		double x = state.getDouble(FIELD_X);
85 67
		double y = state.getDouble(FIELD_Y);
......
87 69
		return new Point2D.Double(x, y);
88 70
	}
89 71

  
90
	public void loadFromState(PersistentState state, Object object)
91
			throws PersistenceException {
92
		// Nothing to do here, everything is read in the creation
93
	}
94

  
95 72
	public void saveToState(PersistentState state, Object obj)
96 73
			throws PersistenceException {
97 74
		Point2D point = (Point2D) obj;
98 75
		state.set(FIELD_X, point.getX());
99 76
		state.set(FIELD_Y, point.getY());
100 77
	}
101

  
102
	public String getDomainName() {
103
		// Use the default domain name
104
		return null;
105
	}
106

  
107
	public String getDomainURL() {
108
		// Use the default domain url
109
		return null;
110
	}
111

  
112 78
}

Also available in: Unified diff