teiid SVN: r892 - trunk/server/src/main/java/com/metamatrix/platform/config/service.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 23:23:10 -0400 (Thu, 07 May 2009)
New Revision: 892
Modified:
trunk/server/src/main/java/com/metamatrix/platform/config/service/ConfigurationServiceImpl.java
Log:
Teiid 470 - when importing connector binding from mmadmin, a NPE was occurring.
Modified: trunk/server/src/main/java/com/metamatrix/platform/config/service/ConfigurationServiceImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/config/service/ConfigurationServiceImpl.java 2009-05-08 03:17:07 UTC (rev 891)
+++ trunk/server/src/main/java/com/metamatrix/platform/config/service/ConfigurationServiceImpl.java 2009-05-08 03:23:10 UTC (rev 892)
@@ -762,19 +762,20 @@
if (vmName != null) {
- if (vmName.equalsIgnoreCase("all")) { //$NON-NLS-1$
+ // for now, deploy the binding to all vms
+ // if (vmName.equalsIgnoreCase("all")) { //$NON-NLS-1$
Collection<VMComponentDefn> vms = config.getVMComponentDefns();
for (Iterator<VMComponentDefn> it=vms.iterator(); it.hasNext();) {
VMComponentDefn vm = it.next();
- DeployedComponent dc = this.deployeServiceDefnToVM( (VMComponentDefnID)vm.getID(), connectorBindingName, editor, principalName);
+ DeployedComponent dc = editor.deployServiceDefn(config, binding, (VMComponentDefnID)vm.getID());
}
- } else {
- // TODO: the method from serveradminapi passes in "ALL" and its not currently
- // called from anywhere else
- }
-
+// } else {
+// // TODO: the method from serveradminapi passes in "ALL" and its not currently
+// // called from anywhere else
+// }
+//
}
executeTransaction(editor.getDestination().popActions(), principalName);
@@ -968,8 +969,13 @@
ConfigurationObjectEditor editor = null;
try {
editor = createEditor();
+ Configuration config = getNextStartupConfiguration();
+ ServiceComponentDefn scd = config.getServiceComponentDefn(serviceName);
+
- deployComponent = deployeServiceDefnToVM(theProcessID, serviceName, editor, principalName);
+ deployComponent = editor.deployServiceDefn(config, scd, theProcessID);
+
+
executeTransaction(editor.getDestination().popActions(), principalName);
} catch (ConfigurationException theException) {
clearActions(editor);
@@ -978,19 +984,7 @@
return deployComponent;
}
- private DeployedComponent deployeServiceDefnToVM(VMComponentDefnID theProcessID,
- String serviceName,
- ConfigurationObjectEditor editor,
- String principalName) throws ConfigurationException {
-
- DeployedComponent deployComponent = null;
- Configuration config = getNextStartupConfiguration();
- ServiceComponentDefn scd = config.getServiceComponentDefn(serviceName);
- deployComponent = editor.deployServiceDefn(config, scd, theProcessID);
-
- return deployComponent;
- }
/**
* Check whether the encrypted properties for the specified ComponentDefns can be decrypted.
* @param defns List<ComponentDefn>
15 years, 8 months
teiid SVN: r891 - trunk/adminshell/src/main/resources/scripts.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 23:17:07 -0400 (Thu, 07 May 2009)
New Revision: 891
Modified:
trunk/adminshell/src/main/resources/scripts/adminapi.bsh
trunk/adminshell/src/main/resources/scripts/util.bsh
Log:
Teiid 470 - added new importconnectorbinding method to adminapi.bsh script and fixed the util.bsh script because of malform exceptions after the xml file was converted to char[].
Modified: trunk/adminshell/src/main/resources/scripts/adminapi.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/adminapi.bsh 2009-05-07 23:17:59 UTC (rev 890)
+++ trunk/adminshell/src/main/resources/scripts/adminapi.bsh 2009-05-08 03:17:07 UTC (rev 891)
@@ -175,7 +175,34 @@
return currentContext().internalAdmin.addConnectorBinding(name, readTextFile(xmlFile), new AdminOptions(option));
}
+
/**
+ * Import a {@link ConnectorBinding} into the Configuration.
+ *
+ * @param name
+ * is the Connector Binding name that will be added to Configuration
+ * @param binding
+ * byte array of the connector binding xml file
+ * @param AdminOptions that defines the options on how to import theconnector binding.
+ * There are choices about what to do when a connector binding with the given identifier
+ @ already exists in the system.
+ * See the interface {@link AdminOptions.OnConflict} for details.
+ * <p>
+ * Another option is to ignore a binding connection password decrypt error, when adding a connector
+ * binding whose password was encrypted with a different keystore, so that the new password property
+ * can be set after the connector binding has been added.</p>
+ * @throws AdminException
+ * if there's a system error.
+ * @return the {@link ConnectorBinding} representing the current property values and runtime state.
+ * @since 4.3
+ */
+ConnectorBinding addConnectorBinding(String name, String xmlFile, AdminOptions options){
+ debug("Adding Connector Binding " + name + " from a byte array");
+ checkAdmin();
+ return currentContext().internalAdmin.addConnectorBinding(name, readTextFile(xmlFile), options);
+}
+
+/**
* Deploy a {@link ConnectorBinding} to Configuration
*
* @param connectorBindingIdentifier
Modified: trunk/adminshell/src/main/resources/scripts/util.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/util.bsh 2009-05-07 23:17:59 UTC (rev 890)
+++ trunk/adminshell/src/main/resources/scripts/util.bsh 2009-05-08 03:17:07 UTC (rev 891)
@@ -1,6 +1,7 @@
import java.io.*;
import com.metamatrix.admin.api.core.*;
import com.metamatrix.admin.api.objects.*;
+import com.metamatrix.core.util.*;
debug=false;
@@ -12,13 +13,14 @@
}
byte[] readBinaryFile(String fileName) {
+ InputStream is = null;
if(fileName == null) {
throw new IOException("fileName is null");
}
try {
//try to load file from the classpath
- InputStream is = Object.class.getResourceAsStream("/"+fileName);
+ is = Object.class.getResourceAsStream("/"+fileName);
byte[] result;
if (is == null) {
@@ -26,38 +28,50 @@
is = new FileInputStream(new File(fileName));
}
- //convert to bytes
+
+ }catch(Exception e) {
+ if (is == null) {
+ try {
+ //load from "hardcoded" path
+ is = new FileInputStream(new File(fileName));
+ }catch(Exception e2) {
+
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ }
+
+ //convert to bytes
result = convertToByteArray(is);
- is.close();
+ try {
+ is.close();
+ }catch(Exception e3) {
+ }
return result;
- }catch(e) {
- e.printStackTrace();
- }
- return null;
}
char[] readTextFile(String fileName) {
if(fileName == null) {
throw new IOException("fileName is null");
}
+ char[] result = null;
+
+ try {
+ File file = new File(fileName);
+
+ // changed to use the ObectConverterUtil, instead of the
+ // convertToCharArray() method because it doesn't completely
+ // convert the file, the XML reader throws a malform exception
+ // the test case for ServerAdminImpl also the ObjectConverterUtil
+ // that's why this was changed to use it
+ result = ObjectConverterUtil.convertFileToCharArray(file, null);
- try {
- //try to load file from the classpath
- InputStream is = Object.class.getResourceAsStream("/"+fileName);
-
- char[] result;
- if (is == null) {
- //load from "hardcoded" path
- is = new FileInputStream(new File(fileName));
- }
-
- // convert to bytes
- result = convertToCharArray(is);
- is.close();
- return result;
}catch(e) {
e.printStackTrace();
- }
+ }
+ return result;
}
byte[] convertToByteArray(InputStream in) throws IOException {
15 years, 8 months
teiid SVN: r890 - trunk/server/src/test/resources/config.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 19:17:59 -0400 (Thu, 07 May 2009)
New Revision: 890
Modified:
trunk/server/src/test/resources/config/GateaConnector.cdk
Log:
JBEDSP-977 - converting importcb to use admin. Add new testcase
Modified: trunk/server/src/test/resources/config/GateaConnector.cdk
===================================================================
--- trunk/server/src/test/resources/config/GateaConnector.cdk 2009-05-07 23:17:29 UTC (rev 889)
+++ trunk/server/src/test/resources/config/GateaConnector.cdk 2009-05-07 23:17:59 UTC (rev 890)
@@ -39,7 +39,7 @@
</ComponentType>
</ComponentTypes>
<ConnectorBindings>
- <Connector Name="GateaConnectorBinding" ComponentType="GateaConnectorType" QueuedService="false" IsEnabled="true">
+ <Connector Name="connectorBinding2" ComponentType="GateaConnectorType" QueuedService="false" IsEnabled="true">
<Properties>
<Property Name="GateaHost">nydb01</Property>
<Property Name="TranslatorClass">com.metamatrix.connector.gatea.GateaConnectorTranslator</Property>
15 years, 8 months
teiid SVN: r889 - trunk/server/src/test/java/com/metamatrix/admin/server.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 19:17:29 -0400 (Thu, 07 May 2009)
New Revision: 889
Modified:
trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java
trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java
Log:
JBEDSP-977 - converting importcb to use admin. Add new testcase
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java 2009-05-07 23:15:39 UTC (rev 888)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java 2009-05-07 23:17:29 UTC (rev 889)
@@ -78,6 +78,7 @@
public class FakeConfigurationService implements ConfigurationServiceInterface {
private String CONFIG_FILE_PATH = null;
+ private ConnectorBinding cb = null;
private ConfigurationModelContainerImpl config;
public FakeConfigurationService() {
@@ -554,7 +555,12 @@
String vmName,
String principalName,
Properties properties) throws ConfigurationException {
- return null;
+
+ BasicConfigurationObjectEditor editor = new BasicConfigurationObjectEditor(false);
+ ComponentTypeID id = new ComponentTypeID(connectorType);
+
+ this.cb = editor.createConnectorComponent(Configuration.NEXT_STARTUP_ID, id, connectorBindingName, null);
+ return cb;
}
/**
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java 2009-05-07 23:15:39 UTC (rev 888)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/TestServerConfigAdminImpl.java 2009-05-07 23:17:29 UTC (rev 889)
@@ -31,6 +31,8 @@
import com.metamatrix.admin.api.exception.AdminException;
import com.metamatrix.admin.api.exception.AdminProcessingException;
+import com.metamatrix.admin.api.objects.AdminOptions;
+import com.metamatrix.admin.api.objects.ConnectorBinding;
import com.metamatrix.admin.api.objects.Host;
import com.metamatrix.core.util.ObjectConverterUtil;
import com.metamatrix.core.util.UnitTestUtil;
@@ -143,7 +145,21 @@
char[] data = ObjectConverterUtil.convertFileToCharArray(file, null);
admin.addConnectorType(name, data);
- }
+ }
+
+ public void testAddConnectorBindingUsingNameInCDK() throws Exception {
+ String cdkFileName = "GateaConnector.cdk"; //$NON-NLS-1$
+
+ final String datapath = UnitTestUtil.getTestDataPath();
+ final String fullpathName = datapath + File.separator + "config" + File.separator + cdkFileName;
+
+ File file = new File(fullpathName);
+
+ char[] data = ObjectConverterUtil.convertFileToCharArray(file, null);
+ ConnectorBinding cb = admin.addConnectorBinding("", data, new AdminOptions(AdminOptions.OnConflict.OVERWRITE));
+ assertNotNull(cb);
+
+ }
public void testAddHost() throws Exception {
String hostIdentifier = BOGUS_HOST;
15 years, 8 months
teiid SVN: r888 - trunk/common-internal/src/test/java/com/metamatrix/common/config/xml.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 19:15:39 -0400 (Thu, 07 May 2009)
New Revision: 888
Modified:
trunk/common-internal/src/test/java/com/metamatrix/common/config/xml/TestXMLConfigurationImportExportUtility.java
Log:
JBEDSP-977 - converting importcb to use admin. Add new testcase
Modified: trunk/common-internal/src/test/java/com/metamatrix/common/config/xml/TestXMLConfigurationImportExportUtility.java
===================================================================
--- trunk/common-internal/src/test/java/com/metamatrix/common/config/xml/TestXMLConfigurationImportExportUtility.java 2009-05-07 21:38:37 UTC (rev 887)
+++ trunk/common-internal/src/test/java/com/metamatrix/common/config/xml/TestXMLConfigurationImportExportUtility.java 2009-05-07 23:15:39 UTC (rev 888)
@@ -51,6 +51,7 @@
import com.metamatrix.common.config.util.ConfigurationImportExportUtility;
import com.metamatrix.common.util.ByteArrayHelper;
import com.metamatrix.core.util.FileUtils;
+import com.metamatrix.core.util.ObjectConverterUtil;
import com.metamatrix.core.util.UnitTestUtil;
@@ -380,6 +381,13 @@
if (cb == null) {
fail("didnt import binding");
}
+
+ InputStream is = ObjectConverterUtil.convertToInputStream(new File(filename));
+
+ XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
+
+ ConnectorBinding cb2 = ciu.importConnectorBinding(is, new BasicConfigurationObjectEditor(false), "");
+
}
public void testImportExportConfig() throws Exception {
15 years, 8 months
teiid SVN: r887 - trunk/common-internal/src/main/java/com/metamatrix/common/config/xml.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 17:38:37 -0400 (Thu, 07 May 2009)
New Revision: 887
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLHelperImpl.java
Log:
JBEDSP-977 - converting importcb to use admin. The fix here was when the name was an empty string, the import logic didn't treat it like a null.
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLHelperImpl.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLHelperImpl.java 2009-05-07 21:35:29 UTC (rev 886)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/xml/XMLHelperImpl.java 2009-05-07 21:38:37 UTC (rev 887)
@@ -89,18 +89,6 @@
public class XMLHelperImpl implements ConfigurationPropertyNames {
- /**
- * @see com.metamatrix.common.config.xml.XMLHelper#createDeployedComponent(org.jdom.Element, com.metamatrix.common.config.api.ConfigurationID, com.metamatrix.common.config.api.HostID, com.metamatrix.common.config.api.VMComponentDefnID, com.metamatrix.common.config.api.ProductServiceConfigID, java.util.Map, com.metamatrix.common.config.api.ConfigurationObjectEditor)
- * @since 4.1
- */
-// public DeployedComponent createDeployedComponent(Element element,
-// ConfigurationID configID,
-// HostID hostID,
-// VMComponentDefnID vmID,
-// Map componentTypeMap,
-// ConfigurationObjectEditor editor) throws InvalidConfigurationElementException {
-// return null;
-// }
/**
* This method is used to create a Configuration JDOM Element from a
* Configuration object.
@@ -116,35 +104,8 @@
return configElement;
}
-
/**
- * This method is used to create a ConfigurationInfo JDOM Element from a
- * ConfigurationInfo object.
- *
- * @param info the Object to be converted to a JDOM XML Element
- * @return a JDOM XML Element
- */
-// public Element createConfigurationInfoElement(ConfigurationInfo info) {
-// throw new UnsupportedOperationException("Method createConfigurationInfoElement is unsupported in 4.2"); //$NON-NLS-1$
-
-// Assertion.isNotNull(info);
-//
-// Element configurationInfoElement = new Element(XMLConfig_42__ElementNames.Configuration.ConfigurationInfo.ELEMENT);
-//
-// Date date = info.getLastChangedDate();
-// if (date != null) {
-// configurationInfoElement.setAttribute(XMLConfig_42__ElementNames.Configuration.ConfigurationInfo.Attributes.LAST_CHANGED_DATE, date.toString());
-// }
-//
-// date = info.getCreationDate();
-// if (date !=null) {
-// configurationInfoElement.setAttribute(XMLConfig_42__ElementNames.Configuration.ConfigurationInfo.Attributes.CREATION_DATE, date.toString());
-// }
-// return configurationInfoElement;
- // }
-
- /**
* This method is used to create a DeployedComponent JDOM Element from a
* DeployedComponent object.
*
@@ -172,14 +133,7 @@
Element vmComponentDefnElement = createComponentObjectElement(XMLConfig_ElementNames.Configuration.Process.ELEMENT, defn, true);
return vmComponentDefnElement;
}
-//
-// public Element createDeployedServiceComponentDefnElement(ServiceComponentDefn defn) {
-// Assertion.isNotNull(defn);
-//
-// Element serviceComponentDefnElement = createComponentObjectElement(XMLConfig_ElementNames.Configuration.DeployedService.ELEMENT, defn);
-// serviceComponentDefnElement.setAttribute(XMLConfig_ElementNames.Configuration.DeployedService.Attributes.ROUTING_UUID, defn.getRoutingUUID());
-// return serviceComponentDefnElement;
-// }
+
/**
* This method is used to create a ServiceComponentDefn JDOM Element from a
@@ -210,63 +164,10 @@
Element serviceComponentDefnElement = createComponentObjectElement(XMLConfig_ElementNames.Configuration.AuthenticationProviders.Provider.ELEMENT, defn, true);
return serviceComponentDefnElement;
}
- /**
- * This method is used to create a ServiceComponentDefn JDOM Element from a
- * ServiceComponentDefn object.
- *
- * @param defn the Object to be converted to a JDOM XML Element
- * @return a JDOM XML Element
- */
-// public Element createServiceComponentDefnElement(ResourceDescriptor defn) {
-// Assertion.isNotNull(defn);
-//
-// Element serviceComponentDefnElement = createComponentObjectElement(XMLConfig_ElementNames.ServiceComponentDefns.ServiceComponentDefn.ELEMENT, defn);
-// return serviceComponentDefnElement;
-// }
-
-// public Element createDeployedProductServiceConfigElement(ProductServiceConfig config) {
-// Assertion.isNotNull(config);
-//
-// Element productServiceConfigElement = createComponentObjectElement(XMLConfig_ElementNames.Configuration.ProductServiceConfig.ELEMENT, config);
-//
-// return productServiceConfigElement;
-// }
-//
-// public Element createProductServiceConfigsElement() {
-// return new Element(XMLConfig_ElementNames.ProductServiceConfigs.ELEMENT);
-//
-// }
-
-
+
/**
- * This method is used to create a ProductServiceConfig JDOM Element from a
- * ProductServiceConfig object.
- *
- * @param config the Object to be converted to a JDOM XML Element
- * @return a JDOM XML Element
- */
-// public Element createProductServiceConfigElement(ProductServiceConfig config) {
-// Assertion.isNotNull(config);
-//
-// Element productServiceConfigElement = createComponentObjectElement(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.ELEMENT, config);
-//
-// Iterator iterator = config.getServiceComponentDefnIDs().iterator();
-// while (iterator.hasNext()) {
-// ServiceComponentDefnID id = (ServiceComponentDefnID)iterator.next();
-// boolean isEnabled = config.isServiceEnabled(id);
-//
-// Element idElement = createIDElement(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Service.ELEMENT, id.getName());
-//
-// idElement.setAttribute(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Service.Attributes.IS_ENABLED, (Boolean.valueOf(isEnabled)).toString());
-//
-// productServiceConfigElement.addContent(idElement);
-// }
-// return productServiceConfigElement;
-// }
-
- /**
* This method is used to create a ComponentType JDOM Element from a
* ComponentType object.
*
@@ -457,48 +358,6 @@
}
/**
- * This method is used to create a ProductType JDOM Element from a
- * ProductType object.
- *
- * @param type the Object to be converted to a JDOM XML Element
- * @return a JDOM XML Element
- */
-// public Element createProductTypeElement(ProductType type) {
-// Assertion.isNotNull(type);
-//
-// Element productTypeElement = new Element(XMLConfig_ElementNames.ProductTypes.ProductType.ELEMENT);
-//
-// Iterator iterator = type.getComponentTypeIDs().iterator();
-// while (iterator.hasNext()) {
-// ComponentTypeID id = (ComponentTypeID)iterator.next();
-// Element componentTypeIDElement = createIDElement(XMLConfig_ElementNames.ComponentTypeID.ELEMENT, id.getName());
-// productTypeElement.addContent(componentTypeIDElement);
-// }
-//
-//
-// productTypeElement.setAttribute(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.NAME, type.getName());
-// productTypeElement.setAttribute(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.COMPONENT_TYPE_CODE, new Integer(type.getComponentTypeCode()).toString());
-// productTypeElement.setAttribute(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.DEPLOYABLE, (Boolean.valueOf(type.isDeployable())).toString());
-// productTypeElement.setAttribute(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.DEPRECATED, (Boolean.valueOf(type.isDeprecated())).toString());
-// productTypeElement.setAttribute(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.MONITORABLE, (Boolean.valueOf(type.isMonitored())).toString());
-//
-// // we only add these if they are not null
-// BaseID superID = type.getSuperComponentTypeID();
-// String superIDString;
-// if (superID != null) {
-// superIDString = superID.getName();
-// productTypeElement.setAttribute(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.SUPER_COMPONENT_TYPE, superIDString);
-//
-// }
-//
-// addChangeHistoryElement(type, productTypeElement);
-//
-//
-// return productTypeElement;
-//
-// }
-
- /**
* This method is used to create a Host JDOM Element from a
* Host object.
*
@@ -512,38 +371,7 @@
return hostElement;
}
-// public Element createDeployedVMElementx(DeployedComponent vm) {
-// Assertion.isNotNull(vm);
-//
-// Element hostElement = createComponentObjectElement(XMLConfig_ElementNames.Configuration.Host.ELEMENT, vm, true);
-// return hostElement;
-// }
-// public final boolean is42ConfigurationCompatible(Element root) throws InvalidConfigurationElementException{
-// Element headerElement = root.getChild(XMLConfig_ElementNames.Header.ELEMENT);
-// if (headerElement == null) {
-// throw new InvalidConfigurationElementException("The header element is not found in the configuration under element.", root.getName()); //$NON-NLS-1$
-// }
-//
-// Properties props = getHeaderProperties(headerElement);
-//
-//
-// String sVersion = props.getProperty(XMLConfig_ElementNames.Header.ConfigurationVersion.ELEMENT);
-//
-// if (sVersion == null) {
-// return false;
-// }
-// try {
-// double sv = Double.parseDouble(sVersion);
-// if (sv == ConfigurationPropertyNames.CONFIG_CURR_VERSION_DBL) {
-// return true;
-// }
-// } catch (Throwable t) {
-// return false;
-// }
-// return true;
-// }
-
public Properties getHeaderProperties(Element element) throws InvalidConfigurationElementException{
Properties props=new Properties();
@@ -729,52 +557,6 @@
}
-// private Element addChangeHistoryElementx(ComponentType obj) {
-//
-//// call to create the structure for the properties
-// Element changeHistoryElement = new Element(XMLConfig_ElementNames.ChangeHistory.ELEMENT);
-//
-// String lastChangedBy=null;
-// String lastChangedDate=null;
-// String createdDate=null;
-// String createdBy=null;
-//
-// lastChangedBy = obj.getLastChangedBy();
-// lastChangedDate = ((BasicComponentType) obj).getLastChangedDateString();
-//
-// createdBy = obj.getCreatedBy();
-// createdDate = ((BasicComponentType) obj).getCreatedDateString();
-//
-//
-// if (lastChangedBy == null || lastChangedBy.trim().length() == 0) {
-//
-// } else {
-//
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.LAST_CHANGED_BY, lastChangedBy);
-// }
-//
-// if (lastChangedDate == null) {
-// } else {
-//
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.LAST_CHANGED_DATE, lastChangedDate);
-// }
-//
-// if (createdBy == null || createdBy.trim().length() == 0) {
-// } else {
-//
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.CREATED_BY, createdBy);
-// }
-//
-// if (createdDate == null) {
-// } else {
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.CREATION_DATE,createdDate);
-// }
-//
-// return changeHistoryElement;
-//
-//
-// }
-
private void addChangeHistoryElement(ComponentObject obj, Element element ) {
String lastChangedBy=null;
@@ -856,53 +638,6 @@
}
-
-// private Element addChangeHistoryElementx(ComponentObject obj) {
-//
-// Element changeHistoryElement = new Element(XMLConfig_ElementNames.ChangeHistory.ELEMENT);
-//
-// String lastChangedBy=null;
-// String lastChangedDate=null;
-// String createdDate=null;
-// String createdBy=null;
-//
-// lastChangedBy = obj.getLastChangedBy();
-// lastChangedDate = ((BasicComponentObject) obj).getLastChangedDateString();
-//
-// createdBy = obj.getCreatedBy();
-// createdDate = ((BasicComponentObject) obj).getCreatedDateString();
-//
-//
-// if (lastChangedBy == null || lastChangedBy.trim().length() == 0) {
-//
-// } else {
-//
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.LAST_CHANGED_BY, lastChangedBy);
-// }
-//
-// if (lastChangedDate == null) {
-//
-// } else {
-//
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.LAST_CHANGED_DATE, lastChangedDate);
-//
-// }
-//
-// if (createdBy == null || createdBy.trim().length() == 0) {
-// } else {
-//
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.CREATED_BY, createdBy);
-// }
-//
-// if (createdDate == null) {
-// } else {
-// changeHistoryElement = addPropertyElement(changeHistoryElement, XMLConfig_ElementNames.ChangeHistory.Property.NAMES.CREATION_DATE, createdDate);
-// }
-//
-// return changeHistoryElement;
-// }
-
-
/**
* This method is used to create a Properties JDOM Element from a
* Properties object.
@@ -962,31 +697,8 @@
throw new UnsupportedOperationException("Method createConfigurationsElement is unsupported in 4.2"); //$NON-NLS-1$
}
- /**
- * This method is used to create a Hosts JDOM Element from a
- * Configuration ID object. This element is for structural organization
- * only and does not represent any real configuration object.
- *
- * @return a JDOM XML Element
- */
-// public Element createHostsElement() {
-// throw new UnsupportedOperationException("Method createHostsElement is unsupported in 4.2"); //$NON-NLS-1$
-// }
-
- /**
- * This method is used to create a Host JDOM Element from a
- * Host object.
- *
- * @param host the Object to be converted to a JDOM XML Element
- * @return a JDOM XML Element
- */
-// public Element createHostElement(Host host) {
-// Assertion.isNotNull(host);
-//
-// Element hostElement = createComponentObjectElement(XMLConfig_ElementNames.Configuration.Host.ELEMENT, host);
-// return hostElement;
-// }
+
/**
* This method is used to create a ServiceComponentDefns JDOM Element.
* This element is for structural organization
@@ -1009,9 +721,6 @@
return new Element(XMLConfig_ElementNames.ComponentTypes.ELEMENT);
}
-// public Element createProductTypesElement() {
-// return new Element(XMLConfig_ElementNames.ProductTypes.ELEMENT);
-// }
public Element createConnectorBindingsElement() {
return new Element(XMLConfig_ElementNames.Configuration.ConnectorComponents.ELEMENT);
@@ -1060,9 +769,7 @@
}
addChangeHistoryElement(componentObject, componentObjectElement);
-// componentObjectElement.addContent(chgHistoryElement);
-
return componentObjectElement;
}
@@ -1097,101 +804,27 @@
if (!element.getName().equals(XMLConfig_ElementNames.Configuration.Host.ELEMENT)) {
throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0032, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0032, element.getName()));
}
- if (name == null) {
+ if (name == null || name.trim().length() == 0) {
name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Host.Attributes.NAME);
}
Host host = editor.createHost(configID, name);
-// Element propertiesElement = element.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
-
host = (Host) setDateHistory(host, element, editor);
-// if (propertiesElement != null) {
// now we add the system properties to the configuration object
host = (Host)addProperties(element, host, editor);
-// return host;
-// }
+
return host;
}
- //
- /**
- * This method is used to create a ResourceDescriptor JDOM Element from a
- * ServiceComponentDefn object.
- *
- * @param defn the Object to be converted to a JDOM XML Element
- * @return a JDOM XML Element
- */
-// public Element createResourcePoolElement(ResourceDescriptor resource) {
-// Assertion.isNotNull(resource);
-//
-// Element resourceElement = createComponentObjectElement(XMLConfig_ElementNames.ResourcePools.ResourcePool.ELEMENT, resource);
-// return resourceElement;
-// }
-
-// public Element createResourcePoolsElement() {
-// return new Element(XMLConfig_ElementNames.ResourcePools.ELEMENT);
-// }
-
public Element createAuthenticationProviderElement() {
return new Element(XMLConfig_ElementNames.Configuration.AuthenticationProviders.ELEMENT);
}
-
-
- /**
- * This method will create a Resource configuration object from an XML element
- * that represents a Resource.
- *
- * @param element the JDOM element to convert to a configuration object
- * @param editor the editor to use to create the configuration object
- * @param name the name of the returned configuration object. Note this
- * name will override the name in the JDOM element. If the name parameter
- * is null, the name of the object in the JDOM element will be used as
- * the name of the object.
- * @return the SharedResource configuration object
- * @throws InvalidConfigurationElementException if the element passed in
- * or its XML structure do not conform to the XML structure specfied in
- * the XMLConfig_ElementNames class.
- */
-// public ResourceDescriptor createResourcePool(Element element, ConfigurationID configID, ConfigurationObjectEditor editor) throws InvalidConfigurationElementException{
-// Assertion.isNotNull(element);
-// Assertion.isNotNull(editor);
-//
-// if (!element.getName().equals(XMLConfig_ElementNames.ResourcePools.ResourcePool.ELEMENT)) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0033, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0033, element.getName()), element);
-// }
-//
-// String name = element.getAttributeValue(XMLConfig_ElementNames.ResourcePools.ResourcePool.Attributes.NAME);
-//
-// checkElementValue(name, null, ErrorMessageKeys.CONFIG_ERR_0053);
-//
-// String type = element.getAttributeValue(XMLConfig_ElementNames.ResourcePools.ResourcePool.Attributes.COMPONENT_TYPE);
-//
-// checkElementValue(type, name, ErrorMessageKeys.CONFIG_ERR_0054);
-//
-// ComponentTypeID id = new ComponentTypeID(type);
-//
-// // create the descriptor used to get the resource
-// ResourceDescriptor descriptor = editor.createResourceDescriptor(configID, id, name);
-//
-// Element propertiesElement = element.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
-//
-// descriptor = (ResourceDescriptor) setDateHistory(descriptor, element, editor);
-//
-// if (propertiesElement != null) {
-// // now we add the system properties to the configuration object
-// descriptor = (ResourceDescriptor)addProperties(propertiesElement, descriptor, editor);
-//
-// }
-//
-//
-// return descriptor;
-// }
/**
* This method will create a Resource configuration object from an XML element
@@ -1244,7 +877,6 @@
}
- //
/**
* This method is used to create a ServiceComponentDefn JDOM Element from a
* ServiceComponentDefn object.
@@ -1356,7 +988,7 @@
}
// we will use the passed in name unless it is null...
- if (name == null) {
+ if (name == null || name.trim().length() == 0) {
name = element.getAttributeValue(XMLConfig_ElementNames.ComponentTypes.ComponentType.Attributes.NAME);
}
@@ -1402,71 +1034,8 @@
return createComponentType(rootElement, new BasicConfigurationObjectEditor(), null, true);
}
- /**
- * This method will create a ProductType configuration object from an XML element
- * that represents a ProductType.
- *
- * @param element the JDOM element to convert to a configuration object
- * @param editor the editor to use to create the configuration object
- * @param name the name of the returned configuration object. Note this
- * name will override the name in the JDOM element. If the name parameter
- * is null, the name of the object in the JDOM element will be used as
- * the name of the object.
- * @param componentTypeMap this is a map of ComponentTypeID--->ComponentType
- * it must contain all of the Component types that the ProductType
- * that is represented by the passed in XML element references.
- * @return the ProductType configuration object
- * @throws InvalidConfigurationElementException if the element passed in
- * or its XML structure do not conform to the XML structure specfied in
- * the XMLConfig_ElementNames class.
- */
-// public ProductType createProductType(Element element, ConfigurationObjectEditor editor, Map componentTypeMap, String name)throws InvalidConfigurationElementException{
-// Assertion.isNotNull(element);
-// Assertion.isNotNull(editor);
-//
-// if (!element.getName().equals(XMLConfig_ElementNames.ProductTypes.ProductType.ELEMENT)) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0036, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0036, element.getName()), element);
-// }
-//
-// // retreive the attributes of this ComponentType from the JDOM element
-// String deployable = element.getAttributeValue(XMLConfig_ElementNames.ProductTypes.ProductType.Attributes.DEPLOYABLE);
-//// String monitorable = element.getAttributeValue(XMLConfig_ElementNames.ProductTypes.ProductType.Attributes.MONITORABLE);
-//
-// // we will use the passed in name unless it is null...
-// if (name == null) {
-// name = element.getAttributeValue(XMLConfig_ElementNames.ProductTypes.ProductType.Attributes.NAME);
-// }
-//
-// boolean isDeployable = (Boolean.valueOf(deployable)).booleanValue();
-// // boolean isMonitorable = (Boolean.valueOf(monitorable)).booleanValue();
-//
-// List componentTypeIDs = element.getChildren(XMLConfig_ElementNames.ComponentTypeID.ELEMENT);
-// List componentTypes = new ArrayList();
-// Iterator iter = componentTypeIDs.iterator();
-// while (iter.hasNext()) {
-// Element componentTypeIDElement = (Element)iter.next();
-// String componentTypeIDName = componentTypeIDElement.getAttributeValue(XMLConfig_ElementNames.ComponentTypeID.Attributes.NAME);
-// ComponentTypeID componentTypeID = new ComponentTypeID(componentTypeIDName);
-// ComponentType componentType = (ComponentType)componentTypeMap.get(componentTypeID);
-// if (componentType == null) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0037, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0037, new Object[] {componentTypeID, name}), element);
-// }
-// componentTypes.add(componentType);
-// }
-//
-// // create the ComponentTypeObject
-// ProductType type = editor.createProductType(name, componentTypes, isDeployable, false);
-//
-// return type;
-//// // get the ComponentTypeDefn sub-Elements of this ComponentType
-//// // and create them also.
-//// Collection componentTypeDefnElements = element.getChildren(XMLConfig_ElementNames.ComponentTypes.ComponentType.ComponentTypeDefn.ELEMENT);
-////
-//// type = (ProductType) setDateHistory(type, element, editor);
-////
-//// return (ProductType)addComponentTypeDefns(componentTypeDefnElements, type, editor);
-// }
+
/**
* This method will create a Configuration configuration object from an XML element
* that represents a Configuration.
@@ -1491,7 +1060,7 @@
throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0038, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0038, element.getName()));
}
- if (name==null) {
+ if (name==null || name.trim().length() == 0) {
name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Attributes.NAME);
}
@@ -1504,54 +1073,6 @@
return config;
}
- /**
- * This method will create a LogConfiguration configuration object from an XML element
- * that represents a LogConfiguration.
- *
- * @param element the JDOM element to convert to a configuration object
- * @param editor the editor to use to create the configuration object
- * @param name the name of the returned configuration object. Note this
- * name will override the name in the JDOM element. If the name parameter
- * is null, the name of the object in the JDOM element will be used as
- * the name of the object.
- * @return the LogConfiguration configuration object
- * @throws InvalidConfigurationElementException if the element passed in
- * or its XML structure do not conform to the XML structure specfied in
- * the XMLConfig_ElementNames class.
- */
-// public LogConfiguration createLogConfiguration(Element element) throws InvalidConfigurationElementException{
-// Assertion.isNotNull(element);
-//
-// if (!element.getName().equals(XMLConfig_ElementNames.Configuration.LogConfiguration.ELEMENT)) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0039, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0039, element.getName()), element);
-// }
-//
-// Element propertiesElement = element.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
-// Properties properties = new Properties();
-//
-//
-// List props = propertiesElement.getChildren(XMLConfig_ElementNames.Properties.Property.ELEMENT);
-// Iterator iterator = props.iterator();
-// while (iterator.hasNext()) {
-// Element propertyElement = (Element)iterator.next();
-// String propertyName = propertyElement.getAttributeValue(XMLConfig_ElementNames.Properties.Property.Attributes.NAME);
-// String propertyValue = propertyElement.getText();
-// properties.setProperty(propertyName, propertyValue);
-// }
-//
-// LogConfiguration config = null;
-//
-// try {
-// config = BasicLogConfiguration.createLogConfiguration(properties);
-// }catch(LogConfigurationException e) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0040, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0040,e.getMessage()), element);
-//
-// }
-//
-// return config;
-//
-// }
-
public Element createConnectorBindingElement(ConnectorBinding connector, boolean isExportConfig) {
Assertion.isNotNull(connector);
@@ -1575,7 +1096,7 @@
throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0041, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0041,element.getName()));
}
- if (name==null) {
+ if (name==null || name.trim().length() == 0) {
name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.ConnectorComponents.ConnectorComponent.Attributes.NAME);
}
@@ -1585,8 +1106,6 @@
ComponentTypeID id = new ComponentTypeID(componentType);
-// element.getAttributeValue(XMLConfig_ElementNames.ConnectorComponents.ConnectorComponent.Attributes.QUEUED_SERVICE);
-
String routingUUID = null;
// vah - 09-24-2003
// when importing a configuration use the routing uuid,
@@ -1649,7 +1168,7 @@
throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0042, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0042,element.getName()));
}
- if (name==null) {
+ if (name==null || name.trim().length() == 0) {
name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Services.Service.Attributes.NAME);
}
@@ -1659,31 +1178,13 @@
ComponentTypeID id = new ComponentTypeID(componentType);
-// element.getAttributeValue(XMLConfig_ElementNames.Configuration.ServiceComponentDefns.ServiceComponentDefn.Attributes.QUEUED_SERVICE);
-
String routingUUID = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Services.Service.Attributes.ROUTING_UUID);
ComponentDefn defn = null;
boolean isResourcePool = isResourcePool(componentType);
if (configID == null) {
-/*
- if (!isResourcePool) {
- if (routingUUID == null){
- //allow the object editor to generate a UUID
- defn = (ComponentDefn) editor.createServiceComponentDefn(id, name);
- } else {
- //use the UUID specified in the XML file
- defn = (ComponentDefn) editor.createServiceComponentDefn(id, name, routingUUID);
- }
- editor.setEnabled((ServiceComponentDefn) defn, isEnabled);
- } else {
- defn = editor.createResourceDescriptor(id, name);
-
-
- }
-*/
}else {
if (!isResourcePool) {
@@ -1696,11 +1197,6 @@
}
}
-// else {
-//
-// defn = editor.createResourceDescriptor(configID, id, name);
-//
-// }
}
@@ -1729,108 +1225,8 @@
}
- /**
- * This method will create a ProductServiceConfig configuration object from an XML element
- * that represents a ProductServiceConfig.
- *
- * @param element the JDOM element to convert to a configuration object
- * @param editor the editor to use to create the configuration object
- * @param name the name of the returned configuration object. Note this
- * name will override the name in the JDOM element. If the name parameter
- * is null, the name of the object in the JDOM element will be used as
- * the name of the object.
- * @return the ProductServiceConfig configuration object
- * @throws InvalidConfigurationElementException if the element passed in
- * or its XML structure do not conform to the XML structure specfied in
- * the XMLConfig_ElementNames class.
- */
-// public ProductServiceConfig createProductServiceConfig(Element element, ConfigurationID configID, ConfigurationObjectEditor editor, String name)throws InvalidConfigurationElementException {
-// Assertion.isNotNull(element);
-// Assertion.isNotNull(editor);
-// Assertion.isNotNull(configID);
-//
-// if (!element.getName().equals(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.ELEMENT)) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0043, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0043,element.getName()), element);
-// }
-//
-// if (name==null) {
-// name = element.getAttributeValue(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Attributes.NAME);
-// }
-//
-// String componentType = element.getAttributeValue(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Attributes.COMPONENT_TYPE);
-// checkElementValue(componentType, name, ErrorMessageKeys.CONFIG_ERR_0059);
-//
-//
-// // ConfigurationID configID = (ConfigurationID)config.getID();
-// ProductTypeID id = new ProductTypeID(componentType);
-//
-//
-// // ConfigurationID configID = (ConfigurationID)config.getID();
-//
-// // this new editor is used only as a way to create a product service config
-// // the passed in editor is then used to add the PSC to the configuration
-// // as passed in.
-// // we dont want to add the actions again to the passed in editor.
-// ProductServiceConfig productServiceConfig = editor.createProductServiceConfig(configID, id, name);
-//
-// Collection serviceComponentDefnIDs = element.getChildren(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Service.ELEMENT);
-//
-// if (id.getFullName().equals(MetaMatrixProductVersion.CONNECTOR_PRODUCT_TYPE_NAME)) {
-// Iterator iterator = serviceComponentDefnIDs.iterator();
-// while (iterator.hasNext()) {
-// Element serviceComponentDefnIDElement = (Element)iterator.next();
-// String serviceComponentDefnName = serviceComponentDefnIDElement.getAttributeValue(XMLConfig_ElementNames.ID.Attributes.NAME);
-//
-// String enabled = serviceComponentDefnIDElement.getAttributeValue(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Service.Attributes.IS_ENABLED);
-//
-// if (enabled == null) {
-// enabled = Boolean.TRUE.toString();
-// }
-//
-// ConnectorBindingID serviceComponentDefnID = new ConnectorBindingID(configID, serviceComponentDefnName);
-// productServiceConfig = editor.addServiceComponentDefn(productServiceConfig, serviceComponentDefnID);
-// editor.setEnabled(serviceComponentDefnID, productServiceConfig, Boolean.valueOf(enabled).booleanValue());
-//
-// }
-//
-//
-// } else {
-//
-// Iterator iterator = serviceComponentDefnIDs.iterator();
-// while (iterator.hasNext()) {
-// Element serviceComponentDefnIDElement = (Element)iterator.next();
-// String serviceComponentDefnName = serviceComponentDefnIDElement.getAttributeValue(XMLConfig_ElementNames.ID.Attributes.NAME);
-//
-// String enabled = serviceComponentDefnIDElement.getAttributeValue(XMLConfig_ElementNames.ProductServiceConfigs.ProductServiceConfig.Service.Attributes.IS_ENABLED);
-//
-// if (enabled == null) {
-// enabled = Boolean.TRUE.toString();
-// }
-//
-// ServiceComponentDefnID serviceComponentDefnID = new ServiceComponentDefnID(configID, serviceComponentDefnName);
-// productServiceConfig = editor.addServiceComponentDefn(productServiceConfig, serviceComponentDefnID);
-//
-// editor.setEnabled(serviceComponentDefnID, productServiceConfig, Boolean.valueOf(enabled).booleanValue());
-//
-// }
-//
-// }
-//
-// productServiceConfig = (ProductServiceConfig) setDateHistory(productServiceConfig, element, editor);
-//
-// // add the properties to this ComponentObject...
-// Element propertiesElement = element.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
-// if (propertiesElement != null) {
-// // now we add the system properties to the configuration object
-// productServiceConfig = (ProductServiceConfig)addProperties(propertiesElement, productServiceConfig, editor);
-// return productServiceConfig;
-// }
-//
-// return productServiceConfig;
-// }
-
public DeployedComponent createDeployedServiceComponent(Element element,
ConfigurationID configID,
HostID hostID,
@@ -1854,10 +1250,8 @@
checkElementValue(name, "NAME", ErrorMessageKeys.CONFIG_ERR_0048); //$NON-NLS-1$
String componentTypeIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedService.Attributes.COMPONENT_TYPE);
-// String serviceComponentDefnIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.SERVICE_COMPONENT_DEFN_ID);
checkElementValue(componentTypeIDString, name, ErrorMessageKeys.CONFIG_ERR_0049);
-// checkElementValue(serviceComponentDefnIDString, name, ErrorMessageKeys.CONFIG_ERR_0049);
ComponentType type = null;
@@ -1876,7 +1270,6 @@
ServiceComponentDefnID svcid = null;
if (type.isOfTypeConnector()) {
- // type.getComponentTypeCode() == ComponentType.CONNECTOR_COMPONENT_TYPE_CODE) {
svcid = new ConnectorBindingID(configID, name);
@@ -1897,188 +1290,7 @@
}
-// public DeployedComponent createDeployedVMComponentDefnx(Element element,
-// ConfigurationID configID,
-// HostID hostID,
-// // VMComponentDefnID vmID,
-// // ProductServiceConfigID pscID,
-// ComponentTypeID typeID,
-// ConfigurationObjectEditor editor)
-// throws InvalidConfigurationElementException{
-// Assertion.isNotNull(element);
-// Assertion.isNotNull(editor);
-// Assertion.isNotNull(configID);
-// Assertion.isNotNull(hostID);
-// // Assertion.isNotNull(vmID);
-//
-// DeployedComponent component=null;
-//
-// if (!element.getName().equals(XMLConfig_ElementNames.Configuration.Process.ELEMENT)) {
-// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0044, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0044,element.getName()), element);
-// }
-//
-// String name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Process.Attributes.NAME);
-//// checkElementValue(name, "NAME", ErrorMessageKeys.CONFIG_ERR_0048);
-//
-// String componentTypeIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Process.Attributes.COMPONENT_TYPE);
-//
-// checkElementValue(componentTypeIDString, name, ErrorMessageKeys.CONFIG_ERR_0049);
-//
-//
-//// ComponentType type = null;
-//// Iterator it = componentTypeMap.keySet().iterator();
-//// while (it.hasNext() ) {
-//// ComponentTypeID id = (ComponentTypeID) it.next();
-//// if (id.getFullName().equals(componentTypeIDString)) {
-//// type = (ComponentType) componentTypeMap.get(id);
-//// break;
-//// }
-//// }
-//
-//// if (type == null) {
-//// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0050, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0050, new Object[] {componentTypeIDString, name} ), element);
-//// }
-//
-// // VMComponentDefnID vmID = new VMComponentDefnID(configID, hostID, name);
-/////// component = editor.createDeployedVMComponent(name, configID, hostID, vmID, typeID);
-// // createDeployedServiceComponent(name, configID, hostID,vmID, svcid, pscID, (ComponentTypeID) type.getID());
-//
-//
-// return component;
-// }
-
-
-
/**
- * This method will create a DeployedComponent configuration object from an XML element
- * that represents a DeployedComponent.
- *
- * @param element the JDOM element to convert to a configuration object
- * @param editor the editor to use to create the configuration object
- * @param name the name of the returned configuration object. Note this
- * name will override the name in the JDOM element. If the name parameter
- * is null, the name of the object in the JDOM element will be used as
- * the name of the object.
- * @param serviceComponentDefnMap a map of ServiceComponentDefnID-->ServiceComponentDefn
- * this map must contain at the very least the ServiceComponentDefn that
- * is the service definition of the deployed component that the XML element
- * references. This is used if the deployedComponent is a Service. Otherwise
- * it is ignored.
- * @param vmComponentDefnMap a map of vmComponentDefnID-->vmComponentDefn
- * this map must contain at the very least the vmComponentDefn that
- * is the VM definition of the deployed component that the XML element
- * references. This is used if the deployedComponent is a VM. Otherwise
- * it is ignored.
- * @return the DeployedComponent configuration object
- * @throws InvalidConfigurationElementException if the element passed in
- * or its XML structure do not conform to the XML structure specfied in
- * the XMLConfig_ElementNames class.
- */
-// public DeployedComponent createDeployedComponent(Element element,
-// Configuration config, ConfigurationObjectEditor editor,
-// Map serviceComponentDefnMap, Map vmComponentDefnMap, Map componentTypeMap, String name)
-// throws InvalidConfigurationElementException{
-// throw new UnsupportedOperationException("Method createDeployedComponent is unsupported in 4.2"); //$NON-NLS-1$
-//
-////
-//// Assertion.isNotNull(element);
-//// Assertion.isNotNull(editor);
-//// Assertion.isNotNull(config);
-////
-//// DeployedComponent component;
-////
-//// if (!element.getName().equals(XMLConfig_ElementNames.Configuration.DeployedComponent.ELEMENT)) {
-//// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0044, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0044,element.getName()), element);
-//// }
-////
-//// if (name == null) {
-//// name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.NAME);
-//// }
-////
-//// String productServiceConfigIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.PRODUCT_SERVICE_CONFIG_ID);
-//// String vmComponentDefnIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.VM_COMPONENT_DEFN_ID);
-//// String serviceComponentDefnIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.SERVICE_COMPONENT_DEFN_ID);
-//// String HostIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.HOST_ID);
-////
-//// checkElementValue(vmComponentDefnIDString, name, ErrorMessageKeys.CONFIG_ERR_0045);
-//// checkElementValue(HostIDString, name, ErrorMessageKeys.CONFIG_ERR_0046);
-////
-//// ConfigurationID configID = (ConfigurationID)config.getID();
-////
-//// HostID hostID = new HostID(HostIDString);
-//// VMComponentDefnID vmComponentDefnID = new VMComponentDefnID(configID, vmComponentDefnIDString);
-////
-//// // this will check to see if this is actually a DeployedVMServiceComponent
-//// // these special deployed components dont have values for these ID's
-//// String componentTypeIDString = element.getAttributeValue(XMLConfig_ElementNames.Configuration.DeployedComponent.Attributes.COMPONENT_TYPE);
-////
-//// if (serviceComponentDefnIDString == null && productServiceConfigIDString == null) {
-//// VMComponentDefn defn = (VMComponentDefn)vmComponentDefnMap.get(vmComponentDefnID);
-//// if (defn==null) {
-//// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0047, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0047, new Object[] {name, vmComponentDefnID} ), element);
-////
-//// }
-//// component = editor.createDeployedVMComponent(name, config, hostID, defn);
-////
-//// // else this element represents a normal ServiceComponentDefn object
-//// }else {
-//// checkElementValue(productServiceConfigIDString, name, ErrorMessageKeys.CONFIG_ERR_0048);
-//// checkElementValue(serviceComponentDefnIDString, name, ErrorMessageKeys.CONFIG_ERR_0049);
-////
-//// ComponentType type = null;
-//// Iterator it = componentTypeMap.keySet().iterator();
-//// while (it.hasNext() ) {
-//// ComponentTypeID id = (ComponentTypeID) it.next();
-//// if (id.getFullName().equals(componentTypeIDString)) {
-//// type = (ComponentType) componentTypeMap.get(id);
-//// break;
-//// }
-//// }
-////
-//// if (type == null) {
-//// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0050, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0050, new Object[] {componentTypeIDString, serviceComponentDefnIDString} ), element);
-//// }
-//// ProductServiceConfigID productServiceConfigID = null;
-//// if (type instanceof ConnectorBindingType) {
-////
-//// productServiceConfigID = new ProductServiceConfigID(configID, productServiceConfigIDString);
-////
-//// ConnectorBindingID bindingID = new ConnectorBindingID(configID, serviceComponentDefnIDString);
-//// ConnectorBinding bdefn = (ConnectorBinding)serviceComponentDefnMap.get(bindingID);
-////
-//// if (bdefn==null) {
-//// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0051, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0051, new Object[] {name, serviceComponentDefnIDString} ), element);
-//// }
-//// component = editor.createDeployedServiceComponent(name, config, hostID, vmComponentDefnID, bdefn, productServiceConfigID);
-////
-//// } else {
-////
-//// productServiceConfigID = new ProductServiceConfigID(configID, productServiceConfigIDString);
-////
-//// ServiceComponentDefnID serviceComponentDefnID = new ServiceComponentDefnID(configID, serviceComponentDefnIDString);
-//// ServiceComponentDefn defn = (ServiceComponentDefn)serviceComponentDefnMap.get(serviceComponentDefnID);
-////
-//// if (defn==null) {
-//// throw new InvalidConfigurationElementException(ErrorMessageKeys.CONFIG_ERR_0052, CommonPlugin.Util.getString(ErrorMessageKeys.CONFIG_ERR_0052, new Object[] {name, serviceComponentDefnIDString} ), element);
-//// }
-//// component = editor.createDeployedServiceComponent(name, config, hostID, vmComponentDefnID, defn, productServiceConfigID);
-////
-//// }
-////
-//// }
-////
-//// component = (DeployedComponent) setDateHistory(component, element, editor);
-////
-//// Element propertiesElement = element.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
-//// if (propertiesElement != null) {
-//// // now we add the system properties to the configuration object
-//// return (DeployedComponent)addProperties(propertiesElement, component, editor);
-//// }
-////
-//// return component;
-// }
-
- /**
* This method will create a VMComponentDefn configuration object from an XML element
* that represents a VMComponentDefn.
*
@@ -2102,7 +1314,7 @@
throw new InvalidConfigurationElementException("A Configuration object cannot be created from a JDOM Element type: " + element.getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
}
- if (name==null) {
+ if (name==null || name.trim().length() == 0) {
name = element.getAttributeValue(XMLConfig_ElementNames.Configuration.Process.Attributes.NAME);
}
@@ -2116,13 +1328,9 @@
defn = (VMComponentDefn) setDateHistory(defn, element, editor);
- // add the properties to this ComponentObject...
- // Element propertiesElement = element.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
- // if (propertiesElement != null) {
- // now we add the system properties to the configuration object
- defn = (VMComponentDefn)addProperties(element, defn, editor);
- // }
+ defn = (VMComponentDefn)addProperties(element, defn, editor);
+
return (BasicVMComponentDefn) defn;
}
@@ -2298,8 +1506,6 @@
propertiesElement = propertiesElement.getChild(XMLConfig_ElementNames.Properties.ELEMENT);
}
-
-
Properties props = null;
if (propertiesElement == null) {
props = new Properties();
@@ -2442,7 +1648,4 @@
}
-
-// private static final String NOT_ASSIGNED = "NotAssigned";
-
}
15 years, 8 months
teiid SVN: r885 - in trunk: common-core/src/main/java/com/metamatrix/core/util and 16 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-05-07 17:35:26 -0400 (Thu, 07 May 2009)
New Revision: 885
Added:
trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java
trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java
Removed:
trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java
trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java
Modified:
trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java
trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java
trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java
trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java
trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java
trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java
trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java
trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java
trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java
Log:
Moving WSDLServletUtil out of common core, simplifying rs cache logic
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,225 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Constants pertaining to WSDL servlet execution.
- *
- * @since 4.2
- */
-
-public class WSDLServletUtil {
-
- /**
- * General keys
- */
- public static final String SERVER_URL_KEY = "ServerURL"; //$NON-NLS-1$
-
- public static final String SECURE_PROTOCOL = "Secure"; //$NON-NLS-1$
-
- public static final String VDB_NAME_KEY = "VDBName"; //$NON-NLS-1$
-
- public static final String VDB_VERSION_KEY = "VDBVersion"; //$NON-NLS-1$
-
- public static final String ADD_PROPS = "AdditionalProperties"; //$NON-NLS-1$
-
- public static final String TXN_AUTO_WRAP = "txnAutoWrap"; //$NON-NLS-1$
-
- public static final String ADD_EXEC_PROPS = "AddExecProperties"; //$NON-NLS-1$
-
- public static final String MM_WEBSERVICE_QUERY_TIMEOUT = "com.metamatrix.webservice.querytimeout"; //$NON-NLS-1$
-
- public static final String DISCOVERED_WSDL = "discovered_wsdl"; //$NON-NLS-1$
-
- /*
- * This is the parameter that will tell this servlet when the web service endpoint as defined in WSDL served up by this
- * servlet will use the HTTP vs HTTPS protocol.
- */
- public static final String HTTP_TYPE_PARAMETER_KEY = "httptype"; //$NON-NLS-1$
-
- /*
- * This is the value of the httptype URL request param that will indicate that the returned WSDL should have an http endpoint
- * instead of an https endpoint.
- */
- public static final String HTTP_PARAMETER_VALUE = "http"; //$NON-NLS-1$
-
- /*
- * Static contant representing the standard http protocol.
- */
- public static final String HTTP = "http"; //$NON-NLS-1$
-
- /**
- * Static contant representing the secure http protocol.
- */
- public static final String HTTPS = "https"; //$NON-NLS-1$
-
- /**
- * Default content type for the VDBResourceServlet
- */
- public static final String DEFAULT_CONTENT_TYPE = "text/html"; //$NON-NLS-1$
-
- /**
- * XML content type for the VDBResourceServlet
- */
- public static final String XML_CONTENT_TYPE = "text/xml"; //$NON-NLS-1$
-
- /**
- * WSDL URL Generator keys
- */
- public static final String MMSERVER_HOST_PORT_KEY = "MMServerHostAndPort"; //$NON-NLS-1$
-
- public static final String TARGET_HOST_KEY = "TargetHost"; //$NON-NLS-1$
-
- public static final String TARGET_PORT_KEY = "TargetPort"; //$NON-NLS-1$
-
- public static final String SERVLET_PATH = "/servlet/ArtifactDocumentService"; //$NON-NLS-1$
-
- public static final String SQLQUERYWEBSERVICE_WSDL_PATH = "/services/SqlQueryWebService?wsdl"; //$NON-NLS-1$
-
- public static final String GENERATED_WSDL_NAME = "MetaMatrixDataServices"; //$NON-NLS-1$
-
- public static final String GENERATED_WSDL_FILENAME = GENERATED_WSDL_NAME + ".wsdl"; //$NON-NLS-1$
-
- public static final String COLON = ":"; //$NON-NLS-1$
-
- public static final String SLASH = "/"; //$NON-NLS-1$
-
- public static final String DOUBLE_SLASH = "//"; //$NON-NLS-1$
-
- public static final String AMP = "&"; //$NON-NLS-1$
-
- public static final String QUESTION_MARK = "?"; //$NON-NLS-1$
-
- public static final String EQUALS = "="; //$NON-NLS-1$
-
- public static final String COMMA = ","; //$NON-NLS-1$
-
- private static final String SQLQUERYWEBSERVICE_URL_FORMAT = "{0}://{1}:{2}/{3}"; //$NON-NLS-1$
-
- /*
- * this default value is based on Tomcat's default value in its server.xml file. This value can be overridden by setting the
- * com.metamatrix.webservice.dataservice.httpsport System property for the VM that this servlet is running in.
- */
- private static final String DEFAULT_HTTPS_PORT = "8443"; //$NON-NLS-1$
-
- private static final String DEFAULT_HTTP_PORT = "8080"; //$NON-NLS-1$
-
- private static final String HTTPS_PORT_PROPERTY_KEY = "com.metamatrix.webservice.dataservice.httpsport"; //$NON-NLS-1$
-
- private static final String HTTP_PORT_PROPERTY_KEY = "com.metamatrix.webservice.dataservice.httpport"; //$NON-NLS-1$
-
- /**
- * Returns the formatted url from the supplied info
- *
- * @param scheme the server scheme
- * @param host the server host name
- * @param port the server port
- * @param appContext the context of this application to use in the WSDL url
- * @param serverURLs the list of server url info, first url is full url including protocol. Subsequent items are just the
- * host:port strings.
- * @param vdbName the vdb name
- * @param vdbVersion the vdb version number
- */
- public static String formatURL( String scheme,
- String host,
- String port,
- String appContext,
- List serverURLs,
- String vdbName,
- String vdbVersion ) {
-
- StringBuffer result = new StringBuffer();
- try {
- boolean hasPort = true;
- boolean hasVDBVersion = true;
-
- if (port == null || port.length() == 0) {
- hasPort = false;
- }
-
- if (vdbVersion == null || vdbVersion.trim().length() == 0) {
- hasVDBVersion = false;
- }
-
- result.append(scheme).append(COLON).append(DOUBLE_SLASH).append(host);
-
- if (hasPort) {
- result.append(COLON).append(port);
- }
-
- result.append(appContext).append(SERVLET_PATH).append(SLASH).append(GENERATED_WSDL_FILENAME);
- result.append(QUESTION_MARK).append(SERVER_URL_KEY).append(EQUALS);
- // Append comma-delimited server urls
- Iterator iter = serverURLs.iterator();
- while (iter.hasNext()) {
- String serverURL = (String)iter.next();
- result.append(serverURL);
- // If there is another url coming, add an encoded comma
- if (iter.hasNext()) {
- result.append(URLEncoder.encode(COMMA, "UTF-8")); //$NON-NLS-1$
- }
- }
- result.append(AMP).append(VDB_NAME_KEY).append(EQUALS).append(vdbName);
- if (hasVDBVersion) {
- result.append(AMP).append(VDB_VERSION_KEY).append(EQUALS).append(vdbVersion);
- }
-
- } catch (UnsupportedEncodingException err) {
- // ignore
- }
-
- return result.toString();
- }
-
- /**
- * Returns the formatted wsdl url for the SqlQueryWebService
- *
- * @param server - server name
- * @param appContext the context of this application to use in the WSDL url
- * @param secure - secure ssl (true) or non-secure (false)
- * @return wsdlUrl - String
- * @since 4.3
- */
- public static String getSqlQueryWebServiceUrl( final String server,
- String appContext,
- final boolean secure ) {
-
- appContext=appContext.replace("/",""); //$NON-NLS-1$ //$NON-NLS-2$
- return MessageFormat.format(SQLQUERYWEBSERVICE_URL_FORMAT, new Object[] {secure ? HTTPS : HTTP, server,
- secure ? getHttpsPort() : getHttpPort(), appContext+SQLQUERYWEBSERVICE_WSDL_PATH});
- }
-
- public static final String getHttpsPort() {
- return System.getProperty(HTTPS_PORT_PROPERTY_KEY, DEFAULT_HTTPS_PORT);
- }
-
- public static final String getHttpPort() {
- return System.getProperty(HTTP_PORT_PROPERTY_KEY, DEFAULT_HTTP_PORT);
- }
-}
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,3 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
package com.metamatrix.core.util;
import java.util.concurrent.ThreadFactory;
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -984,7 +984,7 @@
* @return
*/
@SuppressWarnings("unchecked")
- public static <T> T valueOf(String value, Class<T> type){
+ public static <T> T valueOf(String value, Class type){
if(type == String.class) {
return (T) value;
@@ -1013,6 +1013,10 @@
else if (type == Void.class) {
return null;
}
+ else if (type.isEnum()) {
+ return (T)Enum.valueOf(type, value);
+ }
+
else if (type.isAssignableFrom(Map.class)) {
List<String> l = Arrays.asList(value.split(",")); //$NON-NLS-1$
Map m = new HashMap<String, String>();
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-/**
- */
-public class TestWSDLServletUtil extends TestCase {
-
- public static String HTTP = "http"; //$NON-NLS-1$
- public static String HTTPS = "https"; //$NON-NLS-1$
- public static String DEFAULT_APP_CONTEXT = "/metamatrix-soap"; //$NON-NLS-1$
- public static String OTHER_APP_CONTEXT = "/metamatrix-soapiness"; //$NON-NLS-1$
-
- public TestWSDLServletUtil(String name) {
- super(name);
- }
-
- public void testGetMMSAPIUrlAllNullServerNameSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT, true);
- assertEquals("https://null:8443/metamatrix-soap/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
- }
-
- public void testGetMMSAPIUrlAllNullServerNameNonSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT, false);
- assertEquals("http://null:8080/metamatrix-soap/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
- }
-
- public void testGetMMSAPIUrlValidParametersSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01", DEFAULT_APP_CONTEXT, true); //$NON-NLS-1$
- assertEquals("https://slntmm01:8443/metamatrix-soap/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
- }
-
- public void testGetMMSAPIUrlValidParametersNonSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01", OTHER_APP_CONTEXT,false); //$NON-NLS-1$
- assertEquals("http://slntmm01:8080/metamatrix-soapiness/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersNonSecure() {
- List serverURLs = new ArrayList();
- serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080", DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaM...", url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecure() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/Meta...", url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecureNoPort() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null, DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("https://chicago/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatri...", url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecureNoPortNoVdbVersion() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null, OTHER_APP_CONTEXT, serverURLs,"testVDB",null); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("https://chicago/metamatrix-soapiness/servlet/ArtifactDocumentService/Meta...", url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecureNoVdbVersion() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT, serverURLs,"testVDB",""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/Meta...", url); //$NON-NLS-1$
- }
-
- public void testFormatUrlMultipleServers() {
- List serverURLs = new ArrayList();
- serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
- serverURLs.add("boston:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080", DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaM...", url); //$NON-NLS-1$
- }
-
-}
Modified: trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -387,6 +387,11 @@
assertEquals("vdb", StringUtil.getLastToken("/foo/bar.vdb", "."));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ public enum Test {
+ HELLO,
+ WORLD
+ }
+
public void testValueOf() {
assertEquals(Integer.valueOf(21), StringUtil.valueOf("21", Integer.class)); //$NON-NLS-1$
assertEquals(Boolean.valueOf(true), StringUtil.valueOf("true", Boolean.class)); //$NON-NLS-1$
@@ -405,6 +410,6 @@
assertEquals(3, m.size());
assertEquals(m.get("foo"), "bar"); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(m.get("x"), ""); //$NON-NLS-1$ //$NON-NLS-2$
-
+ assertEquals(Test.HELLO, StringUtil.valueOf("HELLO", Test.class)); //$NON-NLS-1$
}
}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,548 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.Serializable;
-import java.util.*;
-
-import com.metamatrix.common.CommonPlugin;
-
-/**
- * <p>This class can be used to represent a collection of intervals. As new intervals are
- * added, they are merged into existing intervals to maintain the most compact description
- * of the intervals that is possible. Interval endpoints are inclusive - a single index
- * can be identified by an interval like [1,1].</p.
- *
- * <p>For instance, if you added the intervals 1-3, 5-9, 4-4, they would be stored as 1-9.</p>
- */
-public class Intervals implements Serializable {
-
- static int BEFORE_FIRST = 0;
- static int WITHIN_INTERVAL = 1;
- static int BETWEEN_INTERVALS = 2;
- static int AFTER_LAST = 3;
-
- private LinkedList intervals;
-
- /**
- * Constructor for Intervals.
- */
- public Intervals() {
- intervals = new LinkedList();
- }
-
- public Intervals(int begin, int end) {
- this();
- addInterval(begin, end);
- }
-
- /**
- * Copy constructor
- * @param intervals
- * @since 4.2
- */
- private Intervals(Collection i) {
- this.intervals = new LinkedList(i);
- }
-
- /**
- * True if this set of intervals contains any intervals.
- * @return True if covers anything, false otherwise
- */
- public boolean hasIntervals() {
- return (intervals.size() > 0);
- }
-
- /**
- * Add an interval from begin to end, inclusive.
- * @param begin Begin index
- * @param end End index
- * @throws IllegalArgumentException If begin > end
- */
- public void addInterval(int begin, int end) {
- if(begin > end) {
- throw new IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0023));
- }
-
- if(intervals.size() == 0) {
- // Add first interval
- intervals.add(new Integer(begin));
- intervals.add(new Integer(end));
-
- } else {
- int[] locations = findLocations(intervals, begin, end);
-
- if(locations[0] == BEFORE_FIRST) {
- if(locations[2] == BEFORE_FIRST) {
- intervals.addFirst(new Integer(end));
- intervals.addFirst(new Integer(begin));
- condense(intervals);
- return;
- } else if(locations[2] == AFTER_LAST) {
- intervals.clear();
- intervals.add(new Integer(begin));
- intervals.add(new Integer(end));
- return;
- }
- } else if(locations[0] == AFTER_LAST) {
- intervals.addLast(new Integer(begin));
- intervals.addLast(new Integer(end));
- condense(intervals);
- return;
-
- } else if(locations[0] == BETWEEN_INTERVALS && locations[2] == BETWEEN_INTERVALS && locations[1] > locations[3]) {
- // Insert between intervals
- intervals.add(locations[1], new Integer(end));
- intervals.add(locations[1], new Integer(begin));
- condense(intervals);
- return;
- }
-
- // All other cases:
-
- // Merge affected intervals
- mergeIntervals(intervals, locations[1], locations[3]);
-
- // Expand to handle added interval
- expandInterval(intervals, locations[1], begin, end);
-
- // Merge adjacent intervals
- condense(intervals);
- }
- }
-
- /**
- * Determines the type of location and relevant interval index for the specified values. These
- * are returned stuffed into an int[] (yes this is ugly).
- * @param intervals Intervals to examine
- * @param beginValue Begin value we're trying to place within the intervals
- * @param endValue End value we're trying to place within the intervals
- * @return Four ints, first is begin location type as defined in javadoc, second is begin index into intervals,
- * third is end location type as defined in javadoc, fourth is end index into intervals
- */
- static int[] findLocations(LinkedList intervals, int beginValue, int endValue) {
- // Initialize return structure
- int[] locations = new int[4];
- locations[0] = -1;
- locations[2] = -1;
-
- int interval = -1;
- Iterator iter = intervals.iterator();
- while(iter.hasNext()) {
- // Update state
- int intervalBegin = ((Integer)iter.next()).intValue();
- int intervalEnd = ((Integer)iter.next()).intValue();
- interval++;
-
- // Determine if beginValue is before or within current interval
- if(locations[0] == -1) {
- if(beginValue < intervalBegin) {
- locations[0] = BETWEEN_INTERVALS;
- locations[1] = interval*2; // record this interval begin
- } else if(beginValue >= intervalBegin && beginValue <= intervalEnd) {
- locations[0] = WITHIN_INTERVAL;
- locations[1] = interval*2; // record this interval begin
- }
- }
-
- // Determine if endValue is before or within current interval
- if(endValue < intervalBegin) {
- locations[2] = BETWEEN_INTERVALS;
- locations[3] = ((interval-1)*2)+1; // record previous interval end
- break;
- } else if(endValue >= intervalBegin && endValue <= intervalEnd) {
- locations[2] = WITHIN_INTERVAL;
- locations[3] = (interval*2)+1; // record this interval end
- break;
- }
- }
-
- // Check for hanging conditions
- if(locations[2] == -1) {
- locations[2] = AFTER_LAST;
- locations[3] = intervals.size() - 1;
-
- if(locations[0] == -1) {
- locations[0] = AFTER_LAST;
- locations[1] = intervals.size() - 2;
- }
- }
-
- // Check for special case beginning conditions
- if(locations[0] == BETWEEN_INTERVALS && locations[1] == 0) {
- locations[0] = BEFORE_FIRST;
- }
-
- if(locations[2] == BETWEEN_INTERVALS && locations[3] < 0) {
- locations[2] = BEFORE_FIRST;
- }
-
- return locations;
- }
-
- static void mergeIntervals(LinkedList intervals, int firstIntervalIndex, int lastIntervalIndex) {
- intervals.subList(firstIntervalIndex+1, lastIntervalIndex).clear();
- }
-
- static void expandInterval(LinkedList intervals, int firstIntervalIndex, int begin, int end) {
- // Set up iterator
- ListIterator iter = intervals.listIterator(firstIntervalIndex);
-
- // Get merged interval bounds
- int mergedBegin = ((Integer) iter.next()).intValue();
- int mergedEnd = ((Integer) iter.next()).intValue();
-
- int newBegin = Math.min(begin, mergedBegin);
- int newEnd = Math.max(end, mergedEnd);
-
- // Change begin and end
- iter.previous();
- iter.set(new Integer(newEnd));
- iter.previous();
- iter.set(new Integer(newBegin));
- }
-
- static void reduceInterval(LinkedList intervals, int firstIntervalIndex, int begin, int end) {
- // Set up iterator
- ListIterator iter = intervals.listIterator(firstIntervalIndex);
-
- // Get merged interval bounds
- int mergedBegin = ((Integer) iter.next()).intValue();
- int mergedEnd = ((Integer) iter.next()).intValue();
-
- if(begin <= mergedBegin) {
- if(end >= mergedEnd) {
- // Removed interval completely covers merged interval
- iter.previous();
- iter.remove();
- iter.previous();
- iter.remove();
- return;
- }
- // There is some left over at the right end of merged interval
- iter.previous();
- iter.previous();
- iter.set(new Integer(end+1));
- } else {
- if(end >= mergedEnd) {
- // There is some left over at the left end of merged interval
- iter.previous();
- iter.set(new Integer(begin-1));
-
- } else {
- // Removed interval is completely within merged interval - split in two
- iter.previous();
- iter.add(new Integer(end+1));
- iter.previous();
- iter.add(new Integer(begin-1));
- }
- }
- }
-
- static void condense(LinkedList intervals) {
- if(intervals.size() <= 2) {
- return;
- }
-
- ListIterator iter = intervals.listIterator();
-
- // Read first interval
- iter.next();
- int lastEnd = ((Integer) iter.next()).intValue();
-
- while(iter.hasNext()) {
- int begin = ((Integer) iter.next()).intValue();
- if(begin == lastEnd + 1) {
- iter.remove();
- iter.previous();
- iter.remove();
- }
- lastEnd = ((Integer) iter.next()).intValue();
- }
- }
-
- /**
- * Remove an interval from begin to end, inclusive. If the
- * current intervals do not contain anything in removed interval,
- * no error is thrown.
- * @param begin Begin index
- * @param end End index
- * @throws IllegalArgumentException If begin > end
- */
- public void removeInterval(int begin, int end) {
- if(begin > end) {
- throw new IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0024));
- }
-
- // Check whether we have any intervals
- if(intervals.size() == 0) {
- return;
- }
-
- // Check the locations of begin and end across locations
- int[] locations = findLocations(intervals, begin, end);
-
- if(locations[0] == BEFORE_FIRST) {
- if(locations[2] == BEFORE_FIRST) {
- return;
- } else if(locations[2] == AFTER_LAST) {
- intervals.clear();
- return;
- }
- } else if(locations[0] == AFTER_LAST) {
- return;
-
- } else if(locations[0] == BETWEEN_INTERVALS && locations[2] == BETWEEN_INTERVALS && locations[1] > locations[3]) {
- // Between intervals
- return;
- }
-
- // All other cases:
-
- // Merge affected intervals
- mergeIntervals(intervals, locations[1], locations[3]);
-
- // Expand to handle added interval
- reduceInterval(intervals, locations[1], begin, end);
-
- // Merge adjacent intervals
- condense(intervals);
- }
-
- public Intervals removeIntervals(Intervals intervalsToRemove) {
- List intervalList = intervalsToRemove.getIntervals();
- for (Iterator iterator = intervalList.iterator(); iterator.hasNext(); ) {
- int[] interval = (int[]) iterator.next();
- removeInterval(interval[0], interval[1]);
- }
- return this;
- }
-
- /**
- * Returns true if the specified interval is contained in the
- * current intervals.
- * @param begin Begin index
- * @param end End index
- * @throws IllegalArgumentException If begin > end
- */
- public boolean containsInterval(int begin, int end) {
- if(begin > end) {
- throw new IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0025));
- }
-
- // Check whether we have any intervals
- int size = intervals.size();
- if(size == 0) {
- return false;
- } else if (size == 2) {
- return (begin >= ((Integer) intervals.getFirst()).intValue() && end <= ((Integer) intervals.getLast()).intValue());
- }
-
- // Check whether the interval is contained completely within an existing interval
- int[] locations = findLocations(intervals, begin, end);
- if(locations[0] == WITHIN_INTERVAL && locations[2] == WITHIN_INTERVAL && locations[1]+1 == locations[3]) {
- return true;
- }
- return false;
- }
-
- /**
- * Determine the portion of the current intervals that overlaps with the
- * specified interval. For example, if the current intervals were [1-5, 10-15]
- * and we asked for the overlap with region [4-11], we would get a result
- * [4-5, 10-11].
- *
- * @param begin
- * @param end
- * @return Intervals set defining overlap
- * @throws IllegalArgumentException If begin > end
- */
- public Intervals getIntersection(int begin, int end) {
- if(begin > end) {
- throw new IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0026));
- }
-
- Intervals overlap = new Intervals();
-
- // Check whether we have any intervals
- if(intervals.size() == 0) {
- return overlap;
- }
-
- // Determine intersection points
- int[] locations = findLocations(intervals, begin, end);
- if(locations[2] == BEFORE_FIRST || locations[0] == AFTER_LAST) {
- // Completely before or after
- return overlap;
- } else if(locations[0] == BETWEEN_INTERVALS && locations[2] == BETWEEN_INTERVALS && locations[1] > locations[3]) {
- // Completely between intervals
- return overlap;
- } else if(locations[0] == WITHIN_INTERVAL && locations[2] == WITHIN_INTERVAL && locations[1]+1 == locations[3]) {
- // Completely within an interval
- overlap.addInterval(begin, end);
- return overlap;
- } else {
- // There is an overlap of one or more intervals
- int startIndex = locations[1];
- int endIndex = locations[3];
-
- // Determine partial beginning interval
- overlap.addInterval(Math.max(((Integer)intervals.get(startIndex)).intValue(), begin),
- Math.min(((Integer)intervals.get(startIndex+1)).intValue(), end) );
-
- // Add all intervals in the middle, if there are any
- int diff = endIndex-startIndex;
- if(diff > 3) {
- Iterator internalIter = intervals.listIterator(startIndex+2);
- int stop = diff-3;
- for(int i=0; i < stop; i=i+2) {
- overlap.addInterval( ((Integer) internalIter.next()).intValue(),
- ((Integer) internalIter.next()).intValue() );
- }
- }
-
- // Determine partial ending interval
- if(diff > 1) {
- overlap.addInterval(Math.max(((Integer)intervals.get(endIndex-1)).intValue(), begin),
- Math.min(((Integer)intervals.get(endIndex)).intValue(), end) );
- }
-
- return overlap;
- }
- }
-
- public Intervals getIntersectionIntervals(Intervals intersectionIntervals) {
- Intervals result = new Intervals();
- List intervalList = intersectionIntervals.getIntervals();
- for (Iterator iterator = intervalList.iterator(); iterator.hasNext(); ) {
- int[] interval = (int[]) iterator.next();
- result.addIntervals(getIntersection(interval[0], interval[1]));
- }
- return result;
- }
-
- public Intervals addIntervals(Intervals additionalIntervals) {
- List intervalList = additionalIntervals.getIntervals();
- for (Iterator iterator = intervalList.iterator(); iterator.hasNext(); ) {
- int[] interval = (int[]) iterator.next();
- addInterval(interval[0], interval[1]);
- }
- return this;
- }
-
- /**
- * Return ordered list of intervals representing current intervals.
- * Each element of the returned list is an int[2] representing a
- * begin/end pair of included interval.
- * @return Ordered list of int[2] representing intervals
- */
- public List getIntervals() {
- List list = new ArrayList();
- Iterator iter = intervals.iterator();
- while(iter.hasNext()) {
- list.add(new int[] { ((Integer)iter.next()).intValue(), ((Integer)iter.next()).intValue() });
- }
- return list;
- }
-
- /**
- * Determine there is one interval with no gaps.
- * Returns true for an empty interval.
- * @return Boolean indicator of whether there is one interval.
- */
- public boolean isContiguous() {
- return intervals.size() <= 2;
- }
-
- /**
- * Compares two intervals for equality
- * @param obj Other object
- * @return True if this equal to obj
- */
- public boolean equals(Object obj) {
- if(this == obj) {
- return true;
- }
-
- if(obj == null || ! (obj instanceof Intervals)) {
- return false;
- }
- Intervals other = (Intervals) obj;
-
- List thisIntervals = getIntervals();
- List otherIntervals = other.getIntervals();
-
- if(thisIntervals.size() != otherIntervals.size()) {
- return false;
- }
-
- for(int i=0; i<thisIntervals.size(); i++) {
- int[] thisInt = (int[]) thisIntervals.get(i);
- int[] otherInt = (int[]) otherIntervals.get(i);
-
- if(thisInt[0] != otherInt[0] || thisInt[1] != otherInt[1]) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Returns hash code for the set of intervals. This hash code is
- * based on the intervals and WILL change with any add or remove
- * call. This requires re-hashing the object.
- * @return Hash code
- */
- public int hashCode() {
- if(intervals.size() == 0) {
- return 0;
- }
-
- return intervals.getLast().hashCode();
- }
-
- /**
- * Returns string representation of intervals. This should be used for debugging only.
- * @return String representing intervals
- */
- public String toString() {
- return intervals.toString();
- }
-
- public int[] getBoundingInterval() {
- int[] result = new int[2];
- if (hasIntervals()) {
- result[0] = ((Integer) intervals.getFirst()).intValue();
- result[1] = ((Integer) intervals.getLast()).intValue();
- } else {
- result[0] = Integer.MIN_VALUE;
- result[1] = Integer.MAX_VALUE;
- }
- return result;
- }
-
- public Intervals copy() {
- return new Intervals(this.intervals);
- }
-}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,113 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * This class is used to return to a client the results of a complex management
- * request. The meaning of "result object" and "failured objects" is dependent upon the context of the method
- * from which this instance is returned.
- * <p>
- * This class uses a Map to hold those objects that were not successfully operated upon and
- * a corresponding exception; therefore, only objects which have a unique hash code for different
- * (but unequivalent) instances should be inserted as failed objects.
- */
-public class MultipleRequestConfirmation implements Serializable {
-
- private Object result = null;
- private Map failures = new HashMap();
-
- /**
- * Construct an empty confirmation instance.
- */
- public MultipleRequestConfirmation() {}
-
- /**
- * Set the result of the method request.
- * @param obj the result object
- */
- public void setResult( Object result ) {
- this.result = result;
- }
-
- /**
- * Get the result of the operation.
- * @return the object that contains or is the results for the operation; while
- * this class can contain a null value for the result, the method from which this
- * object is returned should document whether null results are allowed or expected.
- */
- public Object getResult() {
- return result;
- }
-
- /**
- * Add the object that was not successfully operated upon.
- * @param obj the object with which the operation failed.
- * @param e an exception that describes the failure of this object; may be null
- */
- public void addFailure( Object obj, Throwable e ) {
- failures.put(obj,e);
- }
-
- /**
- * Get the object that were not successfully operated upon, and an exception
- * for each that may describe why the operation failed.
- * @return the map keyed upon the objects with which the operation failed; the
- * value for each object key is the exception that was thrown during the operation
- * upon that object, or null if no exception was thrown during the operation
- * but failure still occurred.
- */
- public Map getFailures() {
- return failures;
- }
-
- /**
- * Get the number of objects that were not successfully operated upon.
- * @return the number of objects with which the operation failed.
- */
- public int getFailuresCount() {
- return failures.size();
- }
-
- /*
- * Determine whether there is a result object for this confirmation.
- * @return true if this confirmation object contains a results object, or false otherwise.
- * @see getResult
- */
- public boolean hasResult() {
- return ( result != null);
- }
-
- /**
- * Determine whether there are any objects that were not successfully operated upon.
- * @return true if at least one operation upon an object was added as failed, or false otherwise.
- */
- public boolean hasFailures() {
- return !failures.isEmpty();
- }
-
-}
-
Deleted: trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java
===================================================================
--- trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,842 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.util.LinkedList;
-
-import junit.framework.TestCase;
-
-/**
- */
-public class TestIntervals extends TestCase {
-
- /**
- * Constructor for TestIntervals.
- * @param arg0
- */
- public TestIntervals(String arg0) {
- super(arg0);
- }
-
- private LinkedList toLinkedList(int[] array) {
- LinkedList intervals = new LinkedList();
- for(int i=0; i<array.length; i++) {
- intervals.add(new Integer(array[i]));
- }
- return intervals;
- }
-
- public void helpTestFindLocations(int[] intervalArray, int begin, int end, int[] expected) {
- int[] actual = Intervals.findLocations(toLinkedList(intervalArray), begin, end);
-
- assertEquals("Unexpected begin type ", expected[0], actual[0]); //$NON-NLS-1$
- assertEquals("Unexpected begin index ", expected[1], actual[1]); //$NON-NLS-1$
- assertEquals("Unexpected end type ", expected[2], actual[2]); //$NON-NLS-1$
- assertEquals("Unexpected end index ", expected[3], actual[3]); //$NON-NLS-1$
- }
-
- // one range - all before first
- public void testFindLocations1() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.BEFORE_FIRST, 0, Intervals.BEFORE_FIRST, -1 };
- helpTestFindLocations(intervals, 0, 1, expected);
- }
-
- // one range - all after last
- public void testFindLocations2() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.AFTER_LAST, 0, Intervals.AFTER_LAST, 1 };
- helpTestFindLocations(intervals, 10, 11, expected);
- }
-
- // one range - overlap begin
- public void testFindLocations3() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.BEFORE_FIRST, 0, Intervals.WITHIN_INTERVAL, 1 };
- helpTestFindLocations(intervals, 0, 7, expected);
- }
-
- // one range - overlap end
- public void testFindLocations4() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0, Intervals.AFTER_LAST, 1 };
- helpTestFindLocations(intervals, 6, 10, expected);
- }
-
- // one range - within
- public void testFindLocations5() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0, Intervals.WITHIN_INTERVAL, 1 };
- helpTestFindLocations(intervals, 6, 7, expected);
- }
-
- // multiple ranges - before, within
- public void testFindLocations6() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.BEFORE_FIRST, 0, Intervals.WITHIN_INTERVAL, 3 };
- helpTestFindLocations(intervals, 0, 17, expected);
- }
-
- // multiple ranges - within, between
- public void testFindLocations7() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0, Intervals.BETWEEN_INTERVALS, 1 };
- helpTestFindLocations(intervals, 6, 12, expected);
- }
-
- // multiple ranges - within, within
- public void testFindLocations8() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0, Intervals.WITHIN_INTERVAL, 5 };
- helpTestFindLocations(intervals, 6, 27, expected);
- }
-
- // multiple ranges - between, within
- public void testFindLocations9() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.BETWEEN_INTERVALS, 2, Intervals.WITHIN_INTERVAL, 5 };
- helpTestFindLocations(intervals, 12, 27, expected);
- }
-
- // multiple ranges - between, after
- public void testFindLocations10() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.BETWEEN_INTERVALS, 2, Intervals.AFTER_LAST, 5 };
- helpTestFindLocations(intervals, 12, 31, expected);
- }
-
- // multiple ranges - within, after
- public void testFindLocations11() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 2, Intervals.AFTER_LAST, 5 };
- helpTestFindLocations(intervals, 17, 31, expected);
- }
-
- public void helpTestMergeIntervals(int[] intervalArray, int firstIndex, int lastIndex, int[] expected) {
- LinkedList intervals = toLinkedList(intervalArray);
- Intervals.mergeIntervals(intervals, firstIndex, lastIndex);
-
- assertEquals("Didn't get expected merge results ", toLinkedList(expected), intervals); //$NON-NLS-1$
- }
-
- public void testMergeIntervals1() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 10 };
- helpTestMergeIntervals(intervals, 0, 1, expected);
- }
-
- public void testMergeIntervals2() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };
- int[] expected = new int[] { 5, 40 };
- helpTestMergeIntervals(intervals, 0, 7, expected);
- }
-
- public void testMergeIntervals3() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };
- int[] expected = new int[] { 5, 10, 15, 30, 35, 40 };
- helpTestMergeIntervals(intervals, 2, 5, expected);
- }
-
- public void testMergeIntervals4() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };
- int[] expected = new int[] { 5, 10, 15, 40 };
- helpTestMergeIntervals(intervals, 2, 7, expected);
- }
-
- public void helpTestExpandIntervals(int[] intervalArray, int firstIndex, int begin, int end, int[] expected) {
- LinkedList intervals = toLinkedList(intervalArray);
- Intervals.expandInterval(intervals, firstIndex, begin, end);
-
- assertEquals("Didn't get expected expanded results ", toLinkedList(expected), intervals); //$NON-NLS-1$
- }
-
- public void testExpandInterval1() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 0, 10 };
- helpTestExpandIntervals(intervals, 0, 0, 9, expected);
- }
-
- public void testExpandInterval2() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 10 };
- helpTestExpandIntervals(intervals, 0, 6, 9, expected);
- }
-
- public void testExpandInterval3() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 0, 15 };
- helpTestExpandIntervals(intervals, 0, 0, 15, expected);
- }
-
- public void testExpandInterval4() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 15 };
- helpTestExpandIntervals(intervals, 0, 6, 15, expected);
- }
-
- public void helpTestCondenseIntervals(int[] intervalArray, int[] expected) {
- LinkedList intervals = toLinkedList(intervalArray);
- Intervals.condense(intervals);
- assertEquals("Didn't get expected condensed results ", toLinkedList(expected), intervals); //$NON-NLS-1$
- }
-
- public void testCondensedInterval1() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 10 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testCondensedInterval2() {
- int[] intervals = new int[] { 5, 10, 11, 15 };
- int[] expected = new int[] { 5, 15 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testCondensedInterval3() {
- int[] intervals = new int[] { 5, 10, 11, 15, 16, 20 };
- int[] expected = new int[] { 5, 20 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testCondensedInterval4() {
- int[] intervals = new int[] { 5, 10, 11, 15, 20, 25, 26, 30 };
- int[] expected = new int[] { 5, 15, 20, 30 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testAddIntervalDistinct() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- String expected = "[5, 10, 15, 20, 25, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalBeforeBeginning() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(0, 1);
- String expected = "[0, 1, 5, 10]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalAtBeginning() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(2, 5);
- String expected = "[2, 10]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalAtEnd() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(9, 15);
- String expected = "[5, 15]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalOverlapping1() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(7, 15);
- i.addInterval(12, 20);
- String expected = "[5, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalOverlapping2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(7, 15);
- i.addInterval(2, 5);
- String expected = "[2, 15]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalOverlapping3() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(6, 19);
- String expected = "[5, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalExpand() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(2, 20);
- String expected = "[2, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalInsert() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(12, 13);
- String expected = "[5, 10, 12, 13, 15, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalWithin() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(6, 7);
- String expected = "[5, 10]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalBetweenBetween() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- i.addInterval(12, 22);
- String expected = "[5, 10, 12, 22, 25, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalBetweenWithin() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- i.addInterval(12, 27);
- String expected = "[5, 10, 12, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalComplex() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- i.addInterval(12, 27);
- i.addInterval(11, 11);
- String expected = "[5, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testAddIntervalError() {
- Intervals i = new Intervals();
- try {
- i.addInterval(5, 3);
- fail("Expected to get IllegalArgumentException when adding illegal interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testRemoveInterval1() {
- Intervals i = new Intervals();
- i.removeInterval(0, 10);
- String expected = "[]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(0, 2);
- String expected = "[5, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval3() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(0, 5);
- String expected = "[6, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval4() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(0, 6);
- String expected = "[7, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval5() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(4, 8);
- String expected = "[9, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval6() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(7, 10);
- String expected = "[5, 6]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval7() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(7, 11);
- String expected = "[5, 6]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval8() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(5, 10);
- String expected = "[]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval9() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(6, 9);
- String expected = "[5, 5, 10, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval10() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(12, 14);
- String expected = "[5, 10, 15, 20]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval11() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(8, 17);
- String expected = "[5, 7, 18, 20]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval12() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(12, 17);
- String expected = "[5, 10, 18, 20]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval13() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(7, 25);
- String expected = "[5, 6]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveInterval14() {
- Intervals i = new Intervals();
- i.addInterval(2, 3);
- i.removeInterval(0, 4);
- assertEquals("Invalid after remove ", "[]", i.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRemoveInterval15() {
- Intervals i = new Intervals();
- i.addInterval(2, 3);
- i.removeInterval(4, 5);
- assertEquals("Invalid after remove ", "[2, 3]", i.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRemoveIntervalInvalid() {
- Intervals i = new Intervals();
- try {
- i.removeInterval(1, 0);
- fail("Expected IllegalArgumentException when removing invalid interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testContainsInterval1() {
- Intervals i = new Intervals();
- assertEquals("Contains is wrong ", false, i.containsInterval(0, 1)); //$NON-NLS-1$
- }
-
- public void testContainsInterval2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", true, i.containsInterval(5, 10)); //$NON-NLS-1$
- }
-
- public void testContainsInterval3() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", true, i.containsInterval(6, 9)); //$NON-NLS-1$
- }
-
- public void testContainsInterval4() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(1, 2)); //$NON-NLS-1$
- }
-
- public void testContainsInterval5() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(20, 21)); //$NON-NLS-1$
- }
-
- public void testContainsInterval6() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(0, 7)); //$NON-NLS-1$
- }
-
- public void testContainsInterval7() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(7, 20)); //$NON-NLS-1$
- }
-
- public void testContainsInterval8() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(12, 15);
- assertEquals("Contains is wrong ", false, i.containsInterval(5, 15)); //$NON-NLS-1$
- }
-
- public void testContainsIntervalInvalid() {
- Intervals i = new Intervals();
- try {
- i.containsInterval(1, 0);
- fail("Expected IllegalArgumentException when checking containment of invalid interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testIntersection1() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- Intervals expected = new Intervals();
- assertEquals("Intersection is wrong ", expected, i.getIntersection(0, 1)); //$NON-NLS-1$
- }
-
- public void testIntersection2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- Intervals expected = new Intervals();
- expected.addInterval(5, 7);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(0, 7)); //$NON-NLS-1$
- }
-
- public void testIntersection3() {
- Intervals i = new Intervals();
- i.addInterval(5,10);
- Intervals expected = new Intervals();
- expected.addInterval(5, 10);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(0, 12)); //$NON-NLS-1$
- }
- public void testIntersection4() {
- Intervals i = new Intervals();
- i.addInterval(5,10);
- Intervals expected = new Intervals();
- expected.addInterval(6, 9);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6, 9)); //$NON-NLS-1$
- }
-
- public void testIntersection5() {
- Intervals i = new Intervals();
- i.addInterval(5,10);
- Intervals expected = new Intervals();
- expected.addInterval(6, 10);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6, 12)); //$NON-NLS-1$
- }
-
- public void testIntersection6() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(6, 10);
- expected.addInterval(15, 16);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6, 16)); //$NON-NLS-1$
- }
-
- public void testIntersection7() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(6, 10);
- expected.addInterval(15, 20);
- expected.addInterval(25, 26);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6, 26)); //$NON-NLS-1$
- }
-
- public void testIntersection8() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(5, 10);
- expected.addInterval(15, 20);
- expected.addInterval(25, 30);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(1, 35)); //$NON-NLS-1$
- }
-
- public void testIntersection9() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(15, 20);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(11, 24)); //$NON-NLS-1$
- }
-
- public void testIntersection10() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(15, 20);
- expected.addInterval(25, 26);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(11, 26)); //$NON-NLS-1$
- }
-
- public void testIntersection11() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(25, 30);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(24, 40)); //$NON-NLS-1$
- }
-
- public void testIntersection12() {
- Intervals i = new Intervals();
- Intervals expected = new Intervals();
- assertEquals("Intersection is wrong ", expected, i.getIntersection(5, 10)); //$NON-NLS-1$
- }
-
- public void testIntersection13() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- Intervals expected = new Intervals();
- assertEquals("Intersection is wrong ", expected, i.getIntersection(11,12)); //$NON-NLS-1$
- }
-
- public void testIntersectionInvalid() {
- Intervals i = new Intervals();
- try {
- i.getIntersection(1, 0);
- fail("Expected IllegalArgumentException when checking containment of invalid interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testEquals1() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
- i1.addInterval(15, 20);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 10);
- i2.addInterval(15, 20);
-
- assertTrue("Equals is wrong ", i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i2.equals(i1)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i1.hashCode() == i2.hashCode()); //$NON-NLS-1$
- }
-
- public void testEquals2() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 11);
-
- assertTrue("Equals is wrong ", !i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", !i2.equals(i1)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i1.hashCode() != i2.hashCode()); //$NON-NLS-1$
- }
-
- public void testEquals3() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
- i1.addInterval(14, 20);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 10);
- i2.addInterval(15, 20);
-
- assertTrue("Equals is wrong ", !i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", !i2.equals(i1)); //$NON-NLS-1$
- }
-
- public void testEquals4() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
- i1.addInterval(15, 20);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 10);
-
- assertTrue("Equals is wrong ", !i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", !i2.equals(i1)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i1.hashCode() != i2.hashCode()); //$NON-NLS-1$
- }
-
- public void testEquals5() {
- Intervals i1 = new Intervals();
- assertTrue("Equals is wrong ", i1.equals(i1)); //$NON-NLS-1$
- }
-
- public void testEquals6() {
- Intervals i1 = new Intervals();
- assertTrue("Equals is wrong ", ! i1.equals(null)); //$NON-NLS-1$
- }
-
- public void testEquals7() {
- Intervals i1 = new Intervals();
- assertTrue("Equals is wrong ", ! i1.equals("abc")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRemoveIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- Intervals y = new Intervals();
- y.addInterval(21, 30);
- x.removeIntervals(y);
- assertEquals("[1, 20, 31, 100]", x.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveMultipleIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- Intervals y = new Intervals();
- y.addInterval(21, 30);
- y.addInterval(41, 50);
- x.removeIntervals(y);
- assertEquals("[1, 20, 31, 40, 51, 100]", x.toString()); //$NON-NLS-1$
- }
-
- public void testGetBoundingInterval() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- int[] result = x.getBoundingInterval();
- assertEquals(1, result[0]);
- assertEquals(100, result[1]);
- }
-
- public void testGetBoundingIntervalWithMultipleIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- x.addInterval(200, 300);
- int[] result = x.getBoundingInterval();
- assertEquals(1, result[0]);
- assertEquals(300, result[1]);
- }
-
- public void testGetBoundingIntervalWithNoIntervals() {
- Intervals x = new Intervals();
- int[] result = x.getBoundingInterval();
- assertEquals(Integer.MIN_VALUE, result[0]);
- assertEquals(Integer.MAX_VALUE, result[1]);
- }
-
- public void testGetIntersectionIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- Intervals y = new Intervals();
- y.addInterval(10, 20);
- assertEquals("[10, 20]", x.getIntersectionIntervals(y).toString()); //$NON-NLS-1$
-
- }
-
- public void testGetIntersectionIntervalsMultiple() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- x.addInterval(201, 300);
- Intervals y = new Intervals();
- y.addInterval(90, 210);
- y.addInterval(290, 300);
- assertEquals("[90, 100, 201, 210, 290, 300]", x.getIntersectionIntervals(y).toString()); //$NON-NLS-1$
- }
-
- public void testConstructorTakesInterval() {
- Intervals x = new Intervals(1, 100);
- assertEquals("[1, 100]", x.toString()); //$NON-NLS-1$
- }
-
- public void testCopy() {
- Intervals x = new Intervals(1, 10);
- x.addInterval(20, 30);
- Intervals y = x.copy();
- assertEquals("[1, 10, 20, 30]", y.toString()); //$NON-NLS-1$
- x.removeInterval(5, 25);
- //changing x should not affect y
- assertEquals("[1, 10, 20, 30]", y.toString()); //$NON-NLS-1$
-
- }
-
- public void testIsContiguous() {
- Intervals x = new Intervals();
- x.addInterval(5, 10);
- x.addInterval(0, 10);
- assertTrue( x.isContiguous() );
- }
-
- public void testIsNotContiguous() {
- Intervals x = new Intervals();
- x.addInterval(5, 10);
- x.addInterval(1, 3);
- assertFalse( x.isContiguous() );
- }
-
- public void testEmptyIntervalsIsContiguous() {
- Intervals x = new Intervals();
- assertTrue( x.isContiguous() );
- }
-}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -22,6 +22,7 @@
package org.teiid.dqp.internal.cache;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -38,15 +39,11 @@
private Map paramValues;
private boolean isFinal;
- private int firstRow;
+ private int firstRow = 1;
//size of this results in memory
private long size= -1;
private int finalRow = -1;
- //hold temp results
- private CursorReceiverWindowBuffer tempResults;
- private Object requestID;
-
public CacheResults(List[] results, int firstRow, boolean isFinal){
this(results, null, firstRow, isFinal);
}
@@ -125,67 +122,27 @@
//add the results to the existing one, this is used
//when building the batched results
- boolean addResults(CacheResults cacheResults, Object requestID){
- int firstRow = cacheResults.getFirstRow() - 1;
- boolean isFinal = cacheResults.isFinal();
- List[] results = cacheResults.getResults();
+ boolean addResults(CacheResults cacheResults){
+ if (this.firstRow + results.length != cacheResults.getFirstRow()) {
+ throw new MetaMatrixRuntimeException(DQPPlugin.Util.getString("ResultSetCache.1"));//$NON-NLS-1$
+ }
this.size += cacheResults.size;
- if(this.requestID == null){
- //first batch
- if(firstRow != 0){
- //the previous batch has been removed
- return false;
- }
-
- if(isFinal){
- this.results = results;
- this.command = cacheResults.getCommand();
- this.analysisRecord = cacheResults.getAnalysisRecord();
- this.firstRow = 1;
- this.isFinal = true;
- this.finalRow = this.results.length;
- return true;
- }
-
- //first time adding the results
- this.requestID = requestID;
- this.tempResults = new CursorReceiverWindowBuffer();
+ List[] batchResults = cacheResults.getResults();
+ if (results == null) {
+ this.results = batchResults;
+ } else if (batchResults.length > 0){
+ this.results = Arrays.copyOf(this.results, this.results.length + batchResults.length);
+ System.arraycopy(batchResults, 0, this.results, this.results.length - batchResults.length, batchResults.length);
}
-
- //check whether it is from same command
- if(!requestID.equals(this.requestID)){
- //could happen to connector
- return true;
- }
- if(results != null && results.length > 0){
- tempResults.add(new int[]{firstRow, firstRow + results.length - 1}, results);
- }
- if(isFinal){
- if(!tempResults.getContents().isContiguous()){
- //should not come here
- throw new MetaMatrixRuntimeException(DQPPlugin.Util.getString("ResultSetCache.1"));//$NON-NLS-1$
- }
- this.results = tempResults.getAllRows();
+ if(cacheResults.isFinal()){
this.command = cacheResults.getCommand();
this.analysisRecord = cacheResults.getAnalysisRecord();
- this.paramValues = cacheResults.getParamValues();
this.firstRow = 1;
this.isFinal = true;
this.finalRow = this.results.length;
-
- //cleanup temp data
- this.tempResults = null;
- this.requestID = null;
}
return true;
}
- //whether we have got all the batches (including the chunks if it is lob)
- boolean hasAllResults(){
- if(!this.isFinal){
- return false;
- }
- return true;
- }
}
Deleted: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.cache;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.common.util.Intervals;
-
-/**
- * Used on the client side of the JDBC driver. Keeps track of batches of rows retrieved from the server.
- * Removes batches based on the decisions of the ReceiverWindow.
- */
-public class CursorReceiverWindowBuffer {
- Intervals bufferIntervals = new Intervals();
- /** Caches the bounding range for the previous call to getRow(). Typically, the next call to getRow() will be lie within these bounds. */
- private int[] currentIntervalsBoundingRange;
- /** Caches the data for the previous call to getRow(). Typically, the next row required will be in this cache. */
- private List[] currentIntervalsData;
- private Map buffer = new HashMap();
-
- public void add(int[] range, List[] data) {
- if (range[1] >= range[0]) {
- bufferIntervals.addInterval(range[0], range[1]);
- buffer.put(new Intervals(range[0], range[1]), data);
- }
- }
-
- public List getRow(int index) {
- if (currentIntervalsBoundingRange != null && currentIntervalsBoundingRange[0] <= index && currentIntervalsBoundingRange[1] >= index) {
- return currentIntervalsData[index-currentIntervalsBoundingRange[0]];
- }
- Iterator iterator = buffer.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry)iterator.next();
- Intervals i = (Intervals) entry.getKey();
- if (i.containsInterval(index, index)) {
- currentIntervalsData = (List[]) entry.getValue();
- currentIntervalsBoundingRange = i.getBoundingInterval();
- return currentIntervalsData[index-currentIntervalsBoundingRange[0]];
- }
- }
- currentIntervalsData = null;
- currentIntervalsBoundingRange=null;
- throw new IndexOutOfBoundsException();
- }
-
- /*
- * @see com.metamatrix.common.window.ReceiverWindowBuffer#getContents()
- */
- public Intervals getContents() {
- return bufferIntervals.copy();
- }
-
- /*
- * @see com.metamatrix.common.window.ReceiverWindowBuffer#removeFromCache(com.metamatrix.common.util.Intervals)
- */
- public void removeFromCache(Intervals toRemove) {
- if (toRemove.hasIntervals()) {
- Iterator iterator = buffer.keySet().iterator();
- while (iterator.hasNext()) {
- Intervals i = (Intervals) iterator.next();
- int[] range = i.getBoundingInterval();
- if (toRemove.containsInterval(range[0], range[1])) {
- iterator.remove();
- bufferIntervals.removeInterval(range[0], range[1]);
- }
- }
- }
- }
-
- public List[] getAllRows() {
- if (!bufferIntervals.isContiguous()) {
- throw new IndexOutOfBoundsException();
- }
- int baseIndex = bufferIntervals.getBoundingInterval()[0];
- int size = bufferIntervals.getBoundingInterval()[1] - baseIndex + 1;
- List[] result = new List[size];
- for (int i=0; i<size; i++) {
- result[i+baseIndex] = getRow(i);
- }
- return result;
- }
-
-
- public boolean containsInterval(int begin, int end) {
- if (currentIntervalsBoundingRange != null &&
- currentIntervalsBoundingRange[0] <= begin &&
- currentIntervalsBoundingRange[1] >= end) {
- return true;
- }
- return bufferIntervals.containsInterval(begin, end);
- }
-}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -33,11 +33,39 @@
import com.metamatrix.cache.Cache.Type;
import com.metamatrix.cache.CacheConfiguration.Policy;
import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.util.HashCodeUtil;
/**
* Used to cache ResultSet based on the exact match of sql string.
*/
public class ResultSetCache {
+
+ static class TempKey {
+ CacheID cacheID;
+ Object requestID;
+
+ public TempKey(CacheID cacheID, Object requestID) {
+ this.cacheID = cacheID;
+ this.requestID = requestID;
+ }
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.hashCode(cacheID.hashCode(), requestID.hashCode());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof TempKey)) {
+ return false;
+ }
+ TempKey other = (TempKey) obj;
+ return (cacheID.equals(other.cacheID) && requestID.equals(other.requestID));
+ }
+ }
+
//configurable parameters
public static final String RS_CACHE_MAX_SIZE = "maxSize"; //$NON-NLS-1$
public static final String RS_CACHE_MAX_AGE = "maxAge"; //$NON-NLS-1$
@@ -49,7 +77,7 @@
private Cache<CacheID, CacheResults> cache;
private String scope;
- private Map<CacheID, CacheResults> tempBatchResults = new HashMap<CacheID, CacheResults>();
+ private Map<TempKey, CacheResults> tempBatchResults = new HashMap<TempKey, CacheResults>();
private int maxSize = 50 * 1024 * 1024; //bytes
private int maxAge = 60 * 60; // seconds
private int maxEntries = 20 * 1024;
@@ -127,30 +155,30 @@
long currentCacheSize = getCacheSize();
+ TempKey key = new TempKey(cacheID, requestID);
//do not cache if it is over cache limit
if(isOverCacheLimit(currentCacheSize, cacheResults.getSize())){
- removeTempResults(cacheID);
+ removeTempResults(key);
return false;
}
synchronized(tempBatchResults){
- CacheResults savedResults = tempBatchResults.get(cacheID);
+ CacheResults savedResults = tempBatchResults.get(key);
if(savedResults == null){
- savedResults = new CacheResults(null, cacheResults.getElements(), 1, false);
- tempBatchResults.put(cacheID, savedResults);
- }
- if(!savedResults.addResults(cacheResults, requestID)){
- removeTempResults(cacheID);
+ savedResults = cacheResults;
+ tempBatchResults.put(key, cacheResults);
+ } else if(!savedResults.addResults(cacheResults)){
+ removeTempResults(key);
return false;
}
//do not cache if it is over cache limit
if(isOverCacheLimit(currentCacheSize, savedResults.getSize())){
- removeTempResults(cacheID);
+ removeTempResults(key);
return false;
}
- if(savedResults.hasAllResults()){
+ if(savedResults.isFinal()){
tempBatchResults.remove(cacheID);
cacheID.setMemorySize(savedResults.getSize());
cache.put(cacheID, savedResults);
@@ -169,8 +197,12 @@
}
return false;
}
+
+ public void removeTempResults(CacheID cacheID, Object requestID){
+ removeTempResults(new TempKey(cacheID, requestID));
+ }
- public void removeTempResults(CacheID cacheID){
+ public void removeTempResults(TempKey cacheID){
synchronized(tempBatchResults){
tempBatchResults.remove(cacheID);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -112,7 +112,7 @@
public void receiveResults(AtomicResultsMessage results) {
boolean isFinal = results.getFinalRow() >= 0;
if (results.isRequestClosed()) {
- rsCache.removeTempResults(cacheID);
+ rsCache.removeTempResults(cacheID, requestId);
} else {
CacheResults cr = new CacheResults(results.getResults(), firstRow, isFinal);
firstRow += results.getResults().length;
@@ -123,7 +123,7 @@
@Override
public void exceptionOccurred(Throwable e) {
- rsCache.removeTempResults(cacheID);
+ rsCache.removeTempResults(cacheID, requestId);
actual.exceptionOccurred(e);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -222,7 +222,7 @@
LogManager.logDetail(LogConstants.CTX_DQP, e, "############# PW EXITING on", requestID, "- error occurred ###########"); //$NON-NLS-1$ //$NON-NLS-2$
//if there is a cache, remove temp results if there is any
if(this.rsCache != null){
- rsCache.removeTempResults(cid);
+ rsCache.removeTempResults(cid, requestID);
}
if (!isCanceled()) {
Deleted: trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.cache;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.teiid.dqp.internal.cache.CursorReceiverWindowBuffer;
-
-import junit.framework.TestCase;
-import com.metamatrix.common.util.Intervals;
-
-public class TestCursorReceiverWindowBuffer extends TestCase {
- CursorReceiverWindowBuffer buffer = new CursorReceiverWindowBuffer();
-
- public void test() {
- add(0,100);
- }
-
- private void add(int start, int end) {
- int[] range = new int[2];
- range[0] = start;
- range[1] = end;
- List[] data = new List[end+1-start];
- for (int i=0; i<end+1-start; i++) {
- data[i] = new ArrayList();
- data[i].add(new Integer(i+start));
- }
- buffer.add(range, data);
- }
-
- public void testGetRow() {
- add(1,100);
- checkRow(50);
- }
-
- public void testGetRowNotZeroBased() {
- add(101,200);
- checkRow(150);
- }
-
- public void testGetRowMultipleBatches() {
- add(1,100);
- add(101,200);
- checkRow(50);
- checkRow(150);
- }
-
- public void testForgetBatchs() {
- add(1,100);
- buffer.removeFromCache(new Intervals(1,100));
- assertEquals("[]", buffer.getContents().toString()); //$NON-NLS-1$
- }
-
- public void testCantForgetBatch() {
- add(1,100);
- buffer.removeFromCache(new Intervals(50,100));
- assertEquals("[1, 100]", buffer.getContents().toString()); //$NON-NLS-1$
- }
-
- public void testForgetTwoBatches() {
- add(1,100);
- add(101,200);
- buffer.removeFromCache(new Intervals(1,200));
- assertEquals("[]", buffer.getContents().toString()); //$NON-NLS-1$
- }
-
- private void checkRow(int index) {
- Integer data = (Integer) buffer.getRow(index).get(0);
- assertEquals(index, data.intValue());
- }
-
-}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -22,26 +22,21 @@
package org.teiid.dqp.internal.cache;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import org.teiid.dqp.internal.cache.CacheID;
-import org.teiid.dqp.internal.cache.CacheResults;
-import org.teiid.dqp.internal.cache.ResultSetCache;
+import org.junit.Test;
-import junit.framework.TestCase;
-
import com.metamatrix.cache.FakeCache.FakeCacheFactory;
import com.metamatrix.common.buffer.impl.SizeUtility;
+import com.metamatrix.core.MetaMatrixRuntimeException;
-public class TestResultSetCache extends TestCase{
-
- public TestResultSetCache(final String name) {
- super(name);
- }
+public class TestResultSetCache {
- public void testSetAndGetResultsForSession() throws Exception{
+ @Test public void testSetAndGetResultsForSession() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -53,11 +48,11 @@
CacheID id2 = new CacheID("12346", "select * from table2"); //$NON-NLS-1$//$NON-NLS-2$
List[] result2 = new List[]{new ArrayList()};
cache.setResults(id2, new CacheResults(result2, 1, true), "req2" ); //$NON-NLS-1$
- assertEquals(cache.getResults(id1, new int[]{1, 500}).getResults(), result1);
- assertEquals(cache.getResults(id2, new int[]{1, 500}).getResults(), result2);
+ assertEquals(result1, cache.getResults(id1, new int[]{1, 500}).getResults());
+ assertEquals(result2, cache.getResults(id2, new int[]{1, 500}).getResults());
}
- public void testSetAndGetResultsForVDB() throws Exception{
+ @Test public void testSetAndGetResultsForVDB() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -73,7 +68,7 @@
assertEquals(cache.getResults(id2, new int[]{1, 500}).getResults(), result2);
}
-// public void testRemoveConnection() throws Exception{
+// @Test public void testRemoveConnection() throws Exception{
// Properties props = new Properties();
// props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
// props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -89,7 +84,7 @@
// assertNull(cache.getResults(id1, new int[]{0, 500})); //$NON-NLS-1$
// }
//
-// public void testRemoveVDB() throws Exception{
+// @Test public void testRemoveVDB() throws Exception{
// Properties props = new Properties();
// props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
// props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -105,7 +100,7 @@
// assertNull(cache.getResults(id1, new int[]{0, 500})); //$NON-NLS-1$
// }
- public void testClearAllCache() throws Exception{
+ @Test public void testClearAllCache() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -121,7 +116,7 @@
assertNull(cache.getResults(id1, new int[]{1, 500}));
}
- public void testSetAndGetResultsForSession1() throws Exception{
+ @Test public void testSetAndGetResultsForSession1() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -142,7 +137,7 @@
assertEquals(cache.getResults(id1, new int[]{1, 2}).getResults()[0], row1);
}
- public void testSetAndGetResultsForSession2() throws Exception{
+ @Test public void testSetAndGetResultsForSession2() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -167,7 +162,7 @@
assertEquals(cache.getResults(id1, new int[]{1, 2}).getResults()[0], row1);
}
- public void testMaxSize() throws Exception{
+ @Test public void testMaxSize() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "1"); //$NON-NLS-1$
@@ -206,7 +201,7 @@
}
- public void testComputeSize() throws Exception{
+ @Test public void testComputeSize() throws Exception{
int cnt = 1000000;
List[] results = new List[cnt];
List row = new ArrayList();
@@ -229,7 +224,7 @@
assertEquals(size, result.getSize());
}
- public void testSetDifferentReqID() throws Exception{
+ @Test(expected=MetaMatrixRuntimeException.class) public void testBatchNotContiguous() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -237,31 +232,9 @@
ResultSetCache cache = new ResultSetCache(props, new FakeCacheFactory());
CacheID id1 = new CacheID("vdb1", "select * from table1"); //$NON-NLS-1$//$NON-NLS-2$
CacheResults result1 = createResults(1000, 1, 100, false);
- CacheResults result2 = createResults(3000, 101, 250, false);
- CacheResults result3 = createResults(2000, 101, 200, true);
- cache.setResults(id1, result1 , "req1"); //$NON-NLS-1$
- cache.setResults(id1, result2, "req2" ); //$NON-NLS-1$
- cache.setResults(id1, result3, "req1" ); //$NON-NLS-1$
- assertEquals(cache.getResults(id1, new int[]{1, 500}).getFinalRow(), 300);
- assertEquals(cache.getResults(id1, new int[]{1, 500}).getResults().length, 300);
- }
-
- public void testBatchNotContiguous() throws Exception{
- Properties props = new Properties();
- props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
- props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
- props.setProperty(ResultSetCache.RS_CACHE_SCOPE, ResultSetCache.RS_CACHE_SCOPE_CONN);
- ResultSetCache cache = new ResultSetCache(props, new FakeCacheFactory());
- CacheID id1 = new CacheID("vdb1", "select * from table1"); //$NON-NLS-1$//$NON-NLS-2$
- CacheResults result1 = createResults(1000, 1, 100, false);
CacheResults result3 = createResults(2000, 102, 200, true);
cache.setResults(id1, result1 , "req1"); //$NON-NLS-1$
- try{
- cache.setResults(id1, result3, "req1" ); //$NON-NLS-1$
- fail("Expect an exception but did not get."); //$NON-NLS-1$
- }catch(Exception e){
- //expect an exception
- }
+ cache.setResults(id1, result3, "req1" ); //$NON-NLS-1$
}
}
Modified: trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -42,8 +42,8 @@
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.axis2.transport.http.HTTPConstants;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.soap.exceptions.SOAPProcessingException;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified: trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -43,7 +43,6 @@
import com.metamatrix.admin.api.objects.LogConfiguration;
import com.metamatrix.common.util.ByteArrayHelper;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.jdbc.api.SQLStates;
import com.metamatrix.soap.SOAPPlugin;
@@ -51,6 +50,7 @@
import com.metamatrix.soap.security.Credential;
import com.metamatrix.soap.sqlquerywebservice.log.LogUtil;
import com.metamatrix.soap.util.EndpointUriTranslatorStrategyImpl;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -35,12 +35,12 @@
import com.metamatrix.admin.api.exception.AdminException;
import com.metamatrix.api.exception.security.LogonException;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.object.MMServerInfo;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -48,7 +48,6 @@
import org.apache.log4j.Logger;
import com.metamatrix.common.api.MMURL;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.CoreConstants;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.LogListener;
@@ -57,6 +56,7 @@
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.util.ErrorMessageKeys;
import com.metamatrix.soap.util.SOAPConstants;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -34,13 +34,13 @@
import org.apache.log4j.Logger;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.util.ErrorMessageKeys;
import com.metamatrix.soap.util.SOAPConstants;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -43,13 +43,13 @@
import org.apache.log4j.Logger;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.LogListener;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.util.ErrorMessageKeys;
import com.metamatrix.soap.util.SOAPConstants;
+import com.metamatrix.soap.util.WSDLServletUtil;
/**
* Servlet to build the WSDL URL for the specified VDB
Modified: trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -30,7 +30,6 @@
import org.apache.axis2.context.MessageContext;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.soap.exceptions.SOAPProcessingException;
import com.metamatrix.soap.handler.ActionUpdateHandler;
import com.metamatrix.soap.service.DataServiceInfo;
Copied: trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java (from rev 872, trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java)
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java (rev 0)
+++ trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.soap.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Constants pertaining to WSDL servlet execution.
+ *
+ * @since 4.2
+ */
+
+public class WSDLServletUtil {
+
+ /**
+ * General keys
+ */
+ public static final String SERVER_URL_KEY = "ServerURL"; //$NON-NLS-1$
+
+ public static final String SECURE_PROTOCOL = "Secure"; //$NON-NLS-1$
+
+ public static final String VDB_NAME_KEY = "VDBName"; //$NON-NLS-1$
+
+ public static final String VDB_VERSION_KEY = "VDBVersion"; //$NON-NLS-1$
+
+ public static final String ADD_PROPS = "AdditionalProperties"; //$NON-NLS-1$
+
+ public static final String TXN_AUTO_WRAP = "txnAutoWrap"; //$NON-NLS-1$
+
+ public static final String ADD_EXEC_PROPS = "AddExecProperties"; //$NON-NLS-1$
+
+ public static final String MM_WEBSERVICE_QUERY_TIMEOUT = "com.metamatrix.webservice.querytimeout"; //$NON-NLS-1$
+
+ public static final String DISCOVERED_WSDL = "discovered_wsdl"; //$NON-NLS-1$
+
+ /*
+ * This is the parameter that will tell this servlet when the web service endpoint as defined in WSDL served up by this
+ * servlet will use the HTTP vs HTTPS protocol.
+ */
+ public static final String HTTP_TYPE_PARAMETER_KEY = "httptype"; //$NON-NLS-1$
+
+ /*
+ * This is the value of the httptype URL request param that will indicate that the returned WSDL should have an http endpoint
+ * instead of an https endpoint.
+ */
+ public static final String HTTP_PARAMETER_VALUE = "http"; //$NON-NLS-1$
+
+ /*
+ * Static contant representing the standard http protocol.
+ */
+ public static final String HTTP = "http"; //$NON-NLS-1$
+
+ /**
+ * Static contant representing the secure http protocol.
+ */
+ public static final String HTTPS = "https"; //$NON-NLS-1$
+
+ /**
+ * Default content type for the VDBResourceServlet
+ */
+ public static final String DEFAULT_CONTENT_TYPE = "text/html"; //$NON-NLS-1$
+
+ /**
+ * XML content type for the VDBResourceServlet
+ */
+ public static final String XML_CONTENT_TYPE = "text/xml"; //$NON-NLS-1$
+
+ /**
+ * WSDL URL Generator keys
+ */
+ public static final String MMSERVER_HOST_PORT_KEY = "MMServerHostAndPort"; //$NON-NLS-1$
+
+ public static final String TARGET_HOST_KEY = "TargetHost"; //$NON-NLS-1$
+
+ public static final String TARGET_PORT_KEY = "TargetPort"; //$NON-NLS-1$
+
+ public static final String SERVLET_PATH = "/servlet/ArtifactDocumentService"; //$NON-NLS-1$
+
+ public static final String SQLQUERYWEBSERVICE_WSDL_PATH = "/services/SqlQueryWebService?wsdl"; //$NON-NLS-1$
+
+ public static final String GENERATED_WSDL_NAME = "MetaMatrixDataServices"; //$NON-NLS-1$
+
+ public static final String GENERATED_WSDL_FILENAME = GENERATED_WSDL_NAME + ".wsdl"; //$NON-NLS-1$
+
+ public static final String COLON = ":"; //$NON-NLS-1$
+
+ public static final String SLASH = "/"; //$NON-NLS-1$
+
+ public static final String DOUBLE_SLASH = "//"; //$NON-NLS-1$
+
+ public static final String AMP = "&"; //$NON-NLS-1$
+
+ public static final String QUESTION_MARK = "?"; //$NON-NLS-1$
+
+ public static final String EQUALS = "="; //$NON-NLS-1$
+
+ public static final String COMMA = ","; //$NON-NLS-1$
+
+ private static final String SQLQUERYWEBSERVICE_URL_FORMAT = "{0}://{1}:{2}/{3}"; //$NON-NLS-1$
+
+ /*
+ * this default value is based on Tomcat's default value in its server.xml file. This value can be overridden by setting the
+ * com.metamatrix.webservice.dataservice.httpsport System property for the VM that this servlet is running in.
+ */
+ private static final String DEFAULT_HTTPS_PORT = "8443"; //$NON-NLS-1$
+
+ private static final String DEFAULT_HTTP_PORT = "8080"; //$NON-NLS-1$
+
+ private static final String HTTPS_PORT_PROPERTY_KEY = "com.metamatrix.webservice.dataservice.httpsport"; //$NON-NLS-1$
+
+ private static final String HTTP_PORT_PROPERTY_KEY = "com.metamatrix.webservice.dataservice.httpport"; //$NON-NLS-1$
+
+ /**
+ * Returns the formatted url from the supplied info
+ *
+ * @param scheme the server scheme
+ * @param host the server host name
+ * @param port the server port
+ * @param appContext the context of this application to use in the WSDL url
+ * @param serverURLs the list of server url info, first url is full url including protocol. Subsequent items are just the
+ * host:port strings.
+ * @param vdbName the vdb name
+ * @param vdbVersion the vdb version number
+ */
+ public static String formatURL( String scheme,
+ String host,
+ String port,
+ String appContext,
+ List serverURLs,
+ String vdbName,
+ String vdbVersion ) {
+
+ StringBuffer result = new StringBuffer();
+ try {
+ boolean hasPort = true;
+ boolean hasVDBVersion = true;
+
+ if (port == null || port.length() == 0) {
+ hasPort = false;
+ }
+
+ if (vdbVersion == null || vdbVersion.trim().length() == 0) {
+ hasVDBVersion = false;
+ }
+
+ result.append(scheme).append(COLON).append(DOUBLE_SLASH).append(host);
+
+ if (hasPort) {
+ result.append(COLON).append(port);
+ }
+
+ result.append(appContext).append(SERVLET_PATH).append(SLASH).append(GENERATED_WSDL_FILENAME);
+ result.append(QUESTION_MARK).append(SERVER_URL_KEY).append(EQUALS);
+ // Append comma-delimited server urls
+ Iterator iter = serverURLs.iterator();
+ while (iter.hasNext()) {
+ String serverURL = (String)iter.next();
+ result.append(serverURL);
+ // If there is another url coming, add an encoded comma
+ if (iter.hasNext()) {
+ result.append(URLEncoder.encode(COMMA, "UTF-8")); //$NON-NLS-1$
+ }
+ }
+ result.append(AMP).append(VDB_NAME_KEY).append(EQUALS).append(vdbName);
+ if (hasVDBVersion) {
+ result.append(AMP).append(VDB_VERSION_KEY).append(EQUALS).append(vdbVersion);
+ }
+
+ } catch (UnsupportedEncodingException err) {
+ // ignore
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Returns the formatted wsdl url for the SqlQueryWebService
+ *
+ * @param server - server name
+ * @param appContext the context of this application to use in the WSDL url
+ * @param secure - secure ssl (true) or non-secure (false)
+ * @return wsdlUrl - String
+ * @since 4.3
+ */
+ public static String getSqlQueryWebServiceUrl( final String server,
+ String appContext,
+ final boolean secure ) {
+
+ appContext=appContext.replace("/",""); //$NON-NLS-1$ //$NON-NLS-2$
+ return MessageFormat.format(SQLQUERYWEBSERVICE_URL_FORMAT, new Object[] {secure ? HTTPS : HTTP, server,
+ secure ? getHttpsPort() : getHttpPort(), appContext+SQLQUERYWEBSERVICE_WSDL_PATH});
+ }
+
+ public static final String getHttpsPort() {
+ return System.getProperty(HTTPS_PORT_PROPERTY_KEY, DEFAULT_HTTPS_PORT);
+ }
+
+ public static final String getHttpPort() {
+ return System.getProperty(HTTP_PORT_PROPERTY_KEY, DEFAULT_HTTP_PORT);
+ }
+}
Property changes on: trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java
===================================================================
--- trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -29,7 +29,7 @@
import org.apache.axis2.context.MessageContext;
-import com.metamatrix.common.util.WSDLServletUtil;
+import com.metamatrix.soap.util.WSDLServletUtil;
public class TestActionUpdateHandler extends TestCase{
Modified: trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java
===================================================================
--- trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -28,7 +28,7 @@
import org.apache.axis2.AxisFault;
-import com.metamatrix.common.util.WSDLServletUtil;
+import com.metamatrix.soap.util.WSDLServletUtil;
/**
*
Modified: trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java
===================================================================
--- trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java 2009-05-07 21:28:59 UTC (rev 884)
+++ trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -25,7 +25,7 @@
import java.util.Map;
import java.util.TreeMap;
-import com.metamatrix.common.util.WSDLServletUtil;
+import com.metamatrix.soap.util.WSDLServletUtil;
import junit.framework.TestCase;
Copied: trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java (from rev 872, trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java)
===================================================================
--- trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java (rev 0)
+++ trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java 2009-05-07 21:35:26 UTC (rev 885)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.soap.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.metamatrix.soap.util.WSDLServletUtil;
+
+import junit.framework.TestCase;
+
+/**
+ */
+public class TestWSDLServletUtil extends TestCase {
+
+ public static String HTTP = "http"; //$NON-NLS-1$
+ public static String HTTPS = "https"; //$NON-NLS-1$
+ public static String DEFAULT_APP_CONTEXT = "/metamatrix-soap"; //$NON-NLS-1$
+ public static String OTHER_APP_CONTEXT = "/metamatrix-soapiness"; //$NON-NLS-1$
+
+ public TestWSDLServletUtil(String name) {
+ super(name);
+ }
+
+ public void testGetMMSAPIUrlAllNullServerNameSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT, true);
+ assertEquals("https://null:8443/metamatrix-soap/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
+ }
+
+ public void testGetMMSAPIUrlAllNullServerNameNonSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT, false);
+ assertEquals("http://null:8080/metamatrix-soap/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
+ }
+
+ public void testGetMMSAPIUrlValidParametersSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01", DEFAULT_APP_CONTEXT, true); //$NON-NLS-1$
+ assertEquals("https://slntmm01:8443/metamatrix-soap/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
+ }
+
+ public void testGetMMSAPIUrlValidParametersNonSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01", OTHER_APP_CONTEXT,false); //$NON-NLS-1$
+ assertEquals("http://slntmm01:8080/metamatrix-soapiness/services/SqlQueryWebService?wsdl", url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersNonSecure() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080", DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaM...", url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecure() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/Meta...", url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecureNoPort() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null, DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("https://chicago/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatri...", url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecureNoPortNoVdbVersion() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null, OTHER_APP_CONTEXT, serverURLs,"testVDB",null); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("https://chicago/metamatrix-soapiness/servlet/ArtifactDocumentService/Meta...", url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecureNoVdbVersion() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT, serverURLs,"testVDB",""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/Meta...", url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlMultipleServers() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
+ serverURLs.add("boston:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080", DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaM...", url); //$NON-NLS-1$
+ }
+
+}
Property changes on: trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+
15 years, 8 months
teiid SVN: r884 - trunk/soap/src/main/java/com/metamatrix/soap/service.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-05-07 17:28:59 -0400 (Thu, 07 May 2009)
New Revision: 884
Modified:
trunk/soap/src/main/java/com/metamatrix/soap/service/BasicConnectionPoolFactory.java
trunk/soap/src/main/java/com/metamatrix/soap/service/ConnectionSource.java
Log:
TEIID-497 migrated the fix for case 5042 as an initial solution. The user can now override the driver class using either a teiidpool.properties file in the classpath or with a system property.
Modified: trunk/soap/src/main/java/com/metamatrix/soap/service/BasicConnectionPoolFactory.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/service/BasicConnectionPoolFactory.java 2009-05-07 20:53:09 UTC (rev 883)
+++ trunk/soap/src/main/java/com/metamatrix/soap/service/BasicConnectionPoolFactory.java 2009-05-07 21:28:59 UTC (rev 884)
@@ -22,6 +22,8 @@
package com.metamatrix.soap.service;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Properties;
import javax.sql.DataSource;
@@ -41,6 +43,7 @@
* This is the set of default properties that are used to drive the way that the pools produced by this factory behaves.
*/
private static final Properties defaultProperties = new Properties();
+ public static final String MMPOOL_PROPERTIES_FILENAME = "/teiidpool.properties"; //$NON-NLS-1$
static {
/*
@@ -54,6 +57,9 @@
defaultProperties.setProperty(MIN_EVICTABLE_IDLE_TIME_MILLIS_KEY, String.valueOf(MIN_EVICTABLE_IDLE_TIME_MILLIS_DEFAULT));
defaultProperties.setProperty(TIME_BETWEEN_EVICTION_THREAD_RUNS_KEY,
String.valueOf(TIME_BETWEEN_EVICTION_THREAD_RUNS_DEFAULT));
+ defaultProperties.setProperty(TIME_BETWEEN_EVICTION_THREAD_RUNS_KEY,
+ String.valueOf(TIME_BETWEEN_EVICTION_THREAD_RUNS_DEFAULT));
+ defaultProperties.setProperty(ConnectionSource.DRIVER_CLASS, "com.metamatrix.jdbc.MMDriver"); //$NON-NLS-1$
}
/**
@@ -65,26 +71,52 @@
return null;
}
Properties p = new Properties(poolProperties);
- p.setProperty(JDBCUtil.DRIVER, "com.metamatrix.jdbc.MMDriver");
- p.setProperty(JDBCUtil.USERNAME, poolProperties.getProperty(ConnectionSource.USERNAME));
- p.setProperty(JDBCUtil.PASSWORD, poolProperties.getProperty(ConnectionSource.PASSWORD));
+ /* 1. 'mergedProperties' will contain the available properties, constructed in the correct sequence
+ * so that propery values that should override other values, will override them.
+ * 2. 'mergedProperties' must be recreated from scratch every time 'createConnectionPool' is called.
+ */
+ Properties mergedProperties = createMergedProperties( poolProperties );
+
+ p.setProperty(JDBCUtil.DRIVER, mergedProperties.getProperty(ConnectionSource.DRIVER_CLASS));
+ p.setProperty(JDBCUtil.USERNAME, mergedProperties.getProperty(ConnectionSource.USERNAME));
+ p.setProperty(JDBCUtil.PASSWORD, mergedProperties.getProperty(ConnectionSource.PASSWORD));
p.setProperty(JDBCUtil.DATABASE, poolProperties.getProperty(ConnectionSource.SERVER_URL));
- p.setProperty(SimplePooledConnectionSource.MAXIMUM_RESOURCE_POOL_SIZE, getProperty(MAX_ACTIVE_CONNECTIONS_PROPERTY_KEY));
- p.setProperty(SimplePooledConnectionSource.WAIT_TIME_FOR_RESOURCE, getProperty(MAX_WAIT_PROPERTY_KEY));
+ p.setProperty(SimplePooledConnectionSource.MAXIMUM_RESOURCE_POOL_SIZE, mergedProperties.getProperty(MAX_ACTIVE_CONNECTIONS_PROPERTY_KEY));
+ p.setProperty(SimplePooledConnectionSource.WAIT_TIME_FOR_RESOURCE, mergedProperties.getProperty(MAX_WAIT_PROPERTY_KEY));
return new SimplePooledConnectionSource(p);
}
- /**
- * This method will get a property value from the JVM System properties with the default value from the default properties
- * class level instance being the default value.
- *
- * @param propKey
- * The key for the property to get
- * @return the value of the property for the passed in key
- * @since 4.3
- */
- protected String getProperty(final String propKey) {
- return System.getProperty(propKey, defaultProperties.getProperty(propKey));
+ protected static Properties createMergedProperties( Properties poolProperties ) {
+
+ // 1. start with the default properties
+ Properties mergedProperties = new Properties( defaultProperties );
+
+ // 2. add properties from mmpool.properties
+ mergedProperties.putAll( getMMPoolProperties() );
+
+ // 3. add System.properties
+ mergedProperties.putAll(System.getProperties());
+
+ // 4. add specific poolProperties
+ mergedProperties.putAll( poolProperties );
+
+ return mergedProperties;
}
+
+ protected static Properties getMMPoolProperties() {
+ Properties p = new Properties();
+ InputStream is = BasicConnectionPoolFactory.class.getClassLoader().getResourceAsStream( MMPOOL_PROPERTIES_FILENAME ); //$NON-NLS-1$
+
+ if ( is != null ) {
+ try {
+ p.load( is );
+ } catch( IOException ioe ) {
+ return new Properties();
+ }
+ }
+
+ return p;
+ }
+
}
Modified: trunk/soap/src/main/java/com/metamatrix/soap/service/ConnectionSource.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/service/ConnectionSource.java 2009-05-07 20:53:09 UTC (rev 883)
+++ trunk/soap/src/main/java/com/metamatrix/soap/service/ConnectionSource.java 2009-05-07 21:28:59 UTC (rev 884)
@@ -50,6 +50,11 @@
* This is a property key that is used for the password used to connect to an MM Server.
*/
public static final String PASSWORD = "Password"; //$NON-NLS-1$
+
+ /**
+ * This is a property key that is used for the driver class used to connect to an MM Server.
+ */
+ public static final String DRIVER_CLASS = "DriverClass"; //$NON-NLS-1$
public Connection getConnection(Properties connectionProperties) throws SQLException;
}
15 years, 8 months
teiid SVN: r883 - trunk/server/src/main/java/com/metamatrix/admin/server.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-05-07 16:53:09 -0400 (Thu, 07 May 2009)
New Revision: 883
Modified:
trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java
trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
Log:
JBEDSP-977 - converting importcb to use admin. The change to ServerConfigAdminImpl broke a test in the case a bad binding name is passed in, fixed that issue too.
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java 2009-05-07 20:42:19 UTC (rev 882)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java 2009-05-07 20:53:09 UTC (rev 883)
@@ -217,6 +217,9 @@
}
/**
+ * @param connectorBindingName, is nullable, indicates the name to assign to the importing {@link ConnectorBinding}.
+ * If it is null, then the name defined in the xmlFile will be used.
+ * @param xmlFile is an xml formatted file that defines the connector binding
* @see com.metamatrix.admin.api.server.ServerConfigAdmin#addConnectorBinding(java.lang.String, char[], AdminOptions)
* @since 4.3
*/
@@ -224,71 +227,45 @@
char[] xmlFile, AdminOptions options) throws AdminException {
com.metamatrix.admin.api.objects.ConnectorBinding newBinding = null;
- if (connectorBindingName == null) {
- throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.Connector_Binding_can_not_be_null")); //$NON-NLS-1$
- }
if (xmlFile == null) {
throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.CDK_File_Name_can_not_be_null")); //$NON-NLS-1$
}
+
+ // first, read the xmlfile to determine the defined connnector binding name
+ // because majority of the time, the file will determine the name
+ InputStream is = ObjectConverterUtil.convertToInputStream(xmlFile);
+
+ XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
+ ConnectorBinding binding = null;
+ try {
+ binding = ciu.importConnectorBinding(is, new BasicConfigurationObjectEditor(false), connectorBindingName);
+ } catch (ConfigObjectsNotResolvableException e) {
+ throw new AdminComponentException(e);
+ } catch (InvalidConfigurationElementException e) {
+ throw new AdminComponentException(e);
+ } catch (IOException e) {
+ throw new AdminComponentException(e);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
- // Check if binding allready exists and look at admin options
- Collection existingBindings =
- parent.getConnectorBindings(AdminObject.WILDCARD + AdminObject.DELIMITER + connectorBindingName);
- Collection newBindingNames = new ArrayList(1);
- newBindingNames.add(connectorBindingName);
- Collection updateBindingNames = getBindingNamesToUpdate(existingBindings, newBindingNames, options);
+ // reassign the name in cases where null was passed in
+ connectorBindingName = binding.getName();
+
+ return this.addConnectorBinding(connectorBindingName, binding.getComponentTypeID().getFullName(), binding.getProperties(), options);
- if ( updateBindingNames.size() > 0 && updateBindingNames.iterator().next().equals(connectorBindingName) ) {
- // Add the new binding
- InputStream is = ObjectConverterUtil.convertToInputStream(xmlFile);
-
- XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
- ConnectorBinding binding = null;
- try {
- binding = ciu.importConnectorBinding(is, new BasicConfigurationObjectEditor(false), connectorBindingName);
- is.close();
- } catch (ConfigObjectsNotResolvableException e) {
- throw new AdminComponentException(e);
- } catch (InvalidConfigurationElementException e) {
- throw new AdminComponentException(e);
- } catch (IOException e) {
- throw new AdminComponentException(e);
- }
- // Check that binding password is decryptable
- AdminStatus status = checkDecryption(binding);
- if ( status.getCode() == AdminStatus.CODE_DECRYPTION_FAILED &&
- ! options.containsOption(AdminOptions.BINDINGS_IGNORE_DECRYPT_ERROR)) {
- throw new AdminProcessingException(status.getCode(), status.getMessage());
- }
-
- try {
- is = ObjectConverterUtil.convertToInputStream(xmlFile);
- // pass "ALL" to deploy newly created binding to all vms
- binding = getConfigurationServiceProxy().importConnectorBinding(is, connectorBindingName, "ALL", getUserName());
- if (binding == null) {
- throwProcessingException("ServerConfigAdminImpl.Connector_Type_was_null", new Object[] {connectorBindingName}); //$NON-NLS-1$
- }
- } catch (ConfigurationException e) {
- throw new AdminComponentException(e);
- } catch (ServiceException e) {
- throw new AdminComponentException(e);
- }
-
- //return the new binding
- Collection newBindings =
- parent.getConnectorBindings(AdminObject.WILDCARD + AdminObject.DELIMITER + connectorBindingName);
- newBinding = (com.metamatrix.admin.api.objects.ConnectorBinding) newBindings.iterator().next();
- } else {
- // We didn't add the new connector binding. Return the existing.
- if (existingBindings != null && existingBindings.size() > 0) {
- // Only expecting one existing binding
- newBinding = (com.metamatrix.admin.api.objects.ConnectorBinding) existingBindings.iterator().next();
- }
- }
- return newBinding;
}
/**
+ * @param name, is nullable, indicates the name to assign to the connector type
+ * If name is null, then the name defined in the cdkFile will be used.
* @throws MetaMatrixComponentException
* @throws MetaMatrixProcessingException
* @see com.metamatrix.admin.api.server.ServerConfigAdmin#addConnectorType(java.lang.String, char[])
@@ -298,15 +275,39 @@
char[] cdkFile) throws AdminException {
ComponentType connectorType = null;
- if (name == null) {
- throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.Connector_Type_can_not_be_null")); //$NON-NLS-1$
- }
if (cdkFile == null) {
throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.CDK_File_Name_can_not_be_null")); //$NON-NLS-1$
}
- try {
- InputStream is = ObjectConverterUtil.convertToInputStream(cdkFile);
+ InputStream is = null;
+ if (name == null || name.trim().length() == 0) {
+ is = ObjectConverterUtil.convertToInputStream(cdkFile);
+
+ XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
+ try {
+ connectorType = ciu.importComponentType(is, new BasicConfigurationObjectEditor(false), name);
+ // reassign name in case it was passed in
+ name = connectorType.getFullName();
+ } catch (InvalidConfigurationElementException e) {
+ throw new AdminComponentException(e);
+ } catch (IOException e) {
+ throw new AdminComponentException(e);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ try {
+ is = ObjectConverterUtil.convertToInputStream(cdkFile);
+
connectorType = getConfigurationServiceProxy().importConnectorType(is, name, getUserName());
if (connectorType == null) {
throwProcessingException("ServerConfigAdminImpl.Connector_Type_was_null", new Object[] {name}); //$NON-NLS-1$
@@ -315,7 +316,17 @@
throw new AdminComponentException(e);
} catch (ServiceException e) {
throw new AdminComponentException(e);
- }
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
}
/**
@@ -636,6 +647,8 @@
}
/**
+ * @param name, is nullable, indicates the name to assign to the vdb
+ * If name is null, then use the name defined in the vdbFile.
* @see com.metamatrix.admin.api.server.ServerConfigAdmin#addVDB(java.lang.String, java.lang.String, byte[], char[])
* @since 4.3
*/
@@ -643,7 +656,9 @@
VDBArchive vdb = null;
try {
vdb = new VDBArchive(new ByteArrayInputStream(vdbFile));
- vdb.setName(name);
+ if (name != null) {
+ vdb.setName(name);
+ }
} catch (IOException e) {
throw new AdminComponentException(e);
}
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java 2009-05-07 20:42:19 UTC (rev 882)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java 2009-05-07 20:53:09 UTC (rev 883)
@@ -204,19 +204,32 @@
binding.setServiceID(serviceBinding.getServiceID().getID());
} else {
+
String[] identifierParts = new String[] {
deployedComponent.getHostID().getName(),
deployedComponent.getVMComponentDefnID().getName(),
deployedComponent.getName()
};
- String key = MMAdminObject.buildIdentifier(identifierParts).toUpperCase();
+
+ if (identifierMatches(identifier, identifierParts)) {
+
+ //not in config - create new MMConnectorBinding
+ binding = new MMConnectorBinding(identifierParts);
+ binding.setDeployed(false);
+ binding.setState(MMConnectorBinding.STATE_NOT_DEPLOYED);
- //not in config - create new MMConnectorBinding
- binding = new MMConnectorBinding(identifierParts);
- binding.setDeployed(false);
- binding.setState(MMConnectorBinding.STATE_NOT_DEPLOYED);
-
- results.add(binding);
+
+ binding.setConnectorTypeName(deployedComponent.getComponentTypeID().getFullName());
+ binding.setDescription(deployedComponent.getDescription());
+ binding.setState(serviceBinding.getCurrentState());
+ binding.setStateChangedTime(serviceBinding.getStateChangeTime());
+ binding.setRegistered(true);
+ binding.setServiceID(serviceBinding.getServiceID().getID());
+
+ results.add(binding);
+
+ }
+
}
}
}
15 years, 8 months