Fix findbugs violations in restconf-nb-rfc8040
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / services / simple / impl / RestconfSchemaServiceImpl.java
1 /*
2  * Copyright (c) 2016 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.restconf.nb.rfc8040.services.simple.impl;
9
10 import javax.ws.rs.Path;
11 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
12 import org.opendaylight.restconf.common.schema.SchemaExportContext;
13 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
14 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
15 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
16 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfSchemaService;
17 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19
20 /**
21  * Implementation of {@link RestconfSchemaService}.
22  *
23  */
24 @Path("/")
25 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
26
27     private volatile SchemaContextHandler schemaContextHandler;
28     private volatile DOMMountPointServiceHandler domMountPointServiceHandler;
29     private volatile DOMYangTextSourceProvider sourceProvider;
30
31     /**
32      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}
33      * .
34      *
35      * @param schemaContextHandler
36      *             handling schema context
37      * @param domMountPointServiceHandler
38      *             handling dom mount point service
39      */
40     public RestconfSchemaServiceImpl(final SchemaContextHandler schemaContextHandler,
41                                      final DOMMountPointServiceHandler domMountPointServiceHandler,
42                                      final DOMYangTextSourceProvider sourceProvider) {
43         this.schemaContextHandler = schemaContextHandler;
44         this.domMountPointServiceHandler = domMountPointServiceHandler;
45         this.sourceProvider = sourceProvider;
46     }
47
48     @Override
49     public SchemaExportContext getSchema(final String identifier) {
50         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
51         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
52                 this.domMountPointServiceHandler.get(), sourceProvider);
53     }
54
55     @Override
56     public synchronized void updateHandlers(final Object... handlers) {
57         for (final Object object : handlers) {
58             if (object instanceof SchemaContextHandler) {
59                 schemaContextHandler = (SchemaContextHandler) object;
60             } else if (object instanceof DOMMountPointServiceHandler) {
61                 domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
62             } else if (object instanceof DOMYangTextSourceProvider) {
63                 sourceProvider = (DOMYangTextSourceProvider) object;
64             }
65         }
66     }
67 }