Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
    * JBoss, Home of Professional Open Source
    * Copyright 2005, JBoss Inc., and individual contributors as indicated
    * by the @authors tag. See the copyright.txt in the distribution for a
    * full listing of individual contributors.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
 package org.jboss.xb.binding.sunday.unmarshalling;
 
 import java.util.List;
 import java.util.Set;
 
 

Author(s):
Alexey Loubyansky
Version:
$Revision: 3007 $
 
 public abstract class ModelGroupBinding
    extends TermBinding
    implements Cloneable
 {
    protected final Logger log = Logger.getLogger(getClass());

   
The qualifed name for global groups
 
    protected QName qName;
 
    protected boolean requiredParticle;
 
    protected ModelGroupBinding(SchemaBinding schema)
    {
       super(schema);
    }

   
Get the qName.

Returns:
the qName.
 
    public QName getQName()
    {
       return ;
    }

   
Set the qName.

Parameters:
name the qName.
Throws:
java.lang.IllegalArgumentException for a null qName
 
    public void setQName(QName name)
    {
       if (name == null)
          throw new IllegalArgumentException("Null name");
        = name;
    }
 
    public ParticleHandler getHandler()
    {
       return ;
    }
 
    public void setHandler(ParticleHandler handler)
    {
       this. = handler;
    }
 
    public abstract ElementBinding getArrayItem();

   
Model group that is passed in as an argument to this method must be fully populated with element, wildcard and child model group bindings.

Parameters:
particle
 
    public void addParticle(ParticleBinding particle)
    {
      if(particle.isRequired())
      {
          = true;
      }
   }
   public abstract Collection<ParticleBindinggetParticles();
   public boolean hasRequiredParticle()
   {
      return ;
   }

   
This method is not actually used during parsing. It's here only for internal tests.

Parameters:
qName an element name
Returns:
true if the model group may start with the specified element
   public boolean mayStartWith(QName qName)
   {
      return mayStartWith(qName.);
   }
   public abstract Cursor newCursor(ParticleBinding particle);
   public Object clone() throws CloneNotSupportedException
   {
      return super.clone();
   }
   // Protected
   protected abstract boolean mayStartWith(QName qNameSet<ModelGroupBindingset);
   public boolean isSkip()
   {
      return  == null ? true : .booleanValue();
   }
   public boolean isModelGroup()
   {
      return true;
   }
   public boolean isWildcard()
   {
      return false;
   }
   
   public boolean isElement()
   {
      return false;
   }
   public String toString()
   {
      StringBuffer sb = new StringBuffer();
      sb.append(getGroupType());
      if( != null)
         sb.append(' ').append();
      sb.append(':');
      for(ParticleBinding p : getParticles())
      {
         TermBinding t = p.getTerm();
         sb.append(' ');
         if(t.isElement())
            sb.append(((ElementBinding)t).getQName());
         else if(t.isModelGroup())
         {
            sb.append('{').append(((ModelGroupBinding)t).getGroupType());
            ModelGroupBinding group = (ModelGroupBindingt;
            if(group.getQName() != null)
               sb.append(' ').append(group.getQName());
            sb.append('}');
         }
         else
            sb.append("{wildcard}");
         if(p.getMaxOccursUnbounded())
            sb.append(p.getMinOccurs() == 0 ? '*' : '!');
         else if(p.getMinOccurs() == 0)
            sb.append('?');
      }
      return sb.toString();
   }
   public abstract String getGroupType();
   
   // Inner
   public abstract class Cursor
   {
      protected final ParticleBinding particle;
      protected final boolean trace = .isTraceEnabled();
      protected int occurence;
      protected Cursor(ParticleBinding particle)
      {
         this. = particle;
      }
      public ParticleBinding getParticle()
      {
         return ;
      }
      public ModelGroupBinding getModelGroup()
      {
         return (ModelGroupBinding).getTerm();
      }
      public abstract ParticleBinding getCurrentParticle();
      public abstract ElementBinding getElement();
      public abstract boolean isPositioned();
      public List<ModelGroupBinding.CursorstartElement(QName qNameAttributes attrs)
      {
         return startElement(qNameattrs..true);
      }
      public ElementBinding getElement(QName qNameAttributes attrsboolean ignoreWildcards)
      {
         return getElement(qNameattrs.ignoreWildcards);
      }
      public abstract void endElement(QName qName);
      public int getOccurence()
      {
         return ;
      }
      public boolean repeatElement(QName qName)
      {
         ParticleBinding particle = getCurrentParticle();
         if(particle.getMaxOccursUnbounded() ||
             < particle.getMinOccurs() ||
             < particle.getMaxOccurs())
         {
            ++;
            return true;
         }
         return false;
      }
      
      public abstract boolean isWildcardContent();
      
      // Protected
      protected abstract List<ModelGroupBinding.CursorstartElement(QName qName,
                                           Attributes atts,
                                           Set<ModelGroupBinding.CursorpassedGroups,
                                           List<ModelGroupBinding.CursorgroupStack,
                                           boolean required);
      protected abstract ElementBinding getElement(QName qNameAttributes attsSet<ModelGroupBinding.CursorpassedGroupsboolean ignoreWildcards);
      protected ElementBinding getElement(List<ParticleBindinggroupQName qNameAttributes attsSet<ModelGroupBinding.CursorpassedGroupsboolean ignoreWildcards)
      {
         ElementBinding element = null;
         for(int i = 0; i < group.size(); ++i)
         {
            ParticleBinding nextParticle = (ParticleBinding)group.get(i);
            TermBinding item = nextParticle.getTerm();
            if(item.isElement())
            {
               ElementBinding choice = (ElementBinding)item;
               if(qName.equals(choice.getQName()))
               {
                  element = choice;
                  break;
               }
            }
            else if(item.isModelGroup())
            {
               ModelGroupBinding modelGroup = (ModelGroupBinding)item;
               if(!passedGroups.contains(modelGroup))
               {
                  switch(passedGroups.size())
                  {
                     case 0:
                        passedGroups = Collections.singleton(this);
                        break;
                     case 1:
                        passedGroups = new HashSet<ModelGroupBinding.Cursor>(passedGroups);
                     default:
                        passedGroups.add(this);
                  }
                  ElementBinding e = modelGroup.newCursor(nextParticle).getElement(qNameattspassedGroupsignoreWildcards);
                  if(e != null)
                  {
                     element = e;
                     if(!qName.equals(e.getQName()))
                     {
                        throw new JBossXBRuntimeException(
                           "There is a bug in ModelGroupBinding.Cursor.getElement(QName,Attributes) impl"
                        );
                     }
                     break;
                  }
               }
            }
            else if(!ignoreWildcards)
            {
               WildcardBinding wildcard = (WildcardBinding)item;
               ElementBinding e = wildcard.getElement(qNameatts);
               if(e != null)
               {
                  element = e;
                  if(!qName.equals(e.getQName()))
                  {
                     throw new JBossXBRuntimeException(
                        "There is a bug in ModelGroupBinding.Cursor.getElement(QName,Attributes) impl"
                     );
                  }
                  break;
               }
            }
         }
         return element;
      }
      {
         switch(list.size())
         {
            case 0:
               list = Collections.singletonList(o);
               break;
            case 1:
               list = new ArrayList<ModelGroupBinding.Cursor>(list);
            default:
               list.add(o);
         }
         return list;
      }
   }
New to GrepCode? Check out our FAQ X