Skip to content
Permalink
Browse files
[CXF-5542] Adding the changes to the JAXRS frontend
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1564750 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Feb 5, 2014
1 parent 2319407 commit 5995149d449ebbfdc4d22717409fe9d5e86da48b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
@@ -58,26 +58,28 @@ protected AbstractResourceInfo(Bus bus) {

protected AbstractResourceInfo(Class<?> resourceClass, Class<?> serviceClass,
boolean isRoot, boolean checkContexts, Bus bus) {
this(resourceClass, serviceClass, isRoot, checkContexts, null, bus);
this(resourceClass, serviceClass, isRoot, checkContexts, null, bus, null);
}

protected AbstractResourceInfo(Class<?> resourceClass,
Class<?> serviceClass,
boolean isRoot,
boolean checkContexts,
Map<Class<?>, ThreadLocalProxy<?>> constructorProxies,
Bus bus) {
Bus bus,
Object provider) {
this.bus = bus;
this.serviceClass = serviceClass;
this.resourceClass = resourceClass;
root = isRoot;
if (checkContexts && resourceClass != null) {
findContexts(serviceClass, constructorProxies);
findContexts(serviceClass, provider, constructorProxies);
}
}

private void findContexts(Class<?> cls, Map<Class<?>, ThreadLocalProxy<?>> constructorProxies) {
findContextFields(cls);
private void findContexts(Class<?> cls, Object provider,
Map<Class<?>, ThreadLocalProxy<?>> constructorProxies) {
findContextFields(cls, provider);
findContextSetterMethods(cls);
if (constructorProxies != null) {
Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>> proxies = getConstructorProxyMap(true);
@@ -102,15 +104,15 @@ public Bus getBus() {
public void setResourceClass(Class<?> rClass) {
resourceClass = rClass;
if (serviceClass.isInterface() && resourceClass != null && !resourceClass.isInterface()) {
findContexts(resourceClass, null);
findContexts(resourceClass, null, null);
}
}

public Class<?> getServiceClass() {
return serviceClass;
}

private void findContextFields(Class<?> cls) {
private void findContextFields(Class<?> cls, Object provider) {
if (cls == Object.class || cls == null) {
return;
}
@@ -119,12 +121,28 @@ private void findContextFields(Class<?> cls) {
if (a.annotationType() == Context.class) {
contextFields = addContextField(contextFields, f);
if (f.getType() != Application.class) {
addToMap(getFieldProxyMap(true), f, InjectionUtils.createThreadLocalProxy(f.getType()));
addToMap(getFieldProxyMap(true), f, getFieldThreadLocalProxy(f, provider));
}
}
}
}
findContextFields(cls.getSuperclass());
findContextFields(cls.getSuperclass(), provider);
}

private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object provider) {
if (provider != null) {
synchronized (provider) {
try {
Object proxy = InjectionUtils.extractFieldValue(f, provider);
if (proxy instanceof ThreadLocalProxy) {
return (ThreadLocalProxy<?>)proxy;
}
} catch (Throwable t) {
// continue
}
}
}
return InjectionUtils.createThreadLocalProxy(f.getType());
}

@SuppressWarnings("unchecked")
@@ -35,7 +35,7 @@ public ProviderInfo(T provider, Bus bus) {
public ProviderInfo(T provider,
Map<Class<?>, ThreadLocalProxy<?>> constructorProxies,
Bus bus) {
super(provider.getClass(), provider.getClass(), true, true, constructorProxies, bus);
super(provider.getClass(), provider.getClass(), true, true, constructorProxies, bus, provider);
this.provider = provider;
}

@@ -987,6 +987,15 @@ public static void injectContextProxiesAndApplication(AbstractResourceInfo cri,

for (Field f : cri.getContextFields()) {
Object value = f.getType() == Application.class ? app : cri.getContextFieldProxy(f);
try {
synchronized (instance) {
if (value == InjectionUtils.extractFieldValue(f, instance)) {
continue;
}
}
} catch (Throwable t) {
// continue
}
InjectionUtils.injectFieldValue(f, instance, value);
}
}

0 comments on commit 5995149

Please sign in to comment.