use of javax.xml.stream.XMLStreamException 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 javax.xml.stream.XMLStreamException 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 javax.xml.stream.XMLStreamException in project lucene-solr by apache.
the class XMLResponseParser method readDocument.
protected SolrDocument readDocument(XMLStreamReader parser) throws XMLStreamException {
if (XMLStreamConstants.START_ELEMENT != parser.getEventType()) {
throw new RuntimeException("must be start element, not: " + parser.getEventType());
}
if (!"doc".equals(parser.getLocalName().toLowerCase(Locale.ROOT))) {
throw new RuntimeException("must be 'lst', not: " + parser.getLocalName());
}
SolrDocument doc = new SolrDocument();
StringBuilder builder = new StringBuilder();
KnownType type = null;
String name = null;
// just eat up the events...
int depth = 0;
while (true) {
switch(parser.next()) {
case XMLStreamConstants.START_ELEMENT:
depth++;
// reset the text
builder.setLength(0);
type = KnownType.get(parser.getLocalName());
if (type == null) {
throw new RuntimeException("this must be known type! not: " + parser.getLocalName());
}
name = null;
int cnt = parser.getAttributeCount();
for (int i = 0; i < cnt; i++) {
if ("name".equals(parser.getAttributeLocalName(i))) {
name = parser.getAttributeValue(i);
break;
}
}
//Nested documents
while (type == KnownType.DOC) {
doc.addChildDocument(readDocument(parser));
int event = parser.next();
if (event == XMLStreamConstants.END_ELEMENT) {
//Doc ends
return doc;
}
}
if (name == null) {
throw new XMLStreamException("requires 'name' attribute: " + parser.getLocalName(), parser.getLocation());
}
// Handle multi-valued fields
if (type == KnownType.ARR) {
for (Object val : readArray(parser)) {
doc.addField(name, val);
}
// the array reading clears out the 'endElement'
depth--;
} else if (type == KnownType.LST) {
doc.addField(name, readNamedList(parser));
depth--;
} else if (!type.isLeaf) {
System.out.println("nbot leaf!:" + type);
throw new XMLStreamException("must be value or array", parser.getLocation());
}
break;
case XMLStreamConstants.END_ELEMENT:
if (--depth < 0) {
return doc;
}
//System.out.println( "FIELD:"+type+"::"+name+"::"+builder );
Object val = type.read(builder.toString().trim());
if (val == null) {
throw new XMLStreamException("error reading value:" + type, parser.getLocation());
}
doc.addField(name, val);
break;
// TODO? should this be trimmed? make sure it only gets one/two space?
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CDATA:
case XMLStreamConstants.CHARACTERS:
builder.append(parser.getText());
break;
}
}
}
use of javax.xml.stream.XMLStreamException in project karaf by apache.
the class MavenConfigService method getLocalRepositoryFromSettings.
private static String getLocalRepositoryFromSettings(File file) {
XMLStreamReader reader = null;
try (InputStream fin = new FileInputStream(file)) {
reader = XMLInputFactory.newFactory().createXMLStreamReader(fin);
int event;
String elementName = null;
while ((event = reader.next()) != XMLStreamConstants.END_DOCUMENT) {
if (event == XMLStreamConstants.START_ELEMENT) {
elementName = reader.getLocalName();
} else if (event == XMLStreamConstants.END_ELEMENT) {
elementName = null;
} else if (event == XMLStreamConstants.CHARACTERS && "localRepository".equals(elementName)) {
return reader.getText().trim();
}
}
} catch (Exception e) {
logger.error("Error retrieving maven configuration", e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (XMLStreamException e) {
// Ignore
}
}
}
return null;
}
use of javax.xml.stream.XMLStreamException in project logging-log4j2 by apache.
the class DefaultConfigurationBuilder method writeXmlConfiguration.
@Override
public void writeXmlConfiguration(final OutputStream output) throws IOException {
try {
final XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(output);
writeXmlConfiguration(xmlWriter);
xmlWriter.close();
} catch (final XMLStreamException e) {
if (e.getNestedException() instanceof IOException) {
throw (IOException) e.getNestedException();
}
Throwables.rethrow(e);
}
}
Aggregations