Search in sources :

Example 1 with XmlNamespace

use of com.sun.xml.txw2.annotation.XmlNamespace in project jaxb-ri by eclipse-ee4j.

the class TXW method getTagName.

/*package*/
static QName getTagName(Class<?> c) {
    String localName = "";
    String nsUri = "##default";
    XmlElement xe = c.getAnnotation(XmlElement.class);
    if (xe != null) {
        localName = xe.value();
        nsUri = xe.ns();
    }
    if (localName.length() == 0) {
        localName = c.getName();
        int idx = localName.lastIndexOf('.');
        if (idx >= 0)
            localName = localName.substring(idx + 1);
        localName = Character.toLowerCase(localName.charAt(0)) + localName.substring(1);
    }
    if (nsUri.equals("##default")) {
        Package pkg = c.getPackage();
        if (pkg != null) {
            XmlNamespace xn = pkg.getAnnotation(XmlNamespace.class);
            if (xn != null)
                nsUri = xn.value();
        }
    }
    if (nsUri.equals("##default"))
        nsUri = "";
    return new QName(nsUri, localName);
}
Also used : XmlNamespace(com.sun.xml.txw2.annotation.XmlNamespace) QName(javax.xml.namespace.QName) XmlElement(com.sun.xml.txw2.annotation.XmlElement)

Example 2 with XmlNamespace

use of com.sun.xml.txw2.annotation.XmlNamespace in project jaxb-ri by eclipse-ee4j.

the class ContainerElement method getNamespace.

/**
 * Decides the namespace URI of the given package.
 */
private String getNamespace(Package pkg) {
    if (pkg == null)
        return "";
    String nsUri;
    XmlNamespace ns = pkg.getAnnotation(XmlNamespace.class);
    if (ns != null)
        nsUri = ns.value();
    else
        nsUri = "";
    return nsUri;
}
Also used : XmlNamespace(com.sun.xml.txw2.annotation.XmlNamespace)

Example 3 with XmlNamespace

use of com.sun.xml.txw2.annotation.XmlNamespace in project jaxb-ri by eclipse-ee4j.

the class ContainerElement method addElement.

/**
 * Writes a new element.
 */
@SuppressWarnings("unchecked")
private Object addElement(XmlElement e, Method method, Object[] args) {
    Class<?> rt = method.getReturnType();
    // the last precedence: default name
    String nsUri = "##default";
    String localName = method.getName();
    if (e != null) {
        // then the annotation on this method
        if (e.value().length() != 0)
            localName = e.value();
        nsUri = e.ns();
    }
    if (nsUri.equals("##default")) {
        // look for the annotation on the declaring class
        Class<?> c = method.getDeclaringClass();
        XmlElement ce = c.getAnnotation(XmlElement.class);
        if (ce != null) {
            nsUri = ce.ns();
        }
        if (nsUri.equals("##default"))
            // then default to the XmlNamespace
            nsUri = getNamespace(c.getPackage());
    }
    if (rt == Void.TYPE) {
        // leaf element with just a value
        boolean isCDATA = method.getAnnotation(XmlCDATA.class) != null;
        StartTag st = new StartTag(document, nsUri, localName);
        addChild(st);
        for (Object arg : args) {
            Text text;
            if (isCDATA)
                text = new Cdata(document, st, arg);
            else
                text = new Pcdata(document, st, arg);
            addChild(text);
        }
        addChild(new EndTag());
        return null;
    }
    if (TypedXmlWriter.class.isAssignableFrom(rt)) {
        // sub writer
        return _element(nsUri, localName, (Class<? extends TypedXmlWriter>) rt);
    }
    throw new IllegalSignatureException("Illegal return type: " + rt);
}
Also used : XmlElement(com.sun.xml.txw2.annotation.XmlElement) XmlCDATA(com.sun.xml.txw2.annotation.XmlCDATA)

Aggregations

XmlElement (com.sun.xml.txw2.annotation.XmlElement)2 XmlNamespace (com.sun.xml.txw2.annotation.XmlNamespace)2 XmlCDATA (com.sun.xml.txw2.annotation.XmlCDATA)1 QName (javax.xml.namespace.QName)1