Index: src/org/eclipse/core/internal/content/ContentTypeMatcher.java =================================================================== RCS file: /home/eclipse/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentTypeMatcher.java,v retrieving revision 1.1 diff -u -r1.1 ContentTypeMatcher.java --- src/org/eclipse/core/internal/content/ContentTypeMatcher.java 4 Mar 2005 22:18:54 -0000 1.1 +++ src/org/eclipse/core/internal/content/ContentTypeMatcher.java 8 Mar 2005 16:04:53 -0000 @@ -11,6 +11,8 @@ package org.eclipse.core.internal.content; import java.io.*; +import java.util.ArrayList; +import java.util.List; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.content.*; @@ -54,6 +56,31 @@ */ public IContentType[] findContentTypesFor(String fileName) { return getCatalog().findContentTypesFor(fileName, policy); + } + + public Object[] findRelatedObjects(IContentType type, String fileName, IRelatedRegistry registry) { + List allRelated = new ArrayList(); + // first add any objects directly related to the content type + Object[] related = registry.getRelatedObjects(type); + for (int i = 0; i < related.length; i++) + allRelated.add(related[i]); + // backward compatibility requested - add any objects related to the file name + if (fileName != null) { + related = registry.getRelatedObjects(fileName); + for (int i = 0; i < related.length; i++) + if (!allRelated.contains(related[i])) + // we don't want to return duplicates + allRelated.add(related[i]); + } + // now add any indirectly related objects, walking up the content type hierarchy + while ((type = type.getBaseType()) != null) { + related = registry.getRelatedObjects(type); + for (int i = 0; i < related.length; i++) + if (!allRelated.contains(related[i])) + // we don't want to return duplicates + allRelated.add(related[i]); + } + return allRelated.toArray(); } private ContentTypeCatalog getCatalog() { Index: src/org/eclipse/core/runtime/content/IContentTypeMatcher.java =================================================================== RCS file: /home/eclipse/org.eclipse.core.runtime/src/org/eclipse/core/runtime/content/IContentTypeMatcher.java,v retrieving revision 1.1 diff -u -r1.1 IContentTypeMatcher.java --- src/org/eclipse/core/runtime/content/IContentTypeMatcher.java 4 Mar 2005 22:18:54 -0000 1.1 +++ src/org/eclipse/core/runtime/content/IContentTypeMatcher.java 8 Mar 2005 16:04:53 -0000 @@ -23,6 +23,44 @@ * @since 3.1 */ public interface IContentTypeMatcher { + + /** + * A client-provided registry containing objects that are related to content types. Implementations + * of this interface collaborate with the content type infrastructure in order to support lookup + * of content type related objects. + *

+ * Clients may implement this interface. + *

+ * + * @see IContentTypeMatcher#findRelatedObjects(IContentType, String, IRelatedRegistry) + */ + interface IRelatedRegistry { + /** + * Returns all objects in this client-provided registry that are directly related to the given + * content type. + * + * @param type a content type + * @return an array containing all objects directly related to the given content type + */ + Object[] getRelatedObjects(IContentType type); + + /** + * Returns all objects in this client-provided registry that are directly related to the given + * file name. + *

+ * This method is optional. It only has to be implemented if this registry supports + * file name based association in addition to content type based association. + * Otherwise, it can throw UnsupportedOperationException. + *

+ * + * @param fileName a file name + * @return an array containing all objects directly related to the given file name + * @throws UnsupportedOperationException if this registry does not support file + * name based association + */ + Object[] getRelatedObjects(String fileName); + } + /** * Returns the preferred content type for the given contents and file name. *

@@ -90,6 +128,24 @@ * @return all content types associated to the given file spec */ public IContentType[] findContentTypesFor(String fileName); + + /** + * Returns all objects in the given content type-related registry that are + * related to the content type and file name specified. This method will walk + * the content type hierarchy tree up to a root content type, collecting all related + * objects from the given registry. + *

+ * The file name is optional, and has to be omitted if the given registry + * does not support file name based associations. + *

+ * + * @param type a content type + * @param fileName the name of the file, or null + * @param registry a related registry + * @return all objects in the related registry that are associated to the + * content type + */ + public Object[] findRelatedObjects(IContentType type, String fileName, IRelatedRegistry registry); /** * Tries to obtain a description for the given contents and file name.