From a6cc157a30fea6bd60274c74d2bb0c259b304ebf Mon Sep 17 00:00:00 2001 From: gjoranv Date: Tue, 12 Jul 2022 00:48:57 +0200 Subject: Simplify creation of BundleInstantiationSpec --- .../bundle/BundleInstantiationSpecification.java | 37 ++++++++-------------- .../java/com/yahoo/container/di/Container.java | 2 +- .../yahoo/osgi/provider/model/ComponentModel.java | 4 +-- .../osgi/provider/model/ComponentModelTest.java | 4 +-- 4 files changed, 18 insertions(+), 29 deletions(-) (limited to 'container-core') diff --git a/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java b/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java index d61df4310f0..926c67df0ba 100644 --- a/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java +++ b/container-core/src/main/java/com/yahoo/container/bundle/BundleInstantiationSpecification.java @@ -14,6 +14,8 @@ import com.yahoo.component.ComponentSpecification; */ public final class BundleInstantiationSpecification { + public static final String CONTAINER_SEARCH_AND_DOCPROC = "container-search-and-docproc"; + public final ComponentId id; public final ComponentSpecification classId; public final ComponentSpecification bundle; @@ -31,34 +33,21 @@ public final class BundleInstantiationSpecification { assert (classId!= null); } - private static final String defaultInternalBundle = "container-search-and-docproc"; - - private static BundleInstantiationSpecification getInternalSpecificationFromString(String idSpec, String classSpec) { - return new BundleInstantiationSpecification( - new ComponentSpecification(idSpec), - (classSpec == null || classSpec.isEmpty())? null : new ComponentSpecification(classSpec), - new ComponentSpecification(defaultInternalBundle)); - } - - public static BundleInstantiationSpecification getInternalSearcherSpecification(ComponentSpecification idSpec, - ComponentSpecification classSpec) { - return new BundleInstantiationSpecification(idSpec, classSpec, new ComponentSpecification(defaultInternalBundle)); - } - - // TODO: These are the same for now because they are in the same bundle. - public static BundleInstantiationSpecification getInternalHandlerSpecificationFromStrings(String idSpec, String classSpec) { - return getInternalSpecificationFromString(idSpec, classSpec); - } - - public static BundleInstantiationSpecification getInternalProcessingSpecificationFromStrings(String idSpec, String classSpec) { - return getInternalSpecificationFromString(idSpec, classSpec); + /** + * Create spec for a component from the container-search-and-docproc bundle with the given class name as id. + */ + public static BundleInstantiationSpecification fromSearchAndDocproc(String className) { + return fromSearchAndDocproc(new ComponentSpecification(className), null); } - public static BundleInstantiationSpecification getInternalSearcherSpecificationFromStrings(String idSpec, String classSpec) { - return getInternalSpecificationFromString(idSpec, classSpec); + /** + * Create spec for a component from the container-search-and-docproc bundle with the given id and classId. + */ + public static BundleInstantiationSpecification fromSearchAndDocproc(ComponentSpecification id, ComponentSpecification classId) { + return new BundleInstantiationSpecification(id, classId, new ComponentSpecification(CONTAINER_SEARCH_AND_DOCPROC)); } - public static BundleInstantiationSpecification getFromStrings(String idSpec, String classSpec, String bundleSpec) { + public static BundleInstantiationSpecification fromStrings(String idSpec, String classSpec, String bundleSpec) { return new BundleInstantiationSpecification( new ComponentSpecification(idSpec), (classSpec == null || classSpec.isEmpty())? null : new ComponentSpecification(classSpec), diff --git a/container-core/src/main/java/com/yahoo/container/di/Container.java b/container-core/src/main/java/com/yahoo/container/di/Container.java index 68dda5fbc4c..1baf217da6b 100644 --- a/container-core/src/main/java/com/yahoo/container/di/Container.java +++ b/container-core/src/main/java/com/yahoo/container/di/Container.java @@ -299,7 +299,7 @@ public class Container { } private static BundleInstantiationSpecification bundleInstantiationSpecification(ComponentsConfig.Components config) { - return BundleInstantiationSpecification.getFromStrings(config.id(), config.classId(), config.bundle()); + return BundleInstantiationSpecification.fromStrings(config.id(), config.classId(), config.bundle()); } public static class ComponentGraphResult { diff --git a/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java b/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java index 5bed6fbca9f..84d52bb01c3 100644 --- a/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java +++ b/container-core/src/main/java/com/yahoo/osgi/provider/model/ComponentModel.java @@ -26,7 +26,7 @@ public class ComponentModel { } public ComponentModel(String idSpec, String classSpec, String bundleSpec, String configId) { - this(BundleInstantiationSpecification.getFromStrings(idSpec, classSpec, bundleSpec), configId); + this(BundleInstantiationSpecification.fromStrings(idSpec, classSpec, bundleSpec), configId); } // For vespamodel @@ -36,7 +36,7 @@ public class ComponentModel { // For vespamodel public ComponentModel(String idSpec, String classSpec, String bundleSpec) { - this(BundleInstantiationSpecification.getFromStrings(idSpec, classSpec, bundleSpec)); + this(BundleInstantiationSpecification.fromStrings(idSpec, classSpec, bundleSpec)); } public ComponentId getComponentId() { diff --git a/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java b/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java index 4433b78c807..a1e533158b5 100644 --- a/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java +++ b/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java @@ -14,7 +14,7 @@ public class ComponentModelTest { @Test public void create_from_instantiation_spec() { ComponentModel model = new ComponentModel( - BundleInstantiationSpecification.getFromStrings("id", "class", "bundle")); + BundleInstantiationSpecification.fromStrings("id", "class", "bundle")); verifyBundleSpec(model); } @@ -26,7 +26,7 @@ public class ComponentModelTest { @Test public void create_from_instantiation_spec_and_config_id() throws Exception { ComponentModel model = new ComponentModel( - BundleInstantiationSpecification.getFromStrings("id", "class", "bundle"), "configId"); + BundleInstantiationSpecification.fromStrings("id", "class", "bundle"), "configId"); verifyBundleSpec(model); assertEquals("configId", model.configId); } -- cgit v1.2.3