View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wadl.inference.schema.types;
14  
15  import org.apache.xmlbeans.XmlException;
16  
17  import com.eviware.soapui.impl.wadl.inference.schema.Context;
18  import com.eviware.soapui.impl.wadl.inference.schema.Schema;
19  import com.eviware.soapui.impl.wadl.inference.schema.SchemaSystem;
20  import com.eviware.soapui.impl.wadl.inference.schema.Type;
21  import com.eviware.soapui.inferredSchema.TypeConfig;
22  import com.eviware.soapui.inferredSchema.TypeReferenceConfig;
23  
24  /***
25   * This Type is simply a reference to another, actual Type. It is used when
26   * loading previously saved data, since the Type may not yet be loaded.
27   * 
28   * @author Dain Nilsson
29   */
30  public class TypeReferenceType implements Type
31  {
32  	String name;
33  	String namespace;
34  	SchemaSystem schemaSystem;
35  
36  	/***
37  	 * Constructs a new TypeReferenceType from previously saved data. Should be
38  	 * called in the Type.Factory.
39  	 */
40  	public TypeReferenceType( TypeReferenceConfig xml, Schema schema )
41  	{
42  		schemaSystem = schema.getSystem();
43  		name = xml.getReference().getLocalPart();
44  		namespace = xml.getReference().getNamespaceURI();
45  	}
46  
47  	public TypeConfig save()
48  	{
49  		return schemaSystem.getSchemaForNamespace( namespace ).getType( name ).save();
50  	}
51  
52  	public String getName()
53  	{
54  		return name;
55  	}
56  
57  	public Type validate( Context context ) throws XmlException
58  	{
59  		return schemaSystem.getSchemaForNamespace( namespace ).getType( name );
60  	}
61  
62  	public Schema getSchema()
63  	{
64  		return schemaSystem.getSchemaForNamespace( namespace );
65  	}
66  
67  	public void setSchema( Schema schema )
68  	{
69  		namespace = schema.getNamespace();
70  	}
71  
72  }