1 package org.andromda.repositories.emf.uml22;
2
3 import java.util.Set;
4 import java.util.TreeSet;
5 import org.apache.log4j.Logger;
6 import org.eclipse.emf.common.util.URI;
7 import org.eclipse.emf.ecore.EObject;
8 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
9
10
11
12
13
14
15
16
17
18
19
20 public class EMXProxyResolvingResourceSet extends ResourceSetImpl
21 {
22
23
24
25 private static final Logger logger = Logger.getLogger(EMXProxyResolvingResourceSet.class);
26
27
28
29
30 private static Set<String> connectExceptions = new TreeSet<String>();
31
32
33
34 public EObject getEObject(URI uri, boolean loadOnDemand)
35 {
36 EObject possiblyResolvedObject = null;
37
38
39 if (connectExceptions.contains(uri.toString()))
40 {
41 return possiblyResolvedObject;
42 }
43 long now = System.currentTimeMillis();
44 try
45 {
46
47
48
49
50
51
52
53 possiblyResolvedObject = super.getEObject(uri, loadOnDemand);
54 }
55 catch (Exception e)
56 {
57
58 if (uri.toString().indexOf('?')<0)
59 {
60 if (e.getMessage().contains("FileNotFoundException"))
61 {
62
63
64 logger.warn("Referenced model FileNotFound: " + uri + " " + (System.currentTimeMillis() - now) + " ms: " +
65 uri.toString() + " " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
66 }
67 else
68 {
69 logger.error("Could not load referenced model uri " + " " + (System.currentTimeMillis() - now) + "ms: " +
70 uri.toString() + " " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), e.getCause());
71 }
72 }
73 if (!connectExceptions.contains(uri.toString()))
74 {
75 connectExceptions.add(uri.toString());
76 }
77 }
78 if (possiblyResolvedObject == null)
79 {
80
81 String uriString = uri.toString();
82 int separatorIndex = uriString.lastIndexOf('?');
83 if (separatorIndex > 0)
84 {
85 uriString = uriString.substring(0, separatorIndex);
86 if (!connectExceptions.contains(uriString))
87 {
88 try
89 {
90 possiblyResolvedObject = super.getEObject(URI.createURI(uriString), loadOnDemand);
91 }
92 catch (Exception e)
93 {
94
95
96 if (!connectExceptions.contains(uriString))
97 {
98 connectExceptions.add(uri.toString());
99 }
100 }
101 }
102 }
103 }
104 return possiblyResolvedObject;
105 }
106 }