You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/03/08 08:08:45 UTC
svn commit: r1454256 -
/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
Author: cziegeler
Date: Fri Mar 8 07:08:44 2013
New Revision: 1454256
URL: http://svn.apache.org/r1454256
Log:
SLING-2780 : Make ResourceMetadata read-only when delivered to client code
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java?rev=1454256&r1=1454255&r2=1454256&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java Fri Mar 8 07:08:44 2013
@@ -126,13 +126,18 @@ public class ResourceMetadata extends Ha
*/
public static final String INTERNAL_CONTINUE_RESOLVING = ":org.apache.sling.resource.internal.continue.resolving";
- private boolean isReadOnly = false;
+
+ /**
+ * This map contains the real metadata.
+ * A call to {@link #makeReadOnly()} makes it read-only
+ */
+ private Map<String, Object> dataMap = new HashMap<String, Object>();
/**
* Sets the {@link #CHARACTER_ENCODING} property to <code>encoding</code>
* if not <code>null</code>.
*/
- public void setCharacterEncoding(String encoding) {
+ public void setCharacterEncoding(final String encoding) {
if (encoding != null) {
put(CHARACTER_ENCODING, encoding);
}
@@ -156,7 +161,7 @@ public class ResourceMetadata extends Ha
* Sets the {@link #CONTENT_TYPE} property to <code>contentType</code> if
* not <code>null</code>.
*/
- public void setContentType(String contentType) {
+ public void setContentType(final String contentType) {
if (contentType != null) {
put(CONTENT_TYPE, contentType);
}
@@ -180,7 +185,7 @@ public class ResourceMetadata extends Ha
* Sets the {@link #CONTENT_LENGTH} property to <code>contentType</code>
* if not <code>null</code>.
*/
- public void setContentLength(long contentLength) {
+ public void setContentLength(final long contentLength) {
if (contentLength > 0) {
put(CONTENT_LENGTH, contentLength);
}
@@ -203,7 +208,7 @@ public class ResourceMetadata extends Ha
* Sets the {@link #CREATION_TIME} property to <code>creationTime</code>
* if not negative.
*/
- public void setCreationTime(long creationTime) {
+ public void setCreationTime(final long creationTime) {
if (creationTime >= 0) {
put(CREATION_TIME, creationTime);
}
@@ -226,7 +231,7 @@ public class ResourceMetadata extends Ha
* Sets the {@link #MODIFICATION_TIME} property to
* <code>modificationTime</code> if not negative.
*/
- public void setModificationTime(long modificationTime) {
+ public void setModificationTime(final long modificationTime) {
if (modificationTime >= 0) {
put(MODIFICATION_TIME, modificationTime);
}
@@ -249,7 +254,7 @@ public class ResourceMetadata extends Ha
* Sets the {@link #RESOLUTION_PATH} property to <code>resolutionPath</code>
* if not <code>null</code>.
*/
- public void setResolutionPath(String resolutionPath) {
+ public void setResolutionPath(final String resolutionPath) {
if (resolutionPath != null) {
put(RESOLUTION_PATH, resolutionPath);
}
@@ -273,7 +278,7 @@ public class ResourceMetadata extends Ha
* Sets the {@link #RESOLUTION_PATH_INFO} property to
* <code>resolutionPathInfo</code> if not <code>null</code>.
*/
- public void setResolutionPathInfo(String resolutionPathInfo) {
+ public void setResolutionPathInfo(final String resolutionPathInfo) {
if (resolutionPathInfo != null) {
put(RESOLUTION_PATH_INFO, resolutionPathInfo);
}
@@ -298,65 +303,71 @@ public class ResourceMetadata extends Ha
* result in an exception!
*/
public void makeReadOnly() {
- this.isReadOnly = true;
+ this.dataMap = Collections.unmodifiableMap(this.dataMap);
}
- /**
- * Check if this object is read only and if so throw an unsupported operation exception.
- */
- private void checkReadOnly() {
- if ( this.isReadOnly ) {
- throw new UnsupportedOperationException();
- }
+ @Override
+ public void clear() {
+ this.dataMap.clear();
}
@Override
- public void clear() {
- this.checkReadOnly();
- super.clear();
+ public boolean containsKey(final Object key) {
+ return this.dataMap.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(final Object value) {
+ return this.dataMap.containsValue(value);
}
@Override
public Set<java.util.Map.Entry<String, Object>> entrySet() {
- if ( this.isReadOnly ) {
- // TODO - commons collections?
- //return new UnmodifiableEntrySet(super.entrySet());
- }
- return super.entrySet();
+ return this.dataMap.entrySet();
+ }
+
+ @Override
+ public Object get(final Object key) {
+ return this.dataMap.get(key);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.dataMap.isEmpty();
+ }
+
+ @Override
+ public Set<String> keySet() {
+ return this.dataMap.keySet();
}
@Override
public Object put(final String key, final Object value) {
- this.checkReadOnly();
- return super.put(key, value);
+ return this.dataMap.put(key, value);
}
@Override
public void putAll(final Map<? extends String, ? extends Object> m) {
- this.checkReadOnly();
- super.putAll(m);
+ this.dataMap.putAll(m);
}
@Override
public Object remove(final Object key) {
- this.checkReadOnly();
- return super.remove(key);
+ return this.dataMap.remove(key);
}
-
@Override
- public Set<String> keySet() {
- if ( this.isReadOnly ) {
- return Collections.unmodifiableSet(super.keySet());
- }
- return super.keySet();
+ public int size() {
+ return this.dataMap.size();
}
@Override
public Collection<Object> values() {
- if ( this.isReadOnly ) {
- return Collections.unmodifiableCollection(super.values());
- }
- return super.values();
+ return this.dataMap.values();
+ }
+
+ @Override
+ public String toString() {
+ return "Resource Metadata: " + this.dataMap.toString();
}
}