dtSkins =
+ DTSkinManager.getInstance((IDOMNode)element).getCurrentSkins();
+ for (IDTSkin dtSkin: dtSkins) {
+ if (dtSkin != null) {
+ styleSheets.addAll(dtSkin.getStyleSheets());
+ }
+ }
+ }
+
return styleSheets;
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java
index a6c5289e0..580b34726 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java
@@ -28,6 +28,7 @@ import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle;
import org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo;
import org.eclipse.jst.pagedesigner.css2.widget.BorderUtil;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
/**
@@ -332,6 +333,14 @@ public class CSSFigure extends FlowFigure implements ICSSFigure {
}
g.restoreState();
+ //handle background-image
+ Object bgImage = getCSSStyle().getStyleProperty(ICSSPropertyID.ATTR_BACKGROUND_IMAGE);
+ if (bgImage instanceof Image) {
+ g.setClip(bounds);
+ g.drawImage((Image)bgImage, bounds.x, bounds.y);
+ g.restoreState();
+ }
+
LayoutManager layout = getLayoutManager();
if (layout instanceof ICSSPainter) {
if (useLocalCoordinates()) {
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BackgroundImageMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BackgroundImageMeta.java
new file mode 100644
index 000000000..7c205c24e
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BackgroundImageMeta.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.css2.property;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.jst.pagedesigner.IHTMLConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
+import org.eclipse.jst.pagedesigner.utils.DOMUtil;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.css.CSSValue;
+
+/**
+ * Provides metadata for the "background-image" CSS property.
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class BackgroundImageMeta extends CSSPropertyMeta {
+
+ private static final String[] _keywords = {ICSSPropertyID.VAL_NONE};
+
+ /**
+ * Construct an instance.
+ */
+ public BackgroundImageMeta() {
+ super(false, ICSSPropertyID.VAL_NONE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, java.lang.String, org.eclipse.jst.pagedesigner.css2.ICSSStyle)
+ */
+ @Override
+ public Object calculateCSSValueResult(CSSValue value, String propertyName,
+ ICSSStyle style) {
+ Object ret = null;
+ String valueText = value.getCssText();
+ if (valueText != null && valueText.length() > 0) {
+ valueText = stripURLSyntax(valueText);
+ ret = getImage(valueText, null);
+ }
+ if (ret == null) {
+ ret = getInitialValue(propertyName, style);
+ }
+ return ret;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, java.lang.String, java.lang.String, org.eclipse.jst.pagedesigner.css2.ICSSStyle)
+ */
+ @Override
+ public Object calculateHTMLAttributeOverride(Element element,
+ String htmltag, String propertyName, ICSSStyle style) {
+ Image image = null;
+ if (
+ element != null &&
+ element.getNodeName() != null &&
+ element.getNodeName().equalsIgnoreCase(IHTMLConstants.TAG_BODY)) {
+ if (ICSSPropertyID.ATTR_BACKGROUND_IMAGE.equalsIgnoreCase(propertyName)) {
+ String attrValue = DOMUtil.getAttributeIgnoreCase(element, IHTMLConstants.ATTR_BACKGROUND);
+ if (attrValue != null && attrValue.trim().length() > 0) {
+ image = getImage(attrValue.trim(), element);
+ }
+ }
+ }
+ return image;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()
+ */
+ @Override
+ protected String[] getKeywordValues() {
+ return _keywords;
+ }
+
+ private String stripURLSyntax(String input) {
+ String output = null;
+ if (input != null) {
+ //strip "url(...)"
+ int startPos = input.indexOf("url(") + 4; //$NON-NLS-1
+ if (startPos > -1 && startPos < input.length() - 1) {
+ int endPos = input.indexOf(')', startPos);
+ if (endPos > startPos) {
+ String insideURL = input.substring(startPos, endPos).trim();
+ //strip double-quotes
+ if (insideURL.startsWith("\"") && insideURL.endsWith("\"")) { //$NON-NLS-1 //$NON-NLS-2
+ output = insideURL.substring(1, insideURL.length() - 1);
+ //strip single-quotes
+ } else if (insideURL.startsWith("'") && insideURL.endsWith("'")) { //$NON-NLS-1 //$NON-NLS-2
+ output = insideURL.substring(1, insideURL.length() - 1);
+ } else {
+ output = insideURL;
+ }
+ }
+ }
+ }
+ return output != null ? output : input;
+ }
+
+ /* Image instances returned from this method should not be disposed because
+ * they are cached in the plug-in's ImageRegistry and will be disposed of
+ * by the registry.
+ */
+ private Image getImage(String imagePath, Element element) {
+ Image image = null;
+ if (imagePath != null && imagePath.length() > 0) {
+ ImageRegistry registry = PDPlugin.getDefault().getImageRegistry();
+ image = registry.get(imagePath);
+ if (image == null) {
+ try {
+ URL imageURL = new URL(imagePath);
+ ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(imageURL);
+ image = imageDescriptor.createImage();
+ if (image != null) {
+ registry.put(imagePath, image);
+ }
+ } catch(MalformedURLException mue) {
+ //attempt to resolve as relative to document
+ if (element instanceof IDOMNode) {
+ IDOMModel model = ((IDOMNode)element).getModel();
+ if (model != null) {
+ String baseLocation = model.getBaseLocation();
+ if (baseLocation != null && baseLocation.length() > 0) {
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ if (wsRoot != null) {
+ IResource jspRes = wsRoot.findMember(baseLocation);
+ if (jspRes != null) {
+ IContainer jspFolder = jspRes.getParent();
+ if (jspFolder != null) {
+ IResource imageRes = jspFolder.findMember(imagePath);
+ if (imageRes != null) {
+ URI imageURI = imageRes.getLocationURI();
+ if (imageURI != null) {
+ try {
+ URL imageURL = imageURI.toURL();
+ ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(imageURL);
+ image = imageDescriptor.createImage();
+ if (image != null) {
+ registry.put(imagePath, image);
+ }
+ } catch(MalformedURLException mue2) {
+ //ignore - what else can be done?
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else if (image.isDisposed()) {
+ //shouldn't be able to get here from there, but...just in case
+ registry.remove(imagePath);
+ image = getImage(imagePath, element);
+ }
+ }
+ return image;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java
index 670f3ddc2..e6582bf1f 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java
@@ -27,13 +27,12 @@ public class CSSMetaRegistry {
}
/**
- * class initiallizer
+ * class initializer
*/
private void initialize() {
_map.put(ICSSPropertyID.ATTR_DISPLAY, new DisplayMeta());
_map.put(ICSSPropertyID.ATTR_TEXTALIGN, new TextAlignMeta());
- _map.put(ICSSPropertyID.ATTR_HORIZONTAL_ALIGN,
- new HorizontalAlignMeta());
+ _map.put(ICSSPropertyID.ATTR_HORIZONTAL_ALIGN, new HorizontalAlignMeta());
_map.put(ICSSPropertyID.ATTR_TEXTDECORATION, new TextDecorationMeta());
_map.put(ICSSPropertyID.ATTR_WHITESPACE, new WhiteSpaceMeta());
_map.put(ICSSPropertyID.ATTR_WIDTH, new WidthMeta());
@@ -43,23 +42,17 @@ public class CSSMetaRegistry {
_map.put(ICSSPropertyID.ATTR_BORDER_LEFT_WIDTH, new BorderWidthMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_RIGHT_WIDTH, new BorderWidthMeta());
- _map
- .put(ICSSPropertyID.ATTR_BORDER_BOTTOM_WIDTH,
- new BorderWidthMeta());
+ _map.put(ICSSPropertyID.ATTR_BORDER_BOTTOM_WIDTH, new BorderWidthMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_TOP_WIDTH, new BorderWidthMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_LEFT_STYLE, new BorderStyleMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_RIGHT_STYLE, new BorderStyleMeta());
- _map
- .put(ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE,
- new BorderStyleMeta());
+ _map.put(ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE, new BorderStyleMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_TOP_STYLE, new BorderStyleMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_LEFT_COLOR, new BorderColorMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_RIGHT_COLOR, new BorderColorMeta());
- _map
- .put(ICSSPropertyID.ATTR_BORDER_BOTTOM_COLOR,
- new BorderColorMeta());
+ _map.put(ICSSPropertyID.ATTR_BORDER_BOTTOM_COLOR, new BorderColorMeta());
_map.put(ICSSPropertyID.ATTR_BORDER_TOP_COLOR, new BorderColorMeta());
_map.put(ICSSPropertyID.ATTR_PADDING_LEFT, new PaddingWidthMeta());
@@ -77,8 +70,8 @@ public class CSSMetaRegistry {
_map.put(ICSSPropertyID.ATTR_FONT_STYLE, new FontStyleMeta());
_map.put(ICSSPropertyID.ATTR_FONT_WEIGHT, new FontWeightMeta());
- _map.put(ICSSPropertyID.ATTR_BACKGROUND_COLOR,
- new BackgroundColorMeta());
+ _map.put(ICSSPropertyID.ATTR_BACKGROUND_COLOR, new BackgroundColorMeta());
+ _map.put(ICSSPropertyID.ATTR_BACKGROUND_IMAGE, new BackgroundImageMeta());
_map.put(ICSSPropertyID.ATTR_COLOR, new ColorPropertyMeta());
_map.put(ICSSPropertyID.ATTR_TEXTCOLOR, new ColorPropertyMeta());
@@ -86,14 +79,10 @@ public class CSSMetaRegistry {
_map.put(ICSSPropertyID.ATTR_BORDER_SPACING, new BorderSpacingMeta());
_map.put(ICSSPropertyID.ATTR_LIST_STYLE_TYPE, new ListStyleTypeMeta());
- _map
- .put(ICSSPropertyID.ATTR_LIST_STYLE_IMAGE,
- new ListStyleImageMeta());
- _map.put(ICSSPropertyID.ATTR_LIST_STYLE_POSITION,
- new ListStylePositionMeta());
+ _map.put(ICSSPropertyID.ATTR_LIST_STYLE_IMAGE, new ListStyleImageMeta());
+ _map.put(ICSSPropertyID.ATTR_LIST_STYLE_POSITION, new ListStylePositionMeta());
_map.put(ICSSPropertyID.ATTR_COUNTER_RESET, new CounterResetMeta());
- _map.put(ICSSPropertyID.ATTR_COUNTER_INCREMENT,
- new CounterIncrementMeta());
+ _map.put(ICSSPropertyID.ATTR_COUNTER_INCREMENT, new CounterIncrementMeta());
_map.put(ICSSPropertyID.ATTR_TOP, new PositionOffsetMeta());
_map.put(ICSSPropertyID.ATTR_RIGHT, new PositionOffsetMeta());
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java
index f12d5b595..4930fabf1 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java
@@ -180,6 +180,11 @@ public interface ICSSPropertyID {
*/
public static final String ATTR_BACKGROUND_COLOR = "background-color"; //$NON-NLS-1$
+ /**
+ * css style attribute
+ */
+ public static final String ATTR_BACKGROUND_IMAGE = "background-image"; //$NON-NLS-1$
+
/**
* css style attribute
*/
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/AbstractDTResourceProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/AbstractDTResourceProvider.java
new file mode 100644
index 000000000..125b07787
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/AbstractDTResourceProvider.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+/**
+ * Abstract implementation of IDTResourceProvider that is intended for client
+ * extension.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public abstract class AbstractDTResourceProvider implements IDTResourceProvider {
+
+ /**
+ * The ID of this provider.
+ */
+ protected String id;
+
+ /**
+ * Constructs an instance.
+ *
+ * @param id The ID of this provider.
+ */
+ public AbstractDTResourceProvider(String id) {
+ setId(id);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTResourceProvider#getId()
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the ID of this provider.
+ *
+ * @param id The ID of this provider.
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/AbstractDTSkin.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/AbstractDTSkin.java
new file mode 100644
index 000000000..ef53c157c
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/AbstractDTSkin.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+/**
+ * Abstract implementation of IDTSkin that is intended for client extension.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public abstract class AbstractDTSkin implements IDTSkin {
+
+ /**
+ * The human-readable name of the skin.
+ */
+ protected String name;
+
+ /**
+ * true if this instance is considered the default for its provider.
+ */
+ protected boolean isDefault;
+
+ /**
+ * Constructs an instance.
+ *
+ * @param name The human-readable name of the skin.
+ */
+ public AbstractDTSkin(String name) {
+ this(name, false);
+ }
+
+ /**
+ * Constructs an instance.
+ *
+ * @param name The human-readable name of the skin.
+ * @param isDefault true if this instance is considered the default for its
+ * provider.
+ */
+ public AbstractDTSkin(String name, boolean isDefault) {
+ setName(name);
+ setDefault(isDefault);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTSkin#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the human-readable name of the skin.
+ *
+ * @param name The human-readable name of the skin.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTSkin#isDefault()
+ */
+ public boolean isDefault() {
+ return isDefault;
+ }
+
+ /**
+ * Sets if this instance is considered the default for its provider.
+ *
+ * @param isDefault true if this instance is considered the default for its
+ * provider.
+ */
+ public void setDefault(boolean isDefault) {
+ this.isDefault = isDefault;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DTResourceProviderFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DTResourceProviderFactory.java
new file mode 100644
index 000000000..6dccfd102
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DTResourceProviderFactory.java
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
+import org.eclipse.jst.jsp.core.taglib.ITaglibDescriptor;
+import org.eclipse.jst.jsp.core.taglib.ITaglibRecord;
+import org.eclipse.jst.jsp.core.taglib.TaglibIndex;
+import org.eclipse.jst.pagedesigner.IJMTConstants;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.jst.pagedesigner.utils.StructuredModelUtil;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.osgi.framework.Bundle;
+
+/**
+ * Factory responsible for producing {@link IDTResourceProvider} instances from
+ * org.eclipse.jst.pagedesigner.pageDesignerExtension.dtResourceProvider
+ * extensions.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class DTResourceProviderFactory {
+
+ private static DTResourceProviderFactory instance;
+ private ProviderClassMap providerClassMap;
+ private Map> providerMap;
+ private Logger log = PDPlugin.getLogger(DTResourceProviderFactory.class);
+
+ private DTResourceProviderFactory() {
+ //singleton - no external instantiation
+ providerClassMap = new ProviderClassMap();
+ loadExtensions();
+ providerMap = new HashMap>();
+ }
+
+ /**
+ * Gets the singleton instance.
+ *
+ * @return The singleton instance.
+ */
+ public static synchronized DTResourceProviderFactory getInstance() {
+ if (instance == null) {
+ instance = new DTResourceProviderFactory();
+ }
+ return instance;
+ }
+
+ /**
+ * Returns a List of IDTResourceProvider instances that are active for the
+ * specified IProject instance.
+ *
+ * @param project IProject instance for which to get the active
+ * IDTResourceProvider instances.
+ * @return A List of IDTResourceProvider instances that are active for the
+ * specified IProject instance. List may be empty, but will not be null.
+ */
+ public List getActiveDTResourceProviders(IProject project) {
+ List activeProviders = new ArrayList();
+ if (project != null) {
+ ITaglibRecord[] taglibRecords = TaglibIndex.getAvailableTaglibRecords(project.getFullPath());
+ if (taglibRecords != null && taglibRecords.length > 0) {
+ for (ITaglibRecord taglibRecord: taglibRecords) {
+ ITaglibDescriptor taglibDescriptor = taglibRecord.getDescriptor();
+ if (taglibDescriptor != null) {
+ String taglibURI = taglibDescriptor.getURI();
+ if (taglibURI != null) {
+ activeProviders.addAll(getDTResourceProviders(project, taglibURI));
+ }
+ }
+ }
+ }
+ }
+ return Collections.unmodifiableList(activeProviders);
+ }
+
+ /**
+ * Convenience method to determine IProject instance from the specified
+ * IDOMNode instance and then call {@link #getActiveDTResourceProviders(IProject)}.
+ *
+ * @param domNode IDOMNode instance from which to determine IProject
+ * instance.
+ * @return A List of IDTResourceProvider instances that are active for the
+ * specified IDOMNode instance's IProject instance. List may be empty, but
+ * will not be null.
+ */
+ public List getActiveDTResourceProviders(IDOMNode domNode) {
+ IDOMModel domModel = domNode.getModel();
+ IProject project = null;
+ if (domModel != null) {
+ project = StructuredModelUtil.getProjectFor(domModel);
+ }
+ return getActiveDTResourceProviders(project);
+ }
+
+ /**
+ * Returns a List of IDTResourceProvider instances for the specified
+ * IProject instance and id.
+ *
+ * @param project IProject instance for which a List of IDTResourceProviders
+ * is being requested.
+ * @param id Identifier for which a List of IDTResourceProvider instances is
+ * being requested.
+ * @return A List of IDTResourceProvider instances for the specified
+ * IProject instance and id. List may be empty, but will not be null.
+ */
+ public synchronized List getDTResourceProviders(IProject project, String id) {
+ List providers = new ArrayList();
+ List projectProviders = providerMap.get(project);
+ if (projectProviders == null) {
+ projectProviders = providerClassMap.createInstances();
+ providerMap.put(project, projectProviders);
+ }
+ for (IDTResourceProvider curProvider: projectProviders) {
+ if (curProvider.getId().equals(id)) {
+ providers.add(curProvider);
+ }
+ }
+ return providers;
+ }
+
+ private void loadExtensions() {
+ try {
+ final IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(PDPlugin.getPluginId(), IJMTConstants.EXTENSION_POINT_PAGEDESIGNER);
+ final IExtension[] extensions = extPoint.getExtensions();
+ for (int i = 0; i < extensions.length; i++) {
+ final IExtension extension = extensions[i];
+ final IConfigurationElement[] confElements = extension.getConfigurationElements();
+ for (int j = 0; j < confElements.length; j++) {
+ final IConfigurationElement confElement = confElements[j];
+ if (confElement.getName().equals(IJMTConstants.DT_RESOURCE_PROVIDER)) {
+ final String id = confElement.getAttribute("id"); //$NON-NLS-1$
+ final String providerClassName = confElement.getAttribute("class"); //$NON-NLS-1$
+ final Bundle bundle = Platform.getBundle(confElement.getContributor().getName());
+ if (bundle != null) {
+ try {
+ providerClassMap.add(id, bundle.loadClass(providerClassName));
+ } catch(ClassNotFoundException cnfe) {
+ log.error("Warning.DTResourceProviderFactory.ClassNotFound", providerClassName, id, cnfe); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ } catch(InvalidRegistryObjectException iroe) {
+ log.error("Warning.DTResourceProviderFactory.RegistryError", PDPlugin.getPluginId() + IJMTConstants.EXTENSION_POINT_PAGEDESIGNER + "." + IJMTConstants.DT_RESOURCE_PROVIDER, iroe); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DTSkinManager.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DTSkinManager.java
new file mode 100644
index 000000000..77131cac4
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DTSkinManager.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jst.pagedesigner.utils.StructuredModelUtil;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+
+/**
+ * Manages IDTSkin instances and provides skin-related services.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class DTSkinManager {
+
+ private static Map dtSkinManagerMap =
+ new HashMap();
+
+ private Map currentDTSkinMap;
+
+ private IProject project;
+
+ /**
+ * Constructs an instance (no public instantiation).
+ *
+ * @param project IProject instance for which this instance applies.
+ */
+ private DTSkinManager(IProject project) {
+ this.project = project;
+ currentDTSkinMap = new HashMap();
+ }
+
+ /**
+ * Gets a DTSkinManager instance for the specified project instance.
+ *
+ * @param aProject IProject instance for which a DTSkinManager is being
+ * requested.
+ * @return A DTSkinManager instance for the specified project instance.
+ */
+ public static synchronized DTSkinManager getInstance(IProject aProject) {
+ DTSkinManager dtSkinManager = dtSkinManagerMap.get(aProject);
+ if (dtSkinManager == null) {
+ dtSkinManager = new DTSkinManager(aProject);
+ dtSkinManagerMap.put(aProject, dtSkinManager);
+ }
+ return dtSkinManager;
+ }
+
+ /**
+ * Gets a DTSkinManager instance for the IProject instance associated with
+ * the specified IDOMNode instance.
+ *
+ * @param domNode IDOMNode instance for which a DTSkinManager is being
+ * requested.
+ * @return A DTSkinManager instance for the IProject instance associated
+ * with the specified IDOMNode instance.
+ */
+ public static DTSkinManager getInstance(IDOMNode domNode) {
+ IDOMModel domModel = domNode.getModel();
+ IProject aProject = null;
+ if (domModel != null) {
+ aProject = StructuredModelUtil.getProjectFor(domModel);
+ }
+ return getInstance(aProject);
+ }
+
+ /**
+ * Returns a List of available IDTSkin instances.
+ *
+ * @param id ID for which to get skins.
+ * @return A List of available IDTSkin instances. List may be empty, but
+ * will not be null.
+ */
+ public List getSkins(String id) {
+ List dtSkins = new ArrayList();
+ List dtResourceProviders =
+ DTResourceProviderFactory.getInstance().getActiveDTResourceProviders(project);
+ for (IDTResourceProvider dtResourceProvider: dtResourceProviders) {
+ if (dtResourceProvider.getId().equals(id)) {
+ dtSkins.addAll(dtResourceProvider.getSkins());
+ }
+ }
+ return dtSkins;
+ }
+
+ /**
+ * Returns the current IDTSkin instance for the specified ID.
+ *
+ * @param id The ID (typically nsURI) for which the current IDTSkin instance
+ * is being requested.
+ * @return The current IDTSkin instance for the specified ID. May return
+ * null if there is no current IDTSkin instance for the specified ID.
+ */
+ public IDTSkin getCurrentSkin(String id) {
+ IDTSkin dtSkin = currentDTSkinMap.get(id);
+ if (dtSkin == null) {
+ dtSkin = getDefaultSkin(id);
+ setCurrentSkin(id, dtSkin);
+ }
+ return dtSkin;
+ }
+
+ /**
+ * Sets the current IDTSkin instance for the specified ID.
+ *
+ * @param id The ID (typically nsURI) for which the current IDTSkin instance
+ * is being set.
+ * @param dtSkin The current IDTSkin instance to be set for the specified ID.
+ */
+ public void setCurrentSkin(String id, IDTSkin dtSkin) {
+ if (id != null) {
+ IDTSkin existingDTSkin = currentDTSkinMap.get(id);
+ if (existingDTSkin != null) {
+ existingDTSkin.releaseResources();
+ }
+ if (dtSkin != null) {
+ currentDTSkinMap.put(id, dtSkin);
+ } else {
+ currentDTSkinMap.remove(id);
+ }
+ }
+ }
+
+ /**
+ * Returns a List of all current DTSkin instances (one per id).
+ *
+ * @return A List of all current DTSkin instances (one per id).
+ */
+ public List getCurrentSkins() {
+ List currentDTSkins = new ArrayList();
+ List dtResourceProviders =
+ DTResourceProviderFactory.getInstance().getActiveDTResourceProviders(project);
+ for (IDTResourceProvider dtResourceProvider: dtResourceProviders) {
+ IDTSkin dtSkin = getCurrentSkin(dtResourceProvider.getId());
+ if (dtSkin != null && !currentDTSkins.contains(dtSkin)) {
+ currentDTSkins.add(dtSkin);
+ }
+ }
+ return Collections.unmodifiableList(currentDTSkins);
+ }
+
+ /**
+ * Returns the default IDTSkin instance for the specified ID.
+ *
+ * @param id The ID (typically nsURI) for which the default IDTSkin instance
+ * is being requested.
+ * @return The default IDTSkin instance for the specified ID. May return
+ * null if there is no default IDTSkin instance for the specified ID.
+ */
+ public IDTSkin getDefaultSkin(String id) {
+ IDTSkin firstDTSkin = null;
+ IDTSkin defaultDTSkin = null;
+ for (IDTSkin dtSkin: getSkins(id)) {
+ if (firstDTSkin == null) {
+ firstDTSkin = dtSkin;
+ }
+ if (dtSkin.isDefault()) {
+ defaultDTSkin = dtSkin;
+ break;
+ }
+ }
+ if (defaultDTSkin == null) {
+ defaultDTSkin = firstDTSkin;
+ }
+ return defaultDTSkin;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DefaultDTResourceProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DefaultDTResourceProvider.java
new file mode 100644
index 000000000..8d0a54bd3
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DefaultDTResourceProvider.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Concrete implementation of IDTResourceProvider.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class DefaultDTResourceProvider extends AbstractDTResourceProvider {
+
+ /**
+ * List of IDTSkin instances.
+ */
+ protected List skins;
+
+ /**
+ * Constructs an instance.
+ *
+ * @param id The ID of this provider.
+ */
+ public DefaultDTResourceProvider(String id) {
+ super(id);
+ skins = new ArrayList();
+ }
+
+ /**
+ * Constructs an instance.
+ *
+ * @param id The ID of this provider.
+ * @param skins The List of IDTSkin instances.
+ */
+ public DefaultDTResourceProvider(String id, List skins) {
+ super(id);
+ if (skins != null) {
+ this.skins = skins;
+ } else {
+ this.skins = new ArrayList();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTResourceProvider#getSkins()
+ */
+ public List getSkins() {
+ return Collections.unmodifiableList(skins);
+ }
+
+ /**
+ * Adds the specified IDTSkin instance to the List of IDTSkin instances.
+ *
+ * @param skin IDTSkin instance to be added.
+ * @return true (as per the general contract of the Collection.add method).
+ */
+ public boolean addSkin(IDTSkin skin) {
+ boolean ret = false;
+ if (skin != null) {
+ ret = skins.add(skin);
+ }
+ return ret;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DefaultDTSkin.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DefaultDTSkin.java
new file mode 100644
index 000000000..e6baa46e8
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/DefaultDTSkin.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
+import org.eclipse.jst.jsf.common.ui.internal.utils.ResourceUtils;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.w3c.dom.stylesheets.StyleSheet;
+
+/**
+ * Concrete implementation of AbstractDTSkin.
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class DefaultDTSkin extends AbstractDTSkin {
+
+ private List styleSheetURLs;
+ private List styleSheets;
+ private List models;
+ private Logger log = PDPlugin.getLogger(DefaultDTSkin.class);
+
+ /**
+ * Constructs an instance.
+ *
+ * @param name The human-readable name of the skin.
+ */
+ public DefaultDTSkin(String name) {
+ super(name);
+ }
+
+ /**
+ * Constructs an instance.
+ *
+ * @param name The human-readable name of the skin.
+ * @param isDefault true if this instance is considered the default for its
+ * provider.
+ */
+ public DefaultDTSkin(String name, boolean isDefault) {
+ super(name, isDefault);
+ }
+
+ /**
+ * Constructs an instance.
+ *
+ * @param name The human-readable name of the skin.
+ * @param styleSheetURLs The List of URL instances that provide an absolute
+ * reference to the stylesheets.
+ */
+ public DefaultDTSkin(String name, List styleSheetURLs) {
+ this(name);
+ this.styleSheetURLs = styleSheetURLs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTSkin#getStyleSheets()
+ */
+ public List getStyleSheets() {
+ if (styleSheets == null) {
+ styleSheets = new ArrayList();
+ if (styleSheetURLs != null) {
+ for (URL currentURL: styleSheetURLs) {
+ InputStream in = null;
+ try {
+ in = currentURL.openStream();
+ if (in != null) {
+ IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(currentURL.toExternalForm(), in, null);
+ if (model instanceof ICSSModel) {
+ styleSheets.add((StyleSheet)((ICSSModel)model).getDocument());
+ if (models == null) {
+ models = new ArrayList();
+ }
+ models.add(model);
+ } else {
+ model.releaseFromRead();
+ }
+ }
+ } catch(IOException ioe) {
+ log.error("Warning.DefaultDTSkin.FailureLoadingStyleSheet", name, currentURL.toExternalForm(), ioe); //$NON-NLS-1$
+ } finally {
+ ResourceUtils.ensureClosed(in);
+ }
+ }
+ }
+ }
+ return Collections.unmodifiableList(styleSheets);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTSkin#getStyleSheetLocations()
+ */
+ public List getStyleSheetLocations() {
+ List locations = new ArrayList();
+ if (styleSheetURLs != null) {
+ for (URL currentURL: styleSheetURLs) {
+ locations.add(currentURL.toExternalForm());
+ }
+ }
+ return Collections.unmodifiableList(locations);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.pagedesigner.dtresourceprovider.IDTSkin#releaseResources()
+ */
+ public void releaseResources() {
+ if (models != null) {
+ for (IStructuredModel model: models) {
+ model.releaseFromRead();
+ }
+ models = null;
+ }
+ styleSheets = null;
+ }
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/IDTResourceProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/IDTResourceProvider.java
new file mode 100644
index 000000000..6a5033fbf
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/IDTResourceProvider.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.util.List;
+
+/**
+ * Defines the interface for a Design-Time (DT) "Resource Provider", which
+ * offers such services as might be expected to be provided at runtime by, for
+ * example, a resource servlet.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public interface IDTResourceProvider {
+
+ /**
+ * Returns this instance's ID.
+ *
+ * @return This instance's ID.
+ */
+ public String getId();
+
+ /**
+ * Returns a List of IDTSkin instances.
+ *
+ * @return A List of IDTSkin instances. May return an empty List, but should
+ * not return null.
+ */
+ public List getSkins();
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/IDTSkin.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/IDTSkin.java
new file mode 100644
index 000000000..04623da84
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/IDTSkin.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.util.List;
+
+import org.w3c.dom.stylesheets.StyleSheet;
+
+/**
+ * Interface that a design-time (DT) "skin" must implement.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public interface IDTSkin {
+
+ /**
+ * Returns the human-readable name of the skin.
+ *
+ * @return The human-readable name of the skin.
+ */
+ public String getName();
+
+ /**
+ * Returns a List of StyleSheet instances.
+ *
+ * @return A List of StyleSheet instances. May return an empty List, but
+ * should not return null.
+ */
+ public List getStyleSheets();
+
+ /**
+ * Returns a List of Strings representing locations (typically URIs) of
+ * stylesheets.
+ *
+ * @return List of Strings representing locations (typically URIs) of
+ * stylesheets. May return an empty List, but should not return null.
+ */
+ public List getStyleSheetLocations();
+
+ /**
+ * This will be called before an instance goes out of scope, allowing it to
+ * clean up any necessary resources. The instance should still be usable,
+ * recreating any released resources as necessary on subsequent calls to its
+ * methods.
+ */
+ public void releaseResources();
+
+ /**
+ * Returns true if this skin is considered the default for its provider.
+ *
+ * @return true if this skin is considered the default for its provider,
+ * else false.
+ */
+ public boolean isDefault();
+
+}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/ProviderClassMap.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/ProviderClassMap.java
new file mode 100644
index 000000000..f0ba4d6df
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/dtresourceprovider/ProviderClassMap.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.pagedesigner.dtresourceprovider;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
+import org.eclipse.jst.pagedesigner.PDPlugin;
+
+/**
+ * Used to Map a String ID to a List of Classes and provide convenient access.
+ *
+ * Provisional API - subject to change
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class ProviderClassMap {
+
+ private Map> idToClassListMap;
+ private Logger log = PDPlugin.getLogger(ProviderClassMap.class);
+
+ /**
+ * Creates an instance.
+ */
+ public ProviderClassMap() {
+ idToClassListMap = new HashMap>();
+ }
+
+ /**
+ * Gets the List of Classes associated with the specified ID.
+ *
+ * @param id ID for which to get the List.
+ * @return The List of Classes associated with the specified ID. List may be
+ * empty but will not be null.
+ */
+ public List get(String id) {
+ List classList = idToClassListMap.get(id);
+ if (classList == null) {
+ classList = new ArrayList();
+ idToClassListMap.put(id, classList);
+ }
+ return classList;
+ }
+
+ /**
+ * Adds the specified Class to the List associated with the specified ID.
+ *
+ * @param id ID for which to associate the specified Class.
+ * @param clazz Class to add to the List associated with the specified ID.
+ * @return true (as per the general contract of the Collection.add method).
+ */
+ public boolean add(String id, Class clazz) {
+ List classList = get(id);
+ return classList.add(clazz);
+ }
+
+ /**
+ * Instantiates all classes associated with the specified ID and returns a
+ * List of IDTResourceProvider instances.
+ *
+ * @param id ID for which to instantiate all Classes.
+ * @return a List of IDTResourceProvider instances associated with the
+ * specified ID. List may be empty but will not be null.
+ */
+ public List createInstances(String id) {
+ List providers = new ArrayList();
+ List classList = get(id);
+ for (Class providerClass: classList) {
+ try {
+ Object objProvider = providerClass.newInstance();
+ if (objProvider instanceof IDTResourceProvider) {
+ providers.add((IDTResourceProvider)objProvider);
+ } else {
+ log.error("Warning.ProviderClassMap.NotIDTResourceProvider", providerClass.getName()); //$NON-NLS-1$
+ }
+ } catch(IllegalAccessException iae) {
+ log.error("Warning.ProviderClassMap.IllegalAccess", providerClass.getName(), id, iae); //$NON-NLS-1$
+ } catch(InstantiationException ie) {
+ log.error("Warning.ProviderClassMap.Instantiation", providerClass.getName(), id, ie); //$NON-NLS-1$
+ }
+ }
+ return providers;
+ }
+
+ /**
+ * Instantiates all registered IDTResourceProviders and returns as a List.
+ *
+ * @return List of all registered IDTResourceProviders. List may be empty
+ * but will not be null.
+ */
+ public List createInstances() {
+ List providers = new ArrayList();
+ Set idSet = idToClassListMap.keySet();
+ for (String curId: idSet) {
+ List providersForCurId = createInstances(curId);
+ providers.addAll(providersForCurId);
+ }
+ return providers;
+ }
+
+}
--
cgit v1.2.3