+ final GeneratedClassLoadingStrategy classLoading = getGlobalClassLoadingStrategy();
+ final BindingIndependentMappingService legacyMapping = getGlobalLegacyMappingService(classLoading);
+ BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
+ BindingToNormalizedNodeCodec instance = new BindingToNormalizedNodeCodec(classLoading, legacyMapping, codecRegistry);
+ bundleContext.registerService(SchemaContextListener.class, instance, new Hashtable<String,String>());
+ return instance;
+ }
+
+ private BindingIndependentMappingService getGlobalLegacyMappingService(final GeneratedClassLoadingStrategy classLoading) {
+ BindingIndependentMappingService potential = tryToReuseGlobalMappingServiceInstance();
+ if(potential == null) {
+ potential = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault(),classLoading);
+ bundleContext.registerService(SchemaContextListener.class, (SchemaContextListener) potential, new Hashtable<String,String>());
+ }
+ return potential;
+ }
+
+ private GeneratedClassLoadingStrategy getGlobalClassLoadingStrategy() {
+ ServiceReference<GeneratedClassLoadingStrategy> ref = bundleContext.getServiceReference(GeneratedClassLoadingStrategy.class);
+ return bundleContext.getService(ref);
+ }
+
+ private BindingIndependentMappingService tryToReuseGlobalMappingServiceInstance() {
+ ServiceReference<BindingIndependentMappingService> serviceRef = getBundleContext().getServiceReference(BindingIndependentMappingService.class);
+ if(serviceRef == null) {
+ return null;
+ }
+ return bundleContext.getService(serviceRef);
+