List of usage examples for javax.xml.bind JAXBElement getDeclaredType
public Class<T> getDeclaredType()
From source file:org.kalypso.simulation.core.ant.GMLWeightingOperation.java
private void addSourceSummands(final Feature weightFE, final double factor, final Feature[] sourceFeatures, final List<JAXBElement<? extends AbstractFilterType>> offsetSummands) throws GMLXPathException, SensorException, JAXBException { final GMLXPath sourceZMLPath = asPath(m_data.getSourceZMLProperty()); final GMLXPath sourceIsUsedPath = asPath(m_data.getSourceIsUsedProperty()); final String sourceFilter = m_data.getSourceFilter(); // 8. loop source features for (final Feature sourceFE : sourceFeatures) { if (sourceFE == null) { m_logger.log(Level.WARNING, -1, "Linked source feature missing in Feature: " + weightFE.getId()); // IMPORTANT: just skips this weight; leads probably to wrong results continue; }/*from ww w .j a va2s . c o m*/ // 9. resolve property that is source zml reference final TimeseriesLinkType zmlLink = GMLXPathUtilities.query(sourceZMLPath, sourceFE); final Boolean useThisSource; if (sourceIsUsedPath != null) useThisSource = GMLXPathUtilities.query(sourceIsUsedPath, sourceFE); else useThisSource = Boolean.TRUE; if (!useThisSource.booleanValue()) { m_logger.log(Level.INFO, LoggerUtilities.CODE_NONE, "Ignoriere: " + sourceFE.getId()); continue; } if (zmlLink == null) { m_logger.log(Level.WARNING, LoggerUtilities.CODE_SHOW_DETAILS, "Linked timeserie link missing in Feature: " + weightFE.getId()); //$NON-NLS-1$ // IMPORTANT: just skips this weight; leads probably to wrong results continue; } // 10. build operation filter with parameters from gml final OperationFilterType filter = FilterFactory.OF_FILTER.createOperationFilterType(); offsetSummands.add(FilterFactory.OF_FILTER.createOperationFilter(filter)); filter.setOperator("*"); //$NON-NLS-1$ filter.setOperand(Double.toString(factor)); /* Innermost filter part */ final ZmlFilterType zmlFilter = FilterFactory.OF_FILTER.createZmlFilterType(); final SimpleLinkType simpleLink = m_linkFac.createSimpleLinkType(); final String sourceHref = zmlLink.getHref(); simpleLink.setHref(sourceHref); zmlFilter.setZml(simpleLink); if (sourceFilter != null) { final String strFilterXml = FilterFactory.getFilterPart(sourceFilter); final StringReader sr = new StringReader(strFilterXml); final Unmarshaller unmarshaller = ZmlFactory.JC.createUnmarshaller(); final JAXBElement<?> filterElement = (JAXBElement<?>) unmarshaller.unmarshal(new InputSource(sr)); if (filterElement == null || !AbstractFilterType.class.isAssignableFrom(filterElement.getDeclaredType())) throw new UnsupportedOperationException( "Filter must start with an AbstractFilterType element."); //$NON-NLS-1$ @SuppressWarnings("unchecked") final JAXBElement<AbstractFilterType> af = (JAXBElement<AbstractFilterType>) filterElement; filter.setFilter(af); // HACK final AbstractFilterType abstractFilter = af.getValue(); if (abstractFilter instanceof InterpolationFilterType) ((InterpolationFilterType) abstractFilter) .setFilter(FilterFactory.OF_FILTER.createZmlFilter(zmlFilter)); else throw new UnsupportedOperationException( "Only InterpolationFilter as source-filter supported at the moment."); //$NON-NLS-1$ sr.close(); } else filter.setFilter(FilterFactory.OF_FILTER.createZmlFilter(zmlFilter)); } }
From source file:org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLObjectContainer30.java
/** * Casts an object from the contents into the given type. * @param <T>/* w w w . jav a 2 s .co m*/ * the type to cast to. * @param identifiable * the object to cast. * @param type * the type to cast to. * @return the result of the cast or <code>null</code> if the object wasn't of the given type. */ protected <T extends IdentifiableType> T cast(JAXBElement<? extends IdentifiableType> identifiable, Class<T> type) { if ((identifiable.getDeclaredType() == type) || identifiable.getValue().getClass() == type) { return type.cast(identifiable.getValue()); } return null; }