View Javadoc
1   /*
2    * #%L
3    * settings4j
4    * ===============================================================
5    * Copyright (C) 2008 - 2015 Brabenetz Harald, Austria
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
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
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   * #L%
19   */
20  package org.settings4j.connector;
21  
22  /**
23   * Basic Implementation of {@link org.settings4j.Connector}s which are Property-String-related.
24   * <p>
25   * Only #getString(String) must be implemented. Example implementations are {@link PropertyFileConnector} or {@link SystemPropertyConnector}.
26   * </p>
27   *
28   * @author Harald.Brabenetz
29   */
30  public abstract class AbstractPropertyConnector extends AbstractConnector {
31  
32      @Override
33      // SuppressWarnings PMD.ReturnEmptyArrayRatherThanNull: returning null for this byte-Arrays is OK.
34      @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull")
35      public byte[] getContent(final String key) {
36          final String path = getString(key);
37          if (path != null && getContentResolver() != null) {
38              return getContentResolver().getContent(path);
39          }
40          // else
41          return null;
42  
43      }
44  
45      @Override
46      public Object getObject(final String key) {
47          final String path = getString(key);
48          if (path != null && getObjectResolver() != null) {
49              return getObjectResolver().getObject(path, getContentResolver());
50          }
51          // else
52          return null;
53  
54      }
55  }