4 Replies Latest reply: Dec 15, 2010 8:42 AM by Alexey Loubyansky RSS

Disable system property replacement in a specific xml file

jaikiran pai Master

Consider the following ejb-jar.xml snippet:

<env-entry>
   <env-entry-name>Dummy</env-entry-name>
   <env-entry-value>${java.home}</env-entry-value>
</env-entry>

 

 

By default, JBoss XB replaces ${java.home} with the value set as a System property. Is there a way, I can disable this replacement for a specific file (ejb-jar.xml in this case)?  By the way, I'm trying this against AS trunk.

  • 1. Re: Disable system property replacement in a specific xml file
    Alexey Loubyansky Master

    It can be done per SchemaBinding. E.g.

    @JBossXmlSchema(replacePropertyRefs=false)
    public class Root {...

  • 2. Re: Disable system property replacement in a specific xml file
    jaikiran pai Master

    Does that mean we can't configure it in a runtime? For example, if we wanted to disable this for ejb-jar.xml in "all" profile and allow it for ejb-jar.xml in "default" profile which share the same schema binding classes.

  • 3. Re: Disable system property replacement in a specific xml file
    Alexey Loubyansky Master

    In the AS runtime - no, we can't. There is no deployer configuration option for it.

    From the XB point of view, it's a property of SchemaBinding, so it's possible. What complicates this in the AS is that SchemaBinding's aren't directly passed to the unmarshaller. Instead SchemaResolver is responsible for providing (building & caching) SchemaBinding's *during* unmarshalling and it doesn't modify their properties initialized from annotations.

    A dirty workaround would be to get the resolver in the parsing deployer, ask it to resolve the SchemaBinding and change its property.

  • 4. Re: Disable system property replacement in a specific xml file
    Alexey Loubyansky Master

    With the addition of a new property "Map<String, SchemaBindingInitializer> schemaInitializerInstances" to SchemaResolverConfig (I'd need to make another release of xb of that), this could be done by registering a SchemaBindingInitializer that would modify the properties (initialized with metadata annotations) of the just built SchemaBinding object, e.g.

     

    public class SchemaBindingPropertyInitializer implements SchemaBindingInitializer
    {
       private boolean replacePropertyRefs;
    
       public boolean isReplaceProperyRefs()
       {
          return replacePropertyRefs;
       }
    
       public void setReplacePropertyRefs(boolean replacePropertyRefs)
       {
          this.replacePropertyRefs = replacePropertyRefs;
       }
    
       public SchemaBinding init(SchemaBinding schema)
       {
          schema.setReplacePropertyRefs(replacePropertyRefs);
          return schema;
       }
    }

     

     

    Then in metadata-deployer-jboss-beans.xml we'll need to add schemaInitializerInstances property in SchemaResolverConfig like

     

    <bean name="SchemaResolverConfig"
          class="org.jboss.xb.binding.sunday.unmarshalling.SchemaResolverConfig">
    
          <property name="schemaInitializerInstances">
             <map keyClass="java.lang.String" valueClass="java.lang.String">
                <entry>
                   <key>http://java.sun.com/xml/ns/javaee</key>
                   <value>
                      <bean class="org.jboss.xb.util.SchemaBindingPropertyInitializer">
                         <property name="replacePropertyRefs">true</property>
                      </bean>
                   </value>
                </entry>
             </map>
          </property>
          ...
    

     

     

    Note, that with this configuration every schema with target namespace javaee is going to be affected.

     

    What do you think about this? Note, I am not sure SchemaBindingPropertyInitializer should reside in the XB codebase...