|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2021 IBM Corporation and others. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * IBM Corporation - initial API and implementation |
| 10 | + *******************************************************************************/ |
| 11 | +package io.openliberty.org.jboss.resteasy.common.cdi; |
| 12 | + |
| 13 | +import java.lang.annotation.Annotation; |
| 14 | +import java.lang.reflect.AccessibleObject; |
| 15 | +import java.lang.reflect.Constructor; |
| 16 | +import java.lang.reflect.Type; |
| 17 | + |
| 18 | +import org.jboss.resteasy.core.InjectorFactoryImpl; |
| 19 | +import org.jboss.resteasy.spi.ConstructorInjector; |
| 20 | +import org.jboss.resteasy.spi.InjectorFactory; |
| 21 | +import org.jboss.resteasy.spi.MethodInjector; |
| 22 | +import org.jboss.resteasy.spi.PropertyInjector; |
| 23 | +import org.jboss.resteasy.spi.ResteasyProviderFactory; |
| 24 | +import org.jboss.resteasy.spi.ValueInjector; |
| 25 | +import org.jboss.resteasy.spi.metadata.Parameter; |
| 26 | +import org.jboss.resteasy.spi.metadata.ResourceClass; |
| 27 | +import org.jboss.resteasy.spi.metadata.ResourceConstructor; |
| 28 | +import org.jboss.resteasy.spi.metadata.ResourceLocator; |
| 29 | + |
| 30 | +import com.ibm.websphere.ras.Tr; |
| 31 | +import com.ibm.websphere.ras.TraceComponent; |
| 32 | + |
| 33 | +@SuppressWarnings("rawtypes") |
| 34 | +public class LibertyFallbackInjectorFactory implements InjectorFactory { |
| 35 | + private static final TraceComponent tc = Tr.register(LibertyFallbackInjectorFactory.class); |
| 36 | + |
| 37 | + private final InjectorFactory delegate; |
| 38 | + |
| 39 | + public LibertyFallbackInjectorFactory() { |
| 40 | + InjectorFactory factory; |
| 41 | + try { |
| 42 | + factory = new LibertyCdiInjectorFactory(); |
| 43 | + } catch (Throwable t) { |
| 44 | + if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) { |
| 45 | + Tr.debug(tc, "Caught exception initializing LibertyCdiInjectorFactory - expected if module declines CDI", t); |
| 46 | + } |
| 47 | + factory = new InjectorFactoryImpl(); |
| 48 | + } |
| 49 | + delegate = factory; |
| 50 | + } |
| 51 | + @Override |
| 52 | + public ConstructorInjector createConstructor(Constructor constructor, ResteasyProviderFactory factory) { |
| 53 | + return delegate.createConstructor(constructor, factory); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public PropertyInjector createPropertyInjector(Class resourceClass, ResteasyProviderFactory factory) { |
| 58 | + return delegate.createPropertyInjector(resourceClass, factory); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, String defaultName, Class type, Type genericType, Annotation[] annotations, ResteasyProviderFactory factory) { |
| 63 | + return delegate.createParameterExtractor(injectTargetClass, injectTarget, defaultName, type, genericType, annotations, factory); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, String defaultName, Class type, Type genericType, Annotation[] annotations, boolean useDefault, ResteasyProviderFactory factory) { |
| 68 | + return delegate.createParameterExtractor(injectTargetClass, injectTarget, defaultName, type, genericType, annotations, useDefault, factory); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) { |
| 73 | + return delegate.createParameterExtractor(parameter, providerFactory); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public MethodInjector createMethodInjector(ResourceLocator method, ResteasyProviderFactory factory) { |
| 78 | + return delegate.createMethodInjector(method, factory); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public PropertyInjector createPropertyInjector(ResourceClass resourceClass, ResteasyProviderFactory providerFactory) { |
| 83 | + return delegate.createPropertyInjector(resourceClass, providerFactory); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public ConstructorInjector createConstructor(ResourceConstructor constructor, ResteasyProviderFactory providerFactory) { |
| 88 | + return delegate.createConstructor(constructor, providerFactory); |
| 89 | + } |
| 90 | +} |
0 commit comments