forked from eclipse-ee4j/jersey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename ParameterInserters to ParameterUpdaters (eclipse-ee4j#4170)
* Rename ParameterInserters to ParameterUpdaters to better fit the functionality name Signed-off-by: Jan Supol <[email protected]>
- Loading branch information
Showing
15 changed files
with
137 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation and/or its affiliates. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
|
@@ -28,12 +28,12 @@ | |
* @author Marek Potociar (marek.potociar at oracle.com) | ||
* @author Gaurav Gupta ([email protected]) | ||
*/ | ||
public interface ParameterInserter<T, R> { | ||
public interface ParameterUpdater<T, R> { | ||
|
||
/** | ||
* Name of the parameter to be inserted | ||
* Name of the parameter to be udpated | ||
* | ||
* @return name of the inserted parameter. | ||
* @return name of the updated parameter. | ||
*/ | ||
String getName(); | ||
|
||
|
@@ -45,11 +45,11 @@ public interface ParameterInserter<T, R> { | |
String getDefaultValueString(); | ||
|
||
/** | ||
* Insert the value using ParamConverter#toString (and using | ||
* Update the value using ParamConverter#toString (and using | ||
* the configured {@link #getDefaultValueString() default value}) | ||
* | ||
* @param parameters custom Java type instance value. | ||
* @return converted value. | ||
*/ | ||
R insert(T parameters); | ||
R update(T parameters); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation and/or its affiliates. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
|
@@ -20,22 +20,22 @@ | |
import org.glassfish.jersey.model.Parameter; | ||
|
||
/** | ||
* Provider of parameter inserter. | ||
* Provider of parameter updater. | ||
* | ||
* @author Paul Sandoz | ||
* @author Marek Potociar (marek.potociar at oracle.com) | ||
* @author Gaurav Gupta ([email protected]) | ||
*/ | ||
public interface ParameterInserterProvider { | ||
public interface ParameterUpdaterProvider { | ||
|
||
/** | ||
* Get the inserter configured to insert value of given {@link Parameter parameter}. | ||
* Get the updater configured to update value of given {@link Parameter parameter}. | ||
* <p /> | ||
* If the default value has been set on the parameter, it will be configured | ||
* in the inserter. | ||
* in the updater. | ||
* | ||
* @param parameter client model parameter. | ||
* @return inserter for the method parameter. | ||
* @return updater for the method parameter. | ||
*/ | ||
ParameterInserter<?, ?> get(Parameter parameter); | ||
ParameterUpdater<?, ?> get(Parameter parameter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation and/or its affiliates. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
|
@@ -20,33 +20,33 @@ | |
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.ext.ParamConverter; | ||
|
||
import org.glassfish.jersey.internal.inject.InserterException; | ||
import org.glassfish.jersey.internal.inject.UpdaterException; | ||
import org.glassfish.jersey.internal.util.collection.UnsafeValue; | ||
import org.glassfish.jersey.internal.util.collection.Values; | ||
|
||
/** | ||
* Abstract base class for implementing parameter value inserter | ||
* Abstract base class for implementing parameter value updater | ||
* logic supplied using {@link ParamConverter parameter converters}. | ||
* | ||
* @author Paul Sandoz | ||
* @author Marek Potociar (marek.potociar at oracle.com) | ||
* @author Gaurav Gupta ([email protected]) | ||
*/ | ||
abstract class AbstractParamValueInserter<T> { | ||
abstract class AbstractParamValueUpdater<T> { | ||
|
||
private final ParamConverter<T> paramConverter; | ||
private final String parameterName; | ||
private final String defaultValue; | ||
private final UnsafeValue<String, RuntimeException> convertedDefaultValue; | ||
|
||
/** | ||
* Constructor that initializes parameter inserter. | ||
* Constructor that initializes parameter updater. | ||
* | ||
* @param converter parameter converter. | ||
* @param parameterName name of the parameter. | ||
* @param defaultValueString default parameter value string. | ||
*/ | ||
protected AbstractParamValueInserter(ParamConverter<T> converter, String parameterName, final String defaultValue) { | ||
protected AbstractParamValueUpdater(ParamConverter<T> converter, String parameterName, final String defaultValue) { | ||
this.paramConverter = converter; | ||
this.parameterName = parameterName; | ||
this.defaultValue = defaultValue; | ||
|
@@ -69,7 +69,7 @@ public String get() throws RuntimeException { | |
} | ||
|
||
/** | ||
* Get the name of the parameter this inserter belongs to. | ||
* Get the name of the parameter this updater belongs to. | ||
* | ||
* @return parameter name. | ||
*/ | ||
|
@@ -87,17 +87,17 @@ public String getDefaultValueString() { | |
} | ||
|
||
/** | ||
* Insert parameter value to string using the configured {@link ParamConverter parameter converter}. | ||
* Update parameter value to string using the configured {@link ParamConverter parameter converter}. | ||
* | ||
* A {@link WebApplicationException} / {@link IllegalArgumentException} thrown | ||
* from the converter is propagated unchanged. Any other exception throws by | ||
* the converter is wrapped in a new {@link InserterException} before rethrowing. | ||
* the converter is wrapped in a new {@link UpdaterException} before rethrowing. | ||
* | ||
* @param value parameter value to be converted/inserted. | ||
* @return inserted value of a given Java type. | ||
* @param value parameter value to be converted/updated. | ||
* @return updated value of a given Java type. | ||
* @throws WebApplicationException in case the underlying parameter converter throws | ||
* a {@code WebApplicationException}. The exception is rethrown without a change. | ||
* @throws InserterException wrapping any other exception thrown by the parameter converter. | ||
* @throws UpdaterException wrapping any other exception thrown by the parameter converter. | ||
*/ | ||
protected final String toString(T value) { | ||
String result = convert(value); | ||
|
@@ -113,7 +113,7 @@ private String convert(T value) { | |
} catch (WebApplicationException | IllegalArgumentException ex) { | ||
throw ex; | ||
} catch (Exception ex) { | ||
throw new InserterException(ex); | ||
throw new UpdaterException(ex); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation and/or its affiliates. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
|
@@ -29,35 +29,35 @@ | |
import javax.ws.rs.ProcessingException; | ||
import javax.ws.rs.ext.ParamConverter; | ||
import org.glassfish.jersey.client.internal.LocalizationMessages; | ||
import org.glassfish.jersey.client.inject.ParameterInserter; | ||
import org.glassfish.jersey.client.inject.ParameterUpdater; | ||
|
||
/** | ||
* Insert parameter value as a typed collection. | ||
* Update parameter value as a typed collection. | ||
* | ||
* @param <T> parameter value type. | ||
* @author Paul Sandoz | ||
* @author Marek Potociar (marek.potociar at oracle.com) | ||
* @author Gaurav Gupta ([email protected]) | ||
*/ | ||
abstract class CollectionInserter<T> extends AbstractParamValueInserter<T> | ||
implements ParameterInserter<Collection<T>, Collection<String>> { | ||
abstract class CollectionUpdater<T> extends AbstractParamValueUpdater<T> | ||
implements ParameterUpdater<Collection<T>, Collection<String>> { | ||
|
||
/** | ||
* Create new collection parameter inserter. | ||
* Create new collection parameter updater. | ||
* | ||
* @param converter parameter converter to be used to convert parameter from a custom Java type. | ||
* @param parameterName parameter name. | ||
* @param defaultValue default parameter String value. | ||
*/ | ||
protected CollectionInserter(final ParamConverter<T> converter, | ||
final String parameterName, | ||
final String defaultValue) { | ||
protected CollectionUpdater(final ParamConverter<T> converter, | ||
final String parameterName, | ||
final String defaultValue) { | ||
super(converter, parameterName, defaultValue); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public Collection<String> insert(final Collection<T> values) { | ||
public Collection<String> update(final Collection<T> values) { | ||
Collection<String> results = Collections.EMPTY_LIST; | ||
if (values != null) { | ||
results = values | ||
|
@@ -71,7 +71,7 @@ public Collection<String> insert(final Collection<T> values) { | |
} | ||
|
||
/** | ||
* Get a new collection instance that will be used to store the inserted parameters. | ||
* Get a new collection instance that will be used to store the updated parameters. | ||
* <p/> | ||
* The method is overridden by concrete implementations to return an instance | ||
* of a proper collection sub-type. | ||
|
@@ -80,7 +80,7 @@ public Collection<String> insert(final Collection<T> values) { | |
*/ | ||
protected abstract Collection<String> newCollection(); | ||
|
||
private static final class ListValueOf<T> extends CollectionInserter<T> { | ||
private static final class ListValueOf<T> extends CollectionUpdater<T> { | ||
|
||
ListValueOf(final ParamConverter<T> converter, final String parameter, final String defaultValue) { | ||
super(converter, parameter, defaultValue); | ||
|
@@ -92,7 +92,7 @@ protected List<String> newCollection() { | |
} | ||
} | ||
|
||
private static final class SetValueOf<T> extends CollectionInserter<T> { | ||
private static final class SetValueOf<T> extends CollectionUpdater<T> { | ||
|
||
SetValueOf(final ParamConverter<T> converter, final String parameter, final String defaultValue) { | ||
super(converter, parameter, defaultValue); | ||
|
@@ -104,7 +104,7 @@ protected Set<String> newCollection() { | |
} | ||
} | ||
|
||
private static final class SortedSetValueOf<T> extends CollectionInserter<T> { | ||
private static final class SortedSetValueOf<T> extends CollectionUpdater<T> { | ||
|
||
SortedSetValueOf(final ParamConverter<T> converter, final String parameter, final String defaultValue) { | ||
super(converter, parameter, defaultValue); | ||
|
@@ -117,28 +117,28 @@ protected SortedSet<String> newCollection() { | |
} | ||
|
||
/** | ||
* Get a new {@code CollectionInserter} instance. | ||
* Get a new {@code CollectionUpdater} instance. | ||
* | ||
* @param collectionType raw collection type. | ||
* @param converter parameter converter to be used to convert parameter Java type values into | ||
* String values . | ||
* @param parameterName parameter name. | ||
* @param defaultValue default parameter string value. | ||
* @param <T> converted parameter Java type. | ||
* @return new collection parameter inserter instance. | ||
* @return new collection parameter updated instance. | ||
*/ | ||
public static <T> CollectionInserter getInstance(final Class<?> collectionType, | ||
final ParamConverter<T> converter, | ||
final String parameterName, | ||
final String defaultValue) { | ||
public static <T> CollectionUpdater getInstance(final Class<?> collectionType, | ||
final ParamConverter<T> converter, | ||
final String parameterName, | ||
final String defaultValue) { | ||
if (List.class == collectionType) { | ||
return new ListValueOf<>(converter, parameterName, defaultValue); | ||
} else if (Set.class == collectionType) { | ||
return new SetValueOf<>(converter, parameterName, defaultValue); | ||
} else if (SortedSet.class == collectionType) { | ||
return new SortedSetValueOf<>(converter, parameterName, defaultValue); | ||
} else { | ||
throw new ProcessingException(LocalizationMessages.COLLECTION_INSERTER_TYPE_UNSUPPORTED()); | ||
throw new ProcessingException(LocalizationMessages.COLLECTION_UPDATER_TYPE_UNSUPPORTED()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation and/or its affiliates. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
|
@@ -29,30 +29,30 @@ | |
import org.glassfish.jersey.internal.util.collection.LazyValue; | ||
import org.glassfish.jersey.internal.util.collection.Value; | ||
import org.glassfish.jersey.internal.util.collection.Values; | ||
import org.glassfish.jersey.client.inject.ParameterInserterProvider; | ||
import org.glassfish.jersey.client.inject.ParameterUpdaterProvider; | ||
|
||
/** | ||
* Configurator which initializes and register {@link ParameterInserterProvider} instance into | ||
* Configurator which initializes and register {@link ParameterUpdaterProvider} instance into | ||
* {@link InjectionManager}. | ||
* | ||
* @author Petr Bouda | ||
* @author Gaurav Gupta ([email protected]) | ||
*/ | ||
public class ParameterInserterConfigurator implements BootstrapConfigurator { | ||
public class ParameterUpdaterConfigurator implements BootstrapConfigurator { | ||
|
||
@Override | ||
public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) { | ||
ClientBootstrapBag clientBag = (ClientBootstrapBag) bootstrapBag; | ||
|
||
// Param Converters must be initialized Lazy and created at the time of the call on inserter | ||
// Param Converters must be initialized Lazy and created at the time of the call on updater | ||
LazyValue<ParamConverterFactory> lazyParamConverterFactory = | ||
Values.lazy((Value<ParamConverterFactory>) () -> new ParamConverterFactory( | ||
Providers.getProviders(injectionManager, ParamConverterProvider.class), | ||
Providers.getCustomProviders(injectionManager, ParamConverterProvider.class))); | ||
|
||
ParameterInserterFactory parameterInserter = new ParameterInserterFactory(lazyParamConverterFactory); | ||
clientBag.setParameterInserterProvider(parameterInserter); | ||
injectionManager.register(Bindings.service(parameterInserter) | ||
.to(ParameterInserterProvider.class)); | ||
ParameterUpdaterFactory parameterUpdaterFactory = new ParameterUpdaterFactory(lazyParamConverterFactory); | ||
clientBag.setParameterUpdaterProvider(parameterUpdaterFactory); | ||
injectionManager.register(Bindings.service(parameterUpdaterFactory) | ||
.to(ParameterUpdaterProvider.class)); | ||
} | ||
} |
Oops, something went wrong.