01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.schema;
11:
12: import java.io.File;
13: import java.net.MalformedURLException;
14: import java.net.URL;
15:
16: import org.eclipse.core.resources.IFile;
17: import org.eclipse.pde.internal.core.ischema.ISchema;
18: import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
19:
20: public class SchemaDescriptor implements ISchemaDescriptor {
21:
22: private String fPoint;
23: private URL fSchemaURL;
24: private Schema fSchema;
25: private long fLastModified;
26: private boolean fEditable;
27:
28: public SchemaDescriptor(String extPointID, URL schemaURL) {
29: fPoint = extPointID;
30: fSchemaURL = schemaURL;
31: if (fSchemaURL != null) {
32: File file = new File(fSchemaURL.getFile());
33: if (file.exists())
34: fLastModified = file.lastModified();
35: }
36: }
37:
38: public SchemaDescriptor(IFile file, boolean editable) {
39: this (new File(file.getLocation().toOSString()));
40: fEditable = editable;
41: }
42:
43: public SchemaDescriptor(File file) {
44: try {
45: if (file.exists()) {
46: fSchemaURL = file.toURL();
47: fLastModified = file.lastModified();
48: }
49: } catch (MalformedURLException e) {
50: }
51: }
52:
53: /* (non-Javadoc)
54: * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getPointId()
55: */
56: public String getPointId() {
57: if (fPoint != null)
58: return fPoint;
59: return (fSchema == null) ? null : fSchema.getQualifiedPointId();
60: }
61:
62: /* (non-Javadoc)
63: * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getSchema(boolean)
64: */
65: public ISchema getSchema(boolean abbreviated) {
66: if (fSchema == null && fSchemaURL != null) {
67: if (fEditable)
68: fSchema = new EditableSchema(this , fSchemaURL,
69: abbreviated);
70: else
71: fSchema = new Schema(this , fSchemaURL, abbreviated);
72: fSchema.load();
73: }
74: return fSchema;
75: }
76:
77: /* (non-Javadoc)
78: * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getSchemaURL()
79: */
80: public URL getSchemaURL() {
81: return fSchemaURL;
82: }
83:
84: /* (non-Javadoc)
85: * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#isStandalone()
86: */
87: public boolean isStandalone() {
88: return true;
89: }
90:
91: public long getLastModified() {
92: return fLastModified;
93: }
94:
95: }
|