97fcc07e98acf378f79f615d7cd78b9ce2f00888
[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.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
12 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
13 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
14 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
15 import org.opendaylight.yangtools.concepts.ListenerRegistration;
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      * Creates a new BindingToNormalizedNodeCodec instance.
26      *
27      * @param classLoadingStrategy
28      * @return the BindingToNormalizedNodeCodec instance
29      */
30     public static BindingToNormalizedNodeCodec newInstance(final ClassLoadingStrategy classLoadingStrategy) {
31         final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
32                 StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
33         return new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
34     }
35
36     /**
37      * Registers the given instance with the SchemaService as a SchemaContextListener.
38      *
39      * @param instance the BindingToNormalizedNodeCodec instance
40      * @param schemaService the SchemaService.
41      * @return the ListenerRegistration
42      */
43     public static ListenerRegistration<SchemaContextListener> registerInstance(final BindingToNormalizedNodeCodec instance,
44             final DOMSchemaService schemaService) {
45         return schemaService.registerSchemaContextListener(instance);
46     }
47 }