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:com.vmware.identity.sts.ws.SignatureValidator.java

/**
 * Parses the KeyInfo from the XML signature and extracts the signing
 * certificate. KeyInfo should have the following format:
 *
 * <KeyInfo> <SecurityTokenReference> <Reference URI=""/> OR <KeyIdentifier
 * /> </SecurityTokenReference> </KeyInfo>
 *
 * @param header//from  w ww.j a v a2  s .c o m
 *           not null
 * @return the signing certificate
 */
private Signature extractSignature(SecurityHeaderType header) {
    assert header != null;

    Signature result = null;
    KeyInfoType keyInfo = header.getSignature().getKeyInfo();
    if (keyInfo == null) {
        throwInvalidSecurity("KeyInfo not found");
    }
    logger.debug("Found KeyInfo");
    SecurityTokenReferenceType stRef = getTheValue(keyInfo.getContent(), SecurityTokenReferenceType.class,
            FaultKey.WSSE_INVALID_SECURITY, "SecurityTokenReference not found");
    logger.debug("Found SecurityTokenReference");
    List<Object> stRefContent = stRef.getAny();
    if (stRefContent == null || stRefContent.size() != 1) {
        throwInvalidSecurity("SecurityTokenReference is empty");
    }
    if (!(stRefContent.get(0) instanceof JAXBElement<?>)) {
        throwInvalidSecurity("Unknown SecurityTokenReference content type");
    }
    JAXBElement<?> jaxbElement = (JAXBElement<?>) stRefContent.get(0);
    if (ReferenceType.class.equals(jaxbElement.getDeclaredType())) {
        ReferenceType reference = (ReferenceType) jaxbElement.getValue();
        result = parseReferenceType(header, reference);
    } else if (KeyIdentifierType.class.equals(jaxbElement.getDeclaredType())) {
        KeyIdentifierType keyIdentifier = (KeyIdentifierType) jaxbElement.getValue();
        result = parseKeyIdentifier(header, keyIdentifier);
    } else {
        throw new WSFaultException(FaultKey.WSSE_UNSUPPORTED_SECURITY_TOKEN,
                "Unknown SecurityTokenReference content");
    }

    return result;
}

From source file:com.cisco.dvbu.ps.deploytool.services.TriggerManagerImpl.java

private void populateTriggerAttributes(TriggerResource triggerResource, TriggerType triggerType, long loopCount,
        TriggerScheduleListType scheduleList) {

    triggerType.setId("TR-" + loopCount);
    triggerType.setResourcePath(triggerResource.getPath());
    triggerType.setIsEnabled(triggerResource.isEnabled());
    triggerType.setAnnotation(triggerResource.getAnnotation());
    if (logger.isDebugEnabled()) {
        logger.debug("Processing trigger: " + triggerResource.getPath());
        logger.debug("Rest field is of type: " + triggerResource.getRest().getClass().getName());
        logger.debug("Looping through list:");
    }/*  w w  w  .j  a  va  2s  .c om*/

    long objLoopCount = 0;
    String conditionType = null;
    String actionType = null;
    AttributeList conditionAttributes = null;
    Schedule conditionSchedule = null;
    AttributeList actionAttributes = null;
    BigInteger maxEventsQueued = null;

    for (JAXBElement<?> triggerObj : triggerResource.getRest()) {
        objLoopCount++;

        if (logger.isDebugEnabled()) {
            logger.debug("Rest field[" + objLoopCount + "] is of type: " + triggerObj.getClass().getName());
            logger.debug("JAXB Name: " + triggerObj.getName());
            logger.debug("JAXB Declared Type: " + triggerObj.getDeclaredType());

        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("conditionType")) {
            logger.debug("Processing conditionType");
            conditionType = (String) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("conditionAttributes")) {
            logger.debug("Processing condition attributes");
            conditionAttributes = (AttributeList) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("conditionSchedule")) {
            logger.debug("Processing condition schedule");
            conditionSchedule = (Schedule) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("actionType")) {
            logger.debug("Processing actionType");
            actionType = (String) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("actionAttributes")) {
            logger.debug("Processing action attributes");
            actionAttributes = (AttributeList) triggerObj.getValue();
        }
        if (triggerObj.getName().getLocalPart().toString().equalsIgnoreCase("maxEventsQueued")) {
            logger.debug("Processing max events queued");
            maxEventsQueued = (BigInteger) triggerObj.getValue();
        }
    }

    triggerType.setMaxEventsQueued(maxEventsQueued);
    if (logger.isDebugEnabled()) {
        logger.debug("Condition type: " + conditionType);
        logger.debug("Action type: " + actionType);
    }

    triggerType.setCondition(populateTriggerCondition(conditionType, conditionAttributes, conditionSchedule,
            "TR-" + loopCount, scheduleList));
    triggerType.setAction(populateTriggerAction(actionType, actionAttributes, "TR-" + loopCount));

    if (logger.isDebugEnabled()) {
        if (scheduleList.getSchedule().isEmpty()) {
            logger.debug("Schedule List is empty");
        } else {
            logger.debug("Schedule List size: " + scheduleList.getSchedule().size());
        }
    }
}

From source file:nz.org.take.r2ml.util.ReplacePropertyFunctionTermFilter.java

/**
 * check all Atoms in the formula for occurences of property terms
 * /*w w w  .  ja v a 2s  . co m*/
 * @param qfAndOrNafNegFormula
 * @throws R2MLException
 */
@SuppressWarnings("unchecked")
private void fixFormula(List<JAXBElement<? extends QfAndOrNafNegFormula>> qfAndOrNafNegFormula)
        throws R2MLException {
    //List<Atom> bindings = new ArrayList<Atom>();

    int i = 0;
    for (Object f : qfAndOrNafNegFormula.toArray()) {
        varBindings.push(new ArrayList<Atom>());
        JAXBElement formula = ((JAXBElement) f);
        Class<? extends QfAndOrNafNegFormula> type = formula.getDeclaredType();
        if (DatatypePredicateAtom.class.isAssignableFrom(type)) {
            if (R2MLUtil.isBooleanPredicate((DatatypePredicateAtom) formula.getValue())) {
                ;
                ;// ignore this case The DatatypePredicateHandler will do the rest
            } else {
                handle((Atom) formula.getValue());
            }
        } else if (Atom.class.isAssignableFrom(type)) {
            handle((Atom) formula.getValue());
        } else if (QfConjunction.class.isAssignableFrom(type)) {
            fixFormula(((QfConjunction) (formula.getValue())).getQfAndOrNafNegFormula());
        } else if (QfDisjunction.class.isAssignableFrom(type)) {
            fixFormula(((QfDisjunction) (formula.getValue())).getQfAndOrNafNegFormula());
        } else if (QfNegationAsFailure.class.isAssignableFrom(type)) {
            QfNegationAsFailure qfNegationAsFailure = ((QfNegationAsFailure) (formula.getValue()));
            Atom atom = qfNegationAsFailure.getAtom().getValue();
            handle(atom);
        } else if (QfStrongNegation.class.isAssignableFrom(type)) {
            QfStrongNegation qfStrongNegation = ((QfStrongNegation) (formula.getValue()));
            Atom atom = qfStrongNegation.getAtom().getValue();
            handle(atom);
        } else {
            throw new R2MLException(
                    "unable to check type " + type.getName() + " for occurences of FunctionTerms.");
        }
        addVarBindings(qfAndOrNafNegFormula, i++);
    }
}

From source file:nz.org.take.r2ml.util.ReplacePropertyFunctionTermFilter.java

/**
 * @param atom/*from  w w  w. j av  a 2s .co m*/
 *            an Atom possibly containing a Reference or
 *            AttributeFunctionTerm
 * @return Atoms that bind inserted variables
 * @throws R2MLException
 */
@SuppressWarnings("unchecked")
private void handle(Atom atom) throws R2MLException {

    Class<? extends Atom> type = atom.getClass();

    if (DataClassificationAtom.class.isAssignableFrom(type)) {
        DataClassificationAtom dataClassificationAtom = ((DataClassificationAtom) atom);

        JAXBElement<? extends DataTerm> t = (JAXBElement<? extends DataTerm>) handle(
                dataClassificationAtom.getDataTerm());
        if (t != null) {
            dataClassificationAtom.setDataTerm(t);
        }
    } else if (DatatypePredicateAtom.class.isAssignableFrom(type)) {
        DatatypePredicateAtom datatypePredicateAtom = ((DatatypePredicateAtom) atom);
        if (R2MLUtil.isBooleanPredicate(datatypePredicateAtom)) {
            // do nothing the DatatypePredicateAtomHandler will handle this artefact
            return;
        }
        List<JAXBElement<? extends DataTerm>> datas = datatypePredicateAtom.getDataArguments().getDataTerm();
        handleDataArgs(datas);
        //         for (JAXBElement<? extends DataTerm> t : datatypePredicateAtom
        //               .getDataArguments().getDataTerm())
        //            handle(t);
    } else if (AssociationAtom.class.isAssignableFrom(type)) {
        AssociationAtom aAtom = (AssociationAtom) atom;
        try {
            List<JAXBElement<? extends ObjectTerm>> objects = aAtom.getObjectArguments().getObjectTerm();
            handleObjectArgs(objects);
        } catch (NullPointerException e1) {
        }
        try {
            List<JAXBElement<? extends DataTerm>> datas = aAtom.getDataArguments().getDataTerm();
            handleDataArgs(datas);
        } catch (NullPointerException e) {
        }
    } else if (AttributionAtom.class.isAssignableFrom(type)) {
        AttributionAtom pAtom = (AttributionAtom) atom;
        JAXBElement<? extends ObjectTerm> subt = (JAXBElement<? extends ObjectTerm>) handle(
                pAtom.getSubject().getObjectTerm());
        if (subt != null) {
            Subject newSubject = of.createSubject();
            newSubject.setObjectTerm(subt);
            pAtom.setSubject(newSubject);
        }
        JAXBElement<? extends DataTerm> datT = (JAXBElement<? extends DataTerm>) handle(
                pAtom.getDataValue().getDataTerm());
        if (datT != null) {
            DataValue dv = of.createDataValue();
            dv.setDataTerm(datT);
            pAtom.setDataValue(dv);
        }
    } else if (EqualityAtom.class.isAssignableFrom(type)) {
        EqualityAtom eAtom = (EqualityAtom) atom;
        List<JAXBElement<? extends ObjectTerm>> objects = eAtom.getObjectTerm();
        handleObjectArgs(objects);
        //         for (JAXBElement<? extends ObjectTerm> t : eAtom.getObjectTerm()) {
        //            handle(t);
        //         }
    } else if (InequalityAtom.class.isAssignableFrom(type)) {
        InequalityAtom iAtom = (InequalityAtom) atom;
        List<JAXBElement<? extends ObjectTerm>> objects = iAtom.getObjectTerm();
        handleObjectArgs(objects);
    } else if (ObjectClassificationAtom.class.isAssignableFrom(type)) {
        ObjectClassificationAtom oAtom = (ObjectClassificationAtom) atom;
        JAXBElement<? extends ObjectTerm> objt = (JAXBElement<? extends ObjectTerm>) handle(
                oAtom.getObjectTerm());
        if (objt != null) {
            oAtom.setObjectTerm(objt);
        }
    } else if (ObjectDescriptionAtom.class.isAssignableFrom(type)) {
        // ObjectDescriptionAtom oAtom = (ObjectDescriptionAtom) atom;
        throw new R2MLException("ObjectDescriptionAtom is not supported");
        // TODO build an AttributionAtom respectivly a ReferencePropertyAtom
        // for each slot
    } else if (PropertyAtom.class.isAssignableFrom(type)) {
        throw new R2MLException("Generic PropertyAtom is not supported.");
    } else if (ReferencePropertyAtom.class.isAssignableFrom(type)) {
        ReferencePropertyAtom pAtom = (ReferencePropertyAtom) atom;
        JAXBElement<? extends ObjectTerm> subt = (JAXBElement<? extends ObjectTerm>) handle(
                pAtom.getSubject().getObjectTerm());
        if (subt != null) {
            Subject newSubject = of.createSubject();
            newSubject.setObjectTerm(subt);
            pAtom.setSubject(newSubject);
        }
        JAXBElement<? extends ObjectTerm> objt = (JAXBElement<? extends ObjectTerm>) handle(
                pAtom.getObject().getObjectTerm());
        if (objt != null) {
            de.tu_cottbus.r2ml.Object newObject = of.createObject();
            newObject.setObjectTerm(objt);
            pAtom.setObject(newObject);
        }
    } else if (GenericAtom.class.isAssignableFrom(type)) {
        GenericAtom gAtom = (GenericAtom) atom;
        for (JAXBElement<? extends Term> t : gAtom.getArguments().getTerm()) {
            if (ObjectTerm.class.isAssignableFrom(t.getDeclaredType())) {
                handle(t);
            } else {
                handle(t);
            }
        }
    }
}

From source file:nz.org.take.r2ml.util.ReplacePropertyFunctionTermFilter.java

@SuppressWarnings("unchecked")
private JAXBElement<? extends Term> handle(JAXBElement<? extends Term> value) throws R2MLException {
    // return nothing if this Term is not a PropertyTerm
    JAXBElement<? extends Term> ret = null;
    if (value.getDeclaredType().equals(AttributeFunctionTerm.class)) {
        //          TODO check arguments of the FunctionTerm for nested FunctionTerms 
        AttributeFunctionTerm t = (AttributeFunctionTerm) value.getValue();
        DataVariable var = of.createDataVariable();
        var.setDatatypeID(getDatatypeID(t));
        var.setName(generateVarName(t.getAttributeID()));
        var.setTypeCategory(value.getValue().getTypeCategory());
        AttributionAtom atom = of.createAttributionAtom();
        atom.setAttributeID(t.getAttributeID());
        Subject subject = of.createSubject();
        JAXBElement<? extends ObjectTerm> subTerm = (JAXBElement<? extends ObjectTerm>) handle(
                t.getContextArgument().getObjectTerm());
        if (subTerm != null) {
            subject.setObjectTerm(subTerm);
        } else {//from w  ww  .j av a  2s . com
            subject.setObjectTerm(t.getContextArgument().getObjectTerm());
        }
        atom.setSubject(subject);
        DataValue dValue = of.createDataValue();
        dValue.setDataTerm(of.createDataVariable(var));
        atom.setDataValue(dValue);

        varBindings.peek().add(atom);

        // return the variable
        ret = atom.getDataValue().getDataTerm();

    } else if (value.getDeclaredType().equals(ReferencePropertyFunctionTerm.class)) {
        //          TODO check arguments of the FunctionTerm for more FunctionTerms 
        ReferencePropertyFunctionTerm t = (ReferencePropertyFunctionTerm) value.getValue();
        ObjectVariable var = of.createObjectVariable();
        var.setClassID(getClassID(t));
        var.setName(generateVarName(t.getReferencePropertyID()));
        var.setTypeCategory(value.getValue().getTypeCategory());
        ReferencePropertyAtom atom = of.createReferencePropertyAtom();
        atom.setReferencePropertyID(t.getReferencePropertyID());
        Subject subject = of.createSubject();
        JAXBElement<? extends ObjectTerm> subTerm = (JAXBElement<? extends ObjectTerm>) handle(
                t.getContextArgument().getObjectTerm());
        if (subTerm != null) {
            subject.setObjectTerm(subTerm);
        } else {
            subject.setObjectTerm(t.getContextArgument().getObjectTerm());
        }
        atom.setSubject(subject);
        de.tu_cottbus.r2ml.Object obj = of.createObject();
        obj.setObjectTerm(of.createObjectVariable(var));
        atom.setObject(obj);

        varBindings.peek().add(atom);

        // rerturn the variable
        ret = atom.getObject().getObjectTerm();
    } else if (value.getDeclaredType().equals(DataOperationTerm.class)) {
        DataOperationTerm t = (DataOperationTerm) value.getValue();
        JAXBElement<? extends ObjectTerm> contextTerm = (JAXBElement<? extends ObjectTerm>) handle(
                t.getContextArgument().getObjectTerm());
        if (contextTerm != null) {
            t.getContextArgument().setObjectTerm(contextTerm);
        }
        List<JAXBElement<? extends Term>> args = t.getArguments().getTerm();
        handleArgs(args);
    } else if (value.getDeclaredType().equals(DatatypeFunctionTerm.class)) {
        DatatypeFunctionTerm t = (DatatypeFunctionTerm) value.getValue();
        List<JAXBElement<? extends DataTerm>> datas = t.getDataArguments().getDataTerm();
        handleDataArgs(datas);
    } else if (value.getDeclaredType().equals(GenericFunctionTerm.class)) {
        GenericFunctionTerm t = (GenericFunctionTerm) value.getValue();
        List<JAXBElement<? extends Term>> args = t.getArguments().getTerm();
        handleArgs(args);
    } else if (value.getDeclaredType().equals(ObjectOperationTerm.class)) {
        ObjectOperationTerm t = (ObjectOperationTerm) value.getValue();
        JAXBElement<? extends ObjectTerm> contextTerm = (JAXBElement<? extends ObjectTerm>) handle(
                t.getContextArgument().getObjectTerm());
        if (contextTerm != null) {
            t.getContextArgument().setObjectTerm(contextTerm);
        }
        handleArgs(t.getArguments().getTerm());
    }
    // nothing to return if the term is not a PropertyTerm, else return a variable
    return ret;
}

From source file:org.apache.axis2.datasource.jaxb.JAXBDSContext.java

/**
 * The root element being read is defined by schema/JAXB; however its contents are known by
 * schema/JAXB. Therefore we use unmarshal by the declared type (This method is used to
 * unmarshal rpc elements)/* w ww.jav  a  2s .c o  m*/
 * 
 * @param u Unmarshaller
 * @param reader XMLStreamReader
 * @param type Class
 * @return Object
 * @throws WebServiceException
 */
public static Object unmarshalByType(final Unmarshaller u, final XMLStreamReader reader, final Class type,
        final boolean isList, final JAXBUtils.CONSTRUCTION_TYPE ctype) throws WebServiceException {

    if (DEBUG_ENABLED) {
        log.debug("Invoking unmarshalByType.");
        log.debug("  type = " + type);
        log.debug("  isList = " + isList);
        log.debug("  ctype = " + ctype);
    }

    return AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            try {
                // Unfortunately RPC is type based. Thus a
                // declared type must be used to unmarshal the xml.
                Object jaxb;

                if (!isList) {
                    // case: We are not unmarshalling an xsd:list but an Array.

                    if (type.isArray()) {
                        // If the context is created using package
                        // we will not have common arrays or type array in the context
                        // but there is not much we can do about it so seralize it as
                        // usual
                        if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH) {
                            if (DEBUG_ENABLED) {
                                log.debug("Unmarshal Array via BY_CONTEXT_PATH approach");
                            }
                            jaxb = u.unmarshal(reader, type);
                        }
                        // list on client array on server, Can happen only in start from java
                        // case.
                        else if ((ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY)) {
                            // The type could be any Object or primitive

                            //process primitives first
                            //first verify if we have a primitive type associated in the array.
                            //array could be single dimension or multi dimension.
                            Class cType = type.getComponentType();
                            while (cType.isArray()) {
                                cType = cType.getComponentType();
                            }
                            if (cType.isPrimitive()) {
                                if (DEBUG_ENABLED) {
                                    log.debug("Unmarshal Array of primitive via BY_CLASS_ARRAY approach");
                                }
                                jaxb = u.unmarshal(reader, type);
                            }
                            // process non primitive                          
                            // I will first unmarshall the xmldata to a String[]
                            // Then use the unmarshalled jaxbElement to create
                            // proper type Object Array.

                            else {
                                if (DEBUG_ENABLED) {
                                    log.debug("Unmarshal Array of non-primitive via BY_CLASS_ARRAY approach");
                                }
                                jaxb = unmarshalArray(reader, u, type);
                            }

                        } else {
                            if (DEBUG_ENABLED) {
                                log.debug("Unmarshal Array");
                            }
                            jaxb = u.unmarshal(reader, type);

                        }

                    } else if (type.isEnum()) {
                        // When JAXBContext is created using a context path, it will not 
                        // include Enum classes.
                        // These classes have @XmlEnum annotation but not @XmlType/@XmlElement,
                        // so the user will see MarshallingEx, class not known to ctxt.
                        // 
                        // This is a jax-b defect, for now this fix is in place to pass CTS.
                        // This only fixes the
                        // situation where the enum is the top-level object (e.g., message-part
                        // in rpc-lit scenario)
                        //
                        // Sample of what enum looks like:
                        // @XmlEnum public enum EnumString {
                        // @XmlEnumValue("String1") STRING_1("String1"),
                        // @XmlEnumValue("String2") STRING_2("String2");
                        //
                        // public static getValue(String){} <-- resolves a "value" to an emum
                        // object
                        // ... }
                        if (DEBUG_ENABLED) {
                            log.debug("Unmarshalling " + type.getName() + " as Enum");
                        }

                        JAXBElement<String> enumValue = u.unmarshal(reader,
                                XmlEnumUtils.getConversionType(type));

                        if (enumValue != null) {
                            jaxb = XmlEnumUtils.fromValue(type, enumValue.getValue());
                        } else {
                            jaxb = null;
                        }
                    }
                    //Normal case: We are not unmarshalling a xsd:list or Array
                    else {
                        if (DEBUG_ENABLED) {
                            log.debug("Unmarshalling normal case (not array, not xsd:list, not enum)");
                        }
                        jaxb = u.unmarshal(reader, type);
                    }

                } else {
                    // If this is an xsd:list, we need to return the appropriate
                    // list or array (see NOTE above)
                    // First unmarshal as a String
                    //Second convert the String into a list or array
                    if (DEBUG_ENABLED) {
                        log.debug("Unmarshalling xsd:list");
                    }
                    jaxb = unmarshalAsListOrArray(reader, u, type);

                }
                if (log.isDebugEnabled()) {
                    Class cls;
                    if (jaxb == null) {
                        if (DEBUG_ENABLED) {
                            log.debug("End unmarshalByType returning null object");
                        }

                    } else if (jaxb instanceof JAXBElement) {
                        JAXBElement jbe = (JAXBElement) jaxb;
                        if (DEBUG_ENABLED) {
                            log.debug("End unmarshalByType returning JAXBElement");
                            log.debug("  Class = " + jbe.getDeclaredType());
                            log.debug("  QName = " + jbe.getName());
                        }
                    } else {
                        if (DEBUG_ENABLED) {
                            log.debug("End unmarshalByType returning " + jaxb.getClass());
                        }
                    }
                }
                return jaxb;
            } catch (OMException e) {
                throw e;
            } catch (Throwable t) {
                throw new OMException(t);
            }
        }
    });
}

From source file:org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMinimalMethodMarshaller.java

/**
 * If the PDElement represents an array or List,
 * a new PDElement is returned that models the 
 * the array or List as a series of elements.
 * @param pde/*from  w w  w.java2s. c  o m*/
 * @return new PDElement or same PDElement
 */
private static PDElement processOccurrence(PDElement pde) {
    // All arrays and lists should be marshaled as
    // separate (occurrence) elements
    Element element = pde.getElement();
    if (element != null) {
        Object elementValue = element.getElementValue();
        if (elementValue instanceof JAXBElement) {
            JAXBElement jaxb = (JAXBElement) elementValue;
            Object value = jaxb.getValue();
            if (representAsOccurrence(value, jaxb.getDeclaredType())) {
                if (log.isDebugEnabled()) {
                    log.debug("Build OccurrentArray");
                }
                OccurrenceArray occurrenceArray = new OccurrenceArray(value);
                JAXBElement newJAXBElement = new JAXBElement(jaxb.getName(), jaxb.getDeclaredType(),
                        occurrenceArray);
                element = new Element(newJAXBElement, jaxb.getName());
                pde = new PDElement(pde.getParam(), element, null);
            }
        }
    }
    return pde;
}

From source file:org.apache.bval.jsr.xml.ValidationMappingParser.java

@SuppressWarnings("unchecked")
private Object getSingleValue(Serializable serializable, Class<?> returnType, String defaultPackage) {
    if (serializable instanceof String) {
        String value = (String) serializable;
        return convertToResultType(returnType, value, defaultPackage);
    }//from ww  w  . j a v  a 2  s .c o  m
    if (serializable instanceof JAXBElement<?>) {
        JAXBElement<?> elem = (JAXBElement<?>) serializable;
        if (String.class.equals(elem.getDeclaredType())) {
            String value = (String) elem.getValue();
            return convertToResultType(returnType, value, defaultPackage);
        }
        if (AnnotationType.class.equals(elem.getDeclaredType())) {
            AnnotationType annotationType = (AnnotationType) elem.getValue();
            try {
                Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) returnType;
                return createAnnotation(annotationType, annotationClass, defaultPackage);
            } catch (ClassCastException e) {
                throw new ValidationException("Unexpected parameter value");
            }
        }
    }
    throw new ValidationException("Unexpected parameter value");
}

From source file:org.apache.cxf.ws.security.sts.provider.operation.IssueDelegate.java

@SuppressWarnings("unchecked")
private static <T> T extractType(Object param, Class<T> clazz) {
    if (param instanceof JAXBElement) {
        JAXBElement<?> jaxbElement = (JAXBElement<?>) param;
        if (clazz == jaxbElement.getDeclaredType()) {
            return (T) jaxbElement.getValue();
        }//from  ww  w. j  a  v a  2  s.  c  o  m
    }
    return null;
}

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

protected void marshal(Cluster cluster, JAXBElement<?> jaxbElement, JAXBContext jaxbContext, Path outPath)
        throws FalconException {
    try {//from   ww w. ja  v a  2s .com
        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 " + outPath + " on cluster " + cluster.getName());
            LOG.debug(writer.getBuffer());
        }

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