- private ServiceReferenceRegistryImpl(Map<String, ModuleFactory> factories, LookupRegistry lookupRegistry,
- ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory,
- boolean writable) {
- this.factories = factories;
- this.writable = writable;
- this.lookupRegistry = lookupRegistry;
-
- this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create();
-
- Map<String, Set<String /* QName */>> modifiableFactoryNamesToQNames = new HashMap<>();
- Set<ServiceInterfaceAnnotation> allAnnotations = new HashSet<>();
- Set<String /* qName */> allQNames = new HashSet<>();
-
-
- for (Entry<String, ModuleFactory> entry : factories.entrySet()) {
- if (entry.getKey().equals(entry.getValue().getImplementationName()) == false) {
- logger.error("Possible error in code: Mismatch between supplied and actual name of {}", entry);
- throw new IllegalArgumentException("Possible error in code: Mismatch between supplied and actual name of " + entry);
- }
- Set<ServiceInterfaceAnnotation> siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue());
- Set<String> qNames = InterfacesHelper.getQNames(siAnnotations);
- allAnnotations.addAll(siAnnotations);
- allQNames.addAll(qNames);
- modifiableFactoryNamesToQNames.put(entry.getKey(), Collections.unmodifiableSet(qNames));
- }
- this.factoryNamesToQNames = Collections.unmodifiableMap(modifiableFactoryNamesToQNames);
- this.allQNames = Collections.unmodifiableSet(allQNames);
- // fill namespacesToAnnotations
- Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations =
- new HashMap<>();
- Map<String /* service qName*/, ServiceInterfaceAnnotation> modifiableServiceQNamesToAnnotations = new HashMap<>();
- for (ServiceInterfaceAnnotation sia : allAnnotations) {
- Map<String, ServiceInterfaceAnnotation> ofNamespace = modifiableNamespacesToAnnotations.get(sia.namespace());
- if (ofNamespace == null) {
- ofNamespace = new HashMap<>();
- modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace);
- }
- if (ofNamespace.containsKey(sia.localName())) {
- logger.error("Cannot construct namespacesToAnnotations map, conflict between local names in {}, offending local name: {}, map so far {}",
- sia.namespace(), sia.localName(), modifiableNamespacesToAnnotations);
- throw new IllegalArgumentException("Conflict between local names in " + sia.namespace() + " : " + sia.localName());
- }
- ofNamespace.put(sia.localName(), sia);
- modifiableServiceQNamesToAnnotations.put(sia.value(), sia);
- }
- this.namespacesToAnnotations = Collections.unmodifiableMap(modifiableNamespacesToAnnotations);
- this.serviceQNamesToAnnotations = Collections.unmodifiableMap(modifiableServiceQNamesToAnnotations);
- logger.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames);
- }
-