1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 1999-2002,2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.impl.xs.models;
  22 
  23 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;
  24 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMStateSet;
  25 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;
  26 
  27 /**
  28  *
  29  * Content model Uni-Op node.
  30  *
  31  * @xerces.internal
  32  *
  33  * @author Neil Graham, IBM
  34  * @version $$
  35  */
  36 public class XSCMUniOp extends CMNode {
  37     // -------------------------------------------------------------------
  38     //  Constructors
  39     // -------------------------------------------------------------------
  40     public XSCMUniOp(int type, CMNode childNode) {
  41         super(type);
  42 
  43         // Insure that its one of the types we require
  44         if ((type() != XSParticleDecl.PARTICLE_ZERO_OR_ONE)
  45         &&  (type() != XSParticleDecl.PARTICLE_ZERO_OR_MORE)
  46         &&  (type() != XSParticleDecl.PARTICLE_ONE_OR_MORE)) {
  47             throw new RuntimeException("ImplementationMessages.VAL_UST");
  48         }
  49 
  50         // Store the node and init any data that needs it
  51         fChild = childNode;
  52     }
  53 
  54 
  55     // -------------------------------------------------------------------
  56     //  Package, final methods
  57     // -------------------------------------------------------------------
  58     final CMNode getChild() {
  59         return fChild;
  60     }
  61 
  62 
  63     // -------------------------------------------------------------------
  64     //  Package, inherited methods
  65     // -------------------------------------------------------------------
  66     public boolean isNullable() {
  67         //
  68         //  For debugging purposes, make sure we got rid of all non '*'
  69         //  repetitions. Otherwise, '*' style nodes are always nullable.
  70         //
  71         if (type() == XSParticleDecl.PARTICLE_ONE_OR_MORE)
  72                 return fChild.isNullable();
  73             else
  74                 return true;
  75     }
  76 
  77 
  78     // -------------------------------------------------------------------
  79     //  Protected, inherited methods
  80     // -------------------------------------------------------------------
  81     protected void calcFirstPos(CMStateSet toSet) {
  82         // Its just based on our child node's first pos
  83         toSet.setTo(fChild.firstPos());
  84     }
  85 
  86     protected void calcLastPos(CMStateSet toSet) {
  87         // Its just based on our child node's last pos
  88         toSet.setTo(fChild.lastPos());
  89     }
  90 
  91     /**
  92      * Allows the user to set arbitrary data on this content model
  93      * node. This is used by the a{n,m} optimization that runs
  94      * in constant space. For convenience, set user data in
  95      * children node too.
  96      */
  97     @Override
  98     public void setUserData(Object userData) {
  99         super.setUserData(userData);
 100         fChild.setUserData(userData);
 101     }
 102 
 103 
 104     // -------------------------------------------------------------------
 105     //  Private data members
 106     //
 107     //  fChild
 108     //      This is the reference to the one child that we have for this
 109     //      unary operation.
 110     // -------------------------------------------------------------------
 111     private CMNode  fChild;
 112 } // XSCMUniOp