KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.resources.IStorage;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.pde.internal.core.PDECore;
20 import org.eclipse.pde.internal.core.ischema.ISchema;
21 import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
22
23 public class StorageSchemaDescriptor implements ISchemaDescriptor {
24     private IStorage fStorage;
25     private Schema fSchema;
26
27     public StorageSchemaDescriptor(IStorage storage) {
28         fStorage = storage;
29     }
30
31     public URL JavaDoc getSchemaURL() {
32         return fSchema != null ? fSchema.getURL() : null;
33     }
34     
35     public String JavaDoc getPointId() {
36         return fSchema == null ? null : fSchema.getQualifiedPointId();
37     }
38     
39     protected void loadSchema(boolean abbreviated) {
40         fSchema = new Schema(this, null, false);
41         try {
42             InputStream JavaDoc stream = fStorage.getContents();
43             fSchema.load(fStorage.getContents());
44             stream.close();
45         }
46         catch (CoreException e) {
47             PDECore.logException(e);
48         }
49         catch (IOException JavaDoc e) {
50             PDECore.logException(e);
51         }
52     }
53
54     public void reload() {
55         if (fSchema != null) {
56             fSchema.reload();
57         }
58     }
59
60     public boolean isEnabled() {
61         return true;
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)
69             loadSchema(abbreviated);
70         return fSchema;
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#isStandalone()
75      */

76     public boolean isStandalone() {
77         return true;
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.pde.internal.core.ischema.ISchemaDescriptor#getLastModified()
82      */

83     public long getLastModified() {
84         return 0;
85     }
86
87 }
88
Popular Tags