You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2014/08/28 14:29:38 UTC

svn commit: r1621127 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support: CallContextWrapper.java MutableCallContextWrapper.java

Author: fmui
Date: Thu Aug 28 12:29:38 2014
New Revision: 1621127

URL: http://svn.apache.org/r1621127
Log:
added MutableCallContextWrapper

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/MutableCallContextWrapper.java   (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CallContextWrapper.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CallContextWrapper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CallContextWrapper.java?rev=1621127&r1=1621126&r2=1621127&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CallContextWrapper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CallContextWrapper.java Thu Aug 28 12:29:38 2014
@@ -24,6 +24,13 @@ import java.math.BigInteger;
 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 
+/**
+ * Provides a convenient implementation of the {@link CallContext} interface that can be
+ * subclassed by developers wishing to change, add, or hide call context data.
+ * 
+ * This class implements the Wrapper or Decorator pattern. Methods default to
+ * calling through to the wrapped request object.
+ */
 public class CallContextWrapper implements CallContext {
 
     private final CallContext context;

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/MutableCallContextWrapper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/MutableCallContextWrapper.java?rev=1621127&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/MutableCallContextWrapper.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/MutableCallContextWrapper.java Thu Aug 28 12:29:38 2014
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.support;
+
+import java.io.File;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.commons.server.MutableCallContext;
+
+/**
+ * Provides a convenient implementation of the {@link MutableCallContext}
+ * interface that can be subclassed by developers wishing to change, add, or
+ * hide call context data.
+ * 
+ * If the provided {@link CallContext} object implements the
+ * {@link MutableCallContext} interface, all {@link #get(String)},
+ * {@link #put(String, Object)}, and {@link #remove(String)} calls are forwarded
+ * to this call context object. If this {@link CallContext} object does not
+ * implement the {@link MutableCallContext} interface, the key-value pairs are
+ * stored here and hide the values of the provided {@link CallContext} object.
+ * That is, the first {@link MutableCallContext} object in the chain of
+ * {@link MutableCallContextWrapper} objects manages the data.
+ */
+public class MutableCallContextWrapper implements MutableCallContext {
+
+    private final CallContext context;
+    private final Map<String, Object> values;
+
+    public MutableCallContextWrapper(CallContext context) {
+        this.context = context;
+        if (context instanceof MutableCallContext) {
+            values = null;
+        } else {
+            values = new HashMap<String, Object>();
+        }
+    }
+
+    public Object get(String key) {
+        if (values == null) {
+            return context.get(key);
+        } else {
+            if (values.containsKey(key)) {
+                return values.get(key);
+            } else {
+                return context.get(key);
+            }
+        }
+    }
+
+    public void put(String key, Object value) {
+        if (values == null) {
+            ((MutableCallContext) context).put(key, value);
+        } else {
+            values.put(key, value);
+        }
+    }
+
+    public Object remove(String key) {
+        if (values == null) {
+            return ((MutableCallContext) context).remove(key);
+        } else {
+            Object value = context.get(key);
+            if (value != null) {
+                // hide value of origin call context
+                values.put(key, null);
+                return value;
+            } else {
+                return values.remove(key);
+            }
+        }
+    }
+
+    public String getBinding() {
+        return context.getBinding();
+    }
+
+    public boolean isObjectInfoRequired() {
+        return context.isObjectInfoRequired();
+    }
+
+    public CmisVersion getCmisVersion() {
+        return (CmisVersion) get(CMIS_VERSION);
+    }
+
+    public String getRepositoryId() {
+        return (String) get(REPOSITORY_ID);
+    }
+
+    public String getUsername() {
+        return (String) get(USERNAME);
+    }
+
+    public String getPassword() {
+        return (String) get(PASSWORD);
+    }
+
+    public String getLocale() {
+        return (String) get(LOCALE);
+    }
+
+    public BigInteger getOffset() {
+        return (BigInteger) get(OFFSET);
+    }
+
+    public BigInteger getLength() {
+        return (BigInteger) get(LENGTH);
+    }
+
+    public File getTempDirectory() {
+        return (File) get(TEMP_DIR);
+    }
+
+    public boolean encryptTempFiles() {
+        return Boolean.TRUE.equals(get(ENCRYPT_TEMP_FILE));
+    }
+
+    public int getMemoryThreshold() {
+        return (Integer) get(MEMORY_THRESHOLD);
+    }
+
+    public long getMaxContentSize() {
+        return (Long) get(MAX_CONTENT_SIZE);
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/MutableCallContextWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native