Merge "Change target to ${project.build.target} in a bunch of pom file. Add some...
[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
14 public class SchemaContextProviders {
15
16     public static final SchemaContextProvider fromSchemaService(SchemaService schemaService) {
17         if (schemaService instanceof SchemaContextProvider) {
18             return (SchemaContextProvider) schemaService;
19         }
20         return new SchemaServiceAdapter(schemaService);
21     }
22
23     private final static class SchemaServiceAdapter implements SchemaContextProvider, Delegator<SchemaService> {
24
25         private final SchemaService service;
26
27         public SchemaServiceAdapter(SchemaService service) {
28             super();
29             this.service = service;
30         }
31
32         @Override
33         public SchemaContext getSchemaContext() {
34             return service.getGlobalContext();
35         }
36
37         @Override
38         public SchemaService getDelegate() {
39             return service;
40         }
41
42         @Override
43         public String toString() {
44             return "SchemaServiceAdapter [service=" + service + "]";
45         }
46     }
47 }