src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/MultiplicityCounter.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.internal.xjc.reader.xmlschema;
    28 import java.math.BigInteger;
    29 import com.sun.tools.internal.xjc.model.Multiplicity;
    30 import com.sun.xml.internal.xsom.XSElementDecl;
    31 import com.sun.xml.internal.xsom.XSModelGroup;
    32 import com.sun.xml.internal.xsom.XSModelGroupDecl;
    33 import com.sun.xml.internal.xsom.XSParticle;
    34 import com.sun.xml.internal.xsom.XSWildcard;
    35 import com.sun.xml.internal.xsom.visitor.XSTermFunction;
    37 import static com.sun.tools.internal.xjc.model.Multiplicity.ONE;
    38 import static com.sun.tools.internal.xjc.model.Multiplicity.ZERO;
    40 /**
    41  * Counts {@link Multiplicity} for a particle/term.
    42  *
    43  * @author Kohsuke Kawaguchi
    44  */
    45 public final class MultiplicityCounter implements XSTermFunction<Multiplicity> {
    47     public static final MultiplicityCounter theInstance = new MultiplicityCounter();
    49     private MultiplicityCounter() {}
    51     public Multiplicity particle( XSParticle p ) {
    52         Multiplicity m = p.getTerm().apply(this);
    54         BigInteger max;
    55         if (m.max==null || (BigInteger.valueOf(XSParticle.UNBOUNDED).equals(p.getMaxOccurs())))
    56             max=null;
    57         else
    58             max=p.getMaxOccurs();
    60         return Multiplicity.multiply( m, Multiplicity.create(p.getMinOccurs(),max) );
    61     }
    63     public Multiplicity wildcard(XSWildcard wc) {
    64         return ONE;
    65     }
    67     public Multiplicity modelGroupDecl(XSModelGroupDecl decl) {
    68         return modelGroup(decl.getModelGroup());
    69     }
    71     public Multiplicity modelGroup(XSModelGroup group) {
    72         boolean isChoice = group.getCompositor() == XSModelGroup.CHOICE;
    74         Multiplicity r = ZERO;
    76         for( XSParticle p : group.getChildren()) {
    77             Multiplicity m = particle(p);
    79             if(r==null) {
    80                 r=m;
    81                 continue;
    82             }
    83             if(isChoice) {
    84                 r = Multiplicity.choice(r,m);
    85             } else {
    86                 r = Multiplicity.group(r,m);
    87             }
    88         }
    89         return r;
    90     }
    92     public Multiplicity elementDecl(XSElementDecl decl) {
    93         return ONE;
    94     }
    95 }

mercurial