Merge "Bug-915: Adding static document generation. Currently the API Explorer can...
[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     public static final SchemaContextProvider fromSchemaService(final SchemaService schemaService) {
18         if (schemaService instanceof SchemaContextProvider) {
19             return (SchemaContextProvider) schemaService;
20         }
21         return new SchemaServiceAdapter(schemaService);
22     }
23
24     private final static class SchemaServiceAdapter implements SchemaContextProvider, Delegator<SchemaService> {
25
26         private final SchemaService service;
27
28         public SchemaServiceAdapter(final SchemaService service) {
29             super();
30             this.service = service;
31         }
32
33         @Override
34         public SchemaContext getSchemaContext() {
35             return service.getGlobalContext();
36         }
37
38         @Override
39         public SchemaService getDelegate() {
40             return service;
41         }
42
43         @Override
44         public String toString() {
45             return "SchemaServiceAdapter [service=" + service + "]";
46         }
47     }
48 }