KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > contentassist > VirtualSchemaObject


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.pde.internal.ui.editor.contentassist;
13
14 import java.io.PrintWriter JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
18 import org.eclipse.pde.internal.core.ischema.ISchema;
19 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
20 import org.eclipse.pde.internal.core.schema.SchemaAnnotationHandler;
21 import org.eclipse.pde.internal.core.schema.SchemaRegistry;
22 import org.eclipse.pde.internal.core.util.SchemaUtil;
23 import org.eclipse.pde.internal.core.util.XMLComponentRegistry;
24
25 public class VirtualSchemaObject implements ISchemaObject {
26
27     private String JavaDoc fName;
28     
29     private Object JavaDoc fDescription;
30     
31     private int fType;
32     
33     public VirtualSchemaObject(String JavaDoc name, Object JavaDoc description, int type) {
34         fName = name;
35         fDescription = description;
36         fType = type;
37     }
38     
39     public String JavaDoc getDescription() {
40         if (fDescription instanceof String JavaDoc) {
41             return (String JavaDoc)fDescription;
42         } else if (fDescription instanceof IPluginExtensionPoint) {
43             // Making the description an Object was necessary to defer
44
// the retrieval of the schema description String to
45
// only when it is need - instead of ahead of time.
46
// Retrieval of the String involves reparsing the schema from
47
// file which is has a huge performance cost during content
48
// assist sessions.
49
return getSchemaDescription((IPluginExtensionPoint)fDescription);
50         }
51         return null;
52     }
53     
54     public String JavaDoc getName() {
55         return fName;
56     }
57
58     public ISchemaObject getParent() {
59         return null;
60     }
61
62     public ISchema getSchema() {
63         return null;
64     }
65
66     public void setParent(ISchemaObject parent) {
67     }
68
69     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
70         return null;
71     }
72
73     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
74     }
75
76     public int getVType() {
77         return fType;
78     }
79     
80     public void setVType(int type) {
81         fType = type;
82     }
83     
84     private String JavaDoc getSchemaDescription(IPluginExtensionPoint point) {
85         String JavaDoc description = null;
86         if (point != null) {
87             description = XMLComponentRegistry.Instance().getDescription(
88                     point.getFullId(), XMLComponentRegistry.F_SCHEMA_COMPONENT);
89             if (description == null) {
90                 URL JavaDoc url = SchemaRegistry.getSchemaURL(point);
91                 if (url != null) {
92                     SchemaAnnotationHandler handler =
93                         new SchemaAnnotationHandler();
94                     SchemaUtil.parseURL(url, handler);
95                     description = handler.getDescription();
96                     XMLComponentRegistry.Instance().putDescription(point.getFullId(),
97                             description, XMLComponentRegistry.F_SCHEMA_COMPONENT);
98                 }
99             }
100         }
101         
102         return description;
103     }
104     
105 }
106
Popular Tags