| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.velocity.internal; |
| 21 |
|
|
| 22 |
|
import java.util.Map; |
| 23 |
|
import java.util.Properties; |
| 24 |
|
import java.util.concurrent.ConcurrentHashMap; |
| 25 |
|
|
| 26 |
|
import javax.inject.Inject; |
| 27 |
|
import javax.inject.Singleton; |
| 28 |
|
|
| 29 |
|
import org.xwiki.component.annotation.Component; |
| 30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 31 |
|
import org.xwiki.component.manager.ComponentManager; |
| 32 |
|
import org.xwiki.management.JMXBeanRegistration; |
| 33 |
|
import org.xwiki.velocity.VelocityEngine; |
| 34 |
|
import org.xwiki.velocity.VelocityFactory; |
| 35 |
|
import org.xwiki.velocity.XWikiVelocityException; |
| 36 |
|
import org.xwiki.velocity.internal.jmx.JMXVelocityEngine; |
| 37 |
|
import org.xwiki.velocity.internal.jmx.JMXVelocityEngineMBean; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@link |
| 41 |
|
|
| 42 |
|
@see |
| 43 |
|
@version |
| 44 |
|
|
| 45 |
|
@Component |
| 46 |
|
@Singleton |
| |
|
| 64.7% |
Uncovered Elements: 6 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 47 |
|
public class DefaultVelocityFactory implements VelocityFactory |
| 48 |
|
{ |
| 49 |
|
private static final String MBEANNAME_PREFIX = "type=Velocity,domain=Engines,name="; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
@Inject |
| 55 |
|
private ComponentManager componentManager; |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
@Inject |
| 61 |
|
private JMXBeanRegistration jmxRegistration; |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
@link |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
private Map<String, VelocityEngine> velocityEngines = new ConcurrentHashMap<String, VelocityEngine>(); |
| 68 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0 |
@Override... |
| 70 |
|
public boolean hasVelocityEngine(String key) |
| 71 |
|
{ |
| 72 |
0 |
return this.velocityEngines.containsKey(key); |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
161328 |
@Override... |
| 76 |
|
public VelocityEngine getVelocityEngine(String key) |
| 77 |
|
{ |
| 78 |
161323 |
return this.velocityEngines.get(key); |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 81 |
50 |
@Override... |
| 82 |
|
public VelocityEngine createVelocityEngine(String key, Properties properties) throws XWikiVelocityException |
| 83 |
|
{ |
| 84 |
50 |
VelocityEngine engine; |
| 85 |
50 |
try { |
| 86 |
50 |
engine = this.componentManager.getInstance(VelocityEngine.class); |
| 87 |
|
} catch (ComponentLookupException e) { |
| 88 |
0 |
throw new XWikiVelocityException("Failed to create Velocity Engine", e); |
| 89 |
|
} |
| 90 |
50 |
engine.initialize(properties); |
| 91 |
50 |
this.velocityEngines.put(key, engine); |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
50 |
JMXVelocityEngineMBean mbean = new JMXVelocityEngine(engine); |
| 96 |
50 |
this.jmxRegistration.registerMBean(mbean, MBEANNAME_PREFIX + key); |
| 97 |
|
|
| 98 |
50 |
return engine; |
| 99 |
|
} |
| 100 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 101 |
0 |
@Override... |
| 102 |
|
public VelocityEngine removeVelocityEngine(String key) |
| 103 |
|
{ |
| 104 |
0 |
this.jmxRegistration.unregisterMBean(MBEANNAME_PREFIX + key); |
| 105 |
|
|
| 106 |
0 |
return this.velocityEngines.remove(key); |
| 107 |
|
} |
| 108 |
|
} |