Commits

Anonymous committed d5a8b68

Simplified the locatable factory

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1296e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (3)

src/java/com/opensymphony/xwork2/config/impl/LocatableFactory.java

+package com.opensymphony.xwork2.config.impl;
+
+import com.opensymphony.xwork2.util.location.Located;
+import com.opensymphony.xwork2.util.location.LocationUtils;
+import com.opensymphony.xwork2.inject.Factory;
+import com.opensymphony.xwork2.inject.Scope;
+import com.opensymphony.xwork2.inject.Context;
+
+import java.util.LinkedHashMap;
+
+/**
+ * Attaches location information to the factory.
+ */
+public class LocatableFactory<T> extends Located implements Factory<T> {
+
+
+    private Class implementation;
+    private Class type;
+    private String name;
+    private Scope scope;
+
+    public LocatableFactory(String name, Class type, Class implementation, Scope scope, Object location) {
+        this.implementation = implementation;
+        this.type = type;
+        this.name = name;
+        this.scope = scope;
+        setLocation(LocationUtils.getLocation(location));
+    }
+
+    @SuppressWarnings("unchecked")
+    public T create(Context context) {
+        Object obj = context.getContainer().inject(implementation);
+        return (T) obj;
+    }
+
+    public String toString() {
+        String fields = new LinkedHashMap<String, Object>() {
+            {
+                put("type", type);
+                put("name", name);
+                put("implementation", implementation);
+                put("scope", scope);
+            }
+        }.toString();
+        StringBuilder sb = new StringBuilder(fields);
+        sb.append(super.toString());
+        sb.append(" defined at ");
+        sb.append(getLocation().toString());
+        return sb.toString();
+    }
+}

src/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java

 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.XWorkException;
 import com.opensymphony.xwork2.config.*;
+import com.opensymphony.xwork2.config.impl.LocatableFactory;
 import com.opensymphony.xwork2.config.entities.*;
-import com.opensymphony.xwork2.inject.LocatableFactory;
 import com.opensymphony.xwork2.inject.*;
 import com.opensymphony.xwork2.util.DomHelper;
 import com.opensymphony.xwork2.util.location.LocatableProperties;

src/java/com/opensymphony/xwork2/inject/LocatableFactory.java

-package com.opensymphony.xwork2.inject;
-
-import com.opensymphony.xwork2.util.location.Located;
-import com.opensymphony.xwork2.util.location.LocationUtils;
-
-import java.util.LinkedHashMap;
-
-/**
- * Attaches location information to the factory.
- */
-public class LocatableFactory<T> extends Located implements Factory<T> {
-
-    volatile ContainerImpl.ConstructorInjector<? extends T> constructor;
-    private Class implementation;
-    private Class type;
-    private String name;
-    private Scope scope;
-
-    public LocatableFactory(String name, Class type, Class implementation, Scope scope, Object location) {
-        this.implementation = implementation;
-        this.type = type;
-        this.name = name;
-        this.scope = scope;
-        setLocation(LocationUtils.getLocation(location));
-    }
-
-    @SuppressWarnings("unchecked")
-    public T create(Context context) {
-        if (constructor == null) {
-            this.constructor =
-                    ((ContainerImpl)context.getContainer()).getConstructor(implementation);
-        }
-        InternalContext ctx = new InternalContext((ContainerImpl) context.getContainer());
-        ctx.setExternalContext((ExternalContext)context);
-        return (T) constructor.construct(ctx, type);
-    }
-
-    public String toString() {
-        String fields = new LinkedHashMap<String, Object>() {
-            {
-                put("type", type);
-                put("name", name);
-                put("implementation", implementation);
-                put("scope", scope);
-            }
-        }.toString();
-        StringBuilder sb = new StringBuilder(fields);
-        sb.append(super.toString());
-        sb.append(" defined at ");
-        sb.append(getLocation().toString());
-        return sb.toString();
-    }
-}