ProductInfoServiceImpl.java
6.31 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ValueMap
* org.osgi.framework.BundleContext
* org.osgi.framework.Version
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.license.impl;
import com.adobe.granite.license.License;
import com.adobe.granite.license.ProductInfo;
import com.adobe.granite.license.ProductInfoProvider;
import com.adobe.granite.license.ProductInfoService;
import com.adobe.granite.license.impl.LicenseProvider;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component
@Service
@Reference(name="productInfoProvider", referenceInterface=ProductInfoProvider.class, bind="bindProductInfoProvider", unbind="unbindProductInfoProvider", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
public class ProductInfoServiceImpl
implements ProductInfoService {
private final Logger log = LoggerFactory.getLogger(ProductInfoServiceImpl.class);
private static final String PROP_GRANITE_PRODUCT_VERSION = "granite.product.version";
private static final String PROP_GRANITE_PRODUCT = "granite.product";
private final Map<String, ProductInfoProvider> providers = new HashMap<String, ProductInfoProvider>();
private final Map<String, ProductInfo> infos = new HashMap<String, ProductInfo>();
@Reference
private LicenseProvider licenseProvider;
private ProductInfo defaultProductInfo;
@Override
public ProductInfo[] getInfos() {
Collection<ProductInfo> values = this.infos.values();
if (values.size() == 0) {
values = Collections.singletonList(this.defaultProductInfo);
}
return values.toArray(new ProductInfo[values.size()]);
}
@Override
public License getLicense() {
return this.licenseProvider.getLicense();
}
@Activate
protected void activate(ComponentContext context) {
this.defaultProductInfo = new DefaultProductInfo(context.getBundleContext());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void bindProductInfoProvider(ProductInfoProvider provider, Map<String, Object> properties) {
if (null != this.providers.get(provider.getClass().getName())) {
this.log.debug("Provider [{}] already present, ignoring.", (Object)provider.getClass().getName());
return;
}
Map<String, ProductInfoProvider> map = this.providers;
synchronized (map) {
ProductInfo info = provider.getProductInfo();
if (info != null) {
this.providers.put(provider.getClass().getName(), provider);
this.infos.put(provider.getClass().getName(), info);
this.log.info("Bound new product info provider: [{}] - providers: [{}]", (Object)provider, (Object)this.providers.size());
} else {
this.log.info("ProductInfoProvider returns null, ignored: [{}]", (Object)provider);
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void unbindProductInfoProvider(ProductInfoProvider provider, Map<String, Object> properties) {
Map<String, ProductInfoProvider> map = this.providers;
synchronized (map) {
this.providers.remove(provider.getClass().getName());
this.log.info("Unbound new product info provider: [{}] - providers: [{}]", (Object)provider, (Object)this.providers.size());
Iterator<Map.Entry<String, ProductInfo>> iterator = this.infos.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, ProductInfo> entry = iterator.next();
if (!entry.getKey().equals(provider.getClass().getName())) continue;
iterator.remove();
}
}
}
protected void bindLicenseProvider(LicenseProvider licenseProvider) {
this.licenseProvider = licenseProvider;
}
protected void unbindLicenseProvider(LicenseProvider licenseProvider) {
if (this.licenseProvider == licenseProvider) {
this.licenseProvider = null;
}
}
private static final class DefaultProductInfo
implements ProductInfo {
private Version version;
private String name;
private DefaultProductInfo(BundleContext bundleContext) {
this.version = new Version(bundleContext.getProperty("granite.product.version"));
this.name = bundleContext.getProperty("granite.product");
}
public String getName() {
return this.name;
}
public Version getVersion() {
return this.version;
}
public String getShortName() {
return this.name;
}
public String getShortVersion() {
return "" + this.version.getMajor() + "." + this.version.getMinor();
}
public String getYear() {
return null;
}
public String getVendor() {
return null;
}
public String getVendorUrl() {
return null;
}
public String getUrl() {
return null;
}
public ValueMap getProperties() {
return null;
}
}
}