Nick (gagravarr) wrote,
Nick
gagravarr

Spring in a QName

This post was originally written in September 2010, and was available at http://blogs.alfresco.com/wp/nickb/2010/09/28/spring-in-a-qname/ - I have reposted it here as that blog is no longer online.

Within Alfresco, we make a lot of use of Qualified Names (QNames) for addressing and naming things. Generally, when configuring Alfresco through Spring or properties files, we can use the short form, eg

<bean id="coreBean" class="org.alfresco.some.thing.core">
  <property name="typeQName">
    <value>cm:description</value>
  </property>
</bean>

Within the bean, the NamespaceResolver is used to turn the friendly, short form (eg cm:description) into the full form (eg {http://www.alfresco.org/model/content/1.0}description).

However, every so often you may find yourself trying to configure something with Spring that no-one ever expected you to be trying to do… In this situation, the string form isn’t accepted by the class, and only a real QName object may be sprung in.

As it turns out, creating a real QName object from within Spring isn’t actually too hard to do. So, in case you ever find yourself needing to do it, the definition will look something like this:

<bean id="coreBean" class="org.alfresco.some.thing.core">
  <property name="typeQName">
    <value>
      <bean class="org.alfresco.service.namespace.QName"
              factory-method="createQName">
        <constructor-arg value="http://www.alfresco.org/model/content/1.0" />
        <constructor-arg value="description"/>
      </bean>
    </value>
  </property>
</bean>

Tags: alfresco, spring
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments