2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.dblib.propertiesfileresolver;
24 import java.net.URISyntaxException;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.Optional;
29 import org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider;
30 import org.osgi.framework.FrameworkUtil;
33 * Resolves dblib properties files relative to the directory identified by the JRE property
34 * <code>dblib.properties</code>.
36 public class DblibJREFileResolver implements DblibPropertiesFileResolver {
39 * Key for JRE argument representing the configuration directory
41 private static final String DBLIB_JRE_PROPERTY_KEY = "dblib.properties";
43 private final String successMessage;
45 public DblibJREFileResolver(final String successMessage) {
46 this.successMessage = successMessage;
50 * Parse a properties file location based on JRE argument
52 * @return an Optional File containing the location if it exists, or an empty Optional
55 public Optional<File> resolveFile(final String dblibFileName) {
56 final URL jreArgumentUrl = FrameworkUtil.getBundle(DBLIBResourceProvider.class)
57 .getResource(DBLIB_JRE_PROPERTY_KEY);
59 if (jreArgumentUrl == null) {
60 return Optional.empty();
62 final Path dblibPath = Paths.get(jreArgumentUrl.toURI());
63 return Optional.of(dblibPath.resolve(dblibFileName).toFile());
64 } catch(final URISyntaxException e) {
65 return Optional.empty();
70 public String getSuccessfulResolutionMessage() {
71 return this.successMessage;