aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorMartin Schreier <martin_s@apache.org>2022-01-11 21:30:42 +0100
committerMartin Schreier <martin_s@apache.org>2022-01-11 21:30:42 +0100
commit9a102721d6f0e4ef951901427c43f5c0dc936fd7 (patch)
tree30ba2ff907d396bb8b02db602f96a2e7d85bc5eb /archiva-modules/archiva-base
parenta0c5e5a0b0ad6502b0e3c82862bf57287c6a1c15 (diff)
downloadarchiva-9a102721d6f0e4ef951901427c43f5c0dc936fd7.tar.gz
archiva-9a102721d6f0e4ef951901427c43f5c0dc936fd7.zip
Changing mapper interface
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java46
-rw-r--r--archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java18
-rw-r--r--archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/MultiModelMapper.java (renamed from archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapper.java)43
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml2
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java2
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java5
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java6
7 files changed, 92 insertions, 30 deletions
diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java
new file mode 100644
index 000000000..c77c91cbe
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/AbstractMapper.java
@@ -0,0 +1,46 @@
+package org.apache.archiva.common;
+/*
+ * 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.
+ */
+
+/**
+ * @author Martin Schreier <martin_s@apache.org>
+ */
+public abstract class AbstractMapper<B,T,R> implements MultiModelMapper<B,T,R>
+{
+ @Override
+ public <S2, T2, R2> boolean supports( Class<S2> baseType, Class<T2> destinationType, Class<R2> reverseSourceType )
+ {
+ return (
+ baseType.isAssignableFrom( getBaseType( ) ) &&
+ destinationType.isAssignableFrom( getDestinationType( ) ) &&
+ reverseSourceType.isAssignableFrom( getReverseSourceType( ) )
+ );
+ }
+
+ @Override
+ public int hashCode( )
+ {
+ return getHash();
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ return super.hashCode( ) == obj.hashCode( );
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java
index 30ee0c4c3..159b95d19 100644
--- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java
+++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapperFactory.java
@@ -22,19 +22,21 @@ package org.apache.archiva.common;
*
* @author Martin Schreier <martin_s@apache.org>
*
- * @param <SB> The base source type for the model mapper
- * @param <TB> The base target type for the model mapper
+ * @param <B> The base type for the model mapper
+ * @param <T> The target type for the model mapper
+ * @param <R> The reverse source type for the model mapper
*/
-public interface ModelMapperFactory<SB,TB>
+public interface ModelMapperFactory<B,T,R>
{
/**
* Returns a mapper for the given source and target type. If no mapper is registered for this combination,
* it will throw a {@link IllegalArgumentException}
- * @param sourceType the source type for the mapping
- * @param targetType the destination type
- * @param <S> source type
- * @param <T> destination type
+ * @param baseType the source type for the mapping
+ * @param destinationType the destination type
+ * @param <B2> base type
+ * @param <T2> destination type
+ * @param <R2> Reverse source type
* @return the mapper instance
*/
- <S extends SB, T extends TB> ModelMapper<S, T> getMapper( Class<S> sourceType, Class<T> targetType ) throws IllegalArgumentException;
+ <B2 extends B, T2 extends T, R2 extends R> MultiModelMapper<B2, T2, R2> getMapper( Class<B2> baseType, Class<T2> destinationType, Class<R2> reverseSourceType ) throws IllegalArgumentException;
}
diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapper.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/MultiModelMapper.java
index 1f7fda93b..d28b6da67 100644
--- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/ModelMapper.java
+++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/MultiModelMapper.java
@@ -22,57 +22,72 @@ package org.apache.archiva.common;
*
* @author Martin Schreier <martin_s@apache.org>
*/
-public interface ModelMapper<S,T>
+public interface MultiModelMapper<B,T,R>
{
/**
* Converts the source instance to a new instance of the target type.
* @param source the source instance
* @return a new instance of the target type
*/
- T map(S source);
+ T map( B source);
/**
* Updates the target instance based on the source instance
* @param source the source instance
* @param target the target instance
*/
- void update( S source, T target );
+ void update( B source, T target );
/**
* Converts the target instance back to the source type
- * @param target the target instance
+ * @param source the target instance
* @return a new instance of the source type
*/
- S reverseMap(T target);
+ B reverseMap( R source);
/**
* Updates the source instance based on the target instance
- * @param target the target instance
- * @param source the source instance
+ * @param source the target instance
+ * @param target the source instance
*/
- void reverseUpdate( T target, S source);
+ void reverseUpdate( R source, B target);
/**
* Returns the class name of the source type
* @return the source type
*/
- Class<S> getSourceType();
+ Class<B> getBaseType();
/**
- * Returns the class name of the target type
+ * Returns the class name of type that is the goal for the mapping.
* @return the target type
*/
- Class<T> getTargetType();
+ Class<T> getDestinationType();
+
+ /**
+ * Returns the class name of the source for the reverse mapping.
+ * @return
+ */
+ Class<R> getReverseSourceType();
/**
* Returns <code>true</code>, if the given type are the same or supertype of the mapping types.
- * @param sourceType
- * @param targetType
+ * @param baseType
+ * @param destinationType
+ * @param reverseSourceType
* @param <S>
* @param <T>
* @return
*/
- <S, T> boolean supports( Class<S> sourceType, Class<T> targetType );
+ <S, T, R> boolean supports( Class<S> baseType, Class<T> destinationType, Class<R> reverseSourceType);
+
+ default int getHash() {
+ return getHash(getBaseType( ), getDestinationType( ), getReverseSourceType( ) );
+ }
+
+ static int getHash(Class<?> baseType, Class<?> destinationType, Class<?> reverseSourceType) {
+ return baseType.hashCode( ) ^ destinationType.hashCode( ) ^ reverseSourceType.hashCode( );
+ }
}
diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml
index bd2591722..988c6f598 100644
--- a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/pom.xml
@@ -21,8 +21,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <artifactId>archiva-configuration</artifactId>
<groupId>org.apache.archiva.configuration</groupId>
+ <artifactId>archiva-configuration</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
diff --git a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java
index 6a9520aa7..0fbcd3054 100644
--- a/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java
+++ b/archiva-modules/archiva-base/archiva-configuration/archiva-configuration-model/src/main/java/org/apache/archiva/configuration/model/ConfigurationModel.java
@@ -18,6 +18,8 @@ package org.apache.archiva.configuration.model;
*/
/**
+ * Marker interface that is used for configuration model classes.
+ *
* @author Martin Schreier <martin_s@apache.org>
*/
public interface ConfigurationModel
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java
index ac20ed536..323b071ef 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java
@@ -23,7 +23,6 @@ import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.event.EventSource;
import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.features.RepositoryFeature;
-import org.apache.archiva.repository.storage.StorageAsset;
import java.net.URI;
import java.util.Locale;
@@ -136,12 +135,12 @@ public interface Repository extends EventSource, RepositoryStorage {
* Extension method that allows to provide different features that are not supported by all
* repository types.
*
- * @param clazz The feature class that is requested
* @param <T> This is the class of the feature
+ * @param clazz The feature class that is requested
* @return The feature implementation for this repository instance, if it is supported
* @throws UnsupportedFeatureException if the feature is not supported by this repository type
*/
- <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature(Class<T> clazz) throws UnsupportedFeatureException;
+ <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz) throws UnsupportedFeatureException;
/**
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java
index b01efafd7..694b36dd1 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/AbstractRepository.java
@@ -22,7 +22,6 @@ package org.apache.archiva.repository.base;
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinition;
import com.cronutils.model.definition.CronDefinitionBuilder;
-import com.cronutils.parser.CronParser;
import org.apache.archiva.event.Event;
import org.apache.archiva.event.EventHandler;
import org.apache.archiva.event.EventManager;
@@ -38,7 +37,6 @@ import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.features.RepositoryFeature;
import org.apache.archiva.repository.features.StagingRepositoryFeature;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -200,10 +198,10 @@ public abstract class AbstractRepository implements EditableRepository, EventHan
@SuppressWarnings( "unchecked" )
@Override
- public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
+ public <T extends RepositoryFeature<T>> T getFeature( Class<T> clazz ) throws UnsupportedFeatureException
{
if (featureMap.containsKey( clazz )) {
- return (RepositoryFeature<T>) featureMap.get(clazz);
+ return (T) featureMap.get(clazz);
} else
{
throw new UnsupportedFeatureException( "Feature " + clazz + " not supported" );