blob: a9d5a799904806c7fc7ee8d7c056accc950aa454 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*******************************************************************************
* Copyright (c) 2002-2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.wst.wsi.internal.core.wsdl.xsd;
import java.io.IOException;
import java.io.StringReader;
import java.util.Hashtable;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLInputSource;
/**
* An XMLEntityResolver that allows inline schemas to resolve each other through imports.
*
* @author Lawrence Mandel (lmandel@ca.ibm.com)
*/
public class InlineXSDResolver implements XMLEntityResolver
{
protected Hashtable entities = new Hashtable();
protected XMLInputSource referringSchemaInputSource = null;
protected String referringSchemaNamespace = null;
/**
* Constuctor.
*/
public InlineXSDResolver()
{
}
/* (non-Javadoc)
* @see org.apache.xerces.xni.parser.XMLEntityResolver#resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier)
*/
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
throws XNIException, IOException {
String systemId = resourceIdentifier.getExpandedSystemId();
String publicId = resourceIdentifier.getPublicId();
String namespace = resourceIdentifier.getNamespace();
XMLInputSource is = null;
String schema = null;
if (systemId == null)
{
if(publicId == null)
{
if(namespace == null)
{
return null;
}
else
{
systemId = namespace;
}
}
else
{
systemId = publicId;
}
}
if(referringSchemaNamespace != null && referringSchemaNamespace.equals(systemId))
{
if(referringSchemaInputSource!=null)
{
return referringSchemaInputSource;
}
}
else if ((schema = (String) entities.get(systemId)) != null && !schema.equals(""))
{
is = new XMLInputSource(publicId, systemId, systemId,new StringReader(schema),null);
}
//if(is == null)
//{
// throw new IOException();
//}
return is;
}
/**
* Add an inline schema.
*
* @param targetNamespace - the target namespace of the schema
* @param schema - a string representation of the schema
*/
public void add(String targetNamespace, String schema)
{
entities.put(targetNamespace, schema);
}
/**
* Add the referring inline schema.
*
* @param inputSource - a representation of the inline schema
* @param namespace - the namespace of the inline schema
*/
public void addReferringSchema(XMLInputSource inputSource, String namespace)
{
referringSchemaInputSource = inputSource;
referringSchemaNamespace = namespace;
}
}
|