Package com.sun.xml.bind.v2.schemagen.xmlschema

Examples of com.sun.xml.bind.v2.schemagen.xmlschema.Occurs


                acc.set(bean,t);
        }

        public void parse(final BeanT bean, CharSequence lexical) throws AccessorException, SAXException {
            final String idref = WhiteSpaceProcessor.trim(lexical).toString();
            final UnmarshallingContext context = UnmarshallingContext.getInstance();

            final Callable callable = context.getObjectFromId(idref,acc.valueType);
            if(callable==null) {
                // the IDResolver decided to abort it now
                context.errorUnresolvedIDREF(bean,idref,context.getLocator());
                return;
            }

            TargetT t;
            try {
                t = (TargetT)callable.call();
            } catch (SAXException e) {// from callable.call
                throw e;
            } catch (RuntimeException e) {// from callable.call
                throw e;
            } catch (Exception e) {// from callable.call
                throw new SAXException2(e);
            }
            if(t!=null) {
                assign(bean,t,context);
            } else {
                // try again later
                final LocatorEx loc = new LocatorEx.Snapshot(context.getLocator());
                context.addPatcher(new Patcher() {
                    public void run() throws SAXException {
                        try {
                            TargetT t = (TargetT)callable.call();
                            if(t==null) {
                                context.errorUnresolvedIDREF(bean,idref,loc);
                            } else {
                                assign(bean,t,context);
                            }
                        } catch (AccessorException e) {
                            context.handleError(e);
                        } catch (SAXException e) {// from callable.call
                            throw e;
                        } catch (RuntimeException e) {// from callable.call
                            throw e;
                        } catch (Exception e) {// from callable.call
View Full Code Here


            // these variables have to be set before they are initialized,
            // because the initialization may build other loaders and they may refer to this.
            StructureLoader sl = new StructureLoader(this);
            loader = sl;
            if(ci.hasSubClasses())
                loaderWithTypeSubst = new XsiTypeLoader(this);
            else
                // optimization. we know there can be no @xsi:type
                loaderWithTypeSubst = loader;

View Full Code Here

            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();
    }
View Full Code Here

        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);
        }
View Full Code Here

            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();
    }
View Full Code Here

            child.maxOccurs("unbounded");
        }
    }
   
    protected Occurs addChild(ExplicitGroup sq, QName name, TypeInfo typeInfo) {
        LocalElement le = null;;
        QName type = model.getBindingContext().getTypeName(typeInfo);
        if (type != null) {
            le = sq.element();
            le._attribute("name", name.getLocalPart());
            le.type(type);
        } else {
            if (typeInfo.type instanceof Class) {
                try {
                    QName elemName = model.getBindingContext().getElementName((Class)typeInfo.type);
                    if (elemName.getLocalPart().equals("any") && elemName.getNamespaceURI().equals(XsdNs)) {
                        return sq.any();
                    } else {
                        le = sq.element();
                        le.ref(elemName);
                    }
                } catch (JAXBException je) {
                    throw new WebServiceException(je.getMessage(), je);
                }
            }
View Full Code Here

            typeInfo = param.getTypeInfo();
        } else {
            if (typeInfo.getWrapperType() != null) typeInfo = param.getTypeInfo();
            else repeatedElement = true;
        }
        Occurs child = addChild(sq, param.getName(), typeInfo);
        if (repeatedElement && child != null) {
            child.maxOccurs("unbounded");
        }
    }
View Full Code Here

         * @param ep the element property
         * @param compositor the schema compositor (sequence or all)
         */
        private void handleElementProp(ElementPropertyInfo<T,C> ep, ExplicitGroup compositor) {
            QName ename = ep.getXmlName();
            Occurs occurs = null;

            if (ep.isValueList()) {
                TypeRef<T,C> t = ep.getTypes().get(0);
                LocalElement e = compositor.element();

                QName tn = t.getTagName();
                e.name(tn.getLocalPart());
                List lst = e.simpleType().list();
                writeTypeRef(lst,t, "itemType");
                elementFormDefault.writeForm(e,tn);
                return;
            }

            if (ep.isCollection()) {
                if (ename != null) { // wrapped collection
                    LocalElement e = compositor.element();
                    if(ename.getNamespaceURI().length()>0) {
                        if (!ename.getNamespaceURI().equals(this.uri)) {
                            // TODO: we need to generate the corresponding element declaration for this
                            // table 8-25: Property/field element wrapper with ref attribute
                            e.ref(new QName(ename.getNamespaceURI(), ename.getLocalPart()));
                            return;
                        }
                    }
                    elementFormDefault.writeForm(e,ename);

                    ComplexType p = e.name(ename.getLocalPart()).complexType();
                    if(ep.isCollectionNillable()) {
                        e.nillable(true);
                    } else {
                        e.minOccurs(0);
                    }
                    if (ep.getTypes().size() == 1) {
                        compositor = p.sequence();
                    } else {
                        compositor = p.choice();
                        occurs = compositor;
                    }
                } else { // unwrapped collection
                    if (ep.getTypes().size() > 1) {
                        compositor = compositor.choice();
                        occurs = compositor;
                    }
                }
            } else {
                if (ep.getTypes().size() > 1) {
                    compositor = compositor.choice();
                    occurs = compositor;
                }
            }


            // fill in the content model
            for (TypeRef<T,C> t : ep.getTypes()) {
                LocalElement e = compositor.element();
                if (occurs == null) occurs = e;
                QName tn = t.getTagName();

                if(canBeDirectElementRef(t,tn) || (!tn.getNamespaceURI().equals(uri) && tn.getNamespaceURI().length()>0)) {
                    e.ref(tn);
                } else {
                    e.name(tn.getLocalPart());
                    writeTypeRef(e,t, "type");
                    elementFormDefault.writeForm(e,tn);
                }

                if (t.isNillable()) {
                    e.nillable(true);
                }
                if(t.getDefaultValue()!=null)
                    e._default(t.getDefaultValue());
            }

            if (ep.isCollection())
                occurs.maxOccurs("unbounded");

            if (!ep.isRequired())
                // see Spec table 8-13
                occurs.minOccurs(0);
            // else minOccurs defaults to 1
        }
View Full Code Here

         * @param rp
         * @param compositor
         */
        private void handleReferenceProp(ReferencePropertyInfo<T,C> rp, ExplicitGroup compositor) {
            QName ename = rp.getXmlName();
            Occurs occurs = null;

            if (rp.isCollection()) {
                if (ename != null) { // wrapped collection
                    LocalElement e = compositor.element();
                    ComplexType p = e.name(ename.getLocalPart()).complexType();
                    elementFormDefault.writeForm(e,ename);
                    if(rp.isCollectionNillable())
                        e.nillable(true);
                    if (rp.getElements().size() == 1) {
                        compositor = p.sequence();
                    } else {
                        compositor = p.choice();
                        occurs = compositor;
                    }
                } else { // unwrapped collection
                    if (rp.getElements().size() > 1) {
                        compositor = compositor.choice();
                        occurs = compositor;
                    }
                }
            }

            // fill in content model
            TODO.checkSpec("should we loop in the case of a non-collection ep?");
            for (Element<T,C> e : rp.getElements()) {
                LocalElement eref = compositor.element();
                if (occurs == null) occurs = eref;

                QName en = e.getElementName();
                if(e.getScope()!=null) {
                    // scoped. needs to be inlined
                    boolean qualified = en.getNamespaceURI().equals(uri);
                    boolean unqualified = en.getNamespaceURI().equals("");
                    if(qualified || unqualified) {
                        // can be inlined indeed

                        // write form="..." if necessary
                        if(unqualified) {
                            if(elementFormDefault.isEffectivelyQualified)
                                eref.form("unqualified");
                        } else {
                            if(!elementFormDefault.isEffectivelyQualified)
                                eref.form("qualified");
                        }

                        eref.name(en.getLocalPart());

                        // write out type reference
                        if(e instanceof ClassInfo) {
                            writeTypeRef(eref,(ClassInfo<T,C>)e,"type");
                        } else {
                            writeTypeRef(eref,((ElementInfo<T,C>)e).getContentType(),"type");
                        }
                        continue;
                    }
                }
                eref.ref(en);
            }

            WildcardMode wc = rp.getWildcard();
            if( wc != null ) {
                Any any = compositor.any();
                final String pcmode = getProcessContentsModeName(wc);
                if( pcmode != null ) any.processContents(pcmode);
                TODO.schemaGenerator("generate @namespace ???");
                if( occurs == null ) occurs = any;
            }

            if(rp.isCollection())
                occurs.maxOccurs("unbounded");

        }
View Full Code Here

    public void writeBinary(DataHandler dh) throws XMLStreamException {
        int len =0;
        byte[] data = null;
        InputStream is = null;
        ByteArrayOutputStreamEx baos = null;
        try {
            baos = new ByteArrayOutputStreamEx();
            is = dh.getDataSource().getInputStream();
            baos.readFrom(is);
            data = baos.toByteArray();
            len = data.length;
            baos.close();
            is.close();
        } catch (IOException ioe) {
            logger.log(Level.SEVERE, "could not get the inputstream from the data handler", ioe);
        }
        if (len > 1000) {
View Full Code Here

TOP

Related Classes of com.sun.xml.bind.v2.schemagen.xmlschema.Occurs

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.