Remove global BindingToNormalizedNodeCodec instance
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingToNormalizedNodeCodecFactory.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl;
9
10 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
11 import org.opendaylight.controller.sal.core.api.model.SchemaService;
12 import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
13 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
17
18 /**
19  * Factory class for creating and initializing the BindingToNormalizedNodeCodec instances.
20  *
21  * @author Thomas Pantelis
22  */
23 public class BindingToNormalizedNodeCodecFactory {
24     /**
25      * This method is deprecated in favor of newInstance/registerInstance.
26      *
27      * @param classLoadingStrategy
28      * @param schemaService
29      * @return BindingToNormalizedNodeCodec instance
30      */
31     @Deprecated
32     public static BindingToNormalizedNodeCodec getOrCreateInstance(ClassLoadingStrategy classLoadingStrategy,
33                             SchemaService schemaService) {
34         BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
35                 StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
36         BindingToNormalizedNodeCodec instance = new BindingToNormalizedNodeCodec(
37                                classLoadingStrategy, codecRegistry, true);
38         schemaService.registerSchemaContextListener(instance);
39         return instance;
40     }
41
42     /**
43      * Creates a new BindingToNormalizedNodeCodec instance.
44      *
45      * @param classLoadingStrategy
46      * @return the BindingToNormalizedNodeCodec instance
47      */
48     public static BindingToNormalizedNodeCodec newInstance(ClassLoadingStrategy classLoadingStrategy) {
49         BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
50                 StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
51         return new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
52     }
53
54     /**
55      * Registers the given instance with the SchemaService as a SchemaContextListener.
56      *
57      * @param instance the BindingToNormalizedNodeCodec instance
58      * @param schemaService the SchemaService.
59      * @return the ListenerRegistration
60      */
61     public static ListenerRegistration<SchemaContextListener> registerInstance(BindingToNormalizedNodeCodec instance,
62             SchemaService schemaService) {
63         return schemaService.registerSchemaContextListener(instance);
64     }
65 }