KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > schema > SchemaInclude


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.schema;
12
13 import java.io.PrintWriter JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.pde.internal.core.PDECore;
19 import org.eclipse.pde.internal.core.ischema.ISchema;
20 import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
21 import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
22 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
23
24 public class SchemaInclude extends SchemaObject implements ISchemaInclude {
25
26     private static final long serialVersionUID = 1L;
27
28     private String JavaDoc fLocation;
29
30     private ISchema fIncludedSchema;
31
32     private boolean fAbbreviated;
33
34     public SchemaInclude(ISchemaObject parent, String JavaDoc location,
35             boolean abbreviated) {
36         super(parent, location);
37         fLocation = location;
38         fAbbreviated = abbreviated;
39     }
40
41     /**
42      * @see org.eclipse.pde.internal.core.ischema.ISchemaInclude#getLocation()
43      */

44     public String JavaDoc getLocation() {
45         return fLocation;
46     }
47
48     /**
49      * @see org.eclipse.pde.internal.core.ischema.ISchemaInclude#setLocation(java.lang.String)
50      */

51     public void setLocation(String JavaDoc location) throws CoreException {
52         String JavaDoc oldValue = this.fLocation;
53         this.fLocation = location;
54         fIncludedSchema = null;
55         getSchema()
56                 .fireModelObjectChanged(this, P_LOCATION, oldValue, location);
57     }
58
59     /**
60      * @see org.eclipse.pde.core.IWritable#write(java.lang.String,
61      * java.io.PrintWriter)
62      */

63     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
64         writer.print(indent);
65         writer.println("<include schemaLocation=\"" + fLocation + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
66
}
67
68     public ISchema getIncludedSchema() {
69         ISchemaDescriptor descriptor = getSchema().getSchemaDescriptor();
70         if (fAbbreviated) {
71             SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
72             fIncludedSchema = registry.getIncludedSchema(descriptor, fLocation);
73         } else if (fIncludedSchema == null){
74             fIncludedSchema = createInternalSchema(descriptor, fLocation);
75         }
76         return fIncludedSchema;
77     }
78
79     private ISchema createInternalSchema(ISchemaDescriptor desc, String JavaDoc location) {
80         try {
81             URL JavaDoc schemaURL = IncludedSchemaDescriptor.computeURL(desc, location);
82             if (schemaURL == null)
83                 return null;
84             Schema ischema = new Schema(null, schemaURL, fAbbreviated);
85             ischema.load();
86             return ischema;
87         } catch (MalformedURLException JavaDoc e) {
88             return null;
89         }
90     }
91
92     public void dispose() {
93         if (fIncludedSchema != null && !fIncludedSchema.isDisposed()) {
94             fIncludedSchema.dispose();
95             fIncludedSchema = null;
96         }
97     }
98     
99     public boolean equals(Object JavaDoc obj) {
100         if (obj instanceof ISchemaInclude) {
101             ISchemaInclude other = (ISchemaInclude)obj;
102             if (fLocation != null)
103                 return fLocation.equals(other.getLocation());
104             return other.getLocation() == null;
105         }
106         return false;
107     }
108 }
109
Popular Tags