[166208] Update working copy to avoid unnecessary sets
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Base.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Base.java
index 536b3c5..517278b 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Base.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Base.java
@@ -82,6 +82,25 @@
return file;
}
+ /**
+ * Returns <code>true</code> if the attribute is currently set, and <code>false</code>
+ * otherwise.
+ *
+ * @param attributeName
+ * @return <code>true</code> if the attribute is currently set, and <code>false</code>
+ * otherwise
+ */
+ public boolean isAttributeSet(String attributeName) {
+ try {
+ Object obj = map.get(attributeName);
+ if (obj != null)
+ return true;
+ } catch (Exception e) {
+ // ignore
+ }
+ return false;
+ }
+
public String getAttribute(String attributeName, String defaultValue) {
try {
Object obj = map.get(attributeName);
@@ -131,7 +150,7 @@
}
return defaultValue;
}
-
+
public Map getAttribute(String attributeName, Map defaultValue) {
try {
Object obj = map.get(attributeName);
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/WorkingCopyHelper.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/WorkingCopyHelper.java
index bd513a2..eb4ce56 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/WorkingCopyHelper.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/WorkingCopyHelper.java
@@ -37,7 +37,7 @@
public void setAttribute(String attributeName, int value) {
int current = base.getAttribute(attributeName, 0);
- if (current != 0 && current == value)
+ if (base.isAttributeSet(attributeName) && current == value)
return;
isDirty = true;
@@ -47,7 +47,9 @@
public void setAttribute(String attributeName, boolean value) {
boolean current = base.getAttribute(attributeName, false);
-
+ if (base.isAttributeSet(attributeName) && current == value)
+ return;
+
isDirty = true;
base.map.put(attributeName, Boolean.toString(value));
firePropertyChangeEvent(attributeName, new Boolean(current), new Boolean(value));
@@ -55,9 +57,9 @@
public void setAttribute(String attributeName, String value) {
String current = base.getAttribute(attributeName, (String)null);
- if (current != null && current.equals(value))
+ if (base.isAttributeSet(attributeName) && current != null && current.equals(value))
return;
-
+
isDirty = true;
if (value == null)
base.map.remove(attributeName);
@@ -68,9 +70,9 @@
public void setAttribute(String attributeName, List value) {
List current = base.getAttribute(attributeName, (List)null);
- if (current != null && current.equals(value))
+ if (base.isAttributeSet(attributeName) && current != null && current.equals(value))
return;
-
+
isDirty = true;
if (value == null)
base.map.remove(attributeName);
@@ -81,9 +83,9 @@
public void setAttribute(String attributeName, Map value) {
Map current = base.getAttribute(attributeName, (Map)null);
- if (current != null && current.equals(value))
+ if (base.isAttributeSet(attributeName) && current != null && current.equals(value))
return;
-
+
isDirty = true;
if (value == null)
base.map.remove(attributeName);