Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d0f407208eeff6eddc94cd92ae2825a71c8105b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
 *  Copyright (c) 2006, 2008 IBM Corporation and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.pde.internal.ui.editor.contentassist;

import java.io.PrintWriter;
import java.net.URL;
import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
import org.eclipse.pde.internal.core.ischema.ISchema;
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
import org.eclipse.pde.internal.core.schema.SchemaAnnotationHandler;
import org.eclipse.pde.internal.core.schema.SchemaRegistry;
import org.eclipse.pde.internal.core.util.SchemaUtil;
import org.eclipse.pde.internal.core.util.XMLComponentRegistry;

public class VirtualSchemaObject implements ISchemaObject {

	private String fName;

	private Object fDescription;

	private int fType;

	public VirtualSchemaObject(String name, Object description, int type) {
		fName = name;
		fDescription = description;
		fType = type;
	}

	public String getDescription() {
		if (fDescription instanceof String) {
			return (String) fDescription;
		} else if (fDescription instanceof IPluginExtensionPoint) {
			// Making the description an Object was necessary to defer
			// the retrieval of the schema description String to
			// only when it is need - instead of ahead of time.
			// Retrieval of the String involves reparsing the schema from
			// file which is has a huge performance cost during content
			// assist sessions.
			return getSchemaDescription((IPluginExtensionPoint) fDescription);
		}
		return null;
	}

	public String getName() {
		return fName;
	}

	public ISchemaObject getParent() {
		return null;
	}

	public ISchema getSchema() {
		return null;
	}

	public void setParent(ISchemaObject parent) {
	}

	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class adapter) {
		return null;
	}

	public void write(String indent, PrintWriter writer) {
	}

	public int getVType() {
		return fType;
	}

	public void setVType(int type) {
		fType = type;
	}

	private String getSchemaDescription(IPluginExtensionPoint point) {
		String description = null;
		if (point != null) {
			description = XMLComponentRegistry.Instance().getDescription(point.getFullId(), XMLComponentRegistry.F_SCHEMA_COMPONENT);
			if (description == null) {
				URL url = SchemaRegistry.getSchemaURL(point);
				if (url != null) {
					SchemaAnnotationHandler handler = new SchemaAnnotationHandler();
					SchemaUtil.parseURL(url, handler);
					description = handler.getDescription();
					XMLComponentRegistry.Instance().putDescription(point.getFullId(), description, XMLComponentRegistry.F_SCHEMA_COMPONENT);
				}
			}
		}

		return description;
	}

}

Back to the top