<commit_before>/**
 * Licensed to the Austrian Association for Software Tool Integration (AASTI)
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. The AASTI licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openengsb.core.common;

import org.openengsb.core.api.OsgiUtilsService;
import org.openengsb.core.api.WiringService;
import org.openengsb.core.api.persistence.ConfigPersistenceService;

/**
 * Static helper methods providing proxies which access the OSGi service registry for each request to retrieve the
 * correct service implementation. Please keep in mind that each service implementation can change any moment and be
 * either null and/or replaced by a different service.
 */
public final class OpenEngSBCoreServices {

    private static OsgiUtilsService serviceUtils;

    /**
     * This class should not be created
     */
    private OpenEngSBCoreServices() {
    }

    /**
     * Wiring is one of the core concepts in the OpenEngSB. The service retrieved by this method is used to get the
     * endpoints which can be reached within the OpenEngSB.
     */
    public static WiringService getWiringService() {
        return serviceUtils.getOsgiServiceProxy(WiringService.class);
    }

    /**
     * OpenEngSB Core persistence service specialized to retrieve and store ConfigItem. Those are basically simple
     * persistence items which can be stored at various endpoints like file, the "regular" persistence service or
     * anywhere else. The type to request the config persistence service is stored directly at the Configuration objects
     * in a string constant such as RuleConfiguration#TYPE_ID or ContextConfiguration#TYPE_ID
     */
    public static ConfigPersistenceService getConfigPersistenceService(String type) {
        // query osgi context for service with configPersId=id and interface=type
        // TODO: implement
        return null;
    }

    /**
     * Returns the {@link OsgiUtilsService} from the OSGi registry. This service helps to retrieve services from the
     * OSGi registry directly from the code.
     */
    public static OsgiUtilsService getServiceUtilsService() {
        return serviceUtils.getOsgiServiceProxy(OsgiUtilsService.class);
    }

    /**
     * Sets the internal osgiServiceUtils class. This class does not have to be that one exported via
     * {@link #getServiceUtilsService()} since a user can export an implementation of this service with a higher
     * priority (for any reason).
     */
    public static void setOsgiServiceUtils(OsgiUtilsService serviceUtils) {
        OpenEngSBCoreServices.serviceUtils = serviceUtils.getOsgiServiceProxy(OsgiUtilsService.class);
    }

}<commit_msg>[OPENENGSB-1165] Actually add method to retrieve config-persistence from OpenEngSBCoreServices<commit_after>/**
 * Licensed to the Austrian Association for Software Tool Integration (AASTI)
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. The AASTI licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openengsb.core.common;

import org.openengsb.core.api.Constants;
import org.openengsb.core.api.OsgiServiceNotAvailableException;
import org.openengsb.core.api.OsgiUtilsService;
import org.openengsb.core.api.WiringService;
import org.openengsb.core.api.persistence.ConfigPersistenceService;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;

/**
 * Static helper methods providing proxies which access the OSGi service registry for each request to retrieve the
 * correct service implementation. Please keep in mind that each service implementation can change any moment and be
 * either null and/or replaced by a different service.
 */
public final class OpenEngSBCoreServices {

    private static OsgiUtilsService serviceUtils;

    /**
     * This class should not be created
     */
    private OpenEngSBCoreServices() {
    }

    /**
     * Wiring is one of the core concepts in the OpenEngSB. The service retrieved by this method is used to get the
     * endpoints which can be reached within the OpenEngSB.
     */
    public static WiringService getWiringService() throws OsgiServiceNotAvailableException {
        return serviceUtils.getOsgiServiceProxy(WiringService.class);
    }

    /**
     * OpenEngSB Core persistence service specialized to retrieve and store ConfigItem. Those are basically simple
     * persistence items which can be stored at various endpoints like file, the "regular" persistence service or
     * anywhere else. The type to request the config persistence service is stored directly at the Configuration objects
     * in a string constant such as RuleConfiguration#TYPE_ID or ContextConfiguration#TYPE_ID
     */
    public static ConfigPersistenceService getConfigPersistenceService(String type)
        throws OsgiServiceNotAvailableException {
        Filter configPersistenceFilter;
        try {
            configPersistenceFilter = serviceUtils.makeFilter(ConfigPersistenceService.class,
                String.format("(%s=%s)", Constants.CONFIGURATION_ID, type));
        } catch (InvalidSyntaxException e) {
            throw new IllegalArgumentException(String.format(
                "It is not possible to create a filter: (%s=%s)", Constants.CONFIGURATION_ID, type));
        }
        return serviceUtils.getOsgiServiceProxy(configPersistenceFilter, ConfigPersistenceService.class);
    }

    /**
     * Returns the {@link OsgiUtilsService} from the OSGi registry. This service helps to retrieve services from the
     * OSGi registry directly from the code.
     */
    public static OsgiUtilsService getServiceUtilsService() throws OsgiServiceNotAvailableException {
        return serviceUtils.getOsgiServiceProxy(OsgiUtilsService.class);
    }

    /**
     * Sets the internal osgiServiceUtils class. This class does not have to be that one exported via
     * {@link #getServiceUtilsService()} since a user can export an implementation of this service with a higher
     * priority (for any reason).
     */
    public static void setOsgiServiceUtils(OsgiUtilsService serviceUtils) throws OsgiServiceNotAvailableException {
        OpenEngSBCoreServices.serviceUtils = serviceUtils.getOsgiServiceProxy(OsgiUtilsService.class);
    }

}
{'fraction_non_alphanumeric': 0.059168443496801705, 'fraction_numerical': 0.0015991471215351812, 'mean_word_length': 3.7833014659018485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4047670', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1786, 'n_words': 761}