Java tutorial
/** * Copyright 2013 Maxime Bossard * * Licensed 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 fr.mby.portal.coreimpl.session; import java.util.HashMap; import java.util.Map; import org.springframework.util.Assert; import fr.mby.portal.api.app.ISession; /** * @author Maxime Bossard - 2013 * */ public class BasicSession implements ISession { private final String id; private final Map<String, Object> session; /** Protected constructor. */ protected BasicSession(final String id) { super(); this.id = id; this.session = new HashMap<String, Object>(); } @Override public String getId() { return this.id; } @Override public Object getAttribute(final String name) throws IllegalArgumentException { Assert.hasText(name, "No property name provided !"); return this.session.get(name); } @Override public void setAttribute(final String name, final Object value) throws IllegalArgumentException { Assert.hasText(name, "No property name provided !"); this.session.put(name, value); } @Override public Object removeAttribute(final String name) throws IllegalArgumentException { Assert.hasText(name, "No property name provided !"); return this.session.remove(name); } }