geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r392099 - in /geronimo/branches/1.1/modules: security/src/java/org/apache/geronimo/security/jaas/ service-builder/src/java/org/apache/geronimo/deployment/service/ service-builder/src/test/org/apache/geronimo/deployment/service/
Date Thu, 06 Apr 2006 22:31:26 GMT
Author: djencks
Date: Thu Apr  6 15:31:23 2006
New Revision: 392099

URL: http://svn.apache.org/viewcvs?rev=392099&view=rev
Log:
Make EnvironmentBuilder into a PropertyEditor.  Simplify LoginModuleGBean slightly.

Added:
    geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java
  (contents, props changed)
      - copied, changed from r391971, geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ParentIDTest.java
Removed:
    geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ParentIDTest.java
Modified:
    geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/LoginModuleGBean.java
    geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/EnvironmentBuilder.java
    geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java

Modified: geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/LoginModuleGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/LoginModuleGBean.java?rev=392099&r1=392098&r2=392099&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/LoginModuleGBean.java
(original)
+++ geronimo/branches/1.1/modules/security/src/java/org/apache/geronimo/security/jaas/LoginModuleGBean.java
Thu Apr  6 15:31:23 2006
@@ -41,11 +41,6 @@
     private boolean wrapPrincipals;
     private final ClassLoader classLoader;
 
-    public LoginModuleGBean() {
-        classLoader = null;
-        objectName = null;
-    }
-
     public LoginModuleGBean(String loginModuleClass, String objectName, boolean serverSide,
boolean wrapPrincipals, ClassLoader classLoader) {
         this.loginModuleClass = loginModuleClass;
         this.objectName = objectName;
@@ -106,14 +101,8 @@
 
     static {
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(LoginModuleGBean.class,
NameFactory.LOGIN_MODULE);
-        infoFactory.addAttribute("options", Properties.class, true);
-        infoFactory.addAttribute("loginModuleClass", String.class, true);
-        infoFactory.addAttribute("objectName", String.class, false);
-        infoFactory.addAttribute("serverSide", boolean.class, true);
-        infoFactory.addAttribute("loginDomainName", String.class, true);
-        infoFactory.addAttribute("wrapPrincipals", boolean.class, true);
         infoFactory.addAttribute("classLoader", ClassLoader.class, false);
-        infoFactory.addInterface(LoginModuleSettings.class);
+        infoFactory.addInterface(LoginModuleSettings.class, new String[] {"options", "loginModuleClass",
"serverSide", "loginDomainName", "wrapPrincipals"});
         infoFactory.setConstructor(new String[]{"loginModuleClass", "objectName", "serverSide",
"wrapPrincipals", "classLoader"});
 
         GBEAN_INFO = infoFactory.getBeanInfo();

Modified: geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/EnvironmentBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/EnvironmentBuilder.java?rev=392099&r1=392098&r2=392099&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/EnvironmentBuilder.java
(original)
+++ geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/EnvironmentBuilder.java
Thu Apr  6 15:31:23 2006
@@ -17,6 +17,7 @@
 
 package org.apache.geronimo.deployment.service;
 
+import java.beans.PropertyEditorSupport;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -25,7 +26,10 @@
 import java.util.List;
 import java.util.Set;
 
+import javax.xml.namespace.QName;
+
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.common.propertyeditor.PropertyEditorException;
 import org.apache.geronimo.deployment.xbeans.ArtifactType;
 import org.apache.geronimo.deployment.xbeans.ClassFilterType;
 import org.apache.geronimo.deployment.xbeans.DependenciesType;
@@ -42,9 +46,9 @@
 /**
  * @version $Rev:$ $Date:$
  */
-public class EnvironmentBuilder implements XmlAttributeBuilder {
-    private final static String NAMESPACE = EnvironmentDocument.type.getDocumentElementName().getNamespaceURI();
-
+public class EnvironmentBuilder extends PropertyEditorSupport implements XmlAttributeBuilder
{
+    private final static QName QNAME = EnvironmentDocument.type.getDocumentElementName();
+    private final static String NAMESPACE = QNAME.getNamespaceURI();
 
     public static Environment buildEnvironment(EnvironmentType environmentType) {
         Environment environment = new Environment();
@@ -70,7 +74,7 @@
     public static void mergeEnvironments(Environment environment, Environment additionalEnvironment)
{
         if (additionalEnvironment != null) {
             //TODO merge configIds??
-            if (environment.getConfigId() == null){
+            if (environment.getConfigId() == null) {
                 environment.setConfigId(additionalEnvironment.getConfigId());
             }
             environment.addDependencies(additionalEnvironment.getDependencies());
@@ -89,8 +93,10 @@
 
     public static EnvironmentType buildEnvironmentType(Environment environment) {
         EnvironmentType environmentType = EnvironmentType.Factory.newInstance();
-        ArtifactType configId = toArtifactType(environment.getConfigId());
-        environmentType.setConfigId(configId);
+        if (environmentType.isSetConfigId()) {
+            ArtifactType configId = toArtifactType(environment.getConfigId());
+            environmentType.setConfigId(configId);
+        }
 
         List dependencies = toArtifactTypes(environment.getDependencies());
         ArtifactType[] artifactTypes = (ArtifactType[]) dependencies.toArray(new ArtifactType[dependencies.size()]);
@@ -109,7 +115,7 @@
 
     private static ClassFilterType toFilterType(Set filters) {
         String[] classFilters = (String[]) filters.toArray(new String[filters.size()]);
-        ClassFilterType classFilter  = ClassFilterType.Factory.newInstance();
+        ClassFilterType classFilter = ClassFilterType.Factory.newInstance();
         classFilter.setFilterArray(classFilters);
         return classFilter;
     }
@@ -199,7 +205,7 @@
             throw new IllegalArgumentException("Unknown import type: " + artifactType.getImport());
         }
     }
-    
+
     //TODO make private
     static Artifact toArtifact(ArtifactType artifactType) {
         String groupId = artifactType.isSetGroupId() ? artifactType.getGroupId().trim() :
null;
@@ -236,6 +242,30 @@
 
         return buildEnvironment(environmentType);
     }
+
+    public String getAsText() {
+        Environment environment = (Environment) getValue();
+        EnvironmentType environmentType = buildEnvironmentType(environment);
+        XmlOptions xmlOptions = new XmlOptions();
+        xmlOptions.setSaveSyntheticDocumentElement(QNAME);
+        xmlOptions.setSavePrettyPrint();
+        return environmentType.xmlText(xmlOptions);
+    }
+
+    public void setAsText(String text) {
+        try {
+            EnvironmentDocument environmentDocument = EnvironmentDocument.Factory.parse(text);
+            EnvironmentType environmentType = environmentDocument.getEnvironment();
+            Environment environment = (Environment) getValue(environmentType, null, null);
+            setValue(environment);
+
+        } catch (XmlException e) {
+            throw new PropertyEditorException(e);
+        } catch (DeploymentException e) {
+            throw new PropertyEditorException(e);
+        }
+    }
+
 
     //This is added by hand to the xmlAttributeBuilders since it is needed to bootstrap the
ServiceConfigBuilder.
 }

Modified: geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java?rev=392099&r1=392098&r2=392099&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
(original)
+++ geronimo/branches/1.1/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
Thu Apr  6 15:31:23 2006
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Collections;
 import java.util.jar.JarFile;
+import java.beans.PropertyEditorManager;
 
 import javax.xml.namespace.QName;
 
@@ -90,6 +91,7 @@
         this.naming = naming;
         EnvironmentBuilder environmentBuilder = new EnvironmentBuilder();
         xmlAttributeBuilderMap.put(environmentBuilder.getNamespace(), environmentBuilder);
+        //cf registering EnvironmentBuilder as a property editor in the static gbeaninfo
block.
         this.defaultEnvironment = defaultEnvironment;
 
         this.repositories = repositories;
@@ -268,6 +270,8 @@
     public static final GBeanInfo GBEAN_INFO;
 
     static {
+        PropertyEditorManager.registerEditor(Environment.class, EnvironmentBuilder.class);
+
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ServiceConfigBuilder.class,
NameFactory.CONFIG_BUILDER);
 
         infoFactory.addInterface(ConfigurationBuilder.class);

Copied: geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java
(from r391971, geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ParentIDTest.java)
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java?p2=geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java&p1=geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ParentIDTest.java&r1=391971&r2=392099&rev=392099&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ParentIDTest.java
(original)
+++ geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java
Thu Apr  6 15:31:23 2006
@@ -17,15 +17,18 @@
 package org.apache.geronimo.deployment.service;
 
 import java.util.LinkedHashSet;
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
 
 import junit.framework.TestCase;
 import org.apache.geronimo.deployment.xbeans.ArtifactType;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Environment;
 
 /**
  * @version $Rev$ $Date$
  */
-public class ParentIDTest extends TestCase {
+public class EnvironmentBuilderTest extends TestCase {
 
     public void testNoParents() throws Exception {
         LinkedHashSet parentId = EnvironmentBuilder.toArtifacts(new ArtifactType[] {});
@@ -43,4 +46,31 @@
         assertEquals("groupId/artifactId/version/type", ((Artifact)parentId.iterator().next()).toURI().getPath());
     }
 
+    private static final String ENV_1 = "<dep:environment xmlns:dep=\"http://geronimo.apache.org/xml/ns/deployment-1.1\">\n"
+
+            "  <dep:dependencies>\n" +
+            "    <dep:dependency>\n" +
+            "      <dep:groupId>${pom.groupId}</dep:groupId>\n" +
+            "      <dep:artifactId>j2ee-server</dep:artifactId>\n" +
+            "      <dep:version>${pom.currentVersion}</dep:version>\n" +
+            "      <dep:type>car</dep:type>\n" +
+            "    </dep:dependency>\n" +
+            "  </dep:dependencies>\n" +
+            "  <dep:hidden-classes/>\n" +
+            "  <dep:non-overridable-classes/>\n" +
+            "</dep:environment>";
+
+    public void testPropertyEditor() throws Exception {
+        PropertyEditor editor = new EnvironmentBuilder();
+        editor.setAsText(ENV_1);
+        Environment environment = (Environment) editor.getValue();
+        editor.setValue(environment);
+        String text = editor.getAsText();
+        assertEquals(text, ENV_1);
+    }
+
+    public void testPropertyEditorRegistration() throws Exception {
+        ServiceConfigBuilder.getGBeanInfo();
+        PropertyEditor propertyEditor = PropertyEditorManager.findEditor(Environment.class);
+        assertTrue(propertyEditor instanceof EnvironmentBuilder);
+    }
 }

Propchange: geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/branches/1.1/modules/service-builder/src/test/org/apache/geronimo/deployment/service/EnvironmentBuilderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message