source: contrib/MailArchiver/sources/src/serpro/mailarchiver/domain/BaseObject.java @ 6785

Revision 6785, 5.2 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
1/**
2 * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
3 * Copyright (C) 2012  Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/******************************************************************************\
20*
21*  This product was developed by
22*
23*        SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
24*
25*  a government company established under Brazilian law (5.615/70),
26*  at Department of Development of Porto Alegre.
27*
28\******************************************************************************/
29
30package serpro.mailarchiver.domain;
31
32import java.util.Collection;
33import java.util.Collections;
34import java.util.HashMap;
35import java.util.Map;
36
37import javax.jdo.InstanceCallbacks;
38import javax.jdo.listener.AttachCallback;
39import javax.jdo.listener.DetachCallback;
40
41import org.springframework.beans.factory.annotation.Autowired;
42import org.springframework.beans.factory.annotation.Configurable;
43import org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy;
44
45import com.vaadin.data.Item;
46import com.vaadin.data.Property;
47import com.vaadin.data.util.MethodProperty;
48import com.vaadin.data.util.PropertysetItem;
49
50import serpro.mailarchiver.util.Logger;
51import serpro.mailarchiver.util.jdo.InstanceLifecycleListener;
52import serpro.mailarchiver.util.jdo.PersistenceManager;
53import serpro.mailarchiver.util.jdo.PersistenceManagerFactory;
54
55@Configurable
56public abstract class BaseObject
57    implements InstanceCallbacks, AttachCallback, DetachCallback, Item
58{
59    private static final Logger log = Logger.getLocalLogger();
60
61    @Autowired
62    InstanceLifecycleListener lifecycleListener;
63
64    @Autowired
65    private TransactionAwarePersistenceManagerFactoryProxy pmfProxy;
66
67    protected PersistenceManagerFactory getTargetPersistenceManagerFactory() {
68        return (PersistenceManagerFactory) pmfProxy.getTargetPersistenceManagerFactory();
69    }
70
71    protected PersistenceManager getPersistenceManager() {
72        return (PersistenceManager) pmfProxy.getObject().getPersistenceManager();
73    }
74
75    //
76    // Vaadin Item interface
77    //
78
79    private Map<String, Property> propMap;
80
81    public synchronized Property getProperty(String name) {
82        return getItemProperty(name);
83    }
84
85    public PropertysetItem getPropertySet(String... names) {
86        PropertysetItem propSet = new PropertysetItem();
87        for(String name : names) {
88            propSet.addItemProperty(name, getItemProperty(name));
89        }
90        return propSet;
91    }
92
93    @Override
94    public synchronized Property getItemProperty(Object id) {
95        String name = (String) id;
96        if(propMap == null) {
97            propMap = new HashMap<String, Property>();
98        }
99        if(propMap.containsKey(name)) {
100            return propMap.get(name);
101        }
102        Property prop = new MethodProperty(this, name);
103        propMap.put(name, prop);
104        return prop;
105    }
106
107    @Override
108    public synchronized Collection<?> getItemPropertyIds() {
109        if(propMap == null) {
110            propMap = new HashMap<String, Property>();
111        }
112        return Collections.unmodifiableSet(propMap.keySet());
113    }
114
115    @Override
116    public boolean addItemProperty(Object id, Property property)
117            throws UnsupportedOperationException {
118        throw new UnsupportedOperationException("Not supported.");
119    }
120
121    @Override
122    public boolean removeItemProperty(Object id)
123            throws UnsupportedOperationException {
124        throw new UnsupportedOperationException("Not supported.");
125    }
126
127    //
128    //JDO InstanceCallbacks interface
129    //
130
131    @Override
132    public void jdoPreClear() {
133        lifecycleListener.jdoPreClear(this);
134    }
135
136    @Override
137    public void jdoPreDelete() {
138        lifecycleListener.jdoPreDelete(this);
139    }
140
141    @Override
142    public void jdoPostLoad() {
143        lifecycleListener.jdoPostLoad(this);
144    }
145
146    @Override
147    public void jdoPreStore() {
148        lifecycleListener.jdoPreStore(this);
149    }
150
151    //
152    //JDO AttachCallbacks interface
153    //
154
155    @Override
156    public void jdoPreAttach() {
157        lifecycleListener.jdoPreAttach(this);
158    }
159
160    @Override
161    public void jdoPostAttach(Object o) {
162        lifecycleListener.jdoPostAttach(this, o);
163    }
164
165    //
166    //JDO DetachCallbacks interface
167    //
168
169    @Override
170    public void jdoPreDetach() {
171        lifecycleListener.jdoPreDetach(this);
172    }
173
174    @Override
175    public void jdoPostDetach(Object o) {
176        lifecycleListener.jdoPostDetach(this, o);
177    }
178}
Note: See TracBrowser for help on using the repository browser.