geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r512986 - /geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
Date Wed, 28 Feb 2007 21:34:37 GMT
Author: djencks
Date: Wed Feb 28 13:34:36 2007
New Revision: 512986

URL: http://svn.apache.org/viewvc?view=rev&rev=512986
Log:
XBEAN-79 additional method on ObjectRecipe for setting static fields

Modified:
    geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java

Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java?view=diff&rev=512986&r1=512985&r2=512986
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
Wed Feb 28 13:34:36 2007
@@ -195,17 +195,7 @@
         }
         Object instance = result;
 
-        boolean allowPrivate = options.contains(Option.PRIVATE_PROPERTIES);
-        boolean ignoreMissingProperties = options.contains(Option.IGNORE_MISSING_PROPERTIES);
-
-        // set remaining properties
-        for (Map.Entry<Property, Object> entry : RecipeHelper.prioritizeProperties(propertyValues))
{
-            Property propertyName = entry.getKey();
-            Object propertyValue = entry.getValue();
-
-            setProperty(instance, propertyName, propertyValue, allowPrivate, ignoreMissingProperties,
classLoader);
-        }
-
+        setProperties(propertyValues, instance, classLoader);
         // call instance factory method
         if (factoryMethod != null && !Modifier.isStatic(factoryMethod.getModifiers()))
{
             try {
@@ -223,6 +213,44 @@
         }
 
         return instance;
+    }
+    
+    public Class setStaticProperties(ClassLoader classLoader) throws ConstructionException
{
+        unsetProperties.clear();
+        // load the type class
+        Class typeClass = getType(classLoader);
+
+        // verify that it is a class we can construct
+        if (!Modifier.isPublic(typeClass.getModifiers())) {
+            throw new ConstructionException("Class is not public: " + typeClass.getName());
+        }
+        if (Modifier.isInterface(typeClass.getModifiers())) {
+            throw new ConstructionException("Class is an interface: " + typeClass.getName());
+        }
+        if (Modifier.isAbstract(typeClass.getModifiers())) {
+            throw new ConstructionException("Class is abstract: " + typeClass.getName());
+        }
+
+        // clone the properties so they can be used again
+        Map<Property,Object> propertyValues = new LinkedHashMap<Property,Object>(properties);
+
+        setProperties(propertyValues, null, classLoader);
+
+        return typeClass;
+    }
+
+    private void setProperties(Map<Property, Object> propertyValues, Object instance,
ClassLoader classLoader) {
+        boolean allowPrivate = options.contains(Option.PRIVATE_PROPERTIES);
+        boolean ignoreMissingProperties = options.contains(Option.IGNORE_MISSING_PROPERTIES);
+
+        // set remaining properties
+        for (Map.Entry<Property, Object> entry : RecipeHelper.prioritizeProperties(propertyValues))
{
+            Property propertyName = entry.getKey();
+            Object propertyValue = entry.getValue();
+
+            setProperty(instance, propertyName, propertyValue, allowPrivate, ignoreMissingProperties,
classLoader);
+        }
+
     }
 
     private Class getType(ClassLoader classLoader) {



Mime
View raw message