Getting content of XML element
kabirkhan Nov 20, 2007 1:36 PMCan somebody please tell me how to get the contents of the annotation? i.e. I want: @org.jboss.test.microcontainer.beans2.Annotation1. It does not appear to be accessible from any of the things passed in to the methods of AnnotationOverrideHandler?
Also, for a similar schenario I will need to construct a org.w3c.dom.Element from the nested contents of a element. Is that possible?
Schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:jboss:aop-beans:1.0" xmlns="urn:jboss:aop-beans:1.0" xmlns:mc="urn:jboss:bean-deployer:2.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" > ... <xsd:element name="annotation" type="annotationType"> <xsd:annotation> <xsd:documentation> <![CDATA[ A annotation override ]]> </xsd:documentation> </xsd:annotation> </xsd:element> <xsd:complexType name="annotationType"> <xsd:annotation> <xsd:documentation> <![CDATA[ A annotation override ]]> </xsd:documentation> </xsd:annotation> <xsd:complexContent> <xsd:attribute name="expr" type="xsd:string" use="required"/> <xsd:attribute name="invisible" type="xsd:string" use="required"/> </xsd:complexContent> </xsd:complexType> </xsd:schema>
XML:
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="urn:jboss:bean-deployer:2.0"> ... <annotation xmlns="urn:jboss:aop-beans:1.0" expr="class(org.jboss.test.microcontainer.beans2.POJO)" invisible="false"> @org.jboss.test.microcontainer.beans2.Annotation1 </annotation> ... </deployment>
SchemaBindingIntitializer:
public class AOPBeansSchemaInitializer implements SchemaBindingInitializer { ... private static final QName annotationTypeQName = new QName(AOP_BEANS_NS, "annotationType"); TypeBinding type = schema.getType(annotationTypeQName); type.setHandler(AnnotationOverrideHandler.HANDLER); //type.pushInterceptor(annotationQName, AnnotationContentInterceptor.INTERCEPTOR); .... private static class AnnotationOverrideHandler extends DefaultElementHandler { public static final AnnotationOverrideHandler HANDLER = new AnnotationOverrideHandler(); @Override public Object startElement(Object parent, QName name, ElementBinding element) { return new AbstractBeanMetaData(AnnotationOverride.class.getName()); } @Override public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) { AspectBeanMetaDataUtil util = new AspectBeanMetaDataUtil(); AbstractBeanMetaData pointcut = (AbstractBeanMetaData)o; for (int i = 0; i < attrs.getLength(); ++i) { .... } } @Override public Object endElement(Object o, QName name, ElementBinding element) { return super.endElement(o, name, element); } } private static class AnnotationContentInterceptor extends DefaultElementInterceptor { public static final AnnotationContentInterceptor INTERCEPTOR = new AnnotationContentInterceptor(); @Override public void add (Object parent, Object child, QName name) { System.out.println("-----------> " + child); } } }