001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.webengine.session; 023 024/** 025 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 026 */ 027public abstract class AbstractComponent implements Component { 028 029 private static final long serialVersionUID = 3472450841328363350L; 030 031 protected String name; 032 033 private boolean isLive; 034 035 @Override 036 public String getName() { 037 return name; 038 } 039 040 @Override 041 public boolean isLive() { 042 return isLive; 043 } 044 045 @Override 046 public void initialize(UserSession session, String name) throws SessionException { 047 if (isLive) { 048 throw new InvalidStateException(this, "initialize"); 049 } 050 this.name = name; 051 doInitialize(session, name); 052 isLive = true; 053 } 054 055 @Override 056 public void destroy(UserSession session) throws SessionException { 057 if (!isLive) { 058 throw new InvalidStateException(this, "destroy"); 059 } 060 doDestroy(session); 061 name = null; 062 isLive = false; 063 } 064 065 public void doInitialize(UserSession session, String name) throws SessionException { 066 // do nothing by default 067 } 068 069 public void doDestroy(UserSession session) throws SessionException { 070 // do nothing by default 071 } 072 073}