diff options
author | cbridgha | 2005-04-12 21:27:52 +0000 |
---|---|---|
committer | cbridgha | 2005-04-12 21:27:52 +0000 |
commit | 36889d454d28b88a109a9a32c75ac21f431a7b5c (patch) | |
tree | b6012e9211c9683846d11c4f28790b02ed92ee71 | |
parent | a025ed21bb2703f1db04a94b23184846135049da (diff) | |
download | webtools.common-36889d454d28b88a109a9a32c75ac21f431a7b5c.tar.gz webtools.common-36889d454d28b88a109a9a32c75ac21f431a7b5c.tar.xz webtools.common-36889d454d28b88a109a9a32c75ac21f431a7b5c.zip |
*** empty log message ***
5 files changed, 113 insertions, 141 deletions
diff --git a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelFactory.java b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelFactory.java index 760005a3b..71234f221 100644 --- a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelFactory.java +++ b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelFactory.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.wst.common.frameworks.datamodel; -import java.util.List; - import org.eclipse.wst.common.frameworks.internal.datamodel.DataModelExtensionReader; import org.eclipse.wst.common.frameworks.internal.datamodel.DataModelImpl; @@ -20,18 +18,18 @@ public class DataModelFactory { private static DataModelExtensionReader reader; /** - * Looks up the appropriate IDataModelProvider by the specified id and - * constructs a new IDataModel. If the IDataModelProvider is not found then - * a RuntimeException is logged and null is returned. + * Looks up the appropriate IDataModelProvider by the specified id and constructs a new + * IDataModel. If the IDataModelProvider is not found then a RuntimeException is logged and null + * is returned. * * @param dataModelProviderID * the id of the IDataModelProvider * @return a new IDataModel */ public static IDataModel createDataModel(String dataModelProviderID) { - IDataModelProvider provider = loadProvider(dataModelProviderID); - if(provider == null) - return null; + IDataModelProvider provider = loadProvider(dataModelProviderID); + if (provider == null) + return null; return createDataModel(provider); } @@ -41,33 +39,31 @@ public class DataModelFactory { } return reader.getProvider(id); } - /** - * Looks up the appropriate IDataModelProvider by the specified provider Type String and functionGroupID String and - * constructs an array of new DataModelProviderDescriptor. If the IDataModelProvider is not found then - * a RuntimeException is logged and null is returned. - * - * @param providerKind - * the String id of the provider - * - * @return DataModelProviderDescriptor[] - */ - public static DataModelProviderDescriptor[] getProviderDescriptorsForProviderKind(String providerKind) { - List providers = loadProviderForProviderKind(providerKind); - if(providers == null || providers.isEmpty()) - return null; - return (DataModelProviderDescriptor[])providers.toArray(new DataModelProviderDescriptor[providers.size()]); - } - private static List loadProviderForProviderKind(String providerKind) { - if (null == reader) { - reader = new DataModelExtensionReader(); - } - return reader.getProviderDescriptorsForProviderKind(providerKind); - } /** - * Looks up the appropriate IDataModelProvider using the name of the - * specified class. This method is equavalent to - * <code>createDataModel(dataModelProviderClassID.getName())</code>. + * Looks up the appropriate dataModelProviderIDs by the specified dataModelProviderKindID. + * + * @param dataModelProviderKindID + * the String id of the dataModelProviderKindID + * + * @return the array of valid dataModelProviderIDs or an empty array if there are none. + */ + public static String[] getDataModelProviderIDsForKind(String dataModelProviderKindID) { + String[] validProviderIDs = loadProviderForProviderKind(dataModelProviderKindID); + return null != validProviderIDs ? validProviderIDs : new String[0]; + } + + + private static String [] loadProviderForProviderKind(String providerKind) { + if (null == reader) { + reader = new DataModelExtensionReader(); + } + return reader.getProviderDescriptorsForProviderKind(providerKind); + } + + /** + * Looks up the appropriate IDataModelProvider using the name of the specified class. This + * method is equavalent to <code>createDataModel(dataModelProviderClassID.getName())</code>. * * @param dataModelProviderClass * the class whose name is the id of the IDataModelProvider @@ -78,8 +74,7 @@ public class DataModelFactory { } /** - * Creates a new IDataModel using the the specified instance of an - * IDataModelProvider + * Creates a new IDataModel using the the specified instance of an IDataModelProvider * * @param dataModelProviderInstance * @return a new IDataModel diff --git a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelProviderDescriptor.java b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelProviderDescriptor.java deleted file mode 100644 index c16c5c6a8..000000000 --- a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/datamodel/DataModelProviderDescriptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004, 2005 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.wst.common.frameworks.datamodel; - -import org.eclipse.wst.common.frameworks.internal.enablement.Identifiable; - -public class DataModelProviderDescriptor implements Identifiable{ - - private String providerId; - - public DataModelProviderDescriptor(String providerId) { - super(); - this.providerId = providerId; - } - - public IDataModelProvider createProviderInstance(){ - return DataModelFactory.loadProvider(providerId); - } - - public String getID() { - return providerId; - } - - public int getLoadOrder() { - return 0; - } -} diff --git a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/datamodel/DataModelExtensionReader.java b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/datamodel/DataModelExtensionReader.java index 5897d95a5..128d6ebf0 100644 --- a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/datamodel/DataModelExtensionReader.java +++ b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/datamodel/DataModelExtensionReader.java @@ -18,7 +18,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.jem.util.RegistryReader; import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.wst.common.frameworks.datamodel.DataModelProviderDescriptor; import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider; import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; @@ -123,19 +122,21 @@ public class DataModelExtensionReader extends RegistryReader { return element; } - protected List getImplementsExtensions(String providerType) { + public String[] getProviderDescriptorsForProviderKind(String providerType) { readRegistryIfNecessary(); - List providerIds = new ArrayList(); - providerIds.add(getDefinesExtension(providerType)); - if (!implementsExtensions.containsKey(providerType)) { - return providerIds; + List providerList = new ArrayList(); + providerList.add(getDefinesExtension(providerType)); + if (implementsExtensions.containsKey(providerType)) { + List implementsIds = (List) implementsExtensions.get(providerType); + if (implementsIds != null && !implementsIds.isEmpty()) { + providerList.addAll(implementsIds); + } } - List implementsIds = (List) implementsExtensions.get(providerType); - if (implementsIds == null || implementsIds.isEmpty()) { - return providerIds; + String[] providerArray = new String[providerList.size()]; + for (int i = 0; i < providerArray.length; i++) { + providerArray[i] = (String) providerList.get(i); } - providerIds.addAll(implementsIds); - return providerIds; + return providerArray; } private void readRegistryIfNecessary() { @@ -161,16 +162,4 @@ public class DataModelExtensionReader extends RegistryReader { return provider; } - public List getProviderDescriptorsForProviderKind(String providerType) { - List providerIds = getImplementsExtensions(providerType); - List providers = new ArrayList(); - for (int i = 0; i < providerIds.size(); i++) { - providers.add(getProviderDescriptor((String) providerIds.get(i))); - } - return providers; - } - - private DataModelProviderDescriptor getProviderDescriptor(String id) { - return new DataModelProviderDescriptor(id); - } }
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/AbstractIdentifiable.java b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/AbstractIdentifiable.java new file mode 100644 index 000000000..f7d143ecd --- /dev/null +++ b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/AbstractIdentifiable.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2003, 2005 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.wst.common.frameworks.internal.enablement; + +public class AbstractIdentifiable implements Identifiable { + + protected String id; + + public AbstractIdentifiable(String id) { + this.id = id; + } + + public String getID() { + return id; + } + + public int getLoadOrder() { + return 0; + } + +} diff --git a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/DataModelEnablementFactory.java b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/DataModelEnablementFactory.java index 8e8b99246..932a7b79f 100644 --- a/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/DataModelEnablementFactory.java +++ b/plugins/org.eclipse.wst.common.frameworks/src/org/eclipse/wst/common/frameworks/internal/enablement/DataModelEnablementFactory.java @@ -12,57 +12,51 @@ package org.eclipse.wst.common.frameworks.internal.enablement; import org.eclipse.core.resources.IProject; import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.DataModelProviderDescriptor; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider; public class DataModelEnablementFactory { - /** - * Looks up the appropriate IDataModelProvider by the specified providerKind - * String and a context of the containing Project. The method gets an array - * of DataModelProviderDescriptor from the base DataModelFactory then - * filters out Providers based on function group enablement. Finally the - * Provider with the highest priority is returned. If the IDataModelProvider - * is not found then a RuntimeException is logged and null is returned. - * - * @param providerKind - * the String id of the provider kind - * @param curProject - * the containing IProject - * - * @return a new IDataModel - */ - public static IDataModel createDataModel(String providerKind, IProject curProject) { - DataModelProviderDescriptor[] providers = DataModelFactory.getProviderDescriptorsForProviderKind(providerKind); - if (providers == null || providers.length == 0) - return null; - DataModelProviderDescriptor topProvider = getHighestPriorityEnabledProviderDesc(providers, curProject); - if (topProvider == null) - return null; - IDataModelProvider provider = topProvider.createProviderInstance(); - if(provider == null) - return null; - return DataModelFactory.createDataModel(topProvider.createProviderInstance()); - } + /** + * Looks up the appropriate IDataModelProvider by the specified providerKind String and a + * context of the containing Project. The method gets an array of DataModelProviderDescriptor + * from the base DataModelFactory then filters out Providers based on function group enablement. + * Finally the Provider with the highest priority is returned. If the IDataModelProvider is not + * found then a RuntimeException is logged and null is returned. + * + * @param providerKind + * the String id of the provider kind + * @param curProject + * the containing IProject + * + * @return a new IDataModel + */ + public static IDataModel createDataModel(String providerKind, IProject curProject) { + String[] providerIDs = DataModelFactory.getDataModelProviderIDsForKind(providerKind); + if (providerIDs == null || providerIDs.length == 0) + return null; + String topProvider = getHighestPriorityEnabledProviderDesc(providerIDs, curProject); + if (topProvider == null) + return null; + return DataModelFactory.createDataModel(topProvider); + } - private static DataModelProviderDescriptor getHighestPriorityEnabledProviderDesc(DataModelProviderDescriptor[] providers, IProject curProject) { - DataModelProviderDescriptor tempDesc; - DataModelProviderDescriptor baseDesc = providers[0]; - IEnablementIdentifier enablementIdentifier; - DataModelProviderDescriptor topPriorityDesc = null; + private static String getHighestPriorityEnabledProviderDesc(String[] providerIDs, IProject curProject) { + String defaultID = providerIDs[0]; + IEnablementIdentifier enablementIdentifier; + Identifiable tempIdentifiable; + Identifiable topPriorityIdentifiable = null; - for (int i = 1; i < providers.length; i++) { - tempDesc = providers[i]; - enablementIdentifier = EnablementManager.INSTANCE.getIdentifier(tempDesc.getID(), curProject); - if (enablementIdentifier.isEnabled()) { - if (topPriorityDesc == null) - topPriorityDesc = tempDesc; - else if (IdentifiableComparator.instance.compare(tempDesc, topPriorityDesc) == IdentifiableComparator.GREATER_THAN) - topPriorityDesc = tempDesc; - } - } - if(topPriorityDesc == null) - return baseDesc; - return topPriorityDesc; - } + for (int i = 1; i < providerIDs.length; i++) { + tempIdentifiable = new AbstractIdentifiable(providerIDs[i]); + enablementIdentifier = EnablementManager.INSTANCE.getIdentifier(tempIdentifiable.getID(), curProject); + if (enablementIdentifier.isEnabled()) { + if (topPriorityIdentifiable == null) + topPriorityIdentifiable = tempIdentifiable; + else if (IdentifiableComparator.instance.compare(tempIdentifiable, topPriorityIdentifiable) == IdentifiableComparator.GREATER_THAN) + topPriorityIdentifiable = tempIdentifiable; + } + } + if (topPriorityIdentifiable == null) + return defaultID; + return topPriorityIdentifiable.getID(); + } } |