You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2024/09/05 09:43:17 UTC

(uima-uimaj) branch feature/387-Simplify-creation-of-new-UIMAContext created (now caeb6b4c3)

This is an automated email from the ASF dual-hosted git repository.

rec pushed a change to branch feature/387-Simplify-creation-of-new-UIMAContext
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git


      at caeb6b4c3 Issue #387: Simplify creation of new UIMAContext

This branch includes the following new commits:

     new caeb6b4c3 Issue #387: Simplify creation of new UIMAContext

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(uima-uimaj) 01/01: Issue #387: Simplify creation of new UIMAContext

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch feature/387-Simplify-creation-of-new-UIMAContext
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git

commit caeb6b4c3f64acf519f5fe751296502d66ec0961
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Thu Sep 5 11:43:08 2024 +0200

    Issue #387: Simplify creation of new UIMAContext
    
    - Added builder
    - Added another factory method without any arguments for the simplest case
    - Deprecated old factory method
    - Deprecated three-args init method in UimaContextAdmin and added a replacement default method to the interface
---
 .../main/java/org/apache/uima/UIMAFramework.java   | 13 +++++-
 .../java/org/apache/uima/UimaContextAdmin.java     | 13 ++++++
 .../org/apache/uima/UimaContextAdminBuilder.java   | 54 ++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java b/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
index 8617af697..a5debad4f 100644
--- a/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
+++ b/uimaj-core/src/main/java/org/apache/uima/UIMAFramework.java
@@ -1088,7 +1088,10 @@ public abstract class UIMAFramework {
    *          Parameter settings.
    * 
    * @return a new UIMA Context to be used by the application.
+   * @deprecated Use {@link #newUimaContext()} or {@link #uimaContextBuider()} instead.
+   * @forRemoval 4.0.0
    */
+  @Deprecated(since = "3.6.0")
   public static UimaContextAdmin newUimaContext(Logger aLogger, ResourceManager aResourceManager,
           ConfigurationManager aConfigManager) {
     // We use an ugly trick to make the 3 values available to the new UIMA context during its
@@ -1103,10 +1106,18 @@ public abstract class UIMAFramework {
       newContextResourceManager.set(null);
       newContextConfigManager.set(null);
     }
-    context.initializeRoot(aLogger, aResourceManager, aConfigManager);
+    context.initializeRoot(aLogger);
     return context;
   }
 
+  public static UimaContextAdmin newUimaContext() {
+    return uimaContextBuider().build();
+  }
+
+  public static UimaContextAdminBuilder uimaContextBuider() {
+    return new UimaContextAdminBuilder();
+  }
+
   /**
    * Gets the default performance tuning settings for the framework. Advanced users can tweak the
    * framework by modifying these properties and passing the modified Properties object into the
diff --git a/uimaj-core/src/main/java/org/apache/uima/UimaContextAdmin.java b/uimaj-core/src/main/java/org/apache/uima/UimaContextAdmin.java
index 18de3770e..e35166064 100644
--- a/uimaj-core/src/main/java/org/apache/uima/UimaContextAdmin.java
+++ b/uimaj-core/src/main/java/org/apache/uima/UimaContextAdmin.java
@@ -39,6 +39,16 @@ import org.apache.uima.util.Settings;
  * interface. The methods on this interface are for the framework's use only. *
  */
 public interface UimaContextAdmin extends UimaContext {
+  /**
+   * Initializes a root UimaContext.
+   * 
+   * @param aLogger
+   *          the logger that will be returned by this UimaContext's {@link #getLogger()} method.
+   */
+  default void initializeRoot(Logger aLogger) {
+    initializeRoot(aLogger, null, null);
+  }
+
   /**
    * Initializes a root UimaContext.
    * 
@@ -50,7 +60,10 @@ public interface UimaContextAdmin extends UimaContext {
    * @param aConfigurationManager
    *          <b>Deprecated: this parameter is ignored!</b> The ConfigurationManager that will be
    *          used by this UimaContext to access its configuration parameter settings.
+   * @deprecated Use {@link #initializeRoot(Logger)} instead.
+   * @forRemoval 4.0.0
    */
+  @Deprecated(since = "3.6.0")
   void initializeRoot(Logger aLogger, ResourceManager aResourceManager,
           ConfigurationManager aConfigurationManager);
 
diff --git a/uimaj-core/src/main/java/org/apache/uima/UimaContextAdminBuilder.java b/uimaj-core/src/main/java/org/apache/uima/UimaContextAdminBuilder.java
new file mode 100644
index 000000000..fa537bb5d
--- /dev/null
+++ b/uimaj-core/src/main/java/org/apache/uima/UimaContextAdminBuilder.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.uima;
+
+import org.apache.uima.resource.ConfigurationManager;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.util.Logger;
+
+public class UimaContextAdminBuilder {
+  private Logger logger;
+  private ResourceManager resourceManager;
+  private ConfigurationManager configManager;
+
+  public UimaContextAdminBuilder withLogger(Logger aLogger) {
+    logger = aLogger;
+    return this;
+  }
+
+  public UimaContextAdminBuilder withResourceManager(ResourceManager aResourceManager) {
+    resourceManager = aResourceManager;
+    return this;
+  }
+
+  public UimaContextAdminBuilder withConfigurationManager(ConfigurationManager aConfigManager) {
+    configManager = aConfigManager;
+    return this;
+  }
+
+  public UimaContextAdmin build() {
+    var actualLogger = logger != null ? logger : UIMAFramework.getLogger();
+    var actualResMgr = resourceManager != null ? resourceManager
+            : UIMAFramework.newDefaultResourceManager();
+    var actualCfgMgr = configManager != null ? configManager
+            : UIMAFramework.newConfigurationManager();
+
+    return UIMAFramework.newUimaContext(actualLogger, actualResMgr, actualCfgMgr);
+  }
+}