1 11 package org.eclipse.pde.internal.core.schema; 12 13 import java.io.PrintWriter ; 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 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 fLocation; 29 30 private ISchema fIncludedSchema; 31 32 private boolean fAbbreviated; 33 34 public SchemaInclude(ISchemaObject parent, String location, 35 boolean abbreviated) { 36 super(parent, location); 37 fLocation = location; 38 fAbbreviated = abbreviated; 39 } 40 41 44 public String getLocation() { 45 return fLocation; 46 } 47 48 51 public void setLocation(String location) throws CoreException { 52 String oldValue = this.fLocation; 53 this.fLocation = location; 54 fIncludedSchema = null; 55 getSchema() 56 .fireModelObjectChanged(this, P_LOCATION, oldValue, location); 57 } 58 59 63 public void write(String indent, PrintWriter writer) { 64 writer.print(indent); 65 writer.println("<include schemaLocation=\"" + fLocation + "\"/>"); } 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 location) { 80 try { 81 URL 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 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 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 |