Java Code Examples for javax.xml.bind.JAXBElement#getDeclaredType()
The following examples show how to use
javax.xml.bind.JAXBElement#getDeclaredType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleElementLeafProperty.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 2
Source File: X509Register.java From cxf with Apache License 2.0 | 6 votes |
private List<X509Certificate> getCertsFromKeyInfo(KeyInfoType keyInfo) throws CertificateException { List<X509Certificate> certList = new ArrayList<>(); for (Object key : keyInfo.getContent()) { if (key instanceof JAXBElement) { Object value = ((JAXBElement<?>) key).getValue(); if (value instanceof X509DataType) { X509DataType x509Data = (X509DataType) value; List<Object> data = x509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName(); for (Object certO : data) { JAXBElement<?> certO2 = (JAXBElement<?>) certO; if (certO2.getDeclaredType() == byte[].class) { byte[] certContent = (byte[]) certO2.getValue(); X509Certificate cert = (X509Certificate) certFactory .generateCertificate(new ByteArrayInputStream(certContent)); certList.add(cert); } } } } } return certList; }
Example 3
Source File: JAXBElementEntityProvider.java From everrest with Eclipse Public License 2.0 | 6 votes |
@Override public void writeTo(JAXBElement<?> t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { Class<?> declaredType = t.getDeclaredType(); try { JAXBContext jaxbContext = getJAXBContext(declaredType, mediaType); Marshaller marshaller = jaxbContext.createMarshaller(); String charset = getCharset(mediaType); if (!isNullOrEmpty(charset)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, charset); } marshaller.marshal(t, entityStream); } catch (JAXBException e) { throw new IOException(String.format("Can't write to output stream, %s", e)); } }
Example 4
Source File: JAXBElementUtils.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 6 votes |
public static <T> JAXBElement<T> wrap(JAXBElement element, String name, T value) { if (name == null || value == null) { return null; } else { if (element != null) { if (element.getName().equals(QName.valueOf(name)) && element.getDeclaredType() == value.getClass()) { element.setValue(value); return element; } else { return new JAXBElement(QName.valueOf(name), value .getClass(), value); } } else { return new JAXBElement(QName.valueOf(name), value.getClass(), value); } } }
Example 5
Source File: JAXBElementUtils.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 6 votes |
public static <T> JAXBElement<T> wrap(JAXBElement element, String name, Class<T> declaredType) { QName qName = QName.valueOf(name); if (name == null) { return null; } else { if (element == null) { return new JAXBElement(qName, declaredType, null); } else if (element.getName().equals(qName)) { return element; } else { return new JAXBElement(qName, element.getDeclaredType(), element.getValue()); } } }
Example 6
Source File: SingleElementLeafProperty.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 7
Source File: SingleElementLeafProperty.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 8
Source File: SingleElementLeafProperty.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 9
Source File: SingleElementLeafProperty.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 10
Source File: SingleElementLeafProperty.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 11
Source File: SingleElementLeafProperty.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Checks if element is nillable and represented by abstract class. */ private boolean isNillableAbstract(BeanT bean, JAXBContextImpl context, Object value, Class valueTypeClass) { if (!nillable) // check if element is nillable return false; if (valueTypeClass != Object.class) // required type wasn't recognized return false; if (bean.getClass() != JAXBElement.class) // is JAXBElement return false; JAXBElement jaxbElement = (JAXBElement) bean; Class valueClass = value.getClass(); Class declaredTypeClass = jaxbElement.getDeclaredType(); if (declaredTypeClass.equals(valueClass)) // JAXBElement<class> is different from unadapted class) return false; if (!declaredTypeClass.isAssignableFrom(valueClass)) // and is subclass from it return false; if (!Modifier.isAbstract(declaredTypeClass.getModifiers())) // declared class is abstract return false; return acc.isAbstractable(declaredTypeClass); // and is not builtin type }
Example 12
Source File: PartwiseBuilder.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
private void processArticulation (ArticulationInter articulation) { try { logger.debug("Visiting {}", articulation); JAXBElement<?> element = getArticulationObject(articulation.getShape()); // Staff? Staff staff = current.note.getStaff(); // Placement Class<?> classe = element.getDeclaredType(); Method method = classe.getMethod("setPlacement", AboveBelow.class); method.invoke( element.getValue(), (articulation.getCenter().y < current.note.getCenter().y) ? AboveBelow.ABOVE : AboveBelow.BELOW); // Default-Y method = classe.getMethod("setDefaultY", BigDecimal.class); method.invoke(element.getValue(), yOf(articulation.getCenter(), staff)); // Include in Articulations getArticulations().getAccentOrStrongAccentOrStaccato().add(element); } catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException ex) { logger.warn("Error visiting " + articulation, ex); } }
Example 13
Source File: JAXBCopyStrategy.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("unchecked") protected Object copyInternal(ObjectLocator locator, @SuppressWarnings("rawtypes") final JAXBElement jaxbElement) { final Object sourceObject = jaxbElement.getValue(); final Object copyObject = copy( property(locator, "value", sourceObject), sourceObject); @SuppressWarnings("rawtypes") final JAXBElement copyElement = new JAXBElement(jaxbElement.getName(), jaxbElement.getDeclaredType(), jaxbElement.getScope(), copyObject); return copyElement; }
Example 14
Source File: JAXBHelper.java From ph-commons with Apache License 2.0 | 5 votes |
@Nullable public static <DATATYPE> JAXBElement <DATATYPE> getClonedJAXBElement (@Nullable final JAXBElement <DATATYPE> aObj) { if (aObj == null) return null; final DATATYPE aClonedValue = CloneHelper.getClonedValue (aObj.getValue ()); final JAXBElement <DATATYPE> ret = new JAXBElement <> (aObj.getName (), aObj.getDeclaredType (), aObj.getScope (), aClonedValue); ret.setNil (aObj.isNil ()); return ret; }
Example 15
Source File: ScoreExporter.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean visit (Articulation articulation) { try { logger.debug("Visiting {}", articulation); JAXBElement<?> element = getArticulationObject( articulation.getShape()); // Staff ? Staff staff = current.note.getStaff(); // Placement Class<?> classe = element.getDeclaredType(); Method method = classe.getMethod( "setPlacement", AboveBelow.class); method.invoke( element.getValue(), (articulation.getReferencePoint().y < current.note. getCenter().y) ? AboveBelow.ABOVE : AboveBelow.BELOW); // Default-Y method = classe.getMethod("setDefaultY", BigDecimal.class); method.invoke( element.getValue(), yOf(articulation.getReferencePoint(), staff)); // Include in Articulations getArticulations().getAccentOrStrongAccentOrStaccato().add(element); } catch (Exception ex) { logger.warn("Error visiting " + articulation, ex); } return false; }
Example 16
Source File: RequestParser.java From cxf with Apache License 2.0 | 5 votes |
private static <T> T extractType(Object param, Class<T> clazz) { if (param instanceof JAXBElement<?>) { JAXBElement<?> jaxbElement = (JAXBElement<?>) param; if (clazz == jaxbElement.getDeclaredType()) { return clazz.cast(jaxbElement.getValue()); } } return null; }
Example 17
Source File: JSONProvider.java From cxf with Apache License 2.0 | 4 votes |
protected void marshalCollection(Class<?> originalCls, Object collection, Type genericType, String encoding, OutputStream os, MediaType m, Annotation[] anns) throws Exception { Class<?> actualClass = InjectionUtils.getActualType(genericType); actualClass = getActualType(actualClass, genericType, anns); Collection<?> c = originalCls.isArray() ? Arrays.asList((Object[]) collection) : (Collection<?>) collection; Iterator<?> it = c.iterator(); Object firstObj = it.hasNext() ? it.next() : null; String startTag = null; String endTag = null; if (!dropCollectionWrapperElement) { QName qname = null; if (firstObj instanceof JAXBElement) { JAXBElement<?> el = (JAXBElement<?>)firstObj; qname = el.getName(); actualClass = el.getDeclaredType(); } else { qname = getCollectionWrapperQName(actualClass, genericType, firstObj, false); } String prefix = ""; if (!ignoreNamespaces) { prefix = namespaceMap.get(qname.getNamespaceURI()); if (prefix != null) { if (prefix.length() > 0) { prefix += "."; } } else if (qname.getNamespaceURI().length() > 0) { prefix = "ns1."; } } prefix = (prefix == null) ? "" : prefix; startTag = "{\"" + prefix + qname.getLocalPart() + "\":["; endTag = "]}"; } else if (serializeAsArray) { startTag = "["; endTag = "]"; } else { startTag = "{"; endTag = "}"; } os.write(startTag.getBytes()); if (firstObj != null) { XmlJavaTypeAdapter adapter = org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns); marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true), actualClass, genericType, encoding, os); while (it.hasNext()) { os.write(",".getBytes()); marshalCollectionMember(JAXBUtils.useAdapter(it.next(), adapter, true), actualClass, genericType, encoding, os); } } os.write(endTag.getBytes()); }
Example 18
Source File: JAXBElementProvider.java From cxf with Apache License 2.0 | 4 votes |
protected void marshalCollection(Class<?> originalCls, Object collection, Type genericType, String enc, OutputStream os, MediaType m, Annotation[] anns) throws Exception { Class<?> actualClass = InjectionUtils.getActualType(genericType); actualClass = getActualType(actualClass, genericType, anns); Collection<?> c = originalCls.isArray() ? Arrays.asList((Object[]) collection) : (Collection<?>) collection; Iterator<?> it = c.iterator(); Object firstObj = it.hasNext() ? it.next() : null; QName qname = null; if (firstObj instanceof JAXBElement) { JAXBElement<?> el = (JAXBElement<?>)firstObj; qname = el.getName(); actualClass = el.getDeclaredType(); } else { qname = getCollectionWrapperQName(actualClass, genericType, firstObj, true); } if (qname == null) { String message = new org.apache.cxf.common.i18n.Message("NO_COLLECTION_ROOT", BUNDLE).toString(); throw new WebApplicationException(Response.serverError() .entity(message).build()); } StringBuilder pi = new StringBuilder(); pi.append(XML_PI_START + (enc == null ? StandardCharsets.UTF_8.name() : enc) + "\"?>"); os.write(pi.toString().getBytes()); String startTag = null; String endTag = null; if (qname.getNamespaceURI().length() > 0) { String prefix = nsPrefixes.get(qname.getNamespaceURI()); if (prefix == null) { prefix = "ns1"; } startTag = "<" + prefix + ":" + qname.getLocalPart() + " xmlns:" + prefix + "=\"" + qname.getNamespaceURI() + "\">"; endTag = "</" + prefix + ":" + qname.getLocalPart() + ">"; } else { startTag = "<" + qname.getLocalPart() + ">"; endTag = "</" + qname.getLocalPart() + ">"; } os.write(startTag.getBytes()); if (firstObj != null) { XmlJavaTypeAdapter adapter = org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns); marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true), actualClass, genericType, enc, os, anns, m, qname.getNamespaceURI()); while (it.hasNext()) { marshalCollectionMember(JAXBUtils.useAdapter(it.next(), adapter, true), actualClass, genericType, enc, os, anns, m, qname.getNamespaceURI()); } } os.write(endTag.getBytes()); }
Example 19
Source File: JSONProvider.java From entando-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void marshalCollection(Class<?> originalCls, Object collection, Type genericType, String encoding, OutputStream os, MediaType m, Annotation[] anns) throws Exception { Class<?> actualClass = InjectionUtils.getActualType(genericType); actualClass = getActualType(actualClass, genericType, anns); Collection<?> c = originalCls.isArray() ? Arrays.asList((Object[]) collection) : (Collection<?>) collection; Iterator<?> it = c.iterator(); Object firstObj = it.hasNext() ? it.next() : null; String startTag = null; String endTag = null; if (!dropCollectionWrapperElement) { QName qname = null; if (firstObj instanceof JAXBElement) { JAXBElement<?> el = (JAXBElement<?>)firstObj; qname = el.getName(); actualClass = el.getDeclaredType(); } else { qname = getCollectionWrapperQName(actualClass, genericType, firstObj, false); } String prefix = ""; if (!ignoreNamespaces) { prefix = namespaceMap.get(qname.getNamespaceURI()); if (prefix != null) { if (prefix.length() > 0) { prefix += "."; } } else if (qname.getNamespaceURI().length() > 0) { prefix = "ns1."; } } prefix = (prefix == null) ? "" : prefix; startTag = "{\"" + prefix + qname.getLocalPart() + "\":["; endTag = "]}"; } else if (serializeAsArray) { startTag = "["; endTag = "]"; } else { startTag = "{"; endTag = "}"; } os.write(startTag.getBytes()); if (firstObj != null) { XmlJavaTypeAdapter adapter = org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns); marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true), actualClass, genericType, encoding, os); while (it.hasNext()) { os.write(",".getBytes()); marshalCollectionMember(JAXBUtils.useAdapter(it.next(), adapter, true), actualClass, genericType, encoding, os); } } os.write(endTag.getBytes()); }
Example 20
Source File: RoundtripTest.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
@Override protected void checkSample(File sample) throws Exception { // TODO Auto-generated method stub final JAXBContext context = createContext(); logger.debug("Unmarshalling."); final Unmarshaller unmarshaller = context.createUnmarshaller(); // Unmarshall the document final JAXBElement element = (JAXBElement) unmarshaller .unmarshal(sample); final Object object = element.getValue(); logger.debug("Opening session."); // Open the session, save object into the database logger.debug("Saving the object."); final PersistenceManager saveManager = createPersistenceManager(); // saveManager.setDetachAllOnCommit(true); final Transaction saveTransaction = saveManager.currentTransaction(); saveTransaction.setNontransactionalRead(true); saveTransaction.begin(); // final Object merged = saveSession.merge(object); // saveSession.replicate(object, ReplicationMode.OVERWRITE); // saveSession.get // final Serializable id = final Object mergedObject = saveManager.makePersistent(object); // final Object asd = saveManager.detachCopy(object); saveTransaction.commit(); // final Object id = saveManager.getObjectId(mergedObject); final Object identity = JDOHelper.getObjectId(object); final Object id = identity instanceof SingleFieldIdentity ? ((SingleFieldIdentity) identity).getKeyAsObject() : identity; // Close the session saveManager.close(); logger.debug("Opening session."); // Open the session, load the object final PersistenceManager loadManager = createPersistenceManager(); final Transaction loadTransaction = loadManager.currentTransaction(); loadTransaction.setNontransactionalRead(true); logger.debug("Loading the object."); final Object loadedObject = loadManager.getObjectById(mergedObject.getClass(), id); logger.debug("Closing the session."); final JAXBElement mergedElement = new JAXBElement(element.getName(), element.getDeclaredType(), object); final JAXBElement loadedElement = new JAXBElement(element.getName(), element.getDeclaredType(), loadedObject); logger.debug("Checking the document identity."); logger.debug("Source object:\n" + ContextUtils.toString(context, mergedElement)); logger.debug("Result object:\n" + ContextUtils.toString(context, loadedElement)); checkObjects(mergedObject, loadedObject); loadManager.close(); }