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     */
017    package org.apache.camel.util;
018    
019    import org.apache.camel.CamelContext;
020    import org.slf4j.Logger;
021    import org.slf4j.LoggerFactory;
022    
023    /**
024     * Utility dedicated for resolving runtime information related to the platform on which Camel is currently running.
025     */
026    public final class PlatformHelper {
027    
028        private static final Logger LOG = LoggerFactory.getLogger(PlatformHelper.class);
029    
030        private PlatformHelper() {
031        }
032    
033        /**
034         * Determine whether Camel is OSGi-aware. Current implementation of the method checks if the name of the
035         * {@link CamelContext} matches the names of the known OSGi-aware contexts.
036         *
037         * @param camelContext context to be tested against OSGi-awareness
038         * @return true if given context is OSGi-aware, false otherwise
039         */
040        public static boolean isOsgiContext(CamelContext camelContext) {
041            String contextType = camelContext.getClass().getSimpleName();
042            if (contextType.startsWith("Osgi") || contextType.equals("BlueprintCamelContext")) {
043                LOG.trace("{} used - assuming running in the OSGi container.", contextType);
044                return true;
045            } else {
046                LOG.trace("{} used - assuming running in the OSGi container.", contextType);
047                return false;
048            }
049        }
050    
051    }