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.util;
 
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 import  org.apache.xerces.xs.XSAttributeDeclaration;
 import  org.apache.xerces.xs.XSAttributeUse;
 import  org.apache.xerces.xs.XSComplexTypeDefinition;
 import  org.apache.xerces.xs.XSConstants;
 import  org.apache.xerces.xs.XSElementDeclaration;
 import  org.apache.xerces.xs.XSModel;
 import  org.apache.xerces.xs.XSModelGroup;
 import  org.apache.xerces.xs.XSNamedMap;
 import  org.apache.xerces.xs.XSObjectList;
 import  org.apache.xerces.xs.XSParticle;
 import  org.apache.xerces.xs.XSSimpleTypeDefinition;
 import  org.apache.xerces.xs.XSTerm;
 import  org.apache.xerces.xs.XSTypeDefinition;
 import  org.apache.xerces.xs.XSWildcard;
This class is used to check consistency between SchemaBinding instances and their corresponding XSD schemas. It can be configured to exclude (or include) validation of certain namespaces (i.e. types, elements and model groups from certain namespaces). By default, namespace "http://www.w3.org/2001/XMLSchema" is excluded. Also specific types identified by their QName can be excluded or included from validation. Simple XSD types are validated only if present in SchemaBinding. The reason for that is many simple types are bound/represented in Java model by java.lang.String which when building SchemaBinding is bound to xsd:string. Current implementation does not ensures complete consistency but only the basics such as existence of type definitions, element declarations, element ordering in groups and possible occurences of particles. When an inconsistency is found handleError(String msg) is called. The default implementation of which throws IllegalStateException. Subclasses can override this method to report errors differently. Sometimes the error itself may not be informative enough to e.g. identify the location of the inconsistency in the schema. In this case logging should be enabled. Default logger is an instance of org.jboss.logging.Logger with category org.jboss.xb.util.SchemaBindingValidator. All the messages are logged from method log(String msg) which subclasses can override.

Author(s):
Alexey Loubyansky
Version:
$Revision: 1.1 $
 
 public class SchemaBindingValidator
 {
    private static final Logger log = Logger.getLogger(SchemaBindingValidator.class);
   
   private static final QName WILDCARD = new QName("wildcard""wildcard"); 
   private Set<StringexcludedNs = new HashSet<String>();
   private Set<QNameexcludedTypes = new HashSet<QName>();
   private Set<QNamevalidatedTypes = new HashSet<QName>();
   private Set<QNamevalidatedElements = new HashSet<QName>();
   private boolean loggingEnabled;
   {
      reset();
   }
   
   
Resets instance variables (such as a set of validated types, elements and also loggingEnabled property). This method is required to invoked before another validation. It is called internally at the end of validate(XSModel xsSchema, SchemaBinding schemaBinding). NOTE: this method doesn't clear excluded namespaces and types.
   public void reset()
   {
      .clear();
   }
   public boolean isLoggingEnabled()
   {
      return ;
   }
   
   public void enableLogging(boolean value)
   {
       = value;
   }

   
Types and elements from the namespace passed into this method will be excluded from validation.

Parameters:
ns namespace to exclude
   public void excludeNs(String ns)
   {
      .add(ns);
   }
   
   
Checks if the specified namespace is excluded from validation.

Parameters:
ns the namespace to check
Returns:
true if the namespace is excluded
   public boolean isNsExcluded(String ns)
   {
      return .contains(ns);
   }
   
   
Removes the namespace from the excluded set. If the namespace has not been excluded, the method does nothing.

Parameters:
ns the namespace to remove from the excluded set.
   public void includeNs(String ns)
   {
      .remove(ns);
   }
   
   
Excludes the specified type from validation.

Parameters:
qName the QName of the type to exclude from validation
   public void excludeType(QName qName)
   {
      .add(qName);
   }
   
   
Checks if the type is excluded from validation.

Parameters:
qName the QName of the type to check
Returns:
true if the type is excluded from validation
   public boolean isTypeExcluded(QName qName)
   {
      return .contains(qName);
   }
   
   
Removes the specified type from the excluded set. If the type has not been excluded, the method does nothing.

Parameters:
qName the QName of type to remove from the excluded set.
   public void includeType(QName qName)
   {
      .remove(qName);
   }
   
   
This method will check that the XSD represented with InputSource and SchemaBinding are consistent. The consistency is checked to certain degree and is far from 100%. Currently it checks just for basic things such as the existence of type definitions, attribute and element declarations and element ordering.

Parameters:
is InputSource of the XSD
binding SchemaBinding
   public void validate(InputSource isSchemaBinding binding)
   {
      XSModel xsModel = Util.loadSchema(isbinding.getSchemaResolver());
      validate(xsModelbinding);
   }
   
   public void validate(String xsdNameClass<?>... cls)
   {
      log("validate: " + xsdName + ", " + Arrays.asList(cls));
      
      URL xsdUrl = Thread.currentThread().getContextClassLoader().getResource("schema/" + xsdName);
      if(xsdUrl == null)
         handleError("Failed to load schema from the classpath: schema/" + xsdName);
      MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
      resolver.mapLocationToClasses(xsdNamecls);
      SchemaBinding binding = resolver.resolve(""nullxsdName);
      XSModel xsModel;
      try
      {
         xsModel = Util.loadSchema(xsdUrl.openStream(), nullresolver);
      }
      catch (IOException e)
      {
         throw new IllegalStateException("Failed to read schema " + xsdNamee);
      }
      validate(xsModelbinding);
   }
   public void validate(XSModel xsSchemaSchemaBinding schemaBinding)
   {
      try
      {
         /* TODO groups are not properly bound
         XSNamedMap groups = xsSchema.getComponents(XSConstants.MODEL_GROUP_DEFINITION);
         for(int i = 0; i < groups.getLength(); ++i)
         {
            XSModelGroupDefinition xsGroupDef = (XSModelGroupDefinition)groups.item(i);
            System.out.println(xsGroupDef.getName());
            QName groupQName = new QName(xsGroupDef.getNamespace(), xsGroupDef.getName());
            ModelGroupBinding groupBinding = schemaBinding.getGroup(groupQName);
            assertNotNull("Group " + groupQName + " exists in the schema binding.", groupBinding);
         }
         */
         XSNamedMap types = xsSchema.getComponents(XSConstants.TYPE_DEFINITION);
         for (int i = 0; i < types.getLength(); ++i)
         {
            XSTypeDefinition xsType = (XSTypeDefinition) types.item(i);
            if (.contains(xsType.getNamespace()))
               continue;
            QName typeQName = new QName(xsType.getNamespace(), xsType.getName());
            if (.contains(typeQName))
               continue;
            TypeBinding typeBinding = schemaBinding.getType(typeQName);
            if (typeBinding == null)
            {
               boolean ignoreIfNotFound = false;
               if (xsType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
               {
                  ignoreIfNotFound = true;
               }
               else
               {
                  XSComplexTypeDefinition xsComplexType = (XSComplexTypeDefinition) xsType;
                  if (xsComplexType.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE)
                  {
                     XSObjectList attributeUses = xsComplexType.getAttributeUses();
                     if (attributeUses.getLength() == 0)
                     {
                        ignoreIfNotFound = true;
                     }
                     else if (attributeUses.getLength() == 1)
                     {
                        XSAttributeUse xsAttrUse = (XSAttributeUse) attributeUses.item(0);
                        XSAttributeDeclaration xsAttr = xsAttrUse.getAttrDeclaration();
                        if (xsAttr.getNamespace() == null && "id".equals(xsAttr.getName()))
                           ignoreIfNotFound = true;
                     }
                  }
               }
               if (!ignoreIfNotFound)
               {
                  if (isLoggingEnabled())
                  {
                     log("SchemaBinding global types: ");
                     for (Iterator<TypeBindingiter = schemaBinding.getTypes(); iter.hasNext();)
                     {
                        TypeBinding type = iter.next();
                        if (!.contains(type.getQName().getNamespaceURI()))
                           log("- " + type.getQName());
                     }
                  }
                  handleError("TypeBinding " + typeQName + " is not found in the SchemaBinding.");
               }
            }
            else
            {
               validate(xsTypetypeBinding);
            }
         }
         XSNamedMap elements = xsSchema.getComponents(XSConstants.ELEMENT_DECLARATION);
         for (int i = 0; i < elements.getLength(); ++i)
         {
            XSElementDeclaration xsElement = (XSElementDeclaration) elements.item(i);
            if (.contains(xsElement.getNamespace()))
               continue;
            QName elementQName = new QName(xsElement.getNamespace(), xsElement.getName());
            ElementBinding elementBinding = schemaBinding.getElement(elementQName);
            if (elementBinding == null)
               handleError("ElementBinding " + elementQName + " is not found in the SchemaBinding.");
            validate(xsElement.getTypeDefinition(), elementBinding.getType());
         }
      }
      finally
      {
         reset();
      }
   }
   
   public void validate(XSElementDeclaration xsElementElementBinding elementBinding)
   {      
      QName xsQName = new QName(xsElement.getNamespace(), xsElement.getName());
      if(xsQName.equals(elementBinding.getQName()))
         handleError("Compared elements have difference names: XSD QName is " + xsQName + ", ElementBinding QName is " + elementBinding.getQName());
      
      log("element " + xsQName);
      
      if(.contains(xsQName))
         return;
      .add(xsQName);
      validate(xsElement.getTypeDefinition(), elementBinding.getType());
   }
   public void validate(XSTypeDefinition xsTypeTypeBinding typeBinding)
   {
      if(xsType.getName() == null)
      {
         if(typeBinding.getQName() != null)
            handleError("XSD type is anonymous but TypeBinding has QName " + typeBinding.getQName());
      }
      else
      {
         if(.contains(xsType.getNamespace()))
            return;
         
         QName xsQName = new QName(xsType.getNamespace(), xsType.getName());
         if(!xsQName.equals(typeBinding.getQName()))
            handleError("Compared types have different names: XSD QName is " + xsQName + ", TypeBinding QName is " + typeBinding.getQName());
         
         if(.contains(xsQName) || .contains(xsQName))
            return;
         .add(xsQName);
      }
      
      if(xsType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
         validate((XSSimpleTypeDefinition)xsTypetypeBinding);
      else
         validate((XSComplexTypeDefinition)xsTypetypeBinding);         
   }
   public void validate(XSSimpleTypeDefinition xsTypeTypeBinding typeBinding)
   {
      // TODO there could xsd types that are mapped to String which is bound by default to xsd:string
      //QName xsQName = xsType.getName() == null ? null : new QName(xsType.getNamespace(), xsType.getName());
      //assertEquals("Simple type expected to be " + (xsType == null ? "anonymous" : "named '" + xsQName + "'"), xsQName, typeBinding.getQName());
      
      if(!typeBinding.isSimple())
         handleError("XSD type " + typeBinding.getQName() + " is simple but TypeBinding is not.");
      // TODO the rest of the simple type stuff?
   }
   public void validate(XSComplexTypeDefinition xsTypeTypeBinding typeBinding)
   {
      QName xsQName = xsType.getName() == null ? null : new QName(xsType.getNamespace(), xsType.getName());
      
      log("complex type " + xsQName);
      
      if(xsQName == null && typeBinding.getQName() != null ||
            xsQName != null && !xsQName.equals(typeBinding.getQName()))
         handleError("Compared complex types have different names: XSD QName is " + xsQName + ", TypeBindign QName is " + typeBinding.getQName());
      XSObjectList xsAttrUses = xsType.getAttributeUses();
      if(xsAttrUses.getLength() == 0)
      {
         // TODO missing id attributes in the schema
         //assertTrue("Type " + typeBinding.getQName() + " has no attributes in the schema", typeBinding.getAttributes().isEmpty());
      }
      else
      {
         for(int i = 0; i < xsAttrUses.getLength(); ++i)
         {
            XSAttributeDeclaration xsAttr = ((XSAttributeUse)xsAttrUses.item(i)).getAttrDeclaration();
            QName xsAttrQName = new QName(xsAttr.getNamespace(), xsAttr.getName());
            AttributeBinding attrBinding = typeBinding.getAttribute(xsAttrQName);
            if(attrBinding == null)
               handleError("Attribute " + xsAttrQName + " is not found in TypeBinding " + typeBinding.getQName());
            validate(xsAttr.getTypeDefinition(), attrBinding.getType());
         }
      }
      
      XSWildcard xsAttrWildcard = xsType.getAttributeWildcard();
      if(xsAttrWildcard != null && typeBinding.getAnyAttribute() == null)
         handleError("TypeBinding " + typeBinding.getQName() + " doesn't have AnyAttributeBinding");
      
      XSSimpleTypeDefinition xsSimpleType = xsType.getSimpleType();
      if(xsSimpleType != null)
      {
         TypeBinding simpleTypeBinding = typeBinding.getSimpleType();
         if(simpleTypeBinding == null)
            handleError("XSD type " + typeBinding.getQName() + " allows text content but its corresponding TypeBinding doesn't.");
         validate(xsSimpleTypesimpleTypeBinding);
      }
      
      XSParticle xsParticle = xsType.getParticle();
      if(xsParticle != null)
      {
         ParticleBinding particleBinding = typeBinding.getParticle();
         if(particleBinding == null)
            handleError("TypeBinding " + xsQName + " doesn't contain a ParticleBinding.");
         validate(xsParticleparticleBinding);
      }
   }
   
   public void validate(XSParticle xsParticleParticleBinding particleBinding)
   {
      XSTerm xsTerm = xsParticle.getTerm();
      TermBinding termBinding = particleBinding.getTerm();
      if(termBinding == null)
         handleError("ParticleBinding doesn't contain a TermBinding.");
      short xsTermType = xsTerm.getType();
      String termStr = null;
      if(xsTermType == XSConstants.MODEL_GROUP)
      {
         termStr = "sequence";
         XSModelGroup xsModelGroup = (XSModelGroup)xsTerm;
         short xsModelGroupCompositor = (xsModelGroup).getCompositor();
         if(XSModelGroup.COMPOSITOR_CHOICE == xsModelGroupCompositor)
            termStr = "choice";
         else if(XSModelGroup.COMPOSITOR_ALL == xsModelGroupCompositor)
            termStr = "all";
         if(!termBinding.isModelGroup())
         {
            // TODO review this
            // let's see whether it's wrapped
            if(xsModelGroup.getParticles().getLength() == 1)
            {
               XSParticle xsWrappedParticle = (XSParticle) xsModelGroup.getParticles().item(0);
               validate(xsWrappedParticleparticleBinding);
            }
            else
               handleError("TermBinding expected to be a " + termStr + " but was " + termBinding);
         }
         else
            validate(xsModelGroup, (ModelGroupBindingtermBinding);
      }
      else if(xsTermType == XSConstants.ELEMENT_DECLARATION)
      {
         XSElementDeclaration xsElement = (XSElementDeclaration) xsTerm;
         QName xsElementName = new QName(xsElement.getNamespace(), xsElement.getName());
         termStr = xsElementName.toString();
         if(!termBinding.isElement())
         {
            // TODO sometimes XB wraps (maybe unnecessarily) repeatable elements into a sequence.
            // the same xml structure can be described differently in xsd
            if (/*(xsParticle.getMaxOccursUnbounded() || xsParticle.getMaxOccurs() > 1) &&*/
                  termBinding instanceof SequenceBinding)
            {
               SequenceBinding seq = (SequenceBindingtermBinding;
               Collection<ParticleBindingparticles = seq.getParticles();
               if(particles.size() == 1)
               {
                  ParticleBinding particle = particles.iterator().next();
                  if(particle.getTerm().isElement())
                  {
                     particleBinding = particle;
                     termBinding = particle.getTerm();
                  }
               }
            }
            
            if(!termBinding.isElement())
               handleError("TermBinding expected to be element " + termStr + " but was " + termBinding);
         }
         
         if(!xsElementName.equals(((ElementBinding)termBinding).getQName()))
            handleError("Compared elements have different names: XSD QName is " + xsElementName + ", ElementBinding QName is " + ((ElementBinding)termBinding).getQName());
      }
      else if(xsTermType == XSConstants.WILDCARD)
      {
         if(!termBinding.isWildcard())
            handleError("TermBinding expected to be a wildcard but was " + termBinding);
         XSWildcard xsWildcard = (XSWildcard) xsTerm;
         WildcardBinding wildcardBinding = (WildcardBindingtermBinding;
         if(xsWildcard.getProcessContents() != wildcardBinding.getProcessContents())
            throw new IllegalStateException("Wildcard processContents doesn't match: XSD processContents is " + xsWildcard.getProcessContents() +
                  ", WildcardBinding processContents is " + wildcardBinding.getProcessContents());
         termStr = "wildcard";
      }
      else
         handleError("Unexpected XSTerm type: " + xsTermType);
      
      // TODO minOccurs is not trivial for flattened choices
      //assertEquals("ParticleBinding<" + termStr + "> min occurs.", xsParticle.getMinOccurs(), particleBinding.getMinOccurs());
      
      if(xsParticle.getMaxOccursUnbounded())
      {
         if(!particleBinding.getMaxOccursUnbounded())
            handleError("XSD particle has maxOccurs unbounded but ParticleBinding of " + particleBinding.getTerm() + " does not.");
      }
      else if(xsParticle.getMaxOccurs() != particleBinding.getMaxOccurs())
         handleError("maxOccurs for particle of " + particleBinding.getTerm() + " don't match: XSD maxOccurs=" + xsParticle.getMaxOccurs() +
               ", ParticleBinding maxOccurs=" + particleBinding.getMaxOccurs());
   }
   
   public void validate(XSModelGroup xsModelGroupModelGroupBinding modelGroupBinding)
   {
      short xsCompositor = xsModelGroup.getCompositor();
      boolean all = false;
      if(xsCompositor == XSModelGroup.COMPOSITOR_SEQUENCE)
      {
         log("sequence");
         if(!(modelGroupBinding instanceof SequenceBinding))
         {
            // another chance...
            if(modelGroupBinding instanceof AllBinding || modelGroupBinding instanceof UnorderedSequenceBinding)
               all = true;
            else
               handleError("ModelGroupBinding expected to be a sequence but was " + modelGroupBinding);
         }
      }
      else if(xsCompositor == XSModelGroup.COMPOSITOR_CHOICE)
      {
         log("choice");
         if(modelGroupBinding instanceof SequenceBinding)
         {
            // another chance...
            Collection<ParticleBindingparticles = modelGroupBinding.getParticles();
            if(particles.size() == 1)
            {
               ParticleBinding particleBinding = particles.iterator().next();
               if(particleBinding.getTerm() instanceof ChoiceBinding)
                  modelGroupBinding = (ModelGroupBindingparticleBinding.getTerm();
            }
         }
         if(!(modelGroupBinding instanceof ChoiceBinding))
            handleError("XSD model group is choice but ModelGroupBinding is " + modelGroupBinding);
      }
      else if(xsCompositor == XSModelGroup.COMPOSITOR_ALL)
      {
         log("all");
         if(!(modelGroupBinding instanceof AllBinding))
            handleError("XSD model group is all but ModelGroupBinding is " + modelGroupBinding);
         all = true;
      }
      else
         handleError("Unexpected compositor type for model group " + xsCompositor);
      
      
      XSObjectList xsParticles = xsModelGroup.getParticles();
      Collection<ParticleBindingparticleBindings = modelGroupBinding.getParticles();
      Map<QName, XSParticle> xsElementParticles = null;
      Map<QNameParticleBindingelementParticles = null;
      if(xsParticles.getLength() > 0)
      {
         if(particleBindings == null)
            handleError("XSD model group has " + xsParticles.getLength() + " particles but ModelGroupBinding doesn't have any.");
         if(xsParticles.getLength() != particleBindings.size() || all)
         {
            // let's try making it flat... to the elements
            xsElementParticles = new HashMap<QName, XSParticle>();
            flatten(xsModelGroupxsElementParticles);
            elementParticles = new HashMap<QNameParticleBinding>();
            flatten(modelGroupBindingelementParticles);
            
            if(xsElementParticles.size() != elementParticles.size())
            {
               if (isLoggingEnabled())
               {
                  String msg = "expected particles:\n";
                  for (int i = 0; i < xsParticles.getLength(); ++i)
                  {
                     XSTerm xsTerm = ((XSParticle) xsParticles.item(i)).getTerm();
                     short type = xsTerm.getType();
                     if (type == XSConstants.MODEL_GROUP)
                     {
                        short compositor = ((XSModelGroup) xsTerm).getCompositor();
                        if (compositor == XSModelGroup.COMPOSITOR_SEQUENCE)
                           msg += "- sequence\n";
                        else if (compositor == XSModelGroup.COMPOSITOR_CHOICE)
                           msg += "- choice\n";
                        else if (compositor == XSModelGroup.COMPOSITOR_ALL)
                           msg += "- all\n";
                     }
                     else if (type == XSConstants.ELEMENT_DECLARATION)
                     {
                        XSElementDeclaration element = (XSElementDeclaration) xsTerm;
                        msg += "- " + new QName(element.getNamespace(), element.getName()) + "\n";
                     }
                     else
                     {
                        msg += "- wildcard\n";
                     }
                  }
                  msg += "actual particles:\n";
                  Iterator<ParticleBindingiter = particleBindings.iterator();
                  while (iter.hasNext())
                  {
                     TermBinding term = iter.next().getTerm();
                     if (term.isModelGroup())
                     {
                        if (term instanceof SequenceBinding)
                           msg += "- sequence\n";
                        else if (term instanceof ChoiceBinding)
                           msg += "- choice\n";
                        else
                           msg += "- wildcard\n";
                     }
                     else if (term.isElement())
                        msg += "- " + ((ElementBindingterm).getQName() + "\n";
                     else
                        msg += "- wildcard";
                  }
                  log(msg);
                  
                  List<QNamemissing = new ArrayList<QName>(xsElementParticles.keySet());
                  missing.removeAll(elementParticles.keySet());
                  log("flattened ModelGroupBinding is missing: ");
                  for (Iterator<QNamemissingNames = missing.iterator(); missingNames.hasNext();)
                     log("- " + missingNames.next());
                  missing = new ArrayList<QName>(elementParticles.keySet());
                  missing.removeAll(xsElementParticles.keySet());
                  log("flattened XSModelGroup is missing: ");
                  for (Iterator<QNamemissingNames = missing.iterator(); missingNames.hasNext();)
                     log("- " + missingNames.next());
               }
               handleError("ModelGroupBinding expected to have " + xsParticles.getLength() + " particle(s) but has "
                     + particleBindings.size());
            }
         }
      }
      if(xsElementParticles != null)
      {
         Iterator<ParticleBindingiter = elementParticles.values().iterator();
         while(iter.hasNext())
         {
            ParticleBinding particleBinding = iter.next();
            QName particleQName;
            TermBinding termBinding = particleBinding.getTerm();
            if(termBinding.isWildcard())
               particleQName = ;
            else
               particleQName = ((ElementBinding)termBinding).getQName();
            XSParticle xsParticle = xsElementParticles.get(particleQName);
            if(xsParticle == null)
            {
               if(particleQName == )
                  handleError("WildcardBinding is missing");
               else
                  handleError("ElementBinding " + particleQName + " is missing: " + xsElementParticles.keySet());
            }
            validate(xsParticleparticleBinding);            
         }
      }
      else
      {
         Iterator<ParticleBindingiter = particleBindings.iterator();
         for (int i = 0; i < xsParticles.getLength(); ++i)
         {
            XSParticle xsParticle = (XSParticle) xsParticles.item(i);
            validate(xsParticleiter.next());
         }
      }
   }
   private void flatten(XSModelGroup xsModelGroupMap<QName, XSParticle> elementParticles)
   {
      XSObjectList xsParticles = xsModelGroup.getParticles();
      for(int i = 0; i < xsParticles.getLength(); ++i)
      {
         XSParticle particle = (XSParticle)xsParticles.item(i);
         XSTerm term = particle.getTerm();
         short termType = term.getType();
         if(termType == XSConstants.ELEMENT_DECLARATION)
         {
            XSElementDeclaration element = (XSElementDeclaration) term;
            QName qName = new QName(element.getNamespace(), element.getName());
            elementParticles.put(qNameparticle);
         }
         else if(termType == XSConstants.WILDCARD)
            elementParticles.put(particle);
         else
         {
            XSModelGroup modelGroup = (XSModelGroup) term;
            flatten(modelGroupelementParticles);
         }
      }
   }
   private void flatten(ModelGroupBinding groupMap<QNameParticleBindingelementParticles)
   {
      Iterator<ParticleBindingi = group.getParticles().iterator();
      while(i.hasNext())
      {
         ParticleBinding particle = i.next();
         TermBinding term = particle.getTerm();
         if(term.isElement())
         {
            ElementBinding element = (ElementBindingterm;
            elementParticles.put(element.getQName(), particle);
         }
         else if(term.isWildcard())
            elementParticles.put(particle);
         else
         {
            ModelGroupBinding modelGroup = (ModelGroupBindingterm;
            flatten(modelGroupelementParticles);
         }
      }
   }
   
   
This an error handler method. Default implementation throws IllegalStateException with the message passed in as the argument.

Parameters:
msg the error message
   protected void handleError(String msg)
   {
      throw new IllegalStateException(msg);
   }
   
   
This method is supposed to log a message. Default implementation uses trace logging.

Parameters:
msg the message to log.
   protected void log(String msg)
   {
      if()
         .trace(msg);
   }   
New to GrepCode? Check out our FAQ X