Example usage for javax.xml.bind JAXBElement getDeclaredType

List of usage examples for javax.xml.bind JAXBElement getDeclaredType

Introduction

In this page you can find the example usage for javax.xml.bind JAXBElement getDeclaredType.

Prototype

public Class<T> getDeclaredType() 

Source Link

Document

Returns the Java binding of the xml element declaration's type attribute.

Usage

From source file:org.apache.falcon.lifecycle.engine.oozie.utils.OozieBuilderUtils.java

private static Path marshal(Cluster cluster, JAXBElement<?> jaxbElement, JAXBContext jaxbContext, Path outPath)
        throws FalconException {
    try {/*from   ww  w  . j  ava 2s.c om*/
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        if (LOG.isDebugEnabled()) {
            StringWriter writer = new StringWriter();
            marshaller.marshal(jaxbElement, writer);
            LOG.debug("Writing definition to {} on cluster {}", outPath, cluster.getName());
            LOG.debug(writer.getBuffer().toString());
        }

        FileSystem fs = HadoopClientFactory.get().createProxiedFileSystem(outPath.toUri(),
                ClusterHelper.getConfiguration(cluster));
        OutputStream out = fs.create(outPath);
        try {
            marshaller.marshal(jaxbElement, out);
        } finally {
            out.close();
        }

        LOG.info("Marshalled {} to {}", jaxbElement.getDeclaredType(), outPath);
        return outPath;
    } catch (Exception e) {
        throw new FalconException("Unable to marshall app object", e);
    }
}

From source file:org.apache.falcon.oozie.OozieEntityBuilder.java

protected Path marshal(Cluster cluster, JAXBElement<?> jaxbElement, JAXBContext jaxbContext, Path outPath)
        throws FalconException {
    FileSystem fs = HadoopClientFactory.get().createProxiedFileSystem(outPath.toUri(),
            ClusterHelper.getConfiguration(cluster));
    verifyOozieEntityPath(fs, outPath, jaxbElement.getDeclaredType());
    try {/*from w  w w.  ja  v  a 2s  .  c  om*/
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        if (LOG.isDebugEnabled()) {
            StringWriter writer = new StringWriter();
            marshaller.marshal(jaxbElement, writer);
            LOG.debug("Writing definition to {} on cluster {}", outPath, cluster.getName());
            LOG.debug(writer.getBuffer().toString());
        }

        OutputStream out = fs.create(outPath);

        try {
            marshaller.marshal(jaxbElement, out);
        } finally {
            out.close();
        }

        LOG.info("Marshalled {} to {}", jaxbElement.getDeclaredType(), outPath);
        return outPath;
    } catch (Exception e) {
        throw new FalconException("Unable to marshall app object", e);
    }
}

From source file:org.apache.falcon.workflow.OozieWorkflowBuilder.java

protected void marshal(Cluster cluster, JAXBElement<?> jaxbElement, JAXBContext jaxbContext, Path outPath)
        throws FalconException {
    try {/*ww  w. ja  v  a 2 s . co  m*/
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        FileSystem fs = HadoopClientFactory.get().createFileSystem(outPath.toUri(),
                ClusterHelper.getConfiguration(cluster));
        OutputStream out = fs.create(outPath);
        try {
            marshaller.marshal(jaxbElement, out);
        } finally {
            out.close();
        }
        if (LOG.isDebugEnabled()) {
            StringWriter writer = new StringWriter();
            marshaller.marshal(jaxbElement, writer);
            LOG.debug("Writing definition to {} on cluster {}", outPath, cluster.getName());
            LOG.debug(writer.getBuffer().toString());
        }

        LOG.info("Marshalled {} to {}", jaxbElement.getDeclaredType(), outPath);
    } catch (Exception e) {
        throw new FalconException("Unable to marshall app object", e);
    }
}

From source file:org.apache.ivory.converter.AbstractOozieEntityMapper.java

protected void marshal(Cluster cluster, JAXBElement<?> jaxbElement, JAXBContext jaxbContext, Path outPath)
        throws IvoryException {
    try {//w  ww.  j av a  2  s .  co m
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        FileSystem fs = outPath.getFileSystem(ClusterHelper.getConfiguration(cluster));
        OutputStream out = fs.create(outPath);
        try {
            marshaller.marshal(jaxbElement, out);
        } finally {
            out.close();
        }
        if (LOG.isDebugEnabled()) {
            StringWriter writer = new StringWriter();
            marshaller.marshal(jaxbElement, writer);
            LOG.debug("Writing definition to " + outPath + " on cluster " + cluster.getName());
            LOG.debug(writer.getBuffer());
        }

        LOG.info("Marshalled " + jaxbElement.getDeclaredType() + " to " + outPath);
    } catch (Exception e) {
        throw new IvoryException("Unable to marshall app object", e);
    }
}

From source file:org.apache.openaz.xacml.admin.model.PolicyContainer.java

protected boolean removePolicyFromPolicySet(PolicySetType parent, PolicyType policy) {
    for (JAXBElement<?> element : parent.getPolicySetOrPolicyOrPolicySetIdReference()) {
        if (PolicyType.class.isAssignableFrom(element.getDeclaredType())
                && ((PolicyType) element.getValue()).getPolicyId().equals(policy.getPolicyId())) {
            if (parent.getPolicySetOrPolicyOrPolicySetIdReference().remove(element)) {
                this.removePolicy(policy);
                return true;
            }//from w  w w .j  av  a 2 s  .  c  o  m
            logger.error("Failed to remove policy from parent policy set");
            assert false;
            return false;
        }
    }
    logger.error("Failed to remove policy from policy set, not found.");
    return false;
}

From source file:org.apache.openaz.xacml.admin.model.PolicyContainer.java

protected boolean removePolicySetFromPolicySet(PolicySetType parent, PolicySetType policySet) {
    for (JAXBElement<?> element : parent.getPolicySetOrPolicyOrPolicySetIdReference()) {
        if (PolicySetType.class.isAssignableFrom(element.getDeclaredType())) {
            logger.info(element);//  ww w .  j a v  a  2  s .  c  om
            if (((PolicySetType) element.getValue()).getPolicySetId().equals(policySet.getPolicySetId())) {
                if (parent.getPolicySetOrPolicyOrPolicySetIdReference().remove(element)) {
                    this.removePolicySet(policySet);
                    return true;
                }
                logger.error("Failed to remove policy set from parent policy set");
                assert false;
                return false;
            }
        }
    }
    return false;
}

From source file:org.codice.ddf.catalog.ui.forms.TemplateTransformer.java

/** Convert the JSON representation of a FormTemplate to a QueryTemplateMetacard. */
@Nullable/*w  w w.ja  va 2 s  .  c o m*/
public Metacard toQueryTemplateMetacard(Map<String, Object> formTemplate) {
    try {
        Map<String, Object> filterJson = (Map) formTemplate.get("filterTemplate");
        if (filterJson == null) {
            return null;
        }

        String title = (String) formTemplate.get("title");
        if (StringUtils.isBlank(title)) {
            throw new IllegalArgumentException("Search form title cannot be blank");
        }

        String description = (String) formTemplate.get("description");
        String id = (String) formTemplate.get("id");

        TransformVisitor<JAXBElement> visitor = new TransformVisitor<>(new XmlModelBuilder(registry));
        VisitableJsonElementImpl.create(new FilterNodeMapImpl(filterJson)).accept(visitor);
        JAXBElement filter = visitor.getResult();
        if (!filter.getDeclaredType().equals(FilterType.class)) {
            LOGGER.error("Error occurred during filter processing, root type should be a {} but was {}",
                    FilterType.class.getName(), filter.getDeclaredType().getName());
            return null;
        }

        QueryTemplateMetacard metacard = (id == null) ? new QueryTemplateMetacard(title, description)
                : new QueryTemplateMetacard(title, description, id);

        String filterXml = writer.marshal(filter);
        metacard.setFormsFilter(filterXml);
        Map<String, Object> querySettings = (Map<String, Object>) formTemplate.get("querySettings");
        if (querySettings != null) {
            metacard.setQuerySettings(querySettings);
        }

        return metacard;
    } catch (JAXBException e) {
        LOGGER.error("XML generation failed for query template metacard's filter", e);
    } catch (FilterProcessingException e) {
        LOGGER.error("Could not use filter JSON for template - {}", e.getMessage());
    }
    return null;
}

From source file:org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.TestWfs10JTStoGML200Converter.java

@Test
public void testPolygonTypeToJAXB()
        throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
    Polygon polygon = (Polygon) getGeometryFromWkt(POLYGON);
    assertThat(polygon == null, is(Boolean.FALSE));
    String polygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(polygon);
    PolygonType polygonType = (PolygonType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(polygonGML,
            Wfs10Constants.POLYGON);//w  w  w. j  av  a2s  .com
    assertThat(null != polygonType, is(Boolean.TRUE));
    JAXBElement<PolygonType> polygonTypeJAXBElement = (JAXBElement<PolygonType>) Wfs10JTStoGML200Converter
            .convertGeometryTypeToJAXB(polygonType);
    assertThat(polygonTypeJAXBElement.getName().getLocalPart().equals(Wfs10Constants.POLYGON.getLocalPart()),
            is(Boolean.TRUE));
    assertThat(polygonTypeJAXBElement.getDeclaredType() == PolygonType.class, is(Boolean.TRUE));

    JAXB.marshal(polygonTypeJAXBElement, writer);
    String xml = writer.toString();
    Diff diff = XMLUnit.compareXML(xml, POLYGON_GML);
    assertTrue(XMLUNIT_SIMILAR, diff.similar());
    assertThat(diff.similar(), is(Boolean.TRUE));
    assertThat(diff.identical(), is(Boolean.FALSE));
}

From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsFilterDelegate.java

protected List<FilterType> applyTemporalFallbacks(List<FilterType> filters) {
    if (null == filters || filters.isEmpty()) {
        return filters;
    }//  w ww  .  j  a  v a  2  s. c o m
    String startDate = "";
    String endDate = "";
    String property = "";
    List<FilterType> newFilters = new ArrayList<>();

    for (FilterType filterType : filters) {
        if (null == filterType) {
            continue;
        }
        if (filterType.isSetTemporalOps() && (!isTemporalOpSupported(TEMPORAL_OPERATORS.Before)
                && !isTemporalOpSupported(TEMPORAL_OPERATORS.After)) && !isDuringFilter(filterType)) {
            BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filterType.getTemporalOps()
                    .getValue();
            property = binaryTemporalOpType.getValueReference();
            JAXBElement temporalExpression = binaryTemporalOpType.getExpression();
            TimeInstantType timeInstant = (TimeInstantType) temporalExpression.getValue();
            TimePositionType timePositionType = timeInstant.getTimePosition();
            List<String> value = timePositionType.getValue();

            if (isAfterFilter(filterType)) {
                startDate = value.get(0);
            } else if (isBeforeFilter(filterType)) {
                endDate = value.get(0);
            }
        } else {
            newFilters.add(filterType);
        }
    }

    if (isTemporalOpSupported(TEMPORAL_OPERATORS.During) && (StringUtils.isNotEmpty(startDate))) {
        if (StringUtils.isEmpty(endDate)) {
            endDate = convertDateToIso8601Format(new Date());
        }

        FilterType duringFilter = buildDuringFilterType(
                featureMetacardType.getFeatureType().getLocalPart() + "." + property, startDate, endDate);
        newFilters.add(duringFilter);
    } else if (isTemporalOpSupported(TEMPORAL_OPERATORS.During)
            && (StringUtils.isEmpty(startDate) && StringUtils.isNotEmpty(endDate))) {

        for (FilterType filterType : filters) {
            if (!filterType.isSetTemporalOps()) {
                BinaryLogicOpType binaryLogicOpType = (BinaryLogicOpType) filterType.getLogicOps().getValue();
                List<JAXBElement<?>> list = binaryLogicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps();
                for (JAXBElement<?> element : list) {

                    if (StringUtils.contains(element.getDeclaredType().toString(), ("BinaryTemporalOpType"))) {

                        BinaryTemporalOpType binTemp = (BinaryTemporalOpType) element.getValue();
                        JAXBElement temporalExpression = binTemp.getExpression();
                        TimePeriodType timePeriod = (TimePeriodType) temporalExpression.getValue();
                        TimePositionType timeEndPosition = timePeriod.getEndPosition();
                        List<String> newValue = new ArrayList<String>();
                        newValue.add(endDate);
                        timeEndPosition.unsetValue();
                        timeEndPosition.setValue(newValue);
                        timePeriod.setEndPosition(timeEndPosition);

                    }
                }

            } else if ((!isTemporalOpSupported(TEMPORAL_OPERATORS.Before)
                    && !isTemporalOpSupported(TEMPORAL_OPERATORS.After)) && isDuringFilter(filterType)) {
                BinaryTemporalOpType binaryTemporalOpType = (BinaryTemporalOpType) filterType.getTemporalOps()
                        .getValue();
                JAXBElement temporalExpression = binaryTemporalOpType.getExpression();
                TimePeriodType timePeriod = (TimePeriodType) temporalExpression.getValue();
                TimePositionType timeEndPosition = timePeriod.getEndPosition();
                List<String> newValue = new ArrayList<String>();
                newValue.add(endDate);
                timeEndPosition.unsetValue();
                timeEndPosition.setValue(newValue);
                timePeriod.setEndPosition(timeEndPosition);
            }
        }
    }
    return newFilters;
}

From source file:org.docx4j.XmlUtils.java

public static String JAXBElementDebug(javax.xml.bind.JAXBElement o) {

    String prefix = null;//  w  ww  . j a  v a 2s.  c o  m
    if (o.getName().getNamespaceURI() != null) {
        try {
            prefix = NamespacePrefixMapperUtils.getPreferredPrefix(o.getName().getNamespaceURI(), null, false);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }
    if (prefix != null) {
        return prefix + ':' + o.getName().getLocalPart()
                + " is a javax.xml.bind.JAXBElement; it has declared type " + o.getDeclaredType().getName();
    } else {
        return o.getName() + " is a javax.xml.bind.JAXBElement; it has declared type "
                + o.getDeclaredType().getName();
    }

}