KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.File JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.pde.internal.core.ischema.ISchema;
19 import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
20
21
22 public class SchemaDescriptor implements ISchemaDescriptor {
23     
24     private String JavaDoc fPoint;
25     private URL JavaDoc fSchemaURL;
26     private Schema fSchema;
27     private long fLastModified;
28     private boolean fEditable;
29
30     public SchemaDescriptor(String JavaDoc extPointID, URL JavaDoc schemaURL) {
31         fPoint = extPointID;
32         fSchemaURL = schemaURL;
33         if (fSchemaURL != null) {
34             File JavaDoc file = new File JavaDoc(fSchemaURL.getFile());
35             if (file.exists())
36                 fLastModified = file.lastModified();
37         }
38     }
39     
40     public SchemaDescriptor(IFile file, boolean editable) {
41         this(new File JavaDoc(file.getLocation().toOSString()));
42         fEditable = editable;
43     }
44
45     public SchemaDescriptor(File JavaDoc file) {
46         try {
47             if (file.exists()) {
48                 fSchemaURL = file.toURL();
49                 fLastModified = file.lastModified();
50             }
51         } catch (MalformedURLException JavaDoc e) {
52         }
53     }
54
55     /* (non-Javadoc)
56      * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getPointId()
57      */

58     public String JavaDoc getPointId() {
59         if (fPoint != null)
60             return fPoint;
61         return (fSchema == null) ? null : fSchema.getQualifiedPointId();
62     }
63
64     /* (non-Javadoc)
65      * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getSchema(boolean)
66      */

67     public ISchema getSchema(boolean abbreviated) {
68         if (fSchema == null && fSchemaURL != null) {
69             if (fEditable)
70                 fSchema = new EditableSchema(this, fSchemaURL, abbreviated);
71             else
72                 fSchema = new Schema(this, fSchemaURL, abbreviated);
73             fSchema.load();
74         }
75         return fSchema;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getSchemaURL()
80      */

81     public URL JavaDoc getSchemaURL() {
82         return fSchemaURL;
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#isStandalone()
87      */

88     public boolean isStandalone() {
89         return true;
90     }
91     
92     public long getLastModified() {
93         return fLastModified;
94     }
95
96 }
97
Popular Tags