Managing the JBossXB/JAXB namespace object factories
starksm64 Dec 19, 2004 12:49 PMSo Alexey has resolved the coupling between namespaces and their type discussed here:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=57861
Now there is an issue with user of the JBossXB framework needing to know all of the namespace to object factory mappings. The current example of this issue is the JAAS login configuration parser needing to know all of the possible namespace to object factory mappings for the module-option injection point in the schema. Here is an example document that illustrates how the policy/application-policy/authentication/login-module/module-option element can have a model that is a function of the login-module code:
<?xml version="1.0" encoding="UTF-8"?> <!-- A login-config.xml example that uses the extended schema and jbossxb to marshall non-trival module-options. --> <policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.jboss.org/j2ee/schema/jaas" targetNamespace="http://www.jboss.org/j2ee/schema/jaas" > <application-policy name="testXMLLoginModule"> <authentication> <login-module code="org.jboss.security.auth.spi.XMLLoginModule" flag="required"> <module-option name="userInfo"> <lm:users xmlns:lm="http://www.jboss.org/j2ee/schemas/XMLLoginModule"> <lm:user name="jduke" password="theduke"> <lm:role name="Role1"/> <lm:role name="Role2"/> <lm:role name="Echo"/> <lm:role name="callerJduke" group="CallerPrincipal" /> </lm:user> <lm:user name="scott" password="echoman"> <lm:role name="Echo"/> <lm:role name="ProjectUser"/> <lm:role name="callerScott" group="CallerPrincipal" /> </lm:user> <lm:user name="stark" password="javaman"> <lm:role name="Java"/> <lm:role name="Coder"/> <lm:role name="callerStark" group="CallerPrincipal" /> </lm:user> <lm:user name="jdukeman" password="anotherduke"> <lm:role name="Role2"/> <lm:role name="Role3"/> <lm:role name="callerJdukeman" group="CallerPrincipal" /> </lm:user> <lm:user name="invoker" password="invoker"> <lm:role name="HttpInvoker"/> </lm:user> <lm:user name="admin" password="admin"> <lm:role name="JBossAdmin"/> </lm:user> </lm:users> </module-option> <module-option name="unauthenticatedIdentity">guest</module-option> </login-module> </authentication> </application-policy> </policy>
The schema for the module-option element uses a mixed content model with a schema wildcard component:
<xs:element name="module-option"> <xs:annotation> <xs:documentation>A module option defines a name, value pair that are passed to a LoginModule when it is initialized during the login proceedure. The name attribute defines the option name while the element value is the option value. The type of the value can be anything from a string obtained from the module-option body, to arbitary objects unmarshalled based on the namespace associated with the module-option child element.</xs:documentation> </xs:annotation> <xs:complexType mixed="true"> <xs:sequence> <xs:any namespace="##any"/> </xs:sequence> <xs:attribute name="name" use="required" type="xs:NCName"> <xs:annotation> <xs:documentation>The module option name. This is the key used to store the module value in the LoginModule initalize options Map.</xs:documentation> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element>
Since the new namespace requiring the custom object factory is showing up at the document instance level, its here that namespace object factory should be defined. I could add an attribute for the object factory to the login-module element, but this would couple the login module parser configuration too tightly to the marshalling implementation.
JAXB 1.0 punted on this issue. Is JAXB 2.0 suggesting a way to deal with wildcard schema? It seems that the inline <xs:annotation><xs:appinfo>...</xs:appinfo></xs:annotation> approach used by JAXB 1.0 would be a comprimise way to let the binding framework know how to deal with the content.
Does this same problem manifest in the web services marshalling layer or are wildcards disallowed?