geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r165466 - /geronimo/trunk/modules/security-builder /geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment /geronimo/trunk/modules/security-builder/src/schema /geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service /geronimo/trunk/modules/service-builder/src/schema /geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service
Date Sun, 01 May 2005 07:11:28 GMT
Author: djencks
Date: Sun May  1 00:11:27 2005
New Revision: 165466

URL: http://svn.apache.org/viewcvs?rev=165466&view=rev
Log:
xml reference builder concept and example as login configuration builder

Added:
    geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/LoginConfigBuilder.java
    geronimo/trunk/modules/security-builder/src/schema/geronimo-login-config.xsd
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlReferenceBuilder.java
Modified:
    geronimo/trunk/modules/security-builder/maven.xml
    geronimo/trunk/modules/security-builder/project.xml
    geronimo/trunk/modules/security-builder/src/schema/xmlconfig.xml
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
    geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd
    geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java

Modified: geronimo/trunk/modules/security-builder/maven.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security-builder/maven.xml?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/security-builder/maven.xml (original)
+++ geronimo/trunk/modules/security-builder/maven.xml Sun May  1 00:11:27 2005
@@ -6,16 +6,16 @@
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
-  
+
        http://www.apache.org/licenses/LICENSE-2.0
-  
+
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-  
+
 
 <!-- $Rev$ $Date$ -->
 
@@ -32,7 +32,7 @@
     <preGoal name="java:compile">
         <xmlbeans:schema2java
             sourcedir="${basedir}/src"
-            sourceschema="schema/geronimo-security.xsd"
+            sourceschema="schema/geronimo-security.xsd,schema/geronimo-login-config.xsd"
             xmlconfigs="${basedir}/src/schema/xmlconfig.xml"
             targetdir="${basedir}/target/xmlbeans"
             cataloglocation="${basedir}/../j2ee-schema/src/catalog/resolver-catalog.xml"/>

Modified: geronimo/trunk/modules/security-builder/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security-builder/project.xml?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/security-builder/project.xml (original)
+++ geronimo/trunk/modules/security-builder/project.xml Sun May  1 00:11:27 2005
@@ -6,16 +6,16 @@
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
-  
+
        http://www.apache.org/licenses/LICENSE-2.0
-  
+
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-  
+
 <!-- $Rev$ $Date$ -->
 
 <project>
@@ -61,7 +61,19 @@
              <version>${pom.currentVersion}</version>
        </dependency>
 
-       <!--needed only because security schema references j2ee 1.4 schema for description
element --> 
+        <dependency>
+             <groupId>geronimo</groupId>
+             <artifactId>geronimo-deployment</artifactId>
+             <version>${pom.currentVersion}</version>
+       </dependency>
+
+         <dependency>
+             <groupId>geronimo</groupId>
+             <artifactId>geronimo-service-builder</artifactId>
+             <version>${pom.currentVersion}</version>
+       </dependency>
+
+       <!--needed only because security schema references j2ee 1.4 schema for description
element -->
        <dependency>
              <groupId>geronimo</groupId>
              <artifactId>geronimo-j2ee-schema</artifactId>

Added: geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/LoginConfigBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/LoginConfigBuilder.java?rev=165466&view=auto
==============================================================================
--- geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/LoginConfigBuilder.java
(added)
+++ geronimo/trunk/modules/security-builder/src/java/org/apache/geronimo/security/deployment/LoginConfigBuilder.java
Sun May  1 00:11:27 2005
@@ -0,0 +1,160 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.security.deployment;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.Set;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.deployment.service.XmlReferenceBuilder;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
+import org.apache.geronimo.security.jaas.LoginModuleGBean;
+import org.apache.geronimo.xbeans.geronimo.loginconfig.GerAbstractLoginModuleType;
+import org.apache.geronimo.xbeans.geronimo.loginconfig.GerLoginConfigType;
+import org.apache.geronimo.xbeans.geronimo.loginconfig.GerLoginModuleRefType;
+import org.apache.geronimo.xbeans.geronimo.loginconfig.GerLoginModuleType;
+import org.apache.geronimo.xbeans.geronimo.loginconfig.GerOptionType;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class LoginConfigBuilder implements XmlReferenceBuilder {
+    public static final String LOGIN_CONFIG_NAMESPACE = "http://geronimo.apache.org/xml/ns/loginconfig";
+
+    public String getNamespace() {
+        return LOGIN_CONFIG_NAMESPACE;
+    }
+
+    public Set getReferences(XmlObject xmlObject, DeploymentContext context, J2eeContext
j2eeContext, ClassLoader classLoader) throws DeploymentException {
+        GerLoginConfigType loginConfig = (GerLoginConfigType) xmlObject.copy().changeType(GerLoginConfigType.type);
+        XmlOptions xmlOptions = new XmlOptions();
+        xmlOptions.setLoadLineNumbers();
+        Collection errors = new ArrayList();
+        xmlOptions.setErrorListener(errors);
+        if (!loginConfig.validate(xmlOptions)) {
+            throw new DeploymentException("Invalid login configuration:\n" + errors + "\nDescriptor:
" + loginConfig.toString());
+        }
+        XmlCursor xmlCursor = loginConfig.newCursor();
+        ObjectName nextName = null;
+        try {
+            boolean atStart = true;
+            while ((atStart && xmlCursor.toFirstChild()) || (!atStart &&
xmlCursor.toNextSibling())) {
+                atStart = false;
+                XmlObject child = xmlCursor.getObject();
+                GerAbstractLoginModuleType abstractLoginModule = (GerAbstractLoginModuleType)
child;
+                String controlFlag = abstractLoginModule.getControlFlag().toString();
+                ObjectName loginModuleName;
+                String name;
+                if (abstractLoginModule instanceof GerLoginModuleRefType) {
+                    GerLoginModuleRefType loginModuleRef = (GerLoginModuleRefType) abstractLoginModule;
+                    String domain = trim(loginModuleRef.getDomain());
+                    String server = trim(loginModuleRef.getServer());
+                    String application = trim(loginModuleRef.getApplication());
+                    String module = trim(loginModuleRef.getModule());
+                    String type = trim(loginModuleRef.getType());
+                    if (type == null) {
+                        type = NameFactory.LOGIN_MODULE;
+                    }
+                    name = trim(loginModuleRef.getName());
+                    try {
+                        loginModuleName = NameFactory.getComponentName(domain, server, application,
module, name, type, j2eeContext);
+                    } catch (MalformedObjectNameException e) {
+                        throw new DeploymentException("cannot construct login module name
from parts,", e);
+                    }
+                } else if (abstractLoginModule instanceof GerLoginModuleType) {
+                    //create the LoginModuleGBean also
+                    name = null;
+                    loginModuleName = null;
+
+                    GerLoginModuleType loginModule = (GerLoginModuleType) abstractLoginModule;
+                    name = trim(loginModule.getLoginDomainName());
+                    String className = trim(loginModule.getLoginModuleClass());
+                    boolean serverSide = loginModule.getServerSide();
+                    Properties options = new Properties();
+                    GerOptionType[] optionArray = loginModule.getOptionArray();
+                    for (int j = 0; j < optionArray.length; j++) {
+                        GerOptionType gerOptionType = optionArray[j];
+                        String key = gerOptionType.getName();
+                        String value = trim(gerOptionType.getStringValue());
+                        options.setProperty(key, value);
+                    }
+                    try {
+                        loginModuleName = NameFactory.getComponentName(null, null, null,
null, name, NameFactory.LOGIN_MODULE, j2eeContext);
+                    } catch (MalformedObjectNameException e) {
+                        throw new DeploymentException("cannot construct login module use
name from parts,", e);
+                    }
+                    GBeanData loginModuleGBeanData = new GBeanData(loginModuleName, LoginModuleGBean.GBEAN_INFO);
+                    loginModuleGBeanData.setAttribute("loginDomainName", name);
+                    loginModuleGBeanData.setAttribute("loginModuleClass", className);
+                    loginModuleGBeanData.setAttribute("options", options);
+                    loginModuleGBeanData.setAttribute("serverSide", new Boolean(serverSide));
+
+                    context.addGBean(loginModuleGBeanData);
+                } else {
+                    throw new DeploymentException("Unknown abstract login module type: "
+ abstractLoginModule.getClass());
+                }
+                ObjectName thisName;
+                try {
+                    thisName = NameFactory.getComponentName(null, null, null, null, name,
"LoginModuleUse", j2eeContext);
+                } catch (MalformedObjectNameException e) {
+                    throw new DeploymentException("cannot construct login module use name
from parts,", e);
+                }
+                GBeanData loginModuleUseGBeanData = new GBeanData(thisName, JaasLoginModuleUse.GBEAN_INFO);
+                loginModuleUseGBeanData.setAttribute("controlFlag", controlFlag);
+                loginModuleUseGBeanData.setReferencePattern("LoginModule", loginModuleName);
+                if (nextName != null) {
+                    loginModuleUseGBeanData.setReferencePattern("Next", nextName);
+                }
+                context.addGBean(loginModuleUseGBeanData);
+                nextName = thisName;
+            }
+        } finally {
+            xmlCursor.dispose();
+        }
+        return Collections.singleton(nextName);
+    }
+
+    private String trim(String string) {
+        return string == null ? null : string.trim();
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(LoginConfigBuilder.class, "XmlReferenceBuilder");
+        infoBuilder.addInterface(XmlReferenceBuilder.class);
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Added: geronimo/trunk/modules/security-builder/src/schema/geronimo-login-config.xsd
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security-builder/src/schema/geronimo-login-config.xsd?rev=165466&view=auto
==============================================================================
--- geronimo/trunk/modules/security-builder/src/schema/geronimo-login-config.xsd (added)
+++ geronimo/trunk/modules/security-builder/src/schema/geronimo-login-config.xsd Sun May 
1 00:11:27 2005
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright 2005 The Apache Software Foundation
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<xsd:schema
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
+    xmlns:geronimo="http://geronimo.apache.org/xml/ns/loginconfig"
+    targetNamespace="http://geronimo.apache.org/xml/ns/loginconfig"
+    elementFormDefault="qualified"
+    attributeFormDefault="unqualified"
+    version="1.0">
+
+    <xsd:element name="login-config" type="geronimo:login-configType"/>
+
+    <xsd:complexType name="login-configType">
+        <xsd:annotation>
+            <xsd:documentation>
+                Defines the list of login modules for a login configuration represented by
a GenericSecurityRealm
+            </xsd:documentation>
+        </xsd:annotation>
+        <xsd:sequence>
+            <xsd:choice minOccurs="0" maxOccurs="unbounded">
+                <xsd:element name="login-module-ref" type="geronimo:login-module-refType"
minOccurs="0" maxOccurs="unbounded"/>
+                <xsd:element name="login-module" type="geronimo:login-moduleType" minOccurs="0"
maxOccurs="unbounded"/>
+            </xsd:choice>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="abstract-login-moduleType" abstract="true">
+        <xsd:attribute name="control-flag" type="geronimo:control-flagType" use="required"/>
+    </xsd:complexType>
+
+    <xsd:complexType name="login-module-refType">
+        <xsd:complexContent>
+            <xsd:extension base="geronimo:abstract-login-moduleType">
+                <xsd:sequence>
+                    <xsd:element name="domain" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="server" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="application" type="xsd:string" minOccurs="0"/>
+                    <!--                    <xsd:element name="moduleType" type="xsd:string"
minOccurs="0"/>-->
+                    <xsd:element name="module" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="type" type="xsd:string" minOccurs="0"/>
+                    <xsd:element name="name" type="xsd:string"/>
+                </xsd:sequence>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+
+    <xsd:simpleType name="control-flagType">
+        <xsd:restriction base="xsd:string">
+            <xsd:enumeration value="REQUIRED"/>
+            <xsd:enumeration value="REQUISITE"/>
+            <xsd:enumeration value="SUFFICIENT"/>
+            <xsd:enumeration value="OPTIONAL"/>
+        </xsd:restriction>
+    </xsd:simpleType>
+
+    <xsd:complexType name="login-moduleType">
+        <xsd:complexContent>
+            <xsd:extension base="geronimo:abstract-login-moduleType">
+                <xsd:sequence>
+                    <xsd:element name="login-domain-name" type="xsd:string"/>
+                    <xsd:element name="login-module-class" type="xsd:string"/>
+                    <xsd:element name="option" type="geronimo:optionType" minOccurs="0"
maxOccurs="unbounded"/>
+                </xsd:sequence>
+                <xsd:attribute name="server-side" type="xsd:boolean" use="required"/>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+
+    <xsd:complexType name="optionType">
+        <xsd:simpleContent>
+            <xsd:extension base="xsd:string">
+                <xsd:attribute name="name" type="xsd:string" use="required"/>
+            </xsd:extension>
+        </xsd:simpleContent>
+    </xsd:complexType>
+
+</xsd:schema>

Modified: geronimo/trunk/modules/security-builder/src/schema/xmlconfig.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security-builder/src/schema/xmlconfig.xml?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/security-builder/src/schema/xmlconfig.xml (original)
+++ geronimo/trunk/modules/security-builder/src/schema/xmlconfig.xml Sun May  1 00:11:27 2005
@@ -5,4 +5,9 @@
         <xb:prefix>Ger</xb:prefix>
     </xb:namespace>
 
+    <xb:namespace uri="http://geronimo.apache.org/xml/ns/loginconfig">
+        <xb:package>org.apache.geronimo.xbeans.geronimo.loginconfig</xb:package>
+        <xb:prefix>Ger</xb:prefix>
+    </xb:namespace>
+
 </xb:config>

Modified: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
(original)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
Sun May  1 00:11:27 2005
@@ -1,6 +1,6 @@
 /**
  *
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -19,24 +19,25 @@
 
 import java.beans.PropertyEditor;
 import java.util.HashSet;
-import java.util.Set;
-import java.util.Map;
 import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.common.propertyeditor.PropertyEditors;
+import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.deployment.xbeans.PatternType;
+import org.apache.geronimo.deployment.xbeans.ReferenceType;
 import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GReferenceInfo;
-import org.apache.geronimo.deployment.xbeans.ReferenceType;
-import org.apache.geronimo.deployment.xbeans.PatternType;
 import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
 
 /**
  *
@@ -46,13 +47,19 @@
 public class GBeanBuilder {
     private final GBeanData gbean;
     private final ClassLoader classLoader;
+    private final DeploymentContext context;
+    private final J2eeContext j2eeContext;
     private final Map xmlAttributeBuilderMap;
+    private final Map xmlReferenceBuilderMap;
 
-    GBeanBuilder(ObjectName objectName, GBeanInfo gBeanInfo, ClassLoader classLoader, Map
xmlAttributeBuilderMap) {
+    GBeanBuilder(ObjectName objectName, GBeanInfo gBeanInfo, ClassLoader classLoader, DeploymentContext
context, J2eeContext j2eeContext, Map xmlAttributeBuilderMap, Map xmlReferenceBuilderMap)
{
 
         this.classLoader = classLoader;
+        this.context = context;
+        this.j2eeContext = j2eeContext;
         this.gbean = new GBeanData(objectName, gBeanInfo);
         this.xmlAttributeBuilderMap = xmlAttributeBuilderMap;
+        this.xmlReferenceBuilderMap = xmlReferenceBuilderMap;
     }
 
     public void setAttribute(String name, String type, String text) throws DeploymentException
{
@@ -89,7 +96,7 @@
         String namespace = xmlCursor.getName().getNamespaceURI();
         XmlAttributeBuilder builder = (XmlAttributeBuilder) xmlAttributeBuilderMap.get(namespace);
         if (builder == null) {
-            throw new DeploymentException("No builder deployed for namespace: " + namespace);
+            throw new DeploymentException("No attribute builder deployed for namespace: "
+ namespace);
         }
         XmlObject xmlObject = xmlCursor.getObject();
         GAttributeInfo attribute = gbean.getGBeanInfo().getAttribute(name);
@@ -99,6 +106,19 @@
         String type = attribute.getType();
         Object value = builder.getValue(xmlObject, type, classLoader);
         gbean.setAttribute(name, value);
+    }
+
+    public void setXmlReference(String name, XmlCursor xmlCursor) throws DeploymentException
{
+        String namespace = xmlCursor.getName().getNamespaceURI();
+        XmlReferenceBuilder builder = (XmlReferenceBuilder) xmlReferenceBuilderMap.get(namespace);
+        if (builder == null) {
+            throw new DeploymentException("No reference builder deployed for namespace: "
+ namespace);
+        }
+        XmlObject xmlObject = xmlCursor.getObject();
+        Set references = builder.getReferences(xmlObject, context, j2eeContext, classLoader);
+        if (references != null && !references.isEmpty()) {
+            gbean.setReferencePatterns(name, references);
+        }
     }
 
     public void setReference(String name, ReferenceType pattern, J2eeContext j2eeContext)
throws DeploymentException {

Modified: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
(original)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
Sun May  1 00:11:27 2005
@@ -1,6 +1,6 @@
 /**
  *
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -76,14 +76,16 @@
 
     //TODO this being static is a really good argument that all other builders should have
a reference to this gbean, not use static methods on it.
     private static final Map xmlAttributeBuilderMap = new HashMap();
-    private Map refMap;
+    private static final Map xmlReferenceBuilderMap = new HashMap();
+    private Map attrRefMap;
+    private Map refRefMap;
     private static final QName SERVICE_QNAME = new QName("http://geronimo.apache.org/xml/ns/deployment",
"configuration");
 
     public ServiceConfigBuilder(URI defaultParentId, Repository repository) {
-        this(defaultParentId, repository, null, null);
+        this(defaultParentId, repository, null, null, null);
     }
 
-    public ServiceConfigBuilder(URI defaultParentId, Repository repository, Collection xmlAttributeBuilders,
Kernel kernel) {
+    public ServiceConfigBuilder(URI defaultParentId, Repository repository, Collection xmlAttributeBuilders,
Collection xmlReferenceBuilders, Kernel kernel) {
         this.defaultParentId = defaultParentId;
         this.repository = repository;
         this.kernel = kernel;
@@ -91,10 +93,19 @@
             ReferenceMap.Key key = new ReferenceMap.Key() {
 
                 public Object getKey(Object object) {
-                    return ((XmlAttributeBuilder)object).getNamespace();
+                    return ((XmlAttributeBuilder) object).getNamespace();
                 }
             };
-            refMap = new ReferenceMap(xmlAttributeBuilders, xmlAttributeBuilderMap, key);
+            attrRefMap = new ReferenceMap(xmlAttributeBuilders, xmlAttributeBuilderMap, key);
+        }
+        if (xmlReferenceBuilders != null) {
+            ReferenceMap.Key key = new ReferenceMap.Key() {
+
+                public Object getKey(Object object) {
+                    return ((XmlReferenceBuilder) object).getNamespace();
+                }
+            };
+            refRefMap = new ReferenceMap(xmlReferenceBuilders, xmlReferenceBuilderMap, key);
         }
     }
 
@@ -253,15 +264,12 @@
     }
 
     public static void addGBeans(GbeanType[] gbeans, ClassLoader cl, J2eeContext j2eeContext,
DeploymentContext context) throws DeploymentException {
-        Set result = new HashSet();
         for (int i = 0; i < gbeans.length; i++) {
-            GBeanData gBeanData = getGBeanData(gbeans[i], j2eeContext, cl);
-            context.addGBean(gBeanData);
-            result.add(gBeanData);
+            addGBeanData(gbeans[i], j2eeContext, cl, context);
         }
     }
 
-    public static GBeanData getGBeanData(GbeanType gbean, J2eeContext j2eeContext, ClassLoader
cl) throws DeploymentException {
+    public static ObjectName addGBeanData(GbeanType gbean, J2eeContext j2eeContext, ClassLoader
cl, DeploymentContext context) throws DeploymentException {
         GBeanInfo gBeanInfo = GBeanInfo.getGBeanInfo(gbean.getClass1(), cl);
         ObjectName objectName;
         if (gbean.isSetGbeanName()) {
@@ -280,7 +288,7 @@
                 throw new DeploymentException("Invalid ObjectName: " + namePart, e);
             }
         }
-        GBeanBuilder builder = new GBeanBuilder(objectName, gBeanInfo, cl, xmlAttributeBuilderMap);
+        GBeanBuilder builder = new GBeanBuilder(objectName, gBeanInfo, cl, context, j2eeContext,
xmlAttributeBuilderMap, xmlReferenceBuilderMap);
 
         // set up attributes
         AttributeType[] attributeArray = gbean.getAttributeArray();
@@ -321,8 +329,24 @@
             }
         }
 
+        XmlAttributeType[] xmlReferenceArray = gbean.getXmlReferenceArray();
+        if (xmlReferenceArray != null) {
+            for (int i = 0; i < xmlReferenceArray.length; i++) {
+                XmlAttributeType xmlAttributeType = xmlReferenceArray[i];
+                String name = xmlAttributeType.getName().trim();
+                XmlCursor xmlCursor = xmlAttributeType.newCursor();
+                try {
+                    xmlCursor.toFirstChild();
+                    builder.setXmlReference(name, xmlCursor);
+                } finally {
+                    xmlCursor.dispose();
+                }
+            }
+        }
+
         GBeanData gBeanData = builder.getGBeanData();
-        return gBeanData;
+        context.addGBean(gBeanData);
+        return objectName;
     }
 
     private static URI getDependencyURI(DependencyType dep, Repository repository) throws
DeploymentException {
@@ -358,9 +382,10 @@
         infoFactory.addAttribute("defaultParentId", URI.class, true);
         infoFactory.addReference("Repository", Repository.class, NameFactory.GERONIMO_SERVICE);
         infoFactory.addReference("XmlAttributeBuilders", XmlAttributeBuilder.class, "XmlAttributeBuilder");
+        infoFactory.addReference("XmlReferenceBuilders", XmlReferenceBuilder.class, "XmlReferenceBuilder");
         infoFactory.addAttribute("kernel", Kernel.class, false);
 
-        infoFactory.setConstructor(new String[]{"defaultParentId", "Repository", "XmlAttributeBuilders",
"kernel"});
+        infoFactory.setConstructor(new String[]{"defaultParentId", "Repository", "XmlAttributeBuilders",
"XmlReferenceBuilders", "kernel"});
 
         GBEAN_INFO = infoFactory.getBeanInfo();
     }

Added: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlReferenceBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlReferenceBuilder.java?rev=165466&view=auto
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlReferenceBuilder.java
(added)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlReferenceBuilder.java
Sun May  1 00:11:27 2005
@@ -0,0 +1,35 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.deployment.service;
+
+import java.util.Set;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public interface XmlReferenceBuilder {
+
+    String getNamespace();
+
+    Set getReferences(XmlObject xmlObject, DeploymentContext context, J2eeContext j2EEContext,
ClassLoader classLoader) throws DeploymentException;
+
+}

Modified: geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd (original)
+++ geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd Sun May  1 00:11:27
2005
@@ -6,9 +6,9 @@
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
-  
+
        http://www.apache.org/licenses/LICENSE-2.0
-  
+
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -73,6 +73,7 @@
             <xs:element name="xml-attribute" type="sys:xml-attributeType"/>
             <xs:element name="reference" type="sys:referenceType"/>
             <xs:element name="references" type="sys:referencesType"/>
+            <xs:element name="xml-reference" type="sys:xml-attributeType"/>
         </xs:choice>
         <xs:attribute name="gbeanName" type="xs:string"/>
         <xs:attribute name="name" type="xs:string"/>

Modified: geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java?rev=165466&r1=165465&r2=165466&view=diff
==============================================================================
--- geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
(original)
+++ geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
Sun May  1 00:11:27 2005
@@ -45,7 +45,7 @@
         JavaBeanXmlAttributeBuilder javaBeanXmlAttributeBuilder = new JavaBeanXmlAttributeBuilder();
         //this is kind of cheating, we rely on the builder to iterate through existing members
of the collection.
         referenceCollection.add(javaBeanXmlAttributeBuilder);
-        ServiceConfigBuilder builder = new ServiceConfigBuilder(URI.create("test/foo"), null,
referenceCollection, null);
+        ServiceConfigBuilder builder = new ServiceConfigBuilder(URI.create("test/foo"), null,
referenceCollection, null, null);
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         URL plan1 = cl.getResource("services/plan1.xml");
         ConfigurationDocument doc = ConfigurationDocument.Factory.parse(plan1);



Mime
View raw message