001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.contentassist;
011:
012: import java.io.PrintWriter;
013: import java.net.URL;
014:
015: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
016: import org.eclipse.pde.internal.core.ischema.ISchema;
017: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
018: import org.eclipse.pde.internal.core.schema.SchemaAnnotationHandler;
019: import org.eclipse.pde.internal.core.schema.SchemaRegistry;
020: import org.eclipse.pde.internal.core.util.SchemaUtil;
021: import org.eclipse.pde.internal.core.util.XMLComponentRegistry;
022:
023: public class VirtualSchemaObject implements ISchemaObject {
024:
025: private String fName;
026:
027: private Object fDescription;
028:
029: private int fType;
030:
031: public VirtualSchemaObject(String name, Object description, int type) {
032: fName = name;
033: fDescription = description;
034: fType = type;
035: }
036:
037: public String getDescription() {
038: if (fDescription instanceof String) {
039: return (String) fDescription;
040: } else if (fDescription instanceof IPluginExtensionPoint) {
041: // Making the description an Object was necessary to defer
042: // the retrieval of the schema description String to
043: // only when it is need - instead of ahead of time.
044: // Retrieval of the String involves reparsing the schema from
045: // file which is has a huge performance cost during content
046: // assist sessions.
047: return getSchemaDescription((IPluginExtensionPoint) fDescription);
048: }
049: return null;
050: }
051:
052: public String getName() {
053: return fName;
054: }
055:
056: public ISchemaObject getParent() {
057: return null;
058: }
059:
060: public ISchema getSchema() {
061: return null;
062: }
063:
064: public void setParent(ISchemaObject parent) {
065: }
066:
067: public Object getAdapter(Class adapter) {
068: return null;
069: }
070:
071: public void write(String indent, PrintWriter writer) {
072: }
073:
074: public int getVType() {
075: return fType;
076: }
077:
078: public void setVType(int type) {
079: fType = type;
080: }
081:
082: private String getSchemaDescription(IPluginExtensionPoint point) {
083: String description = null;
084: if (point != null) {
085: description = XMLComponentRegistry.Instance()
086: .getDescription(point.getFullId(),
087: XMLComponentRegistry.F_SCHEMA_COMPONENT);
088: if (description == null) {
089: URL url = SchemaRegistry.getSchemaURL(point);
090: if (url != null) {
091: SchemaAnnotationHandler handler = new SchemaAnnotationHandler();
092: SchemaUtil.parseURL(url, handler);
093: description = handler.getDescription();
094: XMLComponentRegistry.Instance().putDescription(
095: point.getFullId(), description,
096: XMLComponentRegistry.F_SCHEMA_COMPONENT);
097: }
098: }
099: }
100:
101: return description;
102: }
103:
104: }
|