This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/turbine-fulcrum-intake.git
The following commit(s) were added to refs/heads/master by this push:
new 596ef6b6 Modernize
596ef6b6 is described below
commit 596ef6b68b747c3080eee3e7f7536ee05d28a127
Author: Thomas Vandahl <[email protected]>
AuthorDate: Mon Jan 12 21:41:55 2026 +0100
Modernize
---
.../apache/fulcrum/intake/IntakeServiceImpl.java | 139 ++++++---------------
.../apache/fulcrum/intake/model/DoubleField.java | 6 +-
.../org/apache/fulcrum/intake/model/Field.java | 19 ++-
.../apache/fulcrum/intake/model/FloatField.java | 6 +-
.../apache/fulcrum/intake/validator/Validator.java | 2 +-
5 files changed, 52 insertions(+), 120 deletions(-)
diff --git a/src/java/org/apache/fulcrum/intake/IntakeServiceImpl.java
b/src/java/org/apache/fulcrum/intake/IntakeServiceImpl.java
index b0742a5b..f5f8249f 100644
--- a/src/java/org/apache/fulcrum/intake/IntakeServiceImpl.java
+++ b/src/java/org/apache/fulcrum/intake/IntakeServiceImpl.java
@@ -221,13 +221,11 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
return null;
}
- ObjectInputStream in = null;
Map<AppData, File> serialData = null;
- try
+ try (FileInputStream fin = new FileInputStream(serialDataFile);
+ ObjectInputStream in = new ObjectInputStream(fin))
{
- FileInputStream fin = new FileInputStream(serialDataFile);
- in = new ObjectInputStream(fin);
Object o = in.readObject();
if (o instanceof Map)
@@ -241,11 +239,9 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
// This could be old file from intake. Try to delete it
getLogger().info("serialized object is not an intake map,
ignoring");
in.close();
- in = null;
-
+
// Try to delete the file
- boolean result = serialDataFile.delete();
- if ( result == false )
+ if (serialDataFile.delete() == false )
{
getLogger().error("Unknown serialized file could not be
removed");
}
@@ -267,22 +263,6 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
// Null out serialData to be sure
serialData = null;
}
- finally
- {
- // Could be null if we opened a file, didn't find it to be a
- // Map object and then nuked it away.
- try
- {
- if (in != null)
- {
- in.close();
- }
- }
- catch (IOException e)
- {
- getLogger().error("Exception while closing file", e);
- }
- }
// Recreate transient loggers
if (serialData != null)
@@ -293,14 +273,14 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
{
if (group instanceof LogEnabled)
{
-
((LogEnabled)group).enableLogging(getLogger());
+ group.enableLogging(getLogger());
}
for (Field<?> field : group.getFields())
{
if (field instanceof LogEnabled)
{
-
((LogEnabled)field).enableLogging(getLogger());
+ field.enableLogging(getLogger());
}
}
}
@@ -323,7 +303,6 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
*/
private void saveSerialized(String serialDataPath, Map<AppData, File>
appDataElements)
{
-
getLogger().debug(
"Entered saveSerialized(" + serialDataPath
+ ", appDataElements)");
@@ -339,19 +318,17 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
try
{
- boolean result = serialData.createNewFile();
- if ( result == false )
+ if (serialData.createNewFile() == false)
{
getLogger().error("Could not create new serialized file");
}
// Try to delete the file
- result = serialData.delete();
- if ( result == false )
+ if (serialData.delete() == false)
{
getLogger().error("Serialized file could not be removed");
}
-
+
}
catch (IOException e)
{
@@ -361,24 +338,12 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
return;
}
- ObjectOutputStream out = null;
- ObjectInputStream in = null;
-
- try
+ try (FileOutputStream fout = new FileOutputStream(serialDataPath);
+ ObjectOutputStream out = new ObjectOutputStream(fout))
{
// write the appData file out
- FileOutputStream fout = new FileOutputStream(serialDataPath);
- out = new ObjectOutputStream(fout);
out.writeObject(appDataElements);
out.flush();
-
- // read the file back in. for some reason on OSX 10.1
- // this is necessary.
- FileInputStream fin = new FileInputStream(serialDataPath);
- in = new ObjectInputStream(fin);
- /* Map dummy = (Map) */ in.readObject();
-
- getLogger().debug("Serializing successful");
}
catch (IOException e)
{
@@ -386,35 +351,20 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
"Could not write serialized file to " + serialDataPath
+ ", not serializing the XML data", e);
}
- catch (ClassNotFoundException e)
+
+ // read the file back in. for some reason on OSX 10.1
+ // this is necessary.
+ try (FileInputStream fin = new FileInputStream(serialDataPath);
+ ObjectInputStream in = new ObjectInputStream(fin))
{
- getLogger().info(
- "Could not re-read serialized file from " +
serialDataPath, e);
+ /* Map dummy = (Map) */ in.readObject();
+
+ getLogger().debug("Serializing successful");
}
- finally
+ catch (IOException | ClassNotFoundException e)
{
- try
- {
- if (out != null)
- {
- out.close();
- }
- }
- catch (IOException e)
- {
- getLogger().error("Exception while closing file", e);
- }
- try
- {
- if (in != null)
- {
- in.close();
- }
- }
- catch (IOException e)
- {
- getLogger().error("Exception while closing file", e);
- }
+ getLogger().info(
+ "Could not re-read serialized file from " +
serialDataPath, e);
}
getLogger().debug("Saving took " + (System.currentTimeMillis() -
timer));
@@ -491,12 +441,15 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
}
catch (IllegalStateException e)
{
- if (getLogger().isDebugEnabled()) {
- throw new IntakeException("group " + groupName + " was
never borrowed or is already invalid.", e);
- } else {
+ if (getLogger().isDebugEnabled())
+ {
+ throw new IntakeException("group " + groupName + " was
never borrowed or is already invalid.", e);
+ }
+ else
+ {
throw new IntakeException( "group " + groupName
+ " was never borrowed or is already invalid
(stacktrace with log-level debug): "
- + e.getMessage());
+ + e.getMessage());
}
}
catch (Exception e)
@@ -522,7 +475,7 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
if (appData == null)
{
throw new IntakeException(
- "Intake IntakeServiceImpl.Size(groupName): No XML
definition for Group "
+ "Intake IntakeServiceImpl.getSize(groupName): No XML
definition for Group "
+ groupName + " found");
}
@@ -747,7 +700,7 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
Set<File> xmlFiles = new HashSet<File>();
long timeStamp = 0;
-
+
getLogger().debug("logger is " +
getLogger().getClass().getSimpleName());
for (String xmlPath : xmlPathes)
@@ -808,29 +761,13 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
for (File xmlFile : xmlFiles)
{
getLogger().debug("Now parsing: " + xmlFile);
- FileInputStream fis = null;
- try
+ try (FileInputStream fis = new FileInputStream(xmlFile))
{
- fis = new FileInputStream(xmlFile);
AppData appData = (AppData) um.unmarshal(fis);
appDataElements.put(appData, xmlFile);
getLogger().debug("Saving AppData for " + xmlFile);
}
- finally
- {
- if (fis != null)
- {
- try
- {
- fis.close();
- }
- catch (IOException e)
- {
- getLogger().warn("Could not close file " +
xmlFile);
- }
- }
- }
}
getLogger().debug("Parsing took " + (System.currentTimeMillis() -
timer));
@@ -845,7 +782,7 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
// Set the entry pair
appData = entry.getKey();
dataFile = entry.getValue();
-
+
int maxPooledGroups = 0;
List<Group> glist = appData.getGroups();
@@ -915,11 +852,11 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
}
/**
- * Note that the avalon.entry key="urn:avalon:home"
+ * Note that the avalon.entry key="urn:avalon:home"
* and the type is {@link java.io.File}
- *
+ *
* @see
org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- *
+ *
* @param context the Context to use
* @throws ContextException if the context is not found
*/
@@ -933,9 +870,9 @@ public class IntakeServiceImpl extends AbstractLogEnabled
implements
* Avalon component lifecycle method
*
* avalon.dependency
type="org.apache.fulcrum.localization.LocalizationService"
- *
+ *
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- *
+ *
* @param manager the service manager
* @throws ServiceException generic exception
*/
diff --git a/src/java/org/apache/fulcrum/intake/model/DoubleField.java
b/src/java/org/apache/fulcrum/intake/model/DoubleField.java
index d619e5ad..f3dbacc9 100644
--- a/src/java/org/apache/fulcrum/intake/model/DoubleField.java
+++ b/src/java/org/apache/fulcrum/intake/model/DoubleField.java
@@ -62,7 +62,7 @@ public class DoubleField
return;
}
- defaultValue = new Double(prop);
+ defaultValue = Double.valueOf(prop);
}
/**
@@ -83,7 +83,7 @@ public class DoubleField
return;
}
- emptyValue = new Double(prop);
+ emptyValue = Double.valueOf(prop);
}
/**
@@ -106,7 +106,7 @@ public class DoubleField
else
{
return (null == getEmptyValue())
- ? new Double(0.0) : getEmptyValue();
+ ? Double.valueOf(0.0) : getEmptyValue();
}
}
diff --git a/src/java/org/apache/fulcrum/intake/model/Field.java
b/src/java/org/apache/fulcrum/intake/model/Field.java
index 63a70533..63947474 100644
--- a/src/java/org/apache/fulcrum/intake/model/Field.java
+++ b/src/java/org/apache/fulcrum/intake/model/Field.java
@@ -1105,15 +1105,10 @@ public abstract class Field<T> implements Serializable,
LogEnabled
try
{
v = (Validator<T>)
- Class.forName(validatorClassName).newInstance();
+
Class.forName(validatorClassName).getDeclaredConstructor().newInstance();
}
- catch (InstantiationException e)
- {
- throw new IntakeException(
- "Could not create new instance of Validator("
- + validatorClassName + ")", e);
- }
- catch (IllegalAccessException e)
+ catch (InstantiationException | IllegalAccessException |
IllegalArgumentException |
+ InvocationTargetException | NoSuchMethodException e)
{
throw new IntakeException(
"Could not create new instance of Validator("
@@ -1126,16 +1121,16 @@ public abstract class Field<T> implements Serializable,
LogEnabled
+ validatorClassName + ")", e);
}
- if (v instanceof LogEnabled)
+ if (v instanceof LogEnabled logEnabled)
{
- ((LogEnabled)v).enableLogging(log);
+ logEnabled.enableLogging(log);
}
// this should always be true for now
// (until bean property initialization is implemented)
- if (v instanceof InitableByConstraintMap)
+ if (v instanceof InitableByConstraintMap initable)
{
- ((InitableByConstraintMap) v).init(this.ruleMap);
+ initable.init(this.ruleMap);
}
else
{
diff --git a/src/java/org/apache/fulcrum/intake/model/FloatField.java
b/src/java/org/apache/fulcrum/intake/model/FloatField.java
index 3231c1bd..1010a6c2 100644
--- a/src/java/org/apache/fulcrum/intake/model/FloatField.java
+++ b/src/java/org/apache/fulcrum/intake/model/FloatField.java
@@ -62,7 +62,7 @@ public class FloatField
return;
}
- defaultValue = new Float(prop);
+ defaultValue = Float.valueOf(prop);
}
/**
@@ -83,7 +83,7 @@ public class FloatField
return;
}
- emptyValue = new Float(prop);
+ emptyValue = Float.valueOf(prop);
}
/**
@@ -106,7 +106,7 @@ public class FloatField
else
{
return (null == getEmptyValue())
- ? new Float(0.0) : getEmptyValue();
+ ? Float.valueOf(0.0f) : getEmptyValue();
}
}
diff --git a/src/java/org/apache/fulcrum/intake/validator/Validator.java
b/src/java/org/apache/fulcrum/intake/validator/Validator.java
index fb2b6eab..f11ef552 100644
--- a/src/java/org/apache/fulcrum/intake/validator/Validator.java
+++ b/src/java/org/apache/fulcrum/intake/validator/Validator.java
@@ -26,7 +26,6 @@ import org.apache.fulcrum.intake.model.Field;
*
* @author <a href="mailto:[email protected]">John McNally</a>
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
- * @version $Id$
*/
public interface Validator<T>
{
@@ -86,6 +85,7 @@ public interface Validator<T>
*
* @deprecated use isValid(Field) instead
*/
+ @Deprecated
boolean isValid(String testValue);
/**