Search in sources :

Example 1 with Element

use of org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element in project jaxb-ri by eclipse-ee4j.

the class InlineAnnotationReaderImpl method getAllAnnotations.

/**
 * Gets all the annotations on the given declaration.
 */
private Annotation[] getAllAnnotations(Element decl, Locatable srcPos) {
    List<Annotation> r = new ArrayList<>();
    for (AnnotationMirror m : decl.getAnnotationMirrors()) {
        try {
            String fullName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName().toString();
            Class<? extends Annotation> type = SecureLoader.getClassClassLoader(getClass()).loadClass(fullName).asSubclass(Annotation.class);
            Annotation annotation = decl.getAnnotation(type);
            if (annotation != null)
                r.add(LocatableAnnotation.create(annotation, srcPos));
        } catch (ClassNotFoundException e) {
        // just continue
        }
    }
    return r.toArray(new Annotation[0]);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) LocatableAnnotation(org.glassfish.jaxb.runtime.v2.model.annotation.LocatableAnnotation)

Example 2 with Element

use of org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element in project jaxb-ri by eclipse-ee4j.

the class StructureLoader method init.

/**
 * Completes the initialization.
 *
 * <p>
 * To fix the cyclic reference issue, the main part of the initialization needs to be done
 * after a  is set to {@link ClassBeanInfoImpl#loader}.
 */
public void init(JAXBContextImpl context, ClassBeanInfoImpl beanInfo, Accessor<?, Map<QName, String>> attWildcard) {
    UnmarshallerChain chain = new UnmarshallerChain(context);
    for (ClassBeanInfoImpl bi = beanInfo; bi != null; bi = bi.superClazz) {
        for (int i = bi.properties.length - 1; i >= 0; i--) {
            Property p = bi.properties[i];
            switch(p.getKind()) {
                case ATTRIBUTE:
                    if (attUnmarshallers == null)
                        attUnmarshallers = new QNameMap<>();
                    AttributeProperty ap = (AttributeProperty) p;
                    attUnmarshallers.put(ap.attName.toQName(), ap.xacc);
                    break;
                case ELEMENT:
                case REFERENCE:
                case MAP:
                case VALUE:
                    p.buildChildElementUnmarshallers(chain, childUnmarshallers);
                    break;
            }
        }
    }
    this.frameSize = chain.getScopeSize();
    textHandler = childUnmarshallers.get(StructureLoaderBuilder.TEXT_HANDLER);
    catchAll = childUnmarshallers.get(StructureLoaderBuilder.CATCH_ALL);
    if (attWildcard != null) {
        attCatchAll = (Accessor<Object, Map<QName, String>>) attWildcard;
        // altogether, so if we have an att wildcard we need to have an empty qname map.
        if (attUnmarshallers == null)
            attUnmarshallers = EMPTY;
    } else {
        attCatchAll = null;
    }
}
Also used : ClassBeanInfoImpl(org.glassfish.jaxb.runtime.v2.runtime.ClassBeanInfoImpl) UnmarshallerChain(org.glassfish.jaxb.runtime.v2.runtime.property.UnmarshallerChain) QNameMap(org.glassfish.jaxb.runtime.v2.util.QNameMap) AttributeProperty(org.glassfish.jaxb.runtime.v2.runtime.property.AttributeProperty) AttributeProperty(org.glassfish.jaxb.runtime.v2.runtime.property.AttributeProperty) Property(org.glassfish.jaxb.runtime.v2.runtime.property.Property) QNameMap(org.glassfish.jaxb.runtime.v2.util.QNameMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Element

use of org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element in project jaxb-ri by eclipse-ee4j.

the class SingleElementNodeProperty method buildChildElementUnmarshallers.

@Override
public void buildChildElementUnmarshallers(UnmarshallerChain chain, QNameMap<ChildLoader> handlers) {
    JAXBContextImpl context = chain.context;
    for (TypeRef<Type, Class> e : prop.getTypes()) {
        JaxBeanInfo bi = context.getOrCreate((RuntimeTypeInfo) e.getTarget());
        // if the expected Java type is already final, type substitution won't really work anyway.
        // this also traps cases like trying to substitute xsd:long element with xsi:type='xsd:int'
        Loader l = bi.getLoader(context, !Modifier.isFinal(bi.jaxbType.getModifiers()));
        if (e.getDefaultValue() != null)
            l = new DefaultValueLoaderDecorator(l, e.getDefaultValue());
        if (nillable || chain.context.allNillable)
            l = new XsiNilLoader.Single(l, acc);
        handlers.put(e.getTagName(), new ChildLoader(l, acc));
    }
}
Also used : Type(java.lang.reflect.Type) JaxBeanInfo(org.glassfish.jaxb.runtime.v2.runtime.JaxBeanInfo) DefaultValueLoaderDecorator(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.DefaultValueLoaderDecorator) ChildLoader(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.ChildLoader) JAXBContextImpl(org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl) ChildLoader(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.ChildLoader) XsiNilLoader(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.XsiNilLoader) Loader(org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.Loader)

Example 4 with Element

use of org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element in project metro-jax-ws by eclipse-ee4j.

the class ServiceArtifactSchemaGenerator method generate.

public void generate(SchemaOutputResolver resolver) {
    xsdResolver = resolver;
    List<WrapperParameter> wrappers = new ArrayList<>();
    for (JavaMethodImpl method : model.getJavaMethods()) {
        if (method.getBinding().isRpcLit())
            continue;
        for (ParameterImpl p : method.getRequestParameters()) {
            if (p instanceof WrapperParameter) {
                if (WrapperComposite.class.equals((p.getTypeInfo().type))) {
                    wrappers.add((WrapperParameter) p);
                }
            }
        }
        for (ParameterImpl p : method.getResponseParameters()) {
            if (p instanceof WrapperParameter) {
                if (WrapperComposite.class.equals((p.getTypeInfo().type))) {
                    wrappers.add((WrapperParameter) p);
                }
            }
        }
    }
    if (wrappers.isEmpty())
        return;
    HashMap<String, Schema> xsds = initWrappersSchemaWithImports(wrappers);
    postInit(xsds);
    for (WrapperParameter wp : wrappers) {
        String tns = wp.getName().getNamespaceURI();
        Schema xsd = xsds.get(tns);
        Element e = xsd._element(Element.class);
        e._attribute("name", wp.getName().getLocalPart());
        e.type(wp.getName());
        ComplexType ct = xsd._element(ComplexType.class);
        ct._attribute("name", wp.getName().getLocalPart());
        ExplicitGroup sq = ct.sequence();
        for (ParameterImpl p : wp.getWrapperChildren()) if (p.getBinding().isBody())
            addChild(sq, p);
    }
    for (Schema xsd : xsds.values()) xsd.commit();
}
Also used : JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) Schema(com.sun.xml.ws.wsdl.writer.document.xsd.Schema) LocalElement(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.LocalElement) Element(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.Element) ArrayList(java.util.ArrayList) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) ComplexType(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ComplexType) ExplicitGroup(org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.ExplicitGroup)

Aggregations

ArrayList (java.util.ArrayList)2 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)1 ParameterImpl (com.sun.xml.ws.model.ParameterImpl)1 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)1 Schema (com.sun.xml.ws.wsdl.writer.document.xsd.Schema)1 Annotation (java.lang.annotation.Annotation)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 LocatableAnnotation (org.glassfish.jaxb.runtime.v2.model.annotation.LocatableAnnotation)1 ClassBeanInfoImpl (org.glassfish.jaxb.runtime.v2.runtime.ClassBeanInfoImpl)1 JAXBContextImpl (org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl)1 JaxBeanInfo (org.glassfish.jaxb.runtime.v2.runtime.JaxBeanInfo)1 AttributeProperty (org.glassfish.jaxb.runtime.v2.runtime.property.AttributeProperty)1 Property (org.glassfish.jaxb.runtime.v2.runtime.property.Property)1 UnmarshallerChain (org.glassfish.jaxb.runtime.v2.runtime.property.UnmarshallerChain)1 ChildLoader (org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.ChildLoader)1 DefaultValueLoaderDecorator (org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.DefaultValueLoaderDecorator)1 Loader (org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.Loader)1