001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.util; 018 019import java.util.Properties; 020 021/** 022 * This class is a camelCase ordered {@link Properties} where the key/values are stored in the order they are added or 023 * loaded. 024 * <p/> 025 * The keys are stored in the original case, for example a key of <code>camel.main.stream-caching-enabled</code> is 026 * stored as <code>camel.main.stream-caching-enabled</code>. 027 * <p/> 028 * However the lookup of a value by key with the <tt>get</tt> methods, will support camelCase or dash style. 029 * <p/> 030 * Note: This implementation is only intended as implementation detail for Camel tooling such as camel-jbang, and has 031 * only been designed to provide the needed functionality. The complex logic for loading properties has been kept from 032 * the JDK {@link Properties} class. 033 */ 034public final class CamelCaseOrderedProperties extends BaseOrderedProperties { 035 036 @Override 037 public Object get(Object key) { 038 lock.lock(); 039 try { 040 return getProperty(key.toString()); 041 } finally { 042 lock.unlock(); 043 } 044 } 045 046 @Override 047 public String getProperty(String key) { 048 String answer = super.getProperty(key); 049 if (answer == null) { 050 answer = super.getProperty(StringHelper.dashToCamelCase(key)); 051 } 052 if (answer == null) { 053 answer = super.getProperty(StringHelper.camelCaseToDash(key)); 054 } 055 return answer; 056 } 057 058 @Override 059 public String getProperty(String key, String defaultValue) { 060 String answer = getProperty(key); 061 if (answer == null) { 062 answer = defaultValue; 063 } 064 return answer; 065 } 066 067}