Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring XML namespaces : How do I find what are the implementing classes behind them?

In my Spring 3.1 application, I sometime need to change the default behavior of some of the Spring namespaces in my context files. To do that, I create custom classes that implement some interfaces or that extend the default classes Spring uses.

But I find it hard to know exactly what are those classes that Spring uses behind its namespaces! What is the steps required to find them?

For example, the security namespace :

<beans xmlns="http://www.springframework.org/schema/beans"        xmlns:sec="http://www.springframework.org/schema/security"        xsi:schemaLocation="http://www.springframework.org/schema/beans                             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd                            http://www.springframework.org/schema/security                             http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

and something like :

<sec:http>     ...     <sec:logout /> </sec:http> 

How do I find what classes are used by the "<sec:logout />" namespace? I don't find the information by looking at http://www.springframework.org/schema/security/spring-security-3.1.xsd !

Where should I look?

like image 948
electrotype Avatar asked Jun 24 '12 01:06

electrotype


People also ask

How are XML namespaces implemented?

XML Namespaces - The xmlns Attribute When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".

What is namespaces in XML spring?

So, the spring tx namespace is merely a way of identifying things which "belong to" Spring Transactions in an XML configuration document. Visiting the URL of the Spring TX namespace leads you to XML Schemas (rules for what elements, attributes, and values you can have) for the various versions of Spring Transactions.

How do XML namespaces work?

An XML namespace is a collection of names that can be used as element or attribute names in an XML document. The namespace qualifies element names uniquely on the Web in order to avoid conflicts between elements with the same name.

What are namespaces and how they are declared?

A Namespace is a set of unique names. Namespace is a mechanisms by which element and attribute name can be assigned to a group. The Namespace is identified by URI(Uniform Resource Identifiers).


1 Answers

Every Spring namespace has an associated NamespaceHandler implementation. The namespace schemas are mapped to schema files inside Spring JARs in various spring.schemas files (see also Spring DI applicationContext.xml how exactly is xsi:schemaLocation used?).

The XML schema namespaces are also mapped to handler classes in spring.handlers files (several as each Spring JAR might introduce different namespaces). For your convenience here is a list of most common namespaces:

Spring core

  • aop - AopNamespaceHandler
  • c - SimpleConstructorNamespaceHandler
  • cache - CacheNamespaceHandler
  • context - ContextNamespaceHandler
  • jdbc - JdbcNamespaceHandler
  • jee - JeeNamespaceHandler
  • jms - JmsNamespaceHandler
  • lang - LangNamespaceHandler
  • mvc - MvcNamespaceHandler
  • oxm - OxmNamespaceHandler
  • p - SimplePropertyNamespaceHandler
  • task - TaskNamespaceHandler
  • tx - TxNamespaceHandler
  • util - UtilNamespaceHandler

Spring Security

  • security - SecurityNamespaceHandler
  • oauth - OAuthSecurityNamespaceHandler

Spring integration

  • int - IntegrationNamespaceHandler
  • amqp - AmqpNamespaceHandler
  • event - EventNamespaceHandler
  • feed - FeedNamespaceHandler
  • file - FileNamespaceHandler
  • ftp - FtpNamespaceHandler
  • gemfire - GemfireIntegrationNamespaceHandler
  • groovy - GroovyNamespaceHandler
  • http - HttpNamespaceHandler
  • ip - IpNamespaceHandler
  • jdbc - JdbcNamespaceHandler
  • jms - JmsNamespaceHandler
  • jmx - JmxNamespaceHandler
  • mail - MailNamespaceHandler
  • redis - RedisNamespaceHandler
  • rmi - RmiNamespaceHandler
  • script - ScriptNamespaceHandler
  • security - IntegrationSecurityNamespaceHandler
  • sftp - SftpNamespaceHandler
  • stream - StreamNamespaceHandler
  • twitter - TwitterNamespaceHandler
  • ws - WsNamespaceHandler
  • xml - IntegrationXmlNamespaceHandler
  • xmpp - XmppNamespaceHandler

If you browse to the source of each of these classes you will quickly discover various BeanDefinitionParser implementations responsible for parsing actual XML definitions.

like image 58
Tomasz Nurkiewicz Avatar answered Sep 20 '22 08:09

Tomasz Nurkiewicz