Skip to content

Commit

Permalink
Rename ParameterInserters to ParameterUpdaters (#4170)
Browse files Browse the repository at this point in the history
* Rename ParameterInserters to ParameterUpdaters to better fit the functionality name

Signed-off-by: Jan Supol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored and senivam committed Jun 24, 2019
1 parent 1719b46 commit 01cb903
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 137 deletions.
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,7 +18,7 @@


import org.glassfish.jersey.internal.BootstrapBag;
import org.glassfish.jersey.client.inject.ParameterInserterProvider;
import org.glassfish.jersey.client.inject.ParameterUpdaterProvider;

/**
* {@inheritDoc}
Expand All @@ -28,14 +29,14 @@
*/
public class ClientBootstrapBag extends BootstrapBag {

private ParameterInserterProvider parameterInserterProvider;
private ParameterUpdaterProvider parameterUpdaterProvider;

public ParameterInserterProvider getParameterInserterProvider() {
requireNonNull(parameterInserterProvider, ParameterInserterProvider.class);
return parameterInserterProvider;
public ParameterUpdaterProvider getParameterUpdaterProvider() {
requireNonNull(parameterUpdaterProvider, ParameterUpdaterProvider.class);
return parameterUpdaterProvider;
}

public void setParameterInserterProvider(ParameterInserterProvider provider) {
this.parameterInserterProvider = provider;
public void setParameterUpdaterProvider(ParameterUpdaterProvider provider) {
this.parameterUpdaterProvider = provider;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
Expand Down Expand Up @@ -35,7 +35,7 @@
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.ExtendedConfig;
import org.glassfish.jersey.client.internal.LocalizationMessages;
import org.glassfish.jersey.client.internal.inject.ParameterInserterConfigurator;
import org.glassfish.jersey.client.internal.inject.ParameterUpdaterConfigurator;
import org.glassfish.jersey.client.spi.Connector;
import org.glassfish.jersey.client.spi.ConnectorProvider;
import org.glassfish.jersey.internal.AutoDiscoverableConfigurator;
Expand Down Expand Up @@ -416,7 +416,7 @@ private ClientRuntime initRuntime() {
bootstrapBag.setManagedObjectsFinalizer(new ManagedObjectsFinalizer(injectionManager));
List<BootstrapConfigurator> bootstrapConfigurators = Arrays.asList(new RequestScope.RequestScopeConfigurator(),
new ParamConverterConfigurator(),
new ParameterInserterConfigurator(),
new ParameterUpdaterConfigurator(),
new RuntimeConfigConfigurator(runtimeCfgState),
new ContextResolverFactory.ContextResolversConfigurator(),
new MessageBodyFactory.MessageBodyWorkersConfigurator(),
Expand Down
@@ -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
Expand Down Expand Up @@ -28,12 +28,12 @@
* @author Marek Potociar (marek.potociar at oracle.com)
* @author Gaurav Gupta (gaurav.gupta@payara.fish)
*/
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();

Expand All @@ -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);
}
@@ -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
Expand All @@ -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 (gaurav.gupta@payara.fish)
*/
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);
}
@@ -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
Expand All @@ -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 (gaurav.gupta@payara.fish)
*/
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;
Expand All @@ -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.
*/
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down
@@ -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
Expand Down Expand Up @@ -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 (gaurav.gupta@payara.fish)
*/
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
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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());
}
}
}
@@ -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
Expand Down Expand Up @@ -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 (gaurav.gupta@payara.fish)
*/
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));
}
}

0 comments on commit 01cb903

Please sign in to comment.