1 /** 2 * Copyright (C) 2005-2009 Alfresco Software Limited. 3 * 4 * This file is part of the Spring Surf Extension project. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.springframework.extensions.webscripts.connector; 20 21 import java.io.Serializable; 22 import java.util.HashMap; 23 import java.util.Map; 24 25 /** 26 * Container for Connector "session state". Session state consists 27 * of headers, cookies and parameters that need to be bound onto 28 * the connector with subsequent connections. 29 * 30 * This class essentially allows for the mimic of Browser-like 31 * functionality in terms of subsequent Connectors reusing state 32 * from previous Connector responses. 33 * 34 * @author muzquiano 35 */ 36 public class ConnectorSession implements Serializable 37 { 38 private Map<String, String> parameters = null; 39 private Map<String, String> cookies = null; 40 private String endpointId; 41 42 43 /** 44 * Instantiates a new connector session. 45 * 46 * @param endpointId the endpoint id 47 */ 48 public ConnectorSession(String endpointId) 49 { 50 this.endpointId = endpointId; 51 this.parameters = new HashMap<String, String>(16, 1.0f); 52 this.cookies = new HashMap<String, String>(16, 1.0f); 53 } 54 55 /** 56 * Gets the endpoint id. 57 * 58 * @return the endpoint id 59 */ 60 public String getEndpointId() 61 { 62 return this.endpointId; 63 } 64 65 /** 66 * Gets a parameter. 67 * 68 * @param key the key 69 * 70 * @return the parameter 71 */ 72 public String getParameter(String key) 73 { 74 return this.parameters.get(key); 75 } 76 77 /** 78 * Sets a given parameter. 79 * 80 * @param key the key 81 * @param value the value 82 */ 83 public void setParameter(String key, String value) 84 { 85 this.parameters.put(key, value); 86 } 87 88 /** 89 * Returns the parameter keys. 90 * 91 * @return array of parameter keys 92 */ 93 public String[] getParameterKeys() 94 { 95 return this.parameters.keySet().toArray(new String[this.parameters.size()]); 96 } 97 98 /** 99 * Gets a header. 100 * 101 * @param name the name 102 * 103 * @return the header 104 */ 105 public String getCookie(String name) 106 { 107 return (String) this.cookies.get(name); 108 } 109 110 /** 111 * Sets a given header. 112 * 113 * @param name the name 114 * @param value the header 115 */ 116 public void setCookie(String name, String value) 117 { 118 this.cookies.put(name, value); 119 } 120 121 /** 122 * Returns the cookie names. 123 * 124 * @return array of cookie names 125 */ 126 public String[] getCookieNames() 127 { 128 return this.cookies.keySet().toArray(new String[this.cookies.size()]); 129 } 130 }