What the code that you posted does is retrieve the identity constraints
from types that have only one element in their content model. In
particular, this works for constraints that are declared on top-level
elements but not for others.

Since you want not only the constraints, but also their scope, this gets
complicated (almost anything related to Schema identity constraints gets
complicated very quickly). The reason is that identity constraints on
local elements can have different scopes depending on the structure of
the instance document being validated.

So I would start with a set of all the global elements
(SchemaTypeSystem.getGlobalElements()). Then do

element.getIdentityConstraints()

to get the set of identity constraints on each of the elements. Then

SchemaType st = element.getType();
if (st.getContentType() == SchemaType.ELEMENT_CONTENT ||
    st.getContentType() == SchemaType.MIXED_CONTENT)
{
    SchemaParticle p = st.getContentModel();
    switch (p.getParticleType())
    {
    case SchemaParticle.ELEMENT:
      // A local element, continue with checking it for id constraints
and recurse
    case SchemaParticle.CHOICE:
    case SchemaParticle.SEQUENCE:
    case SchemaParticle.ALL:
      // Look for more elements among the particle children
    }
}

So you need to recurse inside the content model of each global element's
type, find all local elements among other kinds of particles (which is
another recursion) and then repeat. Special care must also be taken
because elements can reference each other and so you can end up with
infinite recursion. So you need to stop once you find an id constraint
that you already "know about" or find some other exit condition that
makes sense in your case.

Good luck and let me know if anything that I said above doesn't quite
make sense.

Radu

On Tue, 2007-05-08 at 09:51 -0400, Les Walker wrote:
> A couple of questions
> 
> 1. 
> I am having a problem where I cannot find certain
> schemaIdentityConstraints in the generated code for our XSD. Our code
> walks the schema and derives a mapping from the constrained element to
> its actual constraint and scope in the model. This is working for the
> vast majority of cases, but for some of our top-level elements they
> cannot be found. I am currently checking for the presence of
> constraints by walking the global schemaTypes via the containment
> hierarchy in the tree. Each complex type (we use named types only) is
> checked for constraints as follows:
> 
>     private SchemaIdentityConstraint[] getConstraints(SchemaType
> _schemaType) 
>     { 
>         SchemaIdentityConstraint[] constraints = null; 
>         if(isLocalElement(_schemaType)) 
>         { 
>             SchemaLocalElement local =
> (SchemaLocalElement)_schemaType.getContentModel(); 
>             constraints = local.getIdentityConstraints(); 
>         } 
>         return constraints; 
>     }
> 
> Can anyone tell me what am missing or doing wrong? Are there other
> component types I have to check for constraints? 
> 
> 2. 
> Something else I have noticed is that the generated identity
> constraint for an element in the schema is actually associated against
> its containing schemaType - which makes it hard to use ./xxx  in a
> constraint definition - since the scope in the generated code is one
> step higher than its original definition. Is this intentional? If so,
> I would be interested to know why it is done this way and possibly a
> strategy to manage these scopes in a way consistent with the XSD.
> Currently I have to wrap my selector access with the extra inserted
> element name - this works, but seems awkward.
> 
> 
> any guidance is greatly appreciated
> 
> LW
> 

Notice:  This email message, together with any attachments, may contain 
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated 
entities,  that may be confidential,  proprietary,  copyrighted  and/or legally 
privileged, and is intended solely for the use of the individual or entity 
named in this message. If you are not the intended recipient, and have received 
this message in error, please immediately return this by email and then delete 
it.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to