WW-3820 changes implementation of getInstanceNames(Class<?> type) to return empty set instead of null

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1338660 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lukasz Lenart
2012-05-15 11:42:38 +00:00
parent fca4405004
commit f21793d920
9 changed files with 50 additions and 69 deletions
@@ -741,11 +741,9 @@ public class Dispatcher {
MultiPartRequest mpr = null;
//check for alternate implementations of MultiPartRequest
Set<String> multiNames = getContainer().getInstanceNames(MultiPartRequest.class);
if (multiNames != null) {
for (String multiName : multiNames) {
if (multiName.equals(multipartHandlerName)) {
mpr = getContainer().getInstance(MultiPartRequest.class, multiName);
}
for (String multiName : multiNames) {
if (multiName.equals(multipartHandlerName)) {
mpr = getContainer().getInstance(MultiPartRequest.class, multiName);
}
}
if (mpr == null ) {
@@ -35,7 +35,6 @@ import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.velocity.VelocityManager;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@@ -75,9 +74,6 @@ public class ShowBeansAction extends ActionNamesAction {
chosenName = "struts";
}
Set<String> names = container.getInstanceNames(type);
if (names == null) {
names = Collections.emptySet();
}
if (!names.contains(chosenName)) {
bindings.add(new Binding(getInstanceClassName(container, type, "default"), chosenName, constName, true));
}
@@ -15,20 +15,16 @@
*/
package com.opensymphony.xwork2;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.UnknownHandler;
import com.opensymphony.xwork2.UnknownHandlerManager;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Default implementation of UnknownHandlerManager
*
@@ -69,11 +65,9 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager {
} else {
//add all available UnknownHandlers
Set<String> unknowHandlerNames = container.getInstanceNames(UnknownHandler.class);
if (unknowHandlerNames != null) {
for (String unknowHandlerName : unknowHandlerNames) {
UnknownHandler uh = container.getInstance(UnknownHandler.class, unknowHandlerName);
unknownHandlers.add(uh);
}
for (String unknowHandlerName : unknowHandlerNames) {
UnknownHandler uh = container.getInstance(UnknownHandler.class, unknowHandlerName);
unknownHandlers.add(uh);
}
}
}
@@ -17,7 +17,6 @@ package com.opensymphony.xwork2.config.impl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.DefaultTextProvider;
import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.TextProvider;
@@ -57,7 +56,6 @@ import com.opensymphony.xwork2.util.CompoundRoot;
import com.opensymphony.xwork2.util.PatternMatcher;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import com.opensymphony.xwork2.util.logging.Logger;
@@ -240,13 +238,11 @@ public class DefaultConfiguration implements Configuration {
// Then process any package providers from the plugins
Set<String> packageProviderNames = container.getInstanceNames(PackageProvider.class);
if (packageProviderNames != null) {
for (String name : packageProviderNames) {
PackageProvider provider = container.getInstance(PackageProvider.class, name);
provider.init(this);
provider.loadPackages();
packageProviders.add(provider);
}
for (String name : packageProviderNames) {
PackageProvider provider = container.getInstance(PackageProvider.class, name);
provider.init(this);
provider.loadPackages();
packageProviders.add(provider);
}
rebuildRuntimeConfiguration();
@@ -97,7 +97,7 @@ public interface Container extends Serializable {
/**
* Gets a set of all registered names for the given type
* @param type The instance type
* @return A set of registered names
* @return A set of registered names or empty set if no instances are registered for that type
*/
Set<String> getInstanceNames(Class<?> type);
@@ -558,7 +558,11 @@ class ContainerImpl implements Container {
}
public Set<String> getInstanceNames( final Class<?> type ) {
return factoryNamesByType.get(type);
Set<String> names = factoryNamesByType.get(type);
if (names == null) {
names = Collections.emptySet();
}
return names;
}
ThreadLocal<Object[]> localContext =
@@ -75,38 +75,32 @@ public class OgnlValueStackFactory implements ValueStackFactory {
@Inject
public void setContainer(Container container) throws ClassNotFoundException {
Set<String> names = container.getInstanceNames(PropertyAccessor.class);
if (names != null) {
for (String name : names) {
Class cls = Class.forName(name);
if (cls != null) {
if (Map.class.isAssignableFrom(cls)) {
PropertyAccessor acc = container.getInstance(PropertyAccessor.class, name);
}
OgnlRuntime.setPropertyAccessor(cls, container.getInstance(PropertyAccessor.class, name));
if (compoundRootAccessor == null && CompoundRoot.class.isAssignableFrom(cls)) {
compoundRootAccessor = (CompoundRootAccessor) container.getInstance(PropertyAccessor.class, name);
}
for (String name : names) {
Class cls = Class.forName(name);
if (cls != null) {
if (Map.class.isAssignableFrom(cls)) {
PropertyAccessor acc = container.getInstance(PropertyAccessor.class, name);
}
OgnlRuntime.setPropertyAccessor(cls, container.getInstance(PropertyAccessor.class, name));
if (compoundRootAccessor == null && CompoundRoot.class.isAssignableFrom(cls)) {
compoundRootAccessor = (CompoundRootAccessor) container.getInstance(PropertyAccessor.class, name);
}
}
}
names = container.getInstanceNames(MethodAccessor.class);
if (names != null) {
for (String name : names) {
Class cls = Class.forName(name);
if (cls != null) {
OgnlRuntime.setMethodAccessor(cls, container.getInstance(MethodAccessor.class, name));
}
for (String name : names) {
Class cls = Class.forName(name);
if (cls != null) {
OgnlRuntime.setMethodAccessor(cls, container.getInstance(MethodAccessor.class, name));
}
}
names = container.getInstanceNames(NullHandler.class);
if (names != null) {
for (String name : names) {
Class cls = Class.forName(name);
if (cls != null) {
OgnlRuntime.setNullHandler(cls, new OgnlNullHandlerWrapper(container.getInstance(NullHandler.class, name)));
}
for (String name : names) {
Class cls = Class.forName(name);
if (cls != null) {
OgnlRuntime.setNullHandler(cls, new OgnlNullHandlerWrapper(container.getInstance(NullHandler.class, name)));
}
}
if (compoundRootAccessor == null) {
@@ -21,17 +21,15 @@ public class DefaultFileManagerFactory implements FileManagerFactory {
@Inject
public DefaultFileManagerFactory(Container container) {
Set<String> names = container.getInstanceNames(FileManager.class);
if (names != null) {
for (String fmName : names) {
FileManager fm = container.getInstance(FileManager.class, fmName);
if (fm.support()) {
if (fileManager != null) {
LOG.error("More than one FileManager supports current file system, [#0] and [#1]! "
+ "Remove one of them from the config! Using implementation [#2]",
fm.toString(), fileManager.toString(), fm.toString());
}
fileManager = fm;
for (String fmName : names) {
FileManager fm = container.getInstance(FileManager.class, fmName);
if (fm.support()) {
if (fileManager != null) {
LOG.error("More than one FileManager supports current file system, [#0] and [#1]! "
+ "Remove one of them from the config! Using implementation [#2]",
fm.toString(), fileManager.toString(), fm.toString());
}
fileManager = fm;
}
}
if (fileManager == null) {
@@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -80,7 +81,7 @@ class DummyContainer implements Container {
}
};
}
return null;
return Collections.emptySet();
}
public void setScopeStrategy(Scope.Strategy scopeStrategy) {