]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ProfileActivityBeanRepresentation.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / profile / ProfileActivityBeanRepresentation.java
1 package org.simantics.diagram.profile;
2
3 import java.util.Map;
4
5 import org.simantics.db.RequestProcessor;
6 import org.simantics.db.Resource;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
9 import org.simantics.utils.datastructures.hints.IHintContext.Key;
10 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 /**
15  * @author Tuukka Lehtonen
16  * @since 6.08
17  */
18 public class ProfileActivityBeanRepresentation implements Representation {
19
20         private static final Logger LOGGER = LoggerFactory.getLogger(ProfileActivityBeanRepresentation.class);
21
22         public static Key KEY = new KeyOf(ProfileActivityBean.class, "PROFILE_ACTIVITY_BEAN");
23
24         private final Resource source;
25         private ProfileActivityBean bean;
26
27         public ProfileActivityBeanRepresentation(Resource source) {
28                 this.source = source;
29         }
30
31         @Override
32         public Key getKey() {
33                 return KEY;
34         }
35
36         @SuppressWarnings("unchecked")
37         @Override
38         public <T> T getValue(RequestProcessor processor, Map<String,Object> hints) {
39                 if (bean == null) {
40                         try {
41                                 bean = Profiles.readProfileActivity(processor, source);
42                         } catch (DatabaseException e) {
43                                 LOGGER.error("Failed to read profile activity information from model " + source, e);
44                                 // Prevent the code from attempting further reads from this source
45                                 bean = new ProfileActivityBean();
46                         }
47                 }
48                 return (T) bean;
49         }
50
51 }