1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.context; |
35 |
|
|
36 |
|
import javax.jcr.Node; |
37 |
|
import javax.jcr.RepositoryException; |
38 |
|
|
39 |
|
import org.springframework.beans.factory.BeanFactory; |
40 |
|
import org.springframework.beans.factory.BeanFactoryAware; |
41 |
|
import org.springframework.beans.factory.BeanNameAware; |
42 |
|
import org.springframework.beans.factory.DisposableBean; |
43 |
|
import org.springframework.beans.factory.FactoryBean; |
44 |
|
import org.springframework.beans.factory.InitializingBean; |
45 |
|
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory; |
46 |
|
|
47 |
|
import info.magnolia.context.SystemContext; |
48 |
|
import info.magnolia.jcr.node2bean.Node2BeanException; |
49 |
|
import info.magnolia.jcr.node2bean.Node2BeanProcessor; |
50 |
|
import info.magnolia.module.blossom.node2bean.SpringNode2BeanTransformer; |
51 |
|
import info.magnolia.module.blossom.support.BeanFactoryUtils; |
52 |
|
import info.magnolia.objectfactory.Components; |
53 |
|
import info.magnolia.repository.RepositoryConstants; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@since |
59 |
|
|
|
|
| 95% |
Uncovered Elements: 2 (40) |
Complexity: 13 |
Complexity Density: 0.59 |
|
60 |
|
public class ConfiguredBeanFactoryBean implements FactoryBean, InitializingBean, DisposableBean, BeanNameAware, BeanFactoryAware { |
61 |
|
|
62 |
|
private static final String DEFAULT_WORKSPACE = RepositoryConstants.CONFIG; |
63 |
|
|
64 |
|
private AbstractAutowireCapableBeanFactory beanFactory; |
65 |
|
private String beanName; |
66 |
|
private boolean initialized = false; |
67 |
|
private Class<?> targetClass; |
68 |
|
private Object instance; |
69 |
|
private Class<?> defaultClass; |
70 |
|
|
71 |
|
private String workspace = DEFAULT_WORKSPACE; |
72 |
|
private String path; |
73 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
74 |
|
@Deprecated... |
75 |
|
public String getRepository() { |
76 |
|
return workspace; |
77 |
|
} |
78 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
79 |
|
@Deprecated... |
80 |
|
public void setRepository(String repository) { |
81 |
|
this.workspace = repository; |
82 |
|
} |
83 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
84 |
|
public String getWorkspace() {... |
85 |
|
return workspace; |
86 |
|
} |
87 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
88 |
|
public void setWorkspace(String workspace) {... |
89 |
|
this.workspace = workspace; |
90 |
|
} |
91 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
92 |
|
public String getPath() {... |
93 |
|
return path; |
94 |
|
} |
95 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
96 |
|
public void setPath(String path) {... |
97 |
|
this.path = path; |
98 |
|
} |
99 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
100 |
|
public Class<?> getDefaultClass() {... |
101 |
|
return defaultClass; |
102 |
|
} |
103 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
104 |
|
public void setDefaultClass(Class<?> defaultClass) {... |
105 |
|
this.defaultClass = defaultClass; |
106 |
|
} |
107 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
108 |
2 |
@Override... |
109 |
|
public Object getObject() throws Exception { |
110 |
2 |
if (!initialized) { |
111 |
2 |
initialized = true; |
112 |
2 |
instance = createInstance(); |
113 |
|
} |
114 |
2 |
return instance; |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
117 |
5 |
@Override... |
118 |
|
public Class getObjectType() { |
119 |
5 |
if (instance != null) { |
120 |
1 |
return instance.getClass(); |
121 |
|
} |
122 |
4 |
if (targetClass != null) { |
123 |
2 |
return targetClass; |
124 |
|
} |
125 |
2 |
return defaultClass; |
126 |
|
} |
127 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
128 |
|
@Override... |
129 |
|
public boolean isSingleton() { |
130 |
|
return true; |
131 |
|
} |
132 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
133 |
|
@Override... |
134 |
|
public void setBeanName(String name) { |
135 |
|
this.beanName = name; |
136 |
|
} |
137 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
138 |
|
@Override... |
139 |
|
public void setBeanFactory(BeanFactory beanFactory) { |
140 |
|
this.beanFactory = (AbstractAutowireCapableBeanFactory) beanFactory; |
141 |
|
} |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
1 |
@Override... |
144 |
|
public void destroy() throws Exception { |
145 |
1 |
destroyInstance(); |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
148 |
2 |
@Override... |
149 |
|
public void afterPropertiesSet() throws Exception { |
150 |
2 |
Node node = getConfigurationNode(); |
151 |
2 |
if (node.hasProperty("class")) { |
152 |
1 |
targetClass = Class.forName(node.getProperty("class").getString()); |
153 |
|
} |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
156 |
2 |
protected Object createInstance() throws Exception {... |
157 |
2 |
Node node = getConfigurationNode(); |
158 |
2 |
return transformNode(node); |
159 |
|
} |
160 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
161 |
1 |
protected void destroyInstance() {... |
162 |
1 |
if (instance != null) { |
163 |
1 |
BeanFactoryUtils.destroyBean(instance, beanName, beanFactory); |
164 |
|
} |
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
167 |
2 |
protected Object transformNode(Node node) throws Node2BeanException, RepositoryException {... |
168 |
2 |
SpringNode2BeanTransformer transformer = new SpringNode2BeanTransformer(beanFactory); |
169 |
2 |
transformer.setTopLevelBeanName(beanName); |
170 |
2 |
transformer.setDefaultClass(defaultClass); |
171 |
2 |
return Components.getComponent(Node2BeanProcessor.class).toBean(node, true, transformer, Components.getComponentProvider()); |
172 |
|
} |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
4 |
protected Node getConfigurationNode() throws RepositoryException {... |
175 |
4 |
return Components.getComponent(SystemContext.class).getJCRSession(workspace).getNode(path); |
176 |
|
} |
177 |
|
} |