
org.javastro.ivoa.jaxb.JaxbAnnotationMeta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxbjpa-utils Show documentation
Show all versions of jaxbjpa-utils Show documentation
generic utilities to make using JAXB and JPA easier
The newest version!
/*
* Created on 18 Aug 2021
* Copyright 2021 Paul Harrison ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License in file LICENSE
*/
package org.javastro.ivoa.jaxb;
import java.lang.annotation.Annotation;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.annotation.XmlSchema;
import javax.xml.namespace.QName;
/**
* Create the required entity metadata assuming JAXB Annotation.
*
* @author Paul Harrison ([email protected])
* @since 18 Aug 2021
*/
public class JaxbAnnotationMeta implements EntityMetadata {
private final Class type;
public JaxbAnnotationMeta(Class type) {
this.type = type;
}
public static JaxbAnnotationMeta of(Class clazz) {
return new JaxbAnnotationMeta(clazz);
}
/**
* {@inheritDoc} overrides @see
* org.javastro.ivoa.entities.jaxb.EntityMetadata#getJavaType()
*/
@Override
public Class getJavaType() {
return type;
}
/**
* {@inheritDoc} overrides @see
* org.javastro.ivoa.entities.jaxb.EntityMetadata#getNamespace()
*/
@Override
public String getNamespace() {
String nsURI = "";
for (Annotation annotation : type.getPackage().getAnnotations()) {
if (annotation.annotationType() == XmlSchema.class) {
nsURI = ((XmlSchema) annotation).namespace();
break;
}
}
return nsURI;
}
/**
* {@inheritDoc} overrides @see
* org.javastro.ivoa.entities.jaxb.EntityMetadata#getName()
*/
@Override
public String getName() {
return type.getSimpleName();
}
public JAXBElement element(T o)
{
return new JAXBElement(new QName(getNamespace(), getName()), type, o);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy