Revision 9917 branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/factories/XMLSchemasFactory.java

View differences:

XMLSchemasFactory.java
1 1
package org.gvsig.remoteClient.gml.factories;
2 2

  
3 3
import java.util.Hashtable;
4
import java.util.StringTokenizer;
5 4

  
6
import org.gvsig.remoteClient.gml.GMLException;
7
import org.gvsig.remoteClient.gml.schemas.XMLSchema;
5
import org.gvsig.remoteClient.gml.exceptions.BaseException;
6
import org.gvsig.remoteClient.gml.schemas.XMLNameSpace;
7
import org.gvsig.remoteClient.gml.warnings.GMLWarningMalformed;
8 8

  
9 9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10 10
 *
......
50 50
 *
51 51
 * $Id$
52 52
 * $Log$
53
 * Revision 1.1  2006-08-10 12:00:49  jorpiell
53
 * Revision 1.1.2.1  2007-01-25 16:12:59  jorpiell
54
 * Se han sustituido las clases por las que hay en el nuevo driver de GML.
55
 *
56
 * Revision 1.3  2007/01/15 13:11:00  csanchez
57
 * Sistema de Warnings y Excepciones adaptado a BasicException
58
 *
59
 * Revision 1.2  2006/12/22 11:25:44  csanchez
60
 * Nuevo parser GML 2.x para gml's sin esquema
61
 *
62
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
54 63
 * Primer commit del driver de Gml
55 64
 *
56 65
 *
......
59 68
 * Factory to create Schemas. The XML schema parser
60 69
 * adds a new schema every time it find one when is
61 70
 * parsing a xml (gml) file
71
 * 
62 72
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
73
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
74
 * 
63 75
 */
64 76
public class XMLSchemasFactory {
65 77
	private static Hashtable schemas = new Hashtable();
66 78
	
67
	public static XMLSchema getType(String name){
68
		return (XMLSchema)schemas.get(name);
79
	/**
80
	 *	It gets the schema type by the key "name"
81
	 **/
82
	public static XMLNameSpace getType(String name)
83
	{
84
		return (XMLNameSpace)schemas.get(name);
69 85
	}
70 86

  
71 87
	/**
......
73 89
	 * @param xmlnsName
74 90
	 * XML nameSpace name
75 91
	 * @param xmlnsValue
76
	 * XML nameSpace value
92
	 * XML nameSpace value or URI
77 93
	 */
78 94
	public static void addType(String xmlnsName,String xmlnsValue){
79
		XMLSchema schema = new XMLSchema(xmlnsName,xmlnsValue);
95
		//Add a new namespace instance named "schema"...
96
		XMLNameSpace schema = new XMLNameSpace(xmlnsName,xmlnsValue);
97
		//Now adds a new hash map for import new schemas
80 98
		schemas.put(xmlnsName,schema);
81 99
	}	
82 100
	
......
88 106
	 * URL or file where the nameSpace is located
89 107
	 * @param schema
90 108
	 * Schema
91
	 * @return
92
	 * @throws GMLException
109
	 * @return String
110
	 * @throws BaseException 
93 111
	 */
94
	public static String addSchemaLocation(String namespace,String location,String schema) throws GMLException{
95
		XMLSchema parentSchema = getType(namespace);
96
		XMLSchema childSchema = getSchemaByLocation(location);
97
		childSchema.setLocation(schema);
98
		childSchema.setParent(parentSchema);
99
		if (parentSchema != null){
100
			parentSchema.addChidren(childSchema);
112
	public static String addSchemaLocation(String namespace,String location,String schema) throws BaseException {
113
		XMLNameSpace GMLSchema;
114
		//it gets the schema "default namespace" by the URI, but the W3C Schemas URI must be declared previously
115
		if((GMLSchema = getSchemaByLocation(location))==null){
116
			//GML is badly shaped
117
			// correct form:
118
			//              xmlns:namespace="http://www.w3.org/2001/XMLSchema-instance" 
119
			//				namespace:schemaLocation="www.URI.com file.xsd"
120
			throw new GMLWarningMalformed();
101 121
		}
102
		return childSchema.getName();		
122
		else{
123
			//set the correct location (URI) to the new main namespace
124
			GMLSchema.setLocation(schema);
125
			return GMLSchema.getName();	
126
		}
103 127
	}
104
	
128

  
105 129
	/**
106 130
	 * It find a nameSpace by location. 
107 131
	 * @param location
108 132
	 * URL or file where the nameSpace is located
109 133
	 * @return
110 134
	 */
111
	public static XMLSchema getSchemaByLocation(String location){
135
	public static XMLNameSpace getSchemaByLocation(String location){
112 136
		Object[] keys = schemas.keySet().toArray();
113 137
		for (int i=0 ; i<schemas.size() ; i++){
114
			XMLSchema schema = (XMLSchema)schemas.get(keys[i]);
138
			XMLNameSpace schema = (XMLNameSpace)schemas.get(keys[i]);
115 139
			if (schema.getLocation().equals(location)){
116 140
				return schema;
117 141
			}
......
126 150
		System.out.println("*** SCHEMAS ***");
127 151
		Object[] keys = schemas.keySet().toArray();
128 152
		for (int i=0 ; i<schemas.size() ; i++){
129
			XMLSchema schema = (XMLSchema)schemas.get(keys[i]);
153
			XMLNameSpace schema = (XMLNameSpace)schemas.get(keys[i]);
130 154
			System.out.print("NAME: " + schema.getName());
131
			System.out.print(" LOCATION: " + schema.getLocation());
132
			if (schema.getChildren().size() > 0){
133
				for (int j=0 ; j< schema.getChildren().size() ; j++){
134
					System.out.print(" CHIDREN " + j + "?: " + ((XMLSchema)schema.getChildren().get(j)).getName());
135
				}
136
			}
155
			System.out.print("LOCATION: " + schema.getLocation());
137 156
			System.out.print("\n");
138 157
		}
139 158
	}

Also available in: Unified diff