/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.domain; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.jdo.InstanceCallbacks; import javax.jdo.listener.AttachCallback; import javax.jdo.listener.DetachCallback; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.util.MethodProperty; import com.vaadin.data.util.PropertysetItem; import serpro.mailarchiver.util.Logger; import serpro.mailarchiver.util.jdo.InstanceLifecycleListener; import serpro.mailarchiver.util.jdo.PersistenceManager; import serpro.mailarchiver.util.jdo.PersistenceManagerFactory; @Configurable public abstract class BaseObject implements InstanceCallbacks, AttachCallback, DetachCallback, Item { private static final Logger log = Logger.getLocalLogger(); @Autowired InstanceLifecycleListener lifecycleListener; @Autowired private TransactionAwarePersistenceManagerFactoryProxy pmfProxy; protected PersistenceManagerFactory getTargetPersistenceManagerFactory() { return (PersistenceManagerFactory) pmfProxy.getTargetPersistenceManagerFactory(); } protected PersistenceManager getPersistenceManager() { return (PersistenceManager) pmfProxy.getObject().getPersistenceManager(); } // // Vaadin Item interface // private Map propMap; public synchronized Property getProperty(String name) { return getItemProperty(name); } public PropertysetItem getPropertySet(String... names) { PropertysetItem propSet = new PropertysetItem(); for(String name : names) { propSet.addItemProperty(name, getItemProperty(name)); } return propSet; } @Override public synchronized Property getItemProperty(Object id) { String name = (String) id; if(propMap == null) { propMap = new HashMap(); } if(propMap.containsKey(name)) { return propMap.get(name); } Property prop = new MethodProperty(this, name); propMap.put(name, prop); return prop; } @Override public synchronized Collection getItemPropertyIds() { if(propMap == null) { propMap = new HashMap(); } return Collections.unmodifiableSet(propMap.keySet()); } @Override public boolean addItemProperty(Object id, Property property) throws UnsupportedOperationException { throw new UnsupportedOperationException("Not supported."); } @Override public boolean removeItemProperty(Object id) throws UnsupportedOperationException { throw new UnsupportedOperationException("Not supported."); } // //JDO InstanceCallbacks interface // @Override public void jdoPreClear() { lifecycleListener.jdoPreClear(this); } @Override public void jdoPreDelete() { lifecycleListener.jdoPreDelete(this); } @Override public void jdoPostLoad() { lifecycleListener.jdoPostLoad(this); } @Override public void jdoPreStore() { lifecycleListener.jdoPreStore(this); } // //JDO AttachCallbacks interface // @Override public void jdoPreAttach() { lifecycleListener.jdoPreAttach(this); } @Override public void jdoPostAttach(Object o) { lifecycleListener.jdoPostAttach(this, o); } // //JDO DetachCallbacks interface // @Override public void jdoPreDetach() { lifecycleListener.jdoPreDetach(this); } @Override public void jdoPostDetach(Object o) { lifecycleListener.jdoPostDetach(this, o); } }