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));
}
});
}
}
}
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);
}
}
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);
}
}
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);
}
});
}
}
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);
}
});
}
}
Aggregations