[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-dev
Subject: RE: Trying to use XMLBeans 2.0 and appinfo
From: "Lawrence Jones" <ljones () bea ! com>
Date: 2005-08-30 18:01:52
Message-ID: 4B2B4C417991364996F035E1EE39E2E103448D9E () uskiex01 ! amer ! bea ! com
[Download RAW message or body]
Hi Ian
Not sure whether you meant "how do I get to the annotations on the local
elements within the definition of the complex type Dia in the schema
below?" or "if I had an annotation directly on the Dia <complexType>
definition itself how would I get to that?". So I've attached some code
(based on your HtmlBuilder class) that will help you do either.
But I agree that the approach to annotations could be clearer so I've
raised a JIRA issue to suggest making improvements -
http://issues.apache.org/jira/browse/XMLBEANS-195.
Cheers,
Lawrence
// this corresponds to the <complexType> element named Dia
SchemaAnnotation diaAnn = Dia.type.getAnnotation();
XmlObject[] diaAppInfo = diaAnn.getApplicationInformation();
for (int i = 0; i < diaAppInfo.length; i++) {
GuiDocument gui = null;
try {
gui =
GuiDocument.Factory.parse(diaAppInfo[i].toString());
} catch (XmlException e) {
e.printStackTrace();
}
System.out.println("Dia complex type annotation
getGuiDisplayName() = " + gui.getGui().getDisplayName());
System.out.println("Dia complex type annotation
getFieldName() = " + gui.getGui().getFieldName());
}
// this corresponds to the <sequence> element with the Dia
<complexType>
SchemaParticle contentModel = Dia.type.getContentModel();
// getParticleChildren() gives you the local elements:
lanPrefixList and wanPrefixList
SchemaParticle[] spArray = contentModel.getParticleChildren();
for (int i=0; i<spArray.length; i++) {
// from there you can get their annotations as before
SchemaAnnotation ann2 =
((SchemaLocalElement)spArray[i]).getAnnotation();
XmlObject[] appInfo2 = ann2.getApplicationInformation();
for (int j = 0; j < appInfo2.length; j++) {
GuiDocument gui = null;
try {
gui =
GuiDocument.Factory.parse(appInfo2[j].toString());
} catch (XmlException e) {
e.printStackTrace();
}
System.out.println("[diaObject]
gui.getGui().getGuiDisplayName() = " + gui.getGui().getDisplayName());
System.out.println("[diaObject]
gui.getGui().getFieldName() = " + gui.getGui().getFieldName());
}
}
> -----Original Message-----
> From: Butt, Ian [mailto:ibutt@metasolv.com]
> Sent: Monday, August 29, 2005 12:10 PM
> To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
> Subject: RE: Trying to use XMLBeans 2.0 and appinfo
>
> Thanks Lawrence that certainly got me headed in the right direction.
If
> this is my schema below, I have figured out how to get the main
element's
> app info but how do I go about getting the complex type's annotations
?
> It seems like you can do it fine for global elements since each global
> element gets mapped into a Document class with a type member variable,
but
> complex types seem not to follow this.
>
>
> Thanks again,
>
> Ian
>
>
> public class HtmlBuilder {
>
> public HtmlBuilder() {
> DiaDocument dia = DiaDocument.Factory.newInstance();
> Dia diaObject = dia.addNewDia();
> diaObject.addLanPrefixList("Lan");
> diaObject.addWanPrefixList("Wan");
>
> SchemaAnnotation ann = ((SchemaLocalElement)
> DiaDocument.type.getContentModel()).getAnnotation();
> XmlObject[] appInfo = ann.getApplicationInformation();
> for (int i = 0; i < appInfo.length; i++) {
> GuiDocument gui = null;
> try {
> gui =
GuiDocument.Factory.parse(appInfo[i].toString());
> } catch (XmlException e) {
> e.printStackTrace();
> }
> System.out.println("gui.getGui().getGuiDisplayName() = " +
> gui.getGui().getDisplayName());
> System.out.println("gui.getGui().getFieldName() = " +
> gui.getGui().getFieldName());
>
> }
>
> String[] prefixes = dia.getDia().getLanPrefixListArray();
> for (int i = 0; i < prefixes.length; i++) {
> String prefix = prefixes[i];
>
> }
>
> }
>
> public static void main(String[] args) {
> HtmlBuilder hh = new HtmlBuilder();
> }
> }
>
>
> <xs:schema targetNamespace="http://newservice"
> xmlns:app="http://guiextensions" xmlns:nser="http://newservice"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:complexType name="Dia">
> <xs:sequence>
> <xs:element name="lanPrefixList"
type="xs:string"
> minOccurs="0" maxOccurs="unbounded">
> <xs:annotation>
> <xs:appinfo>
> <app:gui>
>
<app:displayName>Lan Prefix
> List</app:displayName>
>
> <app:fieldName>lPrefixList</app:fieldName>
> </app:gui>
> </xs:appinfo>
> </xs:annotation>
> </xs:element>
> <xs:element name="wanPrefixList"
type="xs:string"
> minOccurs="0" maxOccurs="unbounded">
> <xs:annotation>
> <xs:appinfo>
> <app:gui>
>
<app:displayName>Wan Prefix
> List</app:displayName>
>
> <app:fieldName>wPrefixList</app:fieldName>
> </app:gui>
> </xs:appinfo>
> </xs:annotation>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> <xs:element name="dia" type="nser:Dia">
> <xs:annotation>
> <xs:appinfo>
> <app:gui>
>
<app:displayName>Dia</app:displayName>
>
<app:fieldName>DiaField</app:fieldName>
> </app:gui>
> </xs:appinfo>
> </xs:annotation>
> </xs:element>
> </xs:schema>
>
> -----Original Message-----
> From: Lawrence Jones [mailto:ljones@bea.com]
> Sent: Friday, August 26, 2005 4:47 PM
> To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
> Subject: RE: Trying to use XMLBeans 2.0 and appinfo
>
>
>
> Hi Ian
>
> I think the following thread the user mailing list on 7/19/05 -
>
http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200507.mbox/%3c4B
> 2B4C417991364996F035E1EE39E2E1031F4D0C@uskiex01.amer.bea.com%3e will
> help you.
>
> Cheers,
>
> Lawrence
>
> > -----Original Message-----
> > From: Butt, Ian [mailto:ibutt@metasolv.com]
> > Sent: Friday, August 26, 2005 1:33 PM
> > To: user@xmlbeans.apache.org; dev@xmlbeans.apache.org
> > Subject: Trying to use XMLBeans 2.0 and appinfo
> >
> > I am trying to use XMLBeans to access some information that is
> contained
> > in my annotation, specifically my appinfo. Basically I would like
to
> > retrieve the appinfo contents so that I can build a gui dynamically
> and
> > the appinfo contains various information that I would like to build
my
> gui
> > (i.e. textbox, size, display name, etc...) In the code below
> > schemaType.getAnnotation is empty.
> >
> > import howdy.PurchaseOrderDocument;
> > import org.apache.xmlbeans.XmlObject;
> > import org.apache.xmlbeans.SchemaAnnotation;
> > import org.apache.xmlbeans.SchemaType;
> >
> > public class HtmlBuilder {
> >
> > public HtmlBuilder() {
> > PurchaseOrderDocument po =
> > PurchaseOrderDocument.Factory.newInstance();
> > po.addComment("Hello");
> >
> >
> > SchemaType schemaType = po.schemaType();
> > if (schemaType != null) {
> >
> > if (schemaType.getAnnotation() != null) {
> > XmlObject[] appInfo
> > =po.schemaType().getAnnotation().getApplicationInformation();
> > SchemaAnnotation.Attribute[] attrs =
> > po.schemaType().getAnnotation().getAttributes();
> > for (int i = 0; i < attrs.length; i++) {
> > SchemaAnnotation.Attribute attr = attrs[i];
> > System.out.println("aa" + attr.getName());
> > System.out.println("attr.getValue() = " +
> > attr.getValue());
> > }
> > }
> > }
> >
> > }
> >
> > public static void main(String[] args) {
> > HtmlBuilder hh = new HtmlBuilder();
> > }
> > }
> >
> >
> > Is this possible ? Does anybody have any examples.
> >
> > Thanks,
> >
> > Ian
> >
> >
> > Here is my Schema file:
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > xmlns:app="http://howdy/guiextensions">
> > <xsd:annotation>
> > <xsd:documentation xml:lang="en">
> > Purchase order schema for Example.com.
> > Copyright 2000 Example.com. All rights reserved.
> > </xsd:documentation>
> > </xsd:annotation>
> > <xsd:element name="purchaseOrder" type="PurchaseOrderType">
> > <xsd:annotation>
> > <xsd:appinfo>
> > <app:guiDisplayName>Purchase Order
> > </app:guiDisplayName>
> > </xsd:appinfo>
> > </xsd:annotation>
> > </xsd:element>
> >
> > <xsd:element name="comment" type="xsd:string">
> > <xsd:annotation>
> > <xsd:appinfo>
> > <app:guiDisplayName>Comment
> > </app:guiDisplayName>
> > </xsd:appinfo>
> > </xsd:annotation>
> > </xsd:element>
> > <xsd:complexType name="PurchaseOrderType">
> > <xsd:sequence>
> > <xsd:element name="shipTo" type="USAddress"/>
> > <xsd:element name="billTo" type="USAddress"/>
> > <xsd:element ref="comment" minOccurs="0"/>
> > <xsd:element name="items" type="Items"/>
> > </xsd:sequence>
> > <xsd:attribute name="orderDate" type="xsd:date"/>
> > </xsd:complexType>
> > <xsd:complexType name="USAddress">
> > <xsd:sequence>
> > <xsd:element name="name" type="xsd:string"/>
> > <xsd:element name="street" type="xsd:string"/>
> > <xsd:element name="city" type="xsd:string"/>
> > <xsd:element name="state" type="xsd:string"/>
> > <xsd:element name="zip" type="xsd:decimal"/>
> > </xsd:sequence>
> > <xsd:attribute name="country" type="xsd:NMTOKEN"
> fixed="US"/>
> > </xsd:complexType>
> > <xsd:complexType name="Items">
> > <xsd:sequence>
> > <xsd:element name="item" minOccurs="0"
> > maxOccurs="unbounded">
> > <xsd:complexType>
> > <xsd:sequence>
> > <xsd:element
> name="productName"
> > type="xsd:string"/>
> > <xsd:element
> name="quantity">
> > <xsd:simpleType>
> >
> <xsd:restriction
> > base="xsd:positiveInteger">
> >
> <xsd:maxExclusive
> > value="100"/>
> >
> </xsd:restriction>
> >
> </xsd:simpleType>
> > </xsd:element>
> > <xsd:element
> name="USPrice"
> > type="xsd:decimal"/>
> > <xsd:element
> ref="comment"
> > minOccurs="0"/>
> > <xsd:element
> name="shipDate"
> > type="xsd:date" minOccurs="0"/>
> > </xsd:sequence>
> > <xsd:attribute name="partNum"
> type="SKU"
> > use="required"/>
> > </xsd:complexType>
> > </xsd:element>
> > </xsd:sequence>
> > </xsd:complexType>
> > <!-- Stock Keeping Unit, a code for identifying products -->
> > <xsd:simpleType name="SKU">
> > <xsd:restriction base="xsd:string">
> > <xsd:pattern value="\d{3}-[A-Z]{2}"/>
> > </xsd:restriction>
> > </xsd:simpleType>
> > </xsd:schema>
> >
> > Here is my guiextensions schema file:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema
> > xmlns:gx="http://www.metasolv.com/serviceactivator/guiextensions"
> >
>
targetNamespace="http://www.metasolv.com/serviceactivator/guiextensions"
> > xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> > attributeFormDefault="unqualified">
> > <xs:element name="guiDisplayName" type="xs:string"/>
> > </xs:schema>
> >
> > Ian Butt
> > Senior Software Designer, MetaSolv IP Service Activator
> > MetaSolv Software
> > 360 March Road
> > Ottawa, ON
> > Office Phone: 613-287-8182
> > E-mail: ibutt@metasolv.com <mailto:ibutt@metasolv.com>
> >
> > ++++++CONFIDENTIALITY NOTICE+++++
> > The information in this email may be confidential and/or
> > privileged. This email is intended to be reviewed by only the
> individual
> > or organization named above. If you are not the intended recipient
or
> an
> > authorized representative of the intended recipient, you are hereby
> > notified that any review, dissemination or copying of this email and
> its
> > attachments, if any, or the information contained herein is
> prohibited. If
> > you have received this email in error, please immediately notify the
> > sender by return email and delete this email from your system.
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> > For additional commands, e-mail: dev-help@xmlbeans.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
---------------------------------------------------------------------
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