Return-Path: Delivered-To: apmail-geronimo-xbean-scm-archive@locus.apache.org Received: (qmail 60716 invoked from network); 28 Feb 2007 21:35:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Feb 2007 21:35:07 -0000 Received: (qmail 47334 invoked by uid 500); 28 Feb 2007 21:35:08 -0000 Delivered-To: apmail-geronimo-xbean-scm-archive@geronimo.apache.org Received: (qmail 47295 invoked by uid 500); 28 Feb 2007 21:35:07 -0000 Mailing-List: contact xbean-scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: xbean-scm@geronimo.apache.org Delivered-To: mailing list xbean-scm@geronimo.apache.org Received: (qmail 47242 invoked by uid 99); 28 Feb 2007 21:35:07 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Feb 2007 13:35:07 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Feb 2007 13:34:57 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id B7BC41A981A; Wed, 28 Feb 2007 13:34:37 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: xbean-scm@geronimo.apache.org From: djencks@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070228213437.B7BC41A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 propertyValues = new LinkedHashMap(properties); + + setProperties(propertyValues, null, classLoader); + + return typeClass; + } + + private void setProperties(Map 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 entry : RecipeHelper.prioritizeProperties(propertyValues)) { + Property propertyName = entry.getKey(); + Object propertyValue = entry.getValue(); + + setProperty(instance, propertyName, propertyValue, allowPrivate, ignoreMissingProperties, classLoader); + } + } private Class getType(ClassLoader classLoader) {