### Eclipse Workspace Patch 1.0 #P org.eclipse.rse.core Index: src/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java,v retrieving revision 1.13 diff -u -r1.13 RSEDOMImporter.java --- src/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java 30 Aug 2007 17:13:10 -0000 1.13 +++ src/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java 6 Sep 2007 11:13:34 -0000 @@ -15,12 +15,15 @@ * Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods * Martin Oberhuber (Wind River) - [175680] Deprecate obsolete ISystemRegistry methods * Kevin Doyle (IBM) - [163883] Multiple filter strings are disabled + * Martin Oberhuber (Wind River) - [202416] Protect against NPEs when importing DOM ********************************************************************************/ package org.eclipse.rse.internal.persistence.dom; import java.util.Vector; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.rse.core.IRSECoreRegistry; import org.eclipse.rse.core.IRSESystemType; import org.eclipse.rse.core.RSECorePlugin; @@ -74,8 +77,8 @@ */ public ISystemProfile restoreProfile(RSEDOM dom) { String profileName = dom.getName(); - boolean defaultPrivate = getBooleanValue(dom.getAttribute(IRSEDOMConstants.ATTRIBUTE_DEFAULT_PRIVATE).getValue()); - boolean isActive = getBooleanValue(dom.getAttribute(IRSEDOMConstants.ATTRIBUTE_IS_ACTIVE).getValue()); + boolean defaultPrivate = getBooleanValue(dom, IRSEDOMConstants.ATTRIBUTE_DEFAULT_PRIVATE); + boolean isActive = getBooleanValue(dom, IRSEDOMConstants.ATTRIBUTE_IS_ACTIVE); ISystemProfile profile = new SystemProfile(profileName, isActive); if (profile != null) { profile.setDefaultPrivate(defaultPrivate); @@ -85,11 +88,11 @@ for (int i = 0; i < children.length; i++) { RSEDOMNode child = children[i]; String type = child.getType(); - if (type.equals(IRSEDOMConstants.TYPE_HOST)) { + if (IRSEDOMConstants.TYPE_HOST.equals(type)) { restoreHost(profile, child); - } else if (type.equals(IRSEDOMConstants.TYPE_FILTER_POOL)) { + } else if (IRSEDOMConstants.TYPE_FILTER_POOL.equals(type)) { restoreFilterPool(profile, child); - } else if (type.equals(IRSEDOMConstants.TYPE_PROPERTY_SET)) { + } else if (IRSEDOMConstants.TYPE_PROPERTY_SET.equals(type)) { restorePropertySet(profile, child); } } @@ -109,8 +112,8 @@ String systemTypeId = getAttributeValue(hostNode, IRSEDOMConstants.ATTRIBUTE_SYSTEM_TYPE); String hostName = getAttributeValue(hostNode, IRSEDOMConstants.ATTRIBUTE_HOSTNAME); String description = getAttributeValue(hostNode, IRSEDOMConstants.ATTRIBUTE_DESCRIPTION); - boolean isOffline = getBooleanValue(getAttributeValue(hostNode, IRSEDOMConstants.ATTRIBUTE_OFFLINE)); - boolean isPromptable = getBooleanValue(getAttributeValue(hostNode, IRSEDOMConstants.ATTRIBUTE_PROMPTABLE)); + boolean isOffline = getBooleanValue(hostNode, IRSEDOMConstants.ATTRIBUTE_OFFLINE); + boolean isPromptable = getBooleanValue(hostNode, IRSEDOMConstants.ATTRIBUTE_PROMPTABLE); // create host and set it's attributes try { @@ -127,7 +130,7 @@ host.setOffline(isOffline); host.setPromptable(isPromptable); } catch (Exception e) { - e.printStackTrace(); + logException(e); } // restore children of host @@ -135,9 +138,9 @@ for (int i = 0; i < children.length; i++) { RSEDOMNode child = children[i]; String type = child.getType(); - if (type.equals(IRSEDOMConstants.TYPE_CONNECTOR_SERVICE)) { + if (IRSEDOMConstants.TYPE_CONNECTOR_SERVICE.equals(type)) { restoreConnectorService(host, child); - } else if (type.equals(IRSEDOMConstants.TYPE_PROPERTY_SET)) { + } else if (IRSEDOMConstants.TYPE_PROPERTY_SET.equals(type)) { restorePropertySet(host, child); } } @@ -156,12 +159,8 @@ // String name = connectorServiceNode.getName(); // String type = connectorServiceNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_TYPE).getValue(); // String group = connectorServiceNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_GROUP).getValue(); - boolean useSSL = getBooleanValue(connectorServiceNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_USE_SSL).getValue()); - RSEDOMNodeAttribute att = connectorServiceNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_PORT); - int port = 0; - if (att != null) { - port = getIntegerValue(att.getValue()); - } + boolean useSSL = getBooleanValue(connectorServiceNode, IRSEDOMConstants.ATTRIBUTE_USE_SSL); + int port = getIntegerValue(connectorServiceNode, IRSEDOMConstants.ATTRIBUTE_PORT); // first restore subsystems (since right now we need subsystem to get at service RSEDOMNode[] ssChildren = connectorServiceNode.getChildren(IRSEDOMConstants.TYPE_SUBSYSTEM); @@ -222,8 +221,8 @@ // in most cases (if not all) the subsystem already exists // since createHost() ends up recreating subsystems for each factory String name = subSystemNode.getName(); - String type = subSystemNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_TYPE).getValue(); - boolean isHidden = getBooleanValue(subSystemNode.getAttribute(IRSEDOMConstants.ATTRIBUTE_HIDDEN).getValue()); + String type = getAttributeValue(subSystemNode, IRSEDOMConstants.ATTRIBUTE_TYPE); + boolean isHidden = getBooleanValue(subSystemNode, IRSEDOMConstants.ATTRIBUTE_HIDDEN); ISubSystem subSystem = null; ISubSystemConfiguration factory = getSubSystemConfiguration(type); if (factory != null) { @@ -288,18 +287,18 @@ public ISystemFilter restoreFilter(ISystemFilterPool filterPool, RSEDOMNode node) { // get the node attributes for a filter String name = node.getName(); - boolean supportsNestedFilters = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_SUPPORTS_NESTED_FILTERS).getValue()); - int relativeOrder = getIntegerValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_RELATIVE_ORDER).getValue()); - boolean isDefault = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_DEFAULT).getValue()); - boolean isSetStringsCaseSensitive = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_STRING_CASE_SENSITIVE).getValue()); - boolean isPromptable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_PROMPTABLE).getValue()); - boolean isSetSupportsDuplicateFilterStrings = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_SUPPORTS_DUPLICATE_FILTER_STRINGS).getValue()); - boolean isNonDeletable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_NON_DELETABLE).getValue()); - boolean isNonRenamable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_NON_RENAMABLE).getValue()); - boolean isNonChangable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_NON_CHANGEABLE).getValue()); - boolean isStringsNonChangable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_STRINGS_NON_CHANGABLE).getValue()); - int release = getIntegerValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_RELEASE).getValue()); - boolean isSetSingleFilterStringOnly = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_SINGLE_FILTER_STRING_ONLY).getValue()); + boolean supportsNestedFilters = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_SUPPORTS_NESTED_FILTERS); + int relativeOrder = getIntegerValue(node, IRSEDOMConstants.ATTRIBUTE_RELATIVE_ORDER); + boolean isDefault = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_DEFAULT); + boolean isSetStringsCaseSensitive = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_STRING_CASE_SENSITIVE); + boolean isPromptable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_PROMPTABLE); + boolean isSetSupportsDuplicateFilterStrings = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_SUPPORTS_DUPLICATE_FILTER_STRINGS); + boolean isNonDeletable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_NON_DELETABLE); + boolean isNonRenamable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_NON_RENAMABLE); + boolean isNonChangable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_NON_CHANGEABLE); + boolean isStringsNonChangable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_STRINGS_NON_CHANGABLE); + int release = getIntegerValue(node, IRSEDOMConstants.ATTRIBUTE_RELEASE); + boolean isSetSingleFilterStringOnly = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_SINGLE_FILTER_STRING_ONLY); Vector filterStrings = new Vector(); @@ -346,14 +345,14 @@ // get the node attributes for a filter pool String name = node.getName(); - String type = node.getAttribute(IRSEDOMConstants.ATTRIBUTE_TYPE).getValue(); - String id = node.getAttribute(IRSEDOMConstants.ATTRIBUTE_ID).getValue(); - boolean supportsNestedFilters = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_SUPPORTS_NESTED_FILTERS).getValue()); - boolean isDeletable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_DELETABLE).getValue()); - boolean isDefault = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_DEFAULT).getValue()); - boolean isSetStringsCaseSensitive = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_STRING_CASE_SENSITIVE).getValue()); - boolean isSetSupportsDuplicateFilterStrings = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_SUPPORTS_DUPLICATE_FILTER_STRINGS).getValue()); - int release = getIntegerValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_RELEASE).getValue()); + String type = getAttributeValue(node, IRSEDOMConstants.ATTRIBUTE_TYPE); + String id = getAttributeValue(node, IRSEDOMConstants.ATTRIBUTE_ID); + boolean supportsNestedFilters = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_SUPPORTS_NESTED_FILTERS); + boolean isDeletable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_DELETABLE); + boolean isDefault = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_DEFAULT); + boolean isSetStringsCaseSensitive = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_STRING_CASE_SENSITIVE); + boolean isSetSupportsDuplicateFilterStrings = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_SUPPORTS_DUPLICATE_FILTER_STRINGS); + int release = getIntegerValue(node, IRSEDOMConstants.ATTRIBUTE_RELEASE); // Since old profiles won't have an "singleFilterStringOnlyESet" attribute // we must give it a default value. @@ -366,11 +365,11 @@ RSEDOMNodeAttribute attribute = node.getAttribute("singleFilterStringOnlyESet"); //$NON-NLS-1$ if (attribute != null) { isSingleFilterStringOnlyESet = getBooleanValue(attribute.getValue()); - isSetSingleFilterStringOnly = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_SINGLE_FILTER_STRING_ONLY).getValue()); + isSetSingleFilterStringOnly = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_SINGLE_FILTER_STRING_ONLY); } - String owningParentName = node.getAttribute(IRSEDOMConstants.ATTRIBUTE_OWNING_PARENT_NAME).getValue(); - boolean isNonRenamable = getBooleanValue(node.getAttribute(IRSEDOMConstants.ATTRIBUTE_NON_RENAMABLE).getValue()); + String owningParentName = getAttributeValue(node, IRSEDOMConstants.ATTRIBUTE_OWNING_PARENT_NAME); + boolean isNonRenamable = getBooleanValue(node, IRSEDOMConstants.ATTRIBUTE_NON_RENAMABLE); // create the filter pool and set it's attributes try { @@ -409,7 +408,7 @@ // filterPool.wasRestored(); } } catch (Exception e) { - e.printStackTrace(); + logException(e); } // restore children @@ -417,11 +416,11 @@ for (int i = 0; i < children.length; i++) { RSEDOMNode child = children[i]; String ctype = child.getType(); - if (ctype.equals(IRSEDOMConstants.TYPE_FILTER)) { + if (IRSEDOMConstants.TYPE_FILTER.equals(ctype)) { if (filterPool != null) { restoreFilter(filterPool, child); } - } else if (ctype.equals(IRSEDOMConstants.TYPE_PROPERTY_SET)) { + } else if (IRSEDOMConstants.TYPE_PROPERTY_SET.equals(ctype)) { restorePropertySet(filterPool, child); } } @@ -466,7 +465,7 @@ RSEDOMNodeAttribute[] attributes = propertySetNode.getAttributes(); for (int i = 0; i < attributes.length; i++) { RSEDOMNodeAttribute attribute = attributes[i]; - if (attribute.getKey().equals(IRSEDOMConstants.ATTRIBUTE_DESCRIPTION)) { // descriptions really are stored as attributes + if (IRSEDOMConstants.ATTRIBUTE_DESCRIPTION.equals(attribute.getKey())) { // descriptions really are stored as attributes set.setDescription(attribute.getValue()); } else { String typeStr = attribute.getType(); @@ -479,10 +478,10 @@ for (int i = 0; i < children.length; i++) { RSEDOMNode child = children[i]; String propertyName = child.getName(); - String propertyValue = child.getAttribute(IRSEDOMConstants.ATTRIBUTE_VALUE).getValue(); - String propertyTypeName = child.getAttribute(IRSEDOMConstants.ATTRIBUTE_TYPE).getValue(); + String propertyValue = getAttributeValue(child, IRSEDOMConstants.ATTRIBUTE_VALUE); + String propertyTypeName = getAttributeValue(child, IRSEDOMConstants.ATTRIBUTE_TYPE); IPropertyType propertyType = PropertyType.fromString(propertyTypeName); - if (propertyName.equals(IPropertySet.DESCRIPTION_KEY)) { // any descriptions found as properties should be set directly + if (IPropertySet.DESCRIPTION_KEY.equals(propertyName)) { // any descriptions found as properties should be set directly set.setDescription(propertyValue); } else { set.addProperty(propertyName, propertyValue, propertyType); @@ -523,4 +522,20 @@ } return result; } + + private boolean getBooleanValue(RSEDOMNode node, String attributeName) { + String booleanStr = getAttributeValue(node, attributeName); + return getBooleanValue(booleanStr); + } + + private int getIntegerValue(RSEDOMNode node, String attributeName) { + String intStr = getAttributeValue(node, attributeName); + return getIntegerValue(intStr); + } + + private void logException(Exception e) { + RSECorePlugin.getDefault().getLog().log( + new Status(IStatus.ERROR, RSECorePlugin.getDefault().getBundle().getSymbolicName(), -1, e.getMessage(), e)); + } + } \ No newline at end of file