001/**
002 * Copyright (C) 2006-2025 Talend Inc. - www.talend.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.talend.sdk.component.runtime.manager.service;
017
018import static lombok.AccessLevel.PRIVATE;
019
020import java.util.function.Function;
021
022import javax.json.JsonBuilderFactory;
023import javax.json.JsonReaderFactory;
024import javax.json.JsonWriterFactory;
025import javax.json.stream.JsonGeneratorFactory;
026import javax.json.stream.JsonParserFactory;
027
028import org.talend.sdk.component.api.service.record.RecordBuilderFactory;
029import org.talend.sdk.component.runtime.manager.ComponentManager;
030
031import lombok.NoArgsConstructor;
032
033@NoArgsConstructor(access = PRIVATE)
034public final class DefaultServices {
035
036    public static Object lookup(final String type) {
037        if (type.equals(JsonBuilderFactory.class.getName())) {
038            return ComponentManager.instance().getJsonpBuilderFactory();
039        }
040        if (type.equals(JsonReaderFactory.class.getName())) {
041            return ComponentManager.instance().getJsonpReaderFactory();
042        }
043        if (type.equals(JsonGeneratorFactory.class.getName())) {
044            return ComponentManager.instance().getJsonpGeneratorFactory();
045        }
046        if (type.equals(JsonParserFactory.class.getName())) {
047            return ComponentManager.instance().getJsonpParserFactory();
048        }
049        if (type.equals(JsonWriterFactory.class.getName())) {
050            return ComponentManager.instance().getJsonpWriterFactory();
051        }
052        if (type.equals(RecordBuilderFactory.class.getName())) {
053            final Function<String, RecordBuilderFactory> provider =
054                    ComponentManager.instance().getRecordBuilderFactoryProvider();
055            return provider.apply(null);
056        }
057        throw new IllegalArgumentException(type + " can't be a global service, didn't you pass a null plugin?");
058    }
059}