Search in sources :

Example 1 with XmlWriter

use of org.apache.aries.blueprint.plugin.spi.XmlWriter in project aries by apache.

the class InitContextExample method initContext.

@Override
public void initContext(ContextEnricher contextEnricher) {
    final Map<String, String> customParameters = contextEnricher.getBlueprintConfiguration().getCustomParameters();
    for (final String param : customParameters.keySet()) {
        if (param.startsWith("example.")) {
            final String key = param.split("\\.")[1];
            contextEnricher.addBlueprintContentWriter("enrichContextWithExample-" + key, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
                    xmlStreamWriter.writeEmptyElement("example");
                    xmlStreamWriter.writeDefaultNamespace("http://exampleNamespace");
                    xmlStreamWriter.writeAttribute("id", key);
                    xmlStreamWriter.writeAttribute("value", customParameters.get(param));
                }
            });
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter)

Example 2 with XmlWriter

use of org.apache.aries.blueprint.plugin.spi.XmlWriter in project aries by apache.

the class SpringTransactionalFactory method handleBeanAnnotation.

@Override
public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
    final String nsTx1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX1);
    if (nsTx1 != null) {
        enableAnnotationTx1(contextEnricher, nsTx1);
        final Transactional transactional = annotatedElement.getAnnotation(Transactional.class);
        final String transactionTypeName = getTransactionTypeName(transactional);
        beanEnricher.addBeanContentWriter("javax.transactional.method/" + annotatedElement + "/*/" + transactionTypeName, new XmlWriter() {

            @Override
            public void write(XMLStreamWriter writer) throws XMLStreamException {
                writer.writeEmptyElement("transaction");
                writer.writeDefaultNamespace(nsTx1);
                writer.writeAttribute("method", "*");
                writer.writeAttribute("value", transactionTypeName);
            }
        });
    }
    final String nsTx2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX1);
    if (nsTx2 != null) {
        insertEnableAnnotationTx2(contextEnricher, nsTx2);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with XmlWriter

use of org.apache.aries.blueprint.plugin.spi.XmlWriter in project aries by apache.

the class SpringTransactionalFactory method handleMethodAnnotation.

@Override
public void handleMethodAnnotation(Class<?> clazz, List<Method> methods, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
    final String nsTx1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX1);
    if (nsTx1 != null) {
        enableAnnotationTx1(contextEnricher, nsTx1);
        for (final Method method : methods) {
            final Transactional transactional = method.getAnnotation(Transactional.class);
            final String transactionTypeName = getTransactionTypeName(transactional);
            final String name = method.getName();
            beanEnricher.addBeanContentWriter("javax.transactional.method/" + clazz.getName() + "/" + name + "/" + transactionTypeName, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter writer) throws XMLStreamException {
                    writer.writeEmptyElement("transaction");
                    writer.writeDefaultNamespace(nsTx1);
                    writer.writeAttribute("method", name);
                    writer.writeAttribute("value", transactionTypeName);
                }
            });
        }
    }
    final String nsTx2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_TX2);
    if (nsTx2 != null) {
        insertEnableAnnotationTx2(contextEnricher, nsTx2);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Method(java.lang.reflect.Method) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with XmlWriter

use of org.apache.aries.blueprint.plugin.spi.XmlWriter in project aries by apache.

the class PersistenceContextHandler method handleFieldAnnotation.

@Override
public void handleFieldAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
    final String nsJpa1 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_JPA1);
    if (nsJpa1 != null) {
        for (final Field field : fields) {
            final String name = field.getName();
            final PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
            beanEnricher.addBeanContentWriter("javax.persistence.field.context/" + name, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter writer) throws XMLStreamException {
                    writer.writeEmptyElement("context");
                    writer.writeDefaultNamespace(nsJpa1);
                    writer.writeAttribute("unitname", persistenceContext.unitName());
                    writer.writeAttribute("property", name);
                }
            });
        }
    }
    final String nsJpa2 = Namespaces.getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), Namespaces.PATTERN_NS_JPA2);
    if (nsJpa2 != null) {
        contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new XmlWriter() {

            @Override
            public void write(XMLStreamWriter writer) throws XMLStreamException {
                writer.writeEmptyElement("enable");
                writer.writeDefaultNamespace(nsJpa2);
            }
        });
    }
}
Also used : Field(java.lang.reflect.Field) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) PersistenceContext(javax.persistence.PersistenceContext) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter)

Example 5 with XmlWriter

use of org.apache.aries.blueprint.plugin.spi.XmlWriter in project aries by apache.

the class PersistenceUnitHandler method handleFieldAnnotation.

@Override
public void handleFieldAnnotation(Class<?> clazz, List<Field> fields, ContextEnricher contextEnricher, BeanEnricher beanEnricher) {
    final String nsJpa1 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_JPA1);
    if (nsJpa1 != null) {
        for (final Field field : fields) {
            final String name = field.getName();
            final PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
            beanEnricher.addBeanContentWriter("javax.persistence.field.unit/" + name, new XmlWriter() {

                @Override
                public void write(XMLStreamWriter writer) throws XMLStreamException {
                    writer.writeEmptyElement("unit");
                    writer.writeDefaultNamespace(nsJpa1);
                    writer.writeAttribute("unitname", persistenceUnit.unitName());
                    writer.writeAttribute("property", name);
                }
            });
        }
    }
    final String nsJpa2 = getNamespaceByPattern(contextEnricher.getBlueprintConfiguration().getNamespaces(), PATTERN_NS_JPA2);
    if (nsJpa2 != null) {
        contextEnricher.addBlueprintContentWriter("javax.persistence.enableJpa2", new XmlWriter() {

            @Override
            public void write(XMLStreamWriter writer) throws XMLStreamException {
                writer.writeEmptyElement("enable");
                writer.writeDefaultNamespace(nsJpa2);
            }
        });
    }
}
Also used : Field(java.lang.reflect.Field) PersistenceUnit(javax.persistence.PersistenceUnit) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XmlWriter(org.apache.aries.blueprint.plugin.spi.XmlWriter)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)7 XmlWriter (org.apache.aries.blueprint.plugin.spi.XmlWriter)7 Field (java.lang.reflect.Field)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Method (java.lang.reflect.Method)1 PersistenceContext (javax.persistence.PersistenceContext)1 PersistenceUnit (javax.persistence.PersistenceUnit)1 OsgiServiceProvider (org.ops4j.pax.cdi.api.OsgiServiceProvider)1 Properties (org.ops4j.pax.cdi.api.Properties)1