blob: 61d0d9bba8dab71b1339fab434e1d69b5e930550 (
plain) (
blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.di.componentgraph.core;
import com.google.inject.Key;
import com.yahoo.component.ComponentId;
import com.yahoo.config.ConfigInstance;
import com.yahoo.vespa.config.ConfigKey;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import static com.yahoo.container.di.componentgraph.core.Keys.createKey;
/**
* @author Tony Vaagenes
* @author gjoranv
* @author ollivir
*/
public final class GuiceNode extends Node {
private static final ComponentId guiceNamespace = ComponentId.fromString("Guice");
private final Object myInstance;
private final Annotation annotation;
public GuiceNode(Object myInstance,
Annotation annotation) {
super(componentId(myInstance));
this.myInstance = myInstance;
this.annotation = annotation;
}
@Override
public Set<ConfigKey<ConfigInstance>> configKeys() {
return Collections.emptySet();
}
@Override
public Key<?> instanceKey() {
return createKey(myInstance.getClass(), annotation);
}
@Override
public Class<?> instanceType() {
return myInstance.getClass();
}
@Override
public Class<?> componentType() {
return instanceType();
}
@Override
public List<Node> usedComponents() {
return Collections.emptyList();
}
@Override
protected Object newInstance() {
return myInstance;
}
@Override
public void inject(Node component) {
throw new UnsupportedOperationException("Illegal to inject components to a GuiceNode!");
}
@Override
public String label() {
return String.format("{{%s|Guice}|%s}", instanceType().getSimpleName(), Node.packageName(instanceType()));
}
private static ComponentId componentId(Object instance) {
return Node.syntheticComponentId(instance.getClass().getName(), instance, guiceNamespace);
}
}
|