List of usage examples for javax.xml.bind JAXBElement JAXBElement
public JAXBElement(QName name, Class<T> declaredType, T value)
From source file:org.codice.ddf.spatial.ogc.wfs.v110.catalog.source.WfsSourceTest.java
private JAXBElement<GetFeatureType> getGetFeatureTypeJaxbElement(final GetFeatureType getFeatureType) { return new JAXBElement<>(new QName("http://www.opengis.net/wfs", "GetFeature"), GetFeatureType.class, getFeatureType);/*from w w w . j av a2s. co m*/ }
From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.TestWfsFilterDelegate.java
private JAXBElement<FilterType> getFilterTypeJaxbElement(FilterType filterType) { return new JAXBElement<>(new QName("http://www.opengis.net/ogc", FILTER_QNAME_LOCAL_PART), FilterType.class, filterType);//from ww w. java2s . c o m }
From source file:org.deegree.services.wps.provider.jrxml.contentprovider.DataTableContentProvider.java
@Override public void inspectInputParametersFromJrxml(Map<String, ParameterDescription> parameterDescriptions, List<JAXBElement<? extends ProcessletInputDefinition>> inputs, XMLAdapter jrxmlAdapter, Map<String, String> parameters, List<String> handledParameters) { List<String> tableIds = new ArrayList<String>(); List<OMElement> fieldElements = jrxmlAdapter.getElements(jrxmlAdapter.getRootElement(), new XPath("/jasper:jasperReport/jasper:field", nsContext)); for (OMElement fieldElement : fieldElements) { String fieldName = fieldElement.getAttributeValue(new QName("name")); if (isTableParameter(fieldName)) { String identifier = getIdentifierFromParameter(fieldName); if (!tableIds.contains(identifier)) { tableIds.add(identifier); }// www . j a v a 2 s.c o m } } for (String tableId : tableIds) { LOG.debug("Found table component with id " + tableId); ComplexInputDefinition comp = new ComplexInputDefinition(); addInput(comp, parameterDescriptions, tableId, 1, 0); ComplexFormatType format = new ComplexFormatType(); format.setEncoding("UTF-8"); format.setMimeType(MIME_TYPE); format.setSchema(SCHEMA); comp.setDefaultFormat(format); inputs.add(new JAXBElement<ComplexInputDefinition>(new QName("ProcessInput"), ComplexInputDefinition.class, comp)); this.tableId = tableId; } }
From source file:org.deegree.services.wps.provider.jrxml.contentprovider.map.MapContentProvider.java
@Override public void inspectInputParametersFromJrxml(Map<String, ParameterDescription> parameterDescriptions, List<JAXBElement<? extends ProcessletInputDefinition>> inputs, XMLAdapter jrxmlAdapter, Map<String, String> parameters, List<String> handledParameters) { // for a wms, parameters starting with 'map' are important. three different types are supported: // * wmsXYZ_map -> as image parameter // * wmsXYZ_legend -> as imgage parameter // * wmsXYZ_layerList -> as frame key // where XYZ is a string which is the identifier of the process parameter. Map<String, Pair<Integer, Integer>> mapIds = new HashMap<String, Pair<Integer, Integer>>(); for (String parameterName : parameters.keySet()) { if (!handledParameters.contains(parameterName)) { if (isMapParameter(parameterName)) { String mapId = getIdentifierFromParameter(parameterName); OMElement imgElement = jrxmlAdapter.getElement(jrxmlAdapter.getRootElement(), new XPath(".//jasper:image[jasper:imageExpression/text()='$P{" + parameterName + "}']/jasper:reportElement", JrxmlUtils.nsContext)); if (imgElement != null) { if (parameterName.endsWith(SUFFIXES.MAP_SUFFIX.text)) { if (!mapIds.containsKey(mapId)) { int width = jrxmlAdapter.getRequiredNodeAsInteger(imgElement, new XPath("@width", nsContext)); int height = jrxmlAdapter.getRequiredNodeAsInteger(imgElement, new XPath("@height", nsContext)); mapIds.put(mapId, new Pair<Integer, Integer>(width, height)); }/*from w w w.ja v a2 s. c o m*/ } } if (!mapIds.containsKey(mapId)) { mapIds.put(mapId, null); } // TODO: maybe a status information would be the better way? // remove used parameter handledParameters.add(parameterName); } } } for (String mapId : mapIds.keySet()) { LOG.debug("Found map component with id " + mapId); ComplexInputDefinition comp = new ComplexInputDefinition(); addInput(comp, parameterDescriptions, mapId, 1, 0); ComplexFormatType format = new ComplexFormatType(); format.setEncoding("UTF-8"); format.setMimeType(MIME_TYPE); format.setSchema(SCHEMA); comp.setDefaultFormat(format); // TODO: Metadata (width/height) // Pair<Integer, Integer> mapDim = mapIds.get( mapId ); // if ( mapDim != null ) { // System.out.println( mapDim.getFirst() ); // System.out.println( mapDim.getSecond() ); // try { // Metadata meta = new Metadata(); // MapMetadata mm = new MapMetadata(); // mm.setWidth( BigInteger.valueOf( mapDim.getFirst().longValue() ) ); // mm.setHeight( BigInteger.valueOf( mapDim.getSecond().longValue() ) ); // JAXBContext jc = JAXBContext.newInstance( MapMetadata.class ); // Marshaller marshaller = jc.createMarshaller(); // ByteArrayOutputStream os = new ByteArrayOutputStream(); // XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( os ); // marshaller.marshal( mm, writer ); // os.close(); // writer.close(); // InputStream is = new ByteArrayInputStream( os.toByteArray() ); // XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( is ); // StAXOMBuilder b = new StAXOMBuilder( reader ); // OMElement elem = b.getDocumentElement(); // System.out.println( elem ); // meta.setAny( elem ); // comp.getMetadata().add( meta ); // is.close(); // reader.close(); // } catch ( Exception e ) { // LOG.error( "Could not create map metadata", e ); // } // } inputs.add(new JAXBElement<ComplexInputDefinition>(new QName("ProcessInput"), ComplexInputDefinition.class, comp)); } }
From source file:org.dkpro.core.io.xces.XcesBasicXmlWriter.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null;// w w w . j a va2 s. c o m try { docOS = getOutputStream(aJCas, filenameSuffix); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); XMLEventWriter xmlEventWriter = new IndentingXMLEventWriter( xmlOutputFactory.createXMLEventWriter(docOS)); JAXBContext context = JAXBContext.newInstance(XcesBodyBasic.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); XMLEventFactory xmlef = XMLEventFactory.newInstance(); xmlEventWriter.add(xmlef.createStartDocument()); // Begin cesDoc xmlEventWriter.add(xmlef.createStartElement("", "", "cesDoc")); // Begin and End cesHeader xmlEventWriter.add(xmlef.createStartElement("", "", "cesHeader")); xmlEventWriter.add(xmlef.createEndElement("", "", "cesHeader")); // Begin text and body xmlEventWriter.add(xmlef.createStartElement("", "", "text")); // xmlEventWriter.add(xmlef.createStartElement("", "", "body")); // Begin body of all the paragraphs Collection<Paragraph> parasInCas = JCasUtil.select(aJCas, Paragraph.class); XcesBodyBasic xb = convertToXcesBasicPara(parasInCas); marshaller.marshal(new JAXBElement<XcesBodyBasic>(new QName("body"), XcesBodyBasic.class, xb), xmlEventWriter); // End body of all the paragraphs // xmlEventWriter.add(xmlef.createEndElement("", "", "body")); xmlEventWriter.add(xmlef.createEndElement("", "", "text")); xmlEventWriter.add(xmlef.createEndElement("", "", "cesDoc")); xmlEventWriter.add(xmlef.createEndDocument()); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } }
From source file:org.dkpro.core.io.xces.XcesXmlWriter.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null;//from w w w . java 2 s .c o m try { docOS = getOutputStream(aJCas, filenameSuffix); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); XMLEventWriter xmlEventWriter = new IndentingXMLEventWriter( xmlOutputFactory.createXMLEventWriter(docOS)); JAXBContext context = JAXBContext.newInstance(XcesBody.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); XMLEventFactory xmlef = XMLEventFactory.newInstance(); xmlEventWriter.add(xmlef.createStartDocument()); // Begin cesDoc xmlEventWriter.add(xmlef.createStartElement("", "", "cesDoc")); // Begin and End cesHeader xmlEventWriter.add(xmlef.createStartElement("", "", "cesHeader")); xmlEventWriter.add(xmlef.createEndElement("", "", "cesHeader")); // Begin text and body xmlEventWriter.add(xmlef.createStartElement("", "", "text")); // xmlEventWriter.add(xmlef.createStartElement("", "", "body")); // Begin body of all the paragraphs Collection<Paragraph> parasInCas = JCasUtil.select(aJCas, Paragraph.class); XcesBody xb = convertToXcesPara(parasInCas); marshaller.marshal(new JAXBElement<XcesBody>(new QName("body"), XcesBody.class, xb), xmlEventWriter); // End body of all the paragraphs // xmlEventWriter.add(xmlef.createEndElement("", "", "body")); xmlEventWriter.add(xmlef.createEndElement("", "", "text")); xmlEventWriter.add(xmlef.createEndElement("", "", "cesDoc")); xmlEventWriter.add(xmlef.createEndDocument()); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } }
From source file:org.docx4j.XmlUtils.java
/** Marshal to a String, for object * missing an @XmlRootElement annotation. */ public static String marshaltoString(Object o, boolean suppressDeclaration, boolean prettyprint, JAXBContext jc, String uri, String local, Class declaredType) { // TODO - refactor this. try {/*from w ww. ja v a 2 s .com*/ Marshaller m = jc.createMarshaller(); NamespacePrefixMapperUtils.setProperty(m, NamespacePrefixMapperUtils.getPrefixMapper()); String ignorables = setMcIgnorable( ((McIgnorableNamespaceDeclarator) NamespacePrefixMapperUtils.getPrefixMapper()), o); if (prettyprint) { m.setProperty("jaxb.formatted.output", true); } if (suppressDeclaration) { m.setProperty(Marshaller.JAXB_FRAGMENT, true); } if (Docx4jProperties.getProperty("docx4j.jaxb.marshal.canonicalize", false)) { org.w3c.dom.Document doc = marshaltoW3CDomDocument(o, jc, uri, local, declaredType); byte[] bytes = trimNamespaces(doc, ignorables); return new String(bytes, "UTF-8"); } else { StringWriter sWriter = new StringWriter(); m.marshal(new JAXBElement(new QName(uri, local), declaredType, o), sWriter); return sWriter.toString(); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.docx4j.XmlUtils.java
/** Marshal to a W3C document, for object * missing an @XmlRootElement annotation. */ public static org.w3c.dom.Document marshaltoW3CDomDocument(Object o, JAXBContext jc, String uri, String local, Class declaredType) {//from ww w . ja va2 s . c om // TODO - refactor this. try { Marshaller marshaller = jc.createMarshaller(); NamespacePrefixMapperUtils.setProperty(marshaller, NamespacePrefixMapperUtils.getPrefixMapper()); String ignorables = setMcIgnorable( ((McIgnorableNamespaceDeclarator) NamespacePrefixMapperUtils.getPrefixMapper()), o); org.w3c.dom.Document doc = XmlUtils.getNewDocumentBuilder().newDocument(); // See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html marshaller.marshal(new JAXBElement(new QName(uri, local), declaredType, o), doc); if (Docx4jProperties.getProperty("docx4j.jaxb.marshal.canonicalize", false)) { byte[] bytes = trimNamespaces(doc, ignorables); DocumentBuilder builder = XmlUtils.getDocumentBuilderFactory().newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(bytes)); } else { return doc; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.docx4j.XmlUtils.java
/** Clone this JAXB object * @param value/* w w w . ja v a 2 s . c o m*/ * @param jc * @return */ public static <T> T deepCopy(T value, JAXBContext jc) { if (value == null) { throw new IllegalArgumentException("Can't clone a null argument"); } try { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) value.getClass(); JAXBElement<T> contentObject = new JAXBElement<T>(new QName(clazz.getSimpleName()), clazz, value); JAXBSource source = new JAXBSource(jc, contentObject); JAXBElement<T> elem = jc.createUnmarshaller().unmarshal(source, clazz); /* * Losing content here? * * First, make absolutely sure that what you have is valid. * * For example, Word 2010 is happy to open w:p/w:pict * (as opposed to w:p/w:r/w:pict). * docx4j is happy to marshall w:p/w:pict, but not unmarshall it, * so that content would get dropped here. */ T res; if (value instanceof JAXBElement<?>) { @SuppressWarnings("unchecked") T resT = (T) elem; res = resT; } else { @SuppressWarnings("unchecked") T resT = (T) elem.getValue(); res = resT; } // log.info("deep copy success!"); return res; } catch (JAXBException ex) { throw new IllegalArgumentException(ex); } }
From source file:org.eclipse.winery.common.Util.java
public static <T extends Object> JAXBElement<T> getJAXBElement(Class<T> clazz, T obj) { String namespace = null;// www . ja v a 2 s.co m XmlRootElement xmlRootElement = clazz.getAnnotation(XmlRootElement.class); if (xmlRootElement != null) { namespace = xmlRootElement.namespace(); if ("##default".equals(namespace)) { XmlSchema xmlSchema = clazz.getPackage().getAnnotation(XmlSchema.class); if (xmlSchema != null) { namespace = xmlSchema.namespace(); } else { // trigger default handling namespace = null; } } } if (namespace == null) { // fallback non-specified namespaces namespace = org.eclipse.winery.common.constants.Namespaces.TOSCA_NAMESPACE; } String localName = Util.getLocalName(clazz); QName qname = new QName(namespace, localName); JAXBElement<T> rootElement = new JAXBElement<T>(qname, clazz, obj); return rootElement; }