2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.binding.impl;
10 import java.util.concurrent.atomic.AtomicBoolean;
11 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
12 import org.opendaylight.controller.sal.core.api.model.SchemaService;
13 import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
14 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
15 import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
18 * Factory class for creating and initializing the global BindingToNormalizedNodeCodec instance.
20 * @author Thomas Pantelis
22 public class BindingToNormalizedNodeCodecFactory {
23 private static final AtomicBoolean INSTANCE_CREATED = new AtomicBoolean();
24 private static volatile BindingToNormalizedNodeCodec instance;
27 * Returns the global BindingToNormalizedNodeCodec instance, creating if necessary. The returned instance
28 * is registered with tthe SchemaService as a SchemaContextListener.
30 * @param classLoadingStrategy
31 * @param schemaService
32 * @return the BindingToNormalizedNodeCodec instance
34 public static BindingToNormalizedNodeCodec getOrCreateInstance(ClassLoadingStrategy classLoadingStrategy,
35 SchemaService schemaService) {
36 if(!INSTANCE_CREATED.compareAndSet(false, true)) {
40 BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
41 StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
42 instance = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
44 schemaService.registerSchemaContextListener(instance);
49 public static BindingToNormalizedNodeCodec getInstance() {