[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-dev
Subject: RE: How do I extract the Non-Native Attribute information from the compiled SchemaTypeSystem?
From: "Bharat K. Veeragandham" <bharat () iservicesusa ! com>
Date: 2004-11-18 23:31:07
Message-ID: 8ADFE2B0E0831947B99E3D01A025296B2BA92B () boston ! horizonboston ! com
[Download RAW message or body]
ok , looks like I have to implement the logic that is similar to \
SchemaTypeHierarchyPrinter to get the annotation attribution info for the top level \
objects.
But how do I get the annotation information for the elements declared within the \
complexType? I don see any methods to get the SchemaLocalElement and \
SchemaLocalAttribute info.
For example the my:attrib2 defined for the elements /foo:foo-element/foo:f1 and \
/foo:foo-element/foo-f2
Thanks
Bharat
________________________________
From: Radu Preotiuc-Pietro [mailto:radup@bea.com]
Sent: Thu 11/18/2004 6:07 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from the compiled \
SchemaTypeSystem?
The difference is that you can have:
<xs:element name="foo-element" my:attrib="value1">
<xs:complexType>
...
</xs:complexType>
</xs:element>
or
<xs:element name="foo-element">
<xs:complexType my:attrib="value1">
...
</xs:complexType>
</xs:element>
Your code will work with the second case, in order to capture the first case, you \
need to do SchemaAnnotation ann = element.getAnnotation();
right after getting the element.
-----Original Message-----
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 2:37 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from the compiled \
SchemaTypeSystem?
Here is the code snippet that I was using to print the annotation attribute info \
using the SchemaType.getAnnotation()
public class FooSample {
public static void main(String[] args) {
QName qName = new QName("http://foo.org/2004","foo-element");
SchemaTypeLoader loader = XmlBeans.getContextTypeLoader();
FooSample fooSample = new FooSample();
SchemaGlobalElement element = loader.findElement(qName);
type = element.getType();
fooSample.printTypeInfo(type);
fooSample.printAnnotationAttribs(type);
}
public void printTypeInfo(SchemaType type)
{
if (type.isSimpleType()){
printAnnotationAttribs(type);
}
else
{
printAnnotationAttribs(type);
SchemaProperty[] props = type.getElementProperties();
for (int index=0; index<props.length; index++)
{
printTypeInfo(props[index].getType());
}
}
}
public void printAnnotationAttribs(SchemaType type)
{
SchemaAnnotation annotation = type.getAnnotation();
if (annotation == null)
{
System.out.println("Annotation is null");
return;
}
SchemaAnnotation.Attribute[] myAttribs = annotation.getAttributes();
if ((myAttribs == null)||(myAttribs.length > 0))
{
System.out.println("Annotation Attributes are not available");
return;
}
for (int index=0; index<myAttribs.length;index++ )
{
String localPart = myAttribs[index].getName().getLocalPart() ;
System.out.println("My Annotation Attribute Name = " +localPart+ "; Value = " + \
myAttribs[index].getValue()); }
}
________________________________
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 5:27 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from the compiled \
SchemaTypeSystem?
yes, that is exactly what I want to do. I need to know if a given SchemaComponent \
has any special attribute or not. I need this info not only for the global \
elements/types but also for the inner/local elements and attributes.
I was not sure how to loop inside the SchemaGloablElement' to find the annotation \
information for the local elements f1 and f2.
I was trying to get the type of the global element and use the getAnnotation() on \
the SchemaType interface. But it is returning any annotation attributes.
What is the difference between getAnnotation() on the Global components vs. their \
schema types?
thanks
Bharat
________________________________
From: Radu Preotiuc-Pietro [mailto:radup@bea.com]
Sent: Thursday, November 18, 2004 4:34 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from the compiled \
SchemaTypeSystem?
Most of the Schema* objects also implement the SchemaAnnotated interface, giving you \
access to the .getAnnotation() method. You can certainly loop over all top-level \
elements (using sts.globalElements()), top-level types (using sts.globalTypes()) etc. \
and get the annotation for each one of them. If you are just interested in the \
annotations though, you can very well use an XmlCursor and get all the \
namespace-qualified attributes in your Schema document. But I thought you were \
interested in the relashionship between the SchemaComponent and the annotation on it, \
like "oh, I have a global element named foo and I have one of my special attributes \
on it, therefore I should do something special", rather than just list your \
attributes.
Radu
-----Original Message-----
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 1:07 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from the \
compiled SchemaTypeSystem?
thanks Radu. That helps, but at the same time I am not quite understood how to get \
the annotation attributes for rest of the elements or schema components.
As almost all XSDL elements are allowed to have the annotation elements, is there \
an easy way to loop through each XSDL element to find this info.
________________________________
From: Radu Preotiuc-Pietro [mailto:radup@bea.com]
Sent: Thursday, November 18, 2004 3:07 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from the \
compiled SchemaTypeSystem?
By "non-native attributes" you mean XSD annotations.
In order to get those, do:
SchemaGlobalElement foo = sts.findElement(new QName("http://foo.org/2004 \
<http://foo.org/2004> ","foo-element")); SchemaAnnotation.Attribute[] atts = \
foo.getAnnotation().getAttributes();
Radu
-----Original Message-----
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 9:00 AM
To: xmlbeans-dev@xml.apache.org
Subject: How do I extract the Non-Native Attribute information from the compiled \
SchemaTypeSystem?
Hi,
Can some one help with the XSDL non-native attributes?
I would like to extend the standard XSDL with my own non-native attributes as \
shown in the following schema. XmlBeans compiles the schema w/o any errors but I \
couldn't find a way to get the information about the non-native attributes from the \
compiled type system.
I am using the latest xmlbeans-V2 code.
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:foo="http://foo.org/2004"
xmlns:my="http://foo.org/myExtension"
targetNamespace="http://foo.org/2004"
elementFormDefault="qualified">
<xs:element name="foo-element" my:attrib1="myValue1">
<xs:complexType>
<xs:sequence>
<xs:element name="f1" type="xs:string" my:attrib2="myValue2"/>
<xs:element name="f2" type="xs:string" my:attrib2="myValue3"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks for your help
-Bharat
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic