Revision 24742

View differences:

trunk/extensions/extMetadata/src-test/org/gvsig/metadata/extended/manager/ExtendedMetadataImplTest.java
143 143
	}
144 144
	
145 145
	public void testGetType() {
146
		MDDefinition mdd = new MDDefinition("prueba", "Objeto Metadata de prueba");
146
		MDDefinition mdd = new MDDefinition("1", "prueba", "Objeto Metadata de prueba");
147 147
		ExtendedMetadata md = new ExtendedMetadataImpl(mdd, null);
148 148
		assertEquals(mdd, md.getType());
149 149
	}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/exchanger/XSLTExchanger.java
38 38
import java.io.IOException;
39 39
import java.io.InputStreamReader;
40 40
import java.io.StringWriter;
41
import java.net.URL;
42 41

  
43 42
import javax.xml.transform.OutputKeys;
44 43
import javax.xml.transform.Source;
......
51 50

  
52 51
import org.gvsig.metadata.extended.ExtendedMetadata;
53 52

  
54
import com.iver.andami.Launcher;
55 53
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
56 54

  
57 55

  
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/persistence/H2Persistence.java
43 43

  
44 44
public class H2Persistence implements MDPersistence{
45 45
	
46
	Connection conn = null;
46
	private Connection conn = null;
47 47
	
48 48
	public H2Persistence() {
49 49
		conn = PersonalDBLocator.getInstance().getPersonalDBManager().getConnection();
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/ExtendedMDLibrary.java
30 30

  
31 31
package org.gvsig.metadata.extended;
32 32

  
33
import java.sql.Connection;
34
import java.sql.PreparedStatement;
35
import java.sql.ResultSet;
36
import java.sql.SQLException;
37
import java.sql.Statement;
38

  
33 39
import org.gvsig.metadata.MDLocator;
34 40
import org.gvsig.metadata.MDManager;
35 41
import org.gvsig.metadata.extended.manager.ExtendedMDManagerImpl;
42
import org.gvsig.personaldb.PersonalDBLocator;
36 43
import org.gvsig.tools.locator.BaseLibrary;
37 44
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
38 45

  
......
53 60
        }
54 61
        
55 62
        // INICIALIZAR Base de Datos
63
        dataBaseInit();
56 64
	}
57 65
	
66
	public void dataBaseInit() {
67
		Connection conn = PersonalDBLocator.getInstance().getPersonalDBManager().getConnection();
68
		String sql = "CREATE TABLE IF NOT EXISTS MDDEFINITIONS(ID INT AUTO_INCREMENT(1) PRIMARY KEY, NAME VARCHAR2, DESCRIPTION LONGVARCHAR, FATHER INT DEFAULT 0, EXPORT_NAME VARCHAR2 DEFAULT '');";
69
		String sql2 = "CREATE TABLE IF NOT EXISTS MDELEMENTDEFINITIONS(ID INT AUTO_INCREMENT(1) PRIMARY KEY, NAME VARCHAR2, DESCRIPTION LONGVARCHAR, REQUIRED BOOLEAN DEFAULT true, FATHER INT DEFAULT 0, EXPORT_NAME VARCHAR2 DEFAULT '', TIPO VARCHAR2 DEFAULT 'String', DEF_VALUE VARCHAR2 DEFAULT '');";
70
		PreparedStatement prep;
71
		try {
72
			prep = conn.prepareStatement(sql);
73
			prep.execute();
74
			prep = conn.prepareStatement(sql2);
75
			prep.execute();
76
			conn.close();
77
		} catch (SQLException e) {
78
			// TODO Auto-generated catch block
79
			e.printStackTrace();
80
		}
81
	}
82
	
58 83
}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/registry/MDRegistry.java
32 32

  
33 33
package org.gvsig.metadata.extended.registry;
34 34

  
35
import org.gvsig.metadata.extended.registry.objects.MDDefinition;
35 36
import org.gvsig.metadata.extended.registry.objects.MDElementDefinition;
36 37
import org.gvsig.metadata.extended.registry.objects.MDType;
37 38

  
......
39 40

  
40 41
public interface MDRegistry {
41 42
	
42
	public MDElementDefinition getMDDefinition(String name);
43
	public MDDefinition getMDDefinition(String name);
43 44
	public MDElementDefinition getMDElementDefinition(String name);
44 45
	public MDType getMDType(String name);
45
	public boolean setMDDefinition(MDElementDefinition padre, String name, String description);
46
	public boolean setMDElementDefinition(MDElementDefinition padre, String description, MDType type /* ...*/);
47
	public boolean setMDType(/* ...*/);
46
	public boolean setMDDefinition(MDDefinition mdd);
47
	public boolean setMDElementDefinition(MDElementDefinition mded);
48
	public boolean setMDType(MDType type);
48 49
	
49 50
}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/registry/objects/MDDefinition.java
31 31

  
32 32
package org.gvsig.metadata.extended.registry.objects;
33 33

  
34
import java.util.Map;
34 35

  
36

  
37

  
35 38
public class MDDefinition {
39
	private String id;
36 40
	private String name;
37 41
	private String description;
42
	private MDDefinition father;
43
	private Map<String, MDElementDefinition> elements;
44
	private boolean persisted, changed;
38 45
	
39
	public MDDefinition() {}
46

  
47
	public MDDefinition() {
48
		this.id = "";
49
		this.name = "";
50
		this.description = "";
51
		this.father = null;
52
		this.elements = null;
53
		this.persisted = false;
54
		this.changed = false;
55
	}
56
//	
57
//	public MDDefinition(String name, String description) {
58
//		this.id = "";
59
//		this.name = name;
60
//		this.description = description;
61
//		this.father = null;
62
//		this.elements = null;
63
//		this.persisted = false;
64
//		this.changed = true;
65
//	}
40 66
	
41
	public MDDefinition(String name, String description) {
67
	public MDDefinition(String id, String name, String description) {
68
		this.id = id;
42 69
		this.name = name;
43 70
		this.description = description;
71
		this.father = null;
72
		this.elements = null;
73
		this.persisted = false;
74
		this.changed = true;
44 75
	}
45 76
	
77
//	public MDDefinition(String name, String description, Map<String, MDElementDefinition> elements) {
78
//		this.id = "";
79
//		this.name = name;
80
//		this.description = description;
81
//		this.father = null;
82
//		this.elements = elements;
83
//		this.persisted = false;
84
//		this.changed = true;
85
//	}
86
//	
87
//	public MDDefinition(String name, String description, MDDefinition father, Map<String, MDElementDefinition> elements, boolean persisted, boolean changed) {
88
//		this.id = "";
89
//		this.name = name;
90
//		this.description = description;
91
//		this.father = father;
92
//		this.elements = elements;
93
//		this.persisted = persisted;
94
//		this.changed = changed;
95
//	}
96
//	
97
//	public MDDefinition(String id, String name, String description, MDDefinition father, Map<String, MDElementDefinition> elements) {
98
//		this.id = id;
99
//		this.name = name;
100
//		this.description = description;
101
//		this.father = father;
102
//		this.elements = elements;
103
//		this.persisted = true;
104
//		this.changed = false;
105
//	}
106
	
107
	/**
108
	 * @return the id
109
	 */
110
	public String getId() {
111
		return id;
112
	}
113
	
46 114
	public String getName() {
47 115
		return this.name;
48 116
	}
......
51 119
		return this.description;
52 120
	}
53 121

  
122
	/**
123
	 * @return the elements
124
	 */
125
	public Map<String, MDElementDefinition> getElements() {
126
		return elements;
127
	}
128
	
129
	/**
130
	 * @return the father
131
	 */
132
	public MDDefinition getFather() {
133
		return father;
134
	}
135
	
54 136
	public void setName(String name) {
55 137
		this.name = name;
138
		this.changed = true;
56 139
	}
57 140
	
58 141
	public void setDescription(String description) {
59 142
		this.description = description;
143
		this.changed = true;
60 144
	}
61 145

  
146
	/**
147
	 * @param elements the elements to set
148
	 */
149
	public void setElements(Map<String, MDElementDefinition> elements) {
150
		this.elements = elements;
151
		this.changed = true;
152
	}
153

  
154
	/**
155
	 * @param father the father to set
156
	 */
157
	public void setFather(MDDefinition father) {
158
		this.father = father;
159
		this.changed = true;
160
	}
161

  
162
	/**
163
	 * @param id the id to set
164
	 */
165
	protected void setId(String id) {
166
		this.id = id;
167
	}
168

  
169
	/**
170
	 * @return the changed
171
	 */
172
	public boolean isChanged() {
173
		return changed;
174
	}
175

  
176
	/**
177
	 * @param changed the changed to set
178
	 */
179
	public void setChanged(boolean changed) {
180
		this.changed = changed;
181
	}
182

  
183
	/**
184
	 * @return the persisted
185
	 */
186
	public boolean isPersisted() {
187
		return persisted;
188
	}
189

  
190
	/**
191
	 * @param persisted the persisted to set
192
	 */
193
	public void setPersisted(boolean persisted) {
194
		this.persisted = persisted;
195
	}
196

  
62 197
}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/registry/objects/MDType.java
39 39
	private String name;
40 40
	private Types type;
41 41
	
42
	public MDType() {}
42
	public MDType() {
43
		this.id = "";
44
		this.name = "";
45
		this.type = null;
46
	}
43 47
	
44 48
	public MDType(String name, Types type) {
49
		this.id = "";
45 50
		this.name = name;
46 51
		this.type = type;
47 52
	}
......
61 66
	public void setType(Types type) {
62 67
		this.type = type;
63 68
	}
69

  
70
	/**
71
	 * @return the id
72
	 */
73
	public String getId() {
74
		return id;
75
	}
76

  
77
	/**
78
	 * @param id the id to set
79
	 */
80
	protected void setId(String id) {
81
		this.id = id;
82
	}
64 83
	
65 84
	
66 85
}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/registry/objects/MDElementDefinition.java
32 32

  
33 33
package org.gvsig.metadata.extended.registry.objects;
34 34

  
35
import java.util.HashMap;
36
import java.util.Map;
37 35

  
38 36

  
39 37
public class MDElementDefinition {
40 38
	
39
	private String id;
41 40
	private String name;
42
	private MDType type;
41
	private String type;
43 42
	private Boolean required;
44 43
	private Object defaultValue;
45 44
	private String description;
46
	private Map<String, Object> synonyms = new HashMap<String, Object>();
47
	
48
	public MDElementDefinition() {}
49
	
50
	public MDElementDefinition(String name, MDType type, Boolean required, Object defaultValue, String description) {
45
	private MDDefinition father;
46
	private boolean persisted, changed;
47

  
48
//	public MDElementDefinition() {
49
//		this.id = "";
50
//		this.name = "";
51
//		this.type = null;
52
//		this.required = false;
53
//		this.defaultValue = null;
54
//		this.description = "";
55
//		this.persisted = false;
56
//		this.changed = false;
57
//	}
58
//	
59
	public MDElementDefinition(String name, String type, Boolean required, Object defaultValue, String description) {
60
		this.id = "";
51 61
		this.name = name;
52 62
		this.type = type;
53 63
		this.required = required;
54 64
		this.defaultValue = defaultValue;
55 65
		this.description = description;
66
		this.persisted = false;
67
		this.changed = true;
56 68
	}
57 69
	
70
	public MDElementDefinition(String id, String name, String description, Boolean required, MDDefinition father, String type, String defaultValue) {
71
		this.id = id;
72
		this.name = name;
73
		this.description = description;
74
		this.required = required;
75
		this.father = father;
76
		this.type = type;
77
		this.defaultValue = defaultValue;
78
		this.persisted = false;
79
		this.changed = true;
80
	}
81
	
58 82
	public String getName() {
59 83
		return this.name;
60 84
	}
61 85
	
62
	public MDType getType() {
86
	public String getType() {
63 87
		return this.type;
64 88
	}
65 89
	
......
75 99
		return this.description;
76 100
	}
77 101
	
78
	public Object getSynonym(String name) {
79
		return synonyms.get(name);
80
	}
81
	
82 102
	public void setName(String name) {
83 103
		this.name = name;
104
		this.changed = true;
84 105
	}
85 106
	
86
	public void setType(MDType type) {
107
	public void setType(String type) {
87 108
		this.type = type;
109
		this.changed = true;
88 110
	}
89 111
	
90 112
	public void setRequired(Boolean required) {
91 113
		this.required = required;
114
		this.changed = true;
92 115
	}
93 116
	
94 117
	public void setDefaultValue(Object defaultValue) {
95 118
		this.defaultValue = defaultValue;
119
		this.changed = true;
96 120
	}
97 121
	
98 122
	public void setDescription(String description) {
99 123
		this.description = description;
124
		this.changed = true;
100 125
	}
126

  
127
	/**
128
	 * @return the changed
129
	 */
130
	public boolean isChanged() {
131
		return changed;
132
	}
133

  
134
	/**
135
	 * @param changed the changed to set
136
	 */
137
	public void setChanged(boolean changed) {
138
		this.changed = changed;
139
	}
140

  
141
	/**
142
	 * @return the id
143
	 */
144
	public String getId() {
145
		return id;
146
	}
147

  
148
	/**
149
	 * @param id the id to set
150
	 */
151
	protected void setId(String id) {
152
		this.id = id;
153
	}
154

  
155
	/**
156
	 * @return the persisted
157
	 */
158
	public boolean isPersisted() {
159
		return persisted;
160
	}
161

  
162
	/**
163
	 * @param persisted the persisted to set
164
	 */
165
	public void setPersisted(boolean persisted) {
166
		this.persisted = persisted;
167
	}
168

  
169
	/**
170
	 * @return the required
171
	 */
172
	public Boolean getRequired() {
173
		return required;
174
	}
175

  
176
	/**
177
	 * @return the father
178
	 */
179
	public MDDefinition getFather() {
180
		return father;
181
	}
182

  
183
	/**
184
	 * @param father the father to set
185
	 */
186
	public void setFather(MDDefinition father) {
187
		this.father = father;
188
		this.changed = true;
189
	}
101 190
	
102
	public void setSynonym(String name, Object synonym) {
103
		synonyms.put(name, synonym);
104
	}
105 191
}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extended/registry/MDRegistryImpl.java
32 32
package org.gvsig.metadata.extended.registry;
33 33

  
34 34

  
35
import java.sql.Connection;
36
import java.sql.PreparedStatement;
37
import java.sql.ResultSet;
38
import java.sql.SQLException;
39
import java.util.LinkedHashMap;
40
import java.util.Map;
41

  
42
import org.gvsig.metadata.extended.MDElement;
43
import org.gvsig.metadata.extended.registry.objects.MDDefinition;
35 44
import org.gvsig.metadata.extended.registry.objects.MDElementDefinition;
36 45
import org.gvsig.metadata.extended.registry.objects.MDType;
46
import org.gvsig.personaldb.PersonalDBLocator;
37 47

  
38 48

  
39 49
public class MDRegistryImpl implements MDRegistry {
50
	
51
	private Connection conn = null;
52
	
53
	public MDRegistryImpl() {
54
		conn = PersonalDBLocator.getInstance().getPersonalDBManager().getConnection();
55
	}
40 56

  
41
	public MDElementDefinition getMDDefinition(String name) {
42
		return null;
57
	public MDDefinition getMDDefinition(String name) {
58
		
59
		MDDefinition mdd = null;
60
		String father_id = "";
61
		Map<String, MDElementDefinition> elements = null;
62
		
63
		String sql = "SELECT * FROM MDDEFINITIONS WHERE NAME="+name;
64
		PreparedStatement prep;
65
		try {
66
			prep = conn.prepareStatement(sql);
67
			ResultSet rs = prep.executeQuery();
68
			rs.next();
69
			mdd = new MDDefinition(rs.getString("ID"), rs.getString("NAME"), rs.getString("DESCRIPTION"));
70
			father_id = rs.getString("ID");
71
		} catch (SQLException e) {
72
			// TODO Auto-generated catch block
73
			e.printStackTrace();
74
		}
75
		
76
		mdd.setPersisted(true);
77
		mdd.setChanged(false);
78
		
79
		sql = "SELECT * FROM MDELEMENT DEFINITIONS WHERE FATHER="+father_id;
80
		try {
81
			prep = conn.prepareStatement(sql);
82
			ResultSet rs = prep.executeQuery();
83
			boolean mas = rs.next();
84
			if(mas)
85
				elements = new LinkedHashMap<String, MDElementDefinition>();
86
			while(mas) {
87
				MDElementDefinition mded = new MDElementDefinition(rs.getString("ID"), rs.getString("NAME"), rs.getString("DESCRIPTION"), rs.getBoolean("REQUIRED"), mdd, rs.getString("TIPO"), rs.getString("DEFAULT_VALUE"));
88
				elements.put(rs.getString("NAME"), mded);
89
				mas = rs.next();
90
			}
91
		} catch (SQLException e) {
92
			// TODO Auto-generated catch block
93
			e.printStackTrace();
94
		}
95
		
96
		mdd.setElements(elements);
97
		
98
		return mdd;
43 99
	}
44 100

  
45 101
	public MDElementDefinition getMDElementDefinition(String name) {
102
		// TODO Auto-generated method stub
46 103
		return null;
47 104
	}
48 105

  
49 106
	public MDType getMDType(String name) {
107
		// TODO Auto-generated method stub
50 108
		return null;
51 109
	}
52 110

  
53
	public boolean setMDDefinition(MDElementDefinition padre, String name, String description) {
111
	public boolean setMDDefinition(MDDefinition mdd) {
112
		// TODO Auto-generated method stub
113
		//insert into mddefinitions ( name , description ) values ('hola', 'mundo')
54 114
		return false;
55 115
	}
56 116

  
57
	public boolean setMDElementDefinition(MDElementDefinition padre, String description, MDType type) {
117
	public boolean setMDElementDefinition(MDElementDefinition mded) {
118
		// TODO Auto-generated method stub
58 119
		return false;
59 120
	}
60 121

  
61
	public boolean setMDType() {
122
	public boolean setMDType(MDType type) {
123
		// TODO Auto-generated method stub
62 124
		return false;
63 125
	}
64

  
65 126
	
66
	
67 127
}
trunk/extensions/extMetadata/src/org/gvsig/metadata/extension/MetadataExtension.java
34 34
import org.gvsig.metadata.MDLocator;
35 35
import org.gvsig.metadata.MDManager;
36 36
import org.gvsig.metadata.extended.ExtendedMDLibrary;
37
import org.gvsig.metadata.extended.persistence.H2Persistence;
38 37
import org.gvsig.metadata.extension.gui.DBPreferencesPage;
39 38
import org.gvsig.metadata.extension.gui.MDGUITab;
40 39
import org.gvsig.metadata.extension.gui.MDPreferencesPage;
......
49 48

  
50 49
public class MetadataExtension extends Extension {
51 50

  
52
	public void execute(String arg0) {
53
		// TODO Auto-generated method stub
54
	}
55

  
56 51
	public void initialize() {
57 52
		
58 53
		System.out.println("\nInitializing Metadata Extension...\n");
......
102 97
		MDManager mdm = MDLocator.getInstance().getMDManager();
103 98
		System.out.println("MDManager Implementation: " + mdm.getClass().getName() + "\n");
104 99
		
105
		// PROVISIONAL test de la base de datos --------------------------------------
106
		H2Persistence p = new H2Persistence();
107
		p.queryMD("");
108
		
109 100
		// ------------------------------------------------------------------------------
110 101
	}
102
	
103
	public void execute(String arg0) {
104
		// TODO Auto-generated method stub
105
	}
111 106

  
112 107
	public boolean isEnabled() {
113 108
		// TODO Auto-generated method stub

Also available in: Unified diff