Skip to content

Commit

Permalink
Merge pull request #588 from gastaldi/FORGE-2436
Browse files Browse the repository at this point in the history
FORGE-2436: Deprecated InputComponentInjectionEnricher and introduced inject package
  • Loading branch information
gastaldi committed Oct 8, 2015
2 parents c4f2ffa + f2a21fc commit bec18f6
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

package org.jboss.addon.validation.ui;

import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
import javax.validation.Validator;

import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionPoint;
import org.jboss.forge.addon.ui.validate.UIValidator;

/**
Expand All @@ -26,9 +26,9 @@ public class ValidationInputComponentEnricher implements InputComponentInjection
private Validator validator;

@Override
public void enrich(InjectionPoint injectionPoint, InputComponent<?, ?> input)
public void enrich(InputComponentInjectionPoint injectionPoint, InputComponent<?, ?> input)
{
Class<?> beanType = injectionPoint.getBean().getBeanClass();
Class<?> beanType = injectionPoint.getBeanClass();
UIValidationAdapter adapter = new UIValidationAdapter(validator, input, beanType);
input.addValidator(adapter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

package org.jboss.forge.addon.parser.java.ui.validators;

import javax.enterprise.inject.spi.InjectionPoint;

import org.jboss.forge.addon.ui.facets.HintsFacet;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionPoint;

/**
*
Expand All @@ -22,7 +21,7 @@ public class JLSValidatorEnricher implements InputComponentInjectionEnricher
{

@Override
public void enrich(InjectionPoint injectionPoint, InputComponent<?, ?> input)
public void enrich(InputComponentInjectionPoint injectionPoint, InputComponent<?, ?> input)
{
String inputType = input.getFacet(HintsFacet.class).getInputType();
if (inputType != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

package org.jboss.forge.addon.parser.java.ui.converters;

import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

import org.jboss.forge.addon.parser.java.converters.PackageRootConverter;
import org.jboss.forge.addon.projects.ProjectFactory;
import org.jboss.forge.addon.ui.facets.HintsFacet;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionPoint;
import org.jboss.forge.furnace.services.Imported;

/**
Expand All @@ -34,7 +34,7 @@ public class PackageRootEnricher implements InputComponentInjectionEnricher

@SuppressWarnings("unchecked")
@Override
public void enrich(InjectionPoint injectionPoint, InputComponent<?, ?> input)
public void enrich(InputComponentInjectionPoint injectionPoint, InputComponent<?, ?> input)
{
String inputType = input.getFacet(HintsFacet.class).getInputType();
if (InputType.JAVA_PACKAGE_PICKER.equals(inputType) && String.class == input.getValueType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.jboss.forge.addon.projects.ui;

import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

import org.jboss.forge.addon.convert.ConverterFactory;
Expand All @@ -18,8 +17,9 @@
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIContextProvider;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.SingleValued;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionPoint;
import org.jboss.forge.addon.ui.util.InputComponents;

/**
Expand All @@ -40,7 +40,7 @@ public class DefaultFacetComponentEnricher implements InputComponentInjectionEnr

@SuppressWarnings("unchecked")
@Override
public void enrich(InjectionPoint injectionPoint, InputComponent<?, ?> input)
public void enrich(InputComponentInjectionPoint injectionPoint, InputComponent<?, ?> input)
{
UIContext context = contextProvider.getUIContext();
// Setting for Single valued components only at the moment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
* Enriches an injected {@link InputComponent}
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
* @deprecated This interface declares a strong dependency on CDI. Please use
* {@link org.jboss.forge.addon.ui.input.inject.InputComponentInjectionEnricher} instead
*/
@Deprecated
public interface InputComponentInjectionEnricher
{
public void enrich(InjectionPoint injectionPoint, InputComponent<?, ?> input);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.input.inject;

import org.jboss.forge.addon.ui.input.InputComponent;

/**
* Enriches an injected {@link InputComponent}
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*/
public interface InputComponentInjectionEnricher
{
public void enrich(InputComponentInjectionPoint injectionPoint, InputComponent<?, ?> input);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.input.inject;

import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.Set;

/**
* Provides information about the injection point in a CDI-decoupled manner
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*/
public interface InputComponentInjectionPoint
{
/**
* The bean {@linkplain Class class} of the managed bean or session bean or of the bean that declares the producer
* method or field.
*
* @return the bean {@linkplain Class class}
*/
public Class<?> getBeanClass();

/**
* Get the required type of injection point.
*
* @return the required type
*/
public Type getType();

/**
* Get the required qualifiers of the injection point.
*
* @return the required qualifiers
*/
public Set<Annotation> getQualifiers();

/**
* Get the {@link java.lang.reflect.Field} object in the case of field injection, the
* {@link java.lang.reflect.Method} object in the case of method parameter injection or the
* {@link java.lang.reflect.Constructor} object in the case of constructor parameter injection.
*
* @return the member
*/
public Member getMember();

/**
* Determines if the injection point is a decorator delegate injection point.
*
* @return <tt>true</tt> if the injection point is a decorator delegate injection point, and <tt>false</tt> otherwise
*/
public boolean isDelegate();

/**
* Determines if the injection is a transient field.
*
* @return <tt>true</tt> if the injection point is a transient field, and <tt>false</tt> otherwise
*/
public boolean isTransient();

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class AnnotatedCommandExtension implements Extension
{
private static final Map<AddonId, Set<Method>> annotationMethods = new ConcurrentHashMap<>();

public <T> void observeAnnotationMethods(@WithAnnotations(Command.class) @Observes ProcessAnnotatedType<T> bean, final BeanManager beanManager)
public <T> void observeAnnotationMethods(@WithAnnotations(Command.class) @Observes ProcessAnnotatedType<T> bean,
final BeanManager beanManager)
{
AnnotatedType<T> annotatedType = bean.getAnnotatedType();
AddonId addonId = AddonId.fromCoordinates(Thread.currentThread().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
import org.jboss.forge.addon.ui.facets.HintsFacet;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.impl.facets.HintsFacetImpl;
import org.jboss.forge.addon.ui.impl.input.inject.DefaultInputComponentInjectionPoint;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentFactory;
import org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.SelectComponent;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UIInputMany;
import org.jboss.forge.addon.ui.input.UISelectMany;
import org.jboss.forge.addon.ui.input.UISelectOne;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionEnricher;
import org.jboss.forge.addon.ui.input.inject.InputComponentInjectionPoint;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.furnace.addons.AddonRegistry;
Expand All @@ -45,12 +47,13 @@
*
*/
@Singleton
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "deprecation" })
public class InputComponentProducer implements InputComponentFactory
{
private final AddonRegistry addonRegistry;
private final Environment environment;
private final ConverterFactory converterFactory;
private final Imported<org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher> deprecatedEnrichers;
private final Imported<InputComponentInjectionEnricher> enrichers;

@Inject
Expand All @@ -60,6 +63,8 @@ public InputComponentProducer(AddonRegistry addonRegistry)
this.environment = addonRegistry.getServices(Environment.class).get();
this.converterFactory = addonRegistry.getServices(ConverterFactory.class).get();
this.enrichers = addonRegistry.getServices(InputComponentInjectionEnricher.class);
this.deprecatedEnrichers = addonRegistry
.getServices(org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher.class);
}

@Produces
Expand Down Expand Up @@ -88,10 +93,7 @@ public <T> UISelectOne<T> produceSelectOne(InjectionPoint injectionPoint)
UISelectOne<T> input = createSelectOne(paramName, shortName, valueType);
input.setDeprecated(annotated.isAnnotationPresent(Deprecated.class));
preconfigureInput(input, withAttributes);
for (InputComponentInjectionEnricher enricher : enrichers)
{
enricher.enrich(injectionPoint, input);
}
enrichInput(injectionPoint, input);
return input;
}

Expand Down Expand Up @@ -122,10 +124,7 @@ public <T> UISelectMany<T> produceSelectMany(InjectionPoint injectionPoint)
UISelectMany<T> input = createSelectMany(paramName, shortName, valueType);
input.setDeprecated(annotated.isAnnotationPresent(Deprecated.class));
preconfigureInput(input, withAttributes);
for (InputComponentInjectionEnricher enricher : enrichers)
{
enricher.enrich(injectionPoint, input);
}
enrichInput(injectionPoint, input);
return input;
}

Expand Down Expand Up @@ -156,10 +155,7 @@ public <T> UIInput<T> produceInput(InjectionPoint injectionPoint)
UIInput<T> input = createInput(paramName, shortName, valueType);
input.setDeprecated(annotated.isAnnotationPresent(Deprecated.class));
preconfigureInput(input, withAttributes);
for (InputComponentInjectionEnricher enricher : enrichers)
{
enricher.enrich(injectionPoint, input);
}
enrichInput(injectionPoint, input);
return input;
}

Expand Down Expand Up @@ -190,13 +186,34 @@ public <T> UIInputMany<T> produceInputMany(InjectionPoint injectionPoint)
UIInputMany<T> input = createInputMany(paramName, shortName, valueType);
input.setDeprecated(annotated.isAnnotationPresent(Deprecated.class));
preconfigureInput(input, withAttributes);
for (InputComponentInjectionEnricher enricher : enrichers)
{
enricher.enrich(injectionPoint, input);
}
enrichInput(injectionPoint, input);
return input;
}

@Override
public <T> UIInput<T> createInput(String name, Class<T> valueType)
{
return createInput(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
}

@Override
public <T> UIInputMany<T> createInputMany(String name, Class<T> valueType)
{
return createInputMany(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
}

@Override
public <T> UISelectOne<T> createSelectOne(String name, Class<T> valueType)
{
return createSelectOne(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
}

@Override
public <T> UISelectMany<T> createSelectMany(String name, Class<T> valueType)
{
return createSelectMany(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
}

private <T> Class<T> resolveRealType(Type type)
{
if (type instanceof ParameterizedType)
Expand Down Expand Up @@ -344,33 +361,22 @@ else if (String.class == valueType || Integer.class == valueType)
selectComponent.setValueChoices(choices);
}

private void configureRequiredFacets(InputComponent<?, ?> input)
{
HintsFacetImpl hintsFacet = new HintsFacetImpl(input, environment);
input.install(hintsFacet);
}

@Override
public <T> UIInput<T> createInput(String name, Class<T> valueType)
{
return createInput(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
}

@Override
public <T> UIInputMany<T> createInputMany(String name, Class<T> valueType)
{
return createInputMany(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
}

@Override
public <T> UISelectOne<T> createSelectOne(String name, Class<T> valueType)
private <T> void enrichInput(InjectionPoint injectionPoint, InputComponent<?, ?> input)
{
return createSelectOne(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
for (org.jboss.forge.addon.ui.input.InputComponentInjectionEnricher enricher : deprecatedEnrichers)
{
enricher.enrich(injectionPoint, input);
}
InputComponentInjectionPoint inputInjectionPoint = DefaultInputComponentInjectionPoint.of(injectionPoint);
for (InputComponentInjectionEnricher enricher : enrichers)
{
enricher.enrich(inputInjectionPoint, input);
}
}

@Override
public <T> UISelectMany<T> createSelectMany(String name, Class<T> valueType)
private void configureRequiredFacets(InputComponent<?, ?> input)
{
return createSelectMany(name, InputComponents.DEFAULT_SHORT_NAME, valueType);
HintsFacetImpl hintsFacet = new HintsFacetImpl(input, environment);
input.install(hintsFacet);
}
}
Loading

0 comments on commit bec18f6

Please sign in to comment.