Remove explicit default super-constructor calls
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / impl / SchemaContextProviders.java
1 /*
2  * Copyright (c) 2013 Cisco 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.sal.dom.broker.impl;
9
10 import org.opendaylight.controller.sal.core.api.model.SchemaService;
11 import org.opendaylight.yangtools.concepts.Delegator;
12 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
13 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
14
15 public class SchemaContextProviders {
16
17     private SchemaContextProviders() {
18         throw new UnsupportedOperationException("Utility class.");
19     }
20
21     public static final SchemaContextProvider fromSchemaService(final SchemaService schemaService) {
22         if (schemaService instanceof SchemaContextProvider) {
23             return (SchemaContextProvider) schemaService;
24         }
25         return new SchemaServiceAdapter(schemaService);
26     }
27
28     private static final class SchemaServiceAdapter implements SchemaContextProvider, Delegator<SchemaService> {
29
30         private final SchemaService service;
31
32         public SchemaServiceAdapter(final SchemaService service) {
33             this.service = service;
34         }
35
36         @Override
37         public SchemaContext getSchemaContext() {
38             return service.getGlobalContext();
39         }
40
41         @Override
42         public SchemaService getDelegate() {
43             return service;
44         }
45
46         @Override
47         public String toString() {
48             return "SchemaServiceAdapter [service=" + service + "]";
49         }
50     }
51 }