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
|
/*******************************************************************************
* Copyright (c) 2000, 2006 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 Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.core.schema;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
public class SchemaInclude extends SchemaObject implements ISchemaInclude {
private static final long serialVersionUID = 1L;
private String fLocation;
private ISchema fIncludedSchema;
private boolean fAbbreviated;
public SchemaInclude(ISchemaObject parent, String location,
boolean abbreviated) {
super(parent, location);
fLocation = location;
fAbbreviated = abbreviated;
}
/**
* @see org.eclipse.pde.internal.core.ischema.ISchemaInclude#getLocation()
*/
public String getLocation() {
return fLocation;
}
/**
* @see org.eclipse.pde.internal.core.ischema.ISchemaInclude#setLocation(java.lang.String)
*/
public void setLocation(String location) throws CoreException {
String oldValue = this.fLocation;
this.fLocation = location;
fIncludedSchema = null;
getSchema()
.fireModelObjectChanged(this, P_LOCATION, oldValue, location);
}
/**
* @see org.eclipse.pde.core.IWritable#write(java.lang.String,
* java.io.PrintWriter)
*/
public void write(String indent, PrintWriter writer) {
writer.print(indent);
writer.println("<include schemaLocation=\"" + fLocation + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
}
public ISchema getIncludedSchema() {
ISchemaDescriptor descriptor = getSchema().getSchemaDescriptor();
if (fAbbreviated) {
SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
fIncludedSchema = registry.getIncludedSchema(descriptor, fLocation);
} else if (fIncludedSchema == null){
fIncludedSchema = createInternalSchema(descriptor, fLocation);
}
return fIncludedSchema;
}
private ISchema createInternalSchema(ISchemaDescriptor desc, String location) {
try {
URL schemaURL = IncludedSchemaDescriptor.computeURL(desc, location);
if (schemaURL == null)
return null;
Schema ischema = new Schema(null, schemaURL, fAbbreviated);
ischema.load();
return ischema;
} catch (MalformedURLException e) {
return null;
}
}
public void dispose() {
if (fIncludedSchema != null && !fIncludedSchema.isDisposed()) {
fIncludedSchema.dispose();
fIncludedSchema = null;
}
}
public boolean equals(Object obj) {
if (obj instanceof ISchemaInclude) {
ISchemaInclude other = (ISchemaInclude)obj;
if (fLocation != null)
return fLocation.equals(other.getLocation());
return other.getLocation() == null;
}
return false;
}
}
|