Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » my element is declared in schema A and its type in schema B, how to get its type
my element is declared in schema A and its type in schema B, how to get its type [message #61754] Mon, 20 June 2005 14:49 Go to next message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi,
i have an elemnt declared in schema A
its type is defined in schema B
when parsing the schema A, the value of the type is null!
How can i do?

here is part of the code :
<xsd:element name="IdentificationCode"
type="cnt:CountryIdentificationCodeType"/>

i have included the namespace "cnt" of schema B in the schema A.
when myElement is the XSDElementDeclaration with name : IdentificationCode
and when i try to get the type : CountryIdentificationCodeType
by doing: myElement.getTypedefinition() i have null as value of the type.

What is wrong?
Thanks for your help.
Re: my element is declared in schema A and its type in schema B, how to get its type [message #61779 is a reply to message #61754] Mon, 20 June 2005 15:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Elhadji,

Doing
xsdElementDeclaration.getResolveElementDeclaration().getType Definition()
should return it. If that's null, you're most likely looking at an
unresolved element declaration reference.


elhadji wrote:

> Hi,
> i have an elemnt declared in schema A
> its type is defined in schema B
> when parsing the schema A, the value of the type is null!
> How can i do?
>
> here is part of the code :
> <xsd:element name="IdentificationCode"
> type="cnt:CountryIdentificationCodeType"/>
>
> i have included the namespace "cnt" of schema B in the schema A.
> when myElement is the XSDElementDeclaration with name :
> IdentificationCode
> and when i try to get the type : CountryIdentificationCodeType
> by doing: myElement.getTypedefinition() i have null as value of the type.
>
> What is wrong?
> Thanks for your help.
>
>
Re: my element is declared in schema A and its type in schema B, how to get its type [message #61827 is a reply to message #61779] Tue, 21 June 2005 08:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi Ed,

it must be a basic question; but i don't know what is mean a unresolved
element declaration. What i'm sure is i have validate the schema using
stylus, i have tested what you say but it until returns null for the value
of the type.

What i'm missing?

Thanks for your help!
Re: my element is declared in schema A and its type in schema B, how to get its type [message #61903 is a reply to message #61827] Tue, 21 June 2005 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Elhadji,

You are providing effectively no information that I can use as a basis
for helping you. You've not shown your schemas, so although you are
certain they are valid, I have no such certainty. You've not even
shown me whether you are dealing with a global element declaration or a
local one within a complex type. As far as I know, the type definition
of an element declaration can't be null for a global element
declaration, which I why I'm starting to assume you are dealing with a
reference to an element declaration <xsd:element ref="..."/> and most
likely are hitting the case where the referenced element doesn't resolve
and hence a place holder with the right namespace and name (but no type
definition) is created. The inability to resolve names is most often
caused by failure to load the schema with an absolute URI against which
relative schemaLocations can be properly resolved.

If you need a detailed answer, please provide enough information as the
basis for that, i.e., a relatively complete example and the code you are
using to load and examine the instance.


elhadji wrote:

> Hi Ed,
>
> it must be a basic question; but i don't know what is mean a
> unresolved element declaration. What i'm sure is i have validate the
> schema using stylus, i have tested what you say but it until returns
> null for the value of the type.
>
> What i'm missing?
>
> Thanks for your help!
>
Re: my element is declared in schema A and its type in schema B, how to get its type [message #61978 is a reply to message #61903] Tue, 21 June 2005 16:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi Ed, you're right

here is my schemas :

the 1st and main schema :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="ns:Individu"
xmlns:adr="ns:Adresse"
targetNamespace="ns:Individu"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="ns:Adresse" schemaLocation="Adresse.xsd"/>
<xs:element name="Individu" type="IndividuType">
<xs:annotation>
<xs:documentation>Un petit descriptif du schéma !</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="IndividuType">
<xs:sequence>
<xs:element name="Nom" type="xs:string"/>
<xs:element name="Prenoms" type="xs:string"/>
<xs:element name="Adresse" type="adr:LigneAdresseType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>


the second schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="ns:Adresse"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lat="ns:LigneAdresse"
targetNamespace="ns:Adresse"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="ns:LigneAdresse"
schemaLocation="LigneAdresse.xsd"/>
<xs:element name="Adresse" type="LigneAdresseType"/>
<xs:complexType name="LigneAdresseType">
<xs:simpleContent>
<xs:restriction base="lat:LigneAdresseType">
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

the last schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="ns:LigneAdresse"
targetNamespace="ns:LigneAdresse"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="LigneAdresse" type="LigneAdresseType"/>
<xs:complexType name="LigneAdresseType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Numero" type="xs:string"/>
<xs:attribute name="Rue" type="xs:string" use="optional"/>
<xs:attribute name="CodePostal" type="xs:string" use="optional"/>
<xs:attribute name="Ville" type="xs:string"/>
<xs:attribute name="Pays" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>



My problem is when parsing the main schema and when i try to get the type
of the element named "Adresse" i have null as value;
what is wrong ?


part of the code:
i put here the most important class about the question but it can't run on
standalone(it needs many other classes ), i think it may indicates you how
to help me

Thanks again for your help!
/*
* Copyright (C) 2003 by Genigraph
* All rights reserved.
*
*All usage rights are governed by the applicable Genigraph agreement.
*/

package com.ecitiz.xsd.parser;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTerm;
import org.eclipse.xsd.XSDTypeDefinition;
import org.eclipse.xsd.util.XSDResourceFactoryImpl;
import org.eclipse.xsd.util.XSDResourceImpl;

import com.ecitiz.form.generator.model.Cardinality;
import com.ecitiz.form.generator.model.FieldAttribute;
import com.ecitiz.form.generator.model.Form;
import com.ecitiz.form.generator.model.Section;

/**
* This Action logs an authenticated user off and redirect user to welcome
* screen
*
* @author A. AUDEVART
*/
public class XSDFormParser
{
/*
* This method process the root element
*/

static ArrayList listSection = new ArrayList();
static ArrayList listFieldAttribute = new ArrayList();


public Form createTheRootElement(XSDElementDeclaration elementRoot)
{
// Begin of what i have added
XSDElementDeclaration elementRootRef =
getElementByReference(elementRoot);
//End of what i have added
//Extract the annotation which describes the form.
Annotation annotation = new Annotation();
String help = annotation.createRootAnnotation(elementRootRef);

//Extract the appInfo
AppInfo appInfo = new AppInfo();
String appInfoString = appInfo.createRootAppInfo(elementRootRef);

Cardinality cardinality = new Cardinality(1, 1);

TypeXSD xsdType = new TypeXSD();

ModifyName modifName = new ModifyName(elementRootRef.getName(),
appInfoString);
// String nameXSD = modifName.getXSDName();
String nameForm = modifName.getFormName();


Form form = new Form(nameForm, help);

XSDTypeDefinition elementType = elementRootRef.getTypeDefinition();

if (elementType instanceof XSDComplexTypeDefinition)
{
XSDComplexTypeDefinition aComplexType =
(XSDComplexTypeDefinition) elementType;
//Extract the annotation which describes the first root section.
String annotString = annotation.createAnnotation(elementType);
//Extract the appInfo
String appInfoString2 = appInfo.createAppInfo(elementType);
ModifyName modifNameSection = new
ModifyName(elementType.getName(), appInfoString2);
String sectionNameXSD = modifNameSection.getXSDName();
String sectionName = modifNameSection.getFormName();
Section section = new Section(sectionName, annotString);

section.setCardinality(cardinality);
section.setXSDText(sectionNameXSD);

section = VerifyRepeat.isRepeatSectionType(section);
form.add(section);

ComplexType complex = new ComplexType();
complex.createAttribute(aComplexType, section, cardinality);

XSDParticle particle = aComplexType.getComplexType();
XSDTerm term = particle.getTerm();
XSDModelGroup xsdModelGroup = (XSDModelGroup) term;
EList particleList = xsdModelGroup.getParticles();
for (Iterator iter = particleList.iterator(); iter.hasNext();)
{
XSDParticle aParticle = (XSDParticle) iter.next();
Cardinality cardinality2 =
CardinalityType.processParticle(aParticle);

XSDTerm aTerm = aParticle.getTerm();
XSDElementDeclaration element = (XSDElementDeclaration) aTerm;
XSDElementDeclaration elementRef =
getElementByReference(element);
String help3 = annotation.createAnnotationElemDec(elementRef);

//Extract the appInfo
String appInfoString3 = appInfo.createRootAppInfo(elementRef);

ModifyName modifName2 = new ModifyName(elementRef.getName(),
appInfoString3);
String sectionNameXSD2 = modifName2.getXSDName();
String elementName = modifName2.getFormName();

XSDTypeDefinition elementTypeRef =
elementRef.getTypeDefinition();
xsdType.processingAnElement(section, elementTypeRef,
elementName,
sectionNameXSD2 , cardinality2, help3);
}
}
else
{
String annotString =
annotation.createAnnotation(elementRoot.getType());
SimpleType simpleType = new SimpleType();
XSDSimpleTypeDefinition aSimpleType = (XSDSimpleTypeDefinition)
elementType;

XSDParticle aParticle = (XSDParticle)
aSimpleType.getComplexType();
Cardinality cardinality3;
if ( aParticle != null)
{
cardinality3 = CardinalityType.processParticle(aParticle);
}
else
{
cardinality3 = new Cardinality(1, 1);
}
FieldAttribute field = simpleType.createSimpleType(aSimpleType,
nameForm, cardinality);
if (annotString != null)
{
field.setHelp(annotString);
}
field = VerifyRepeat.isRepeatFieldAttributeType(field);
form.add(field);
}
return form;
}

// Begin of my methods
public XSDElementDeclaration rootElementDeclarationFinder(String
schemaURL)
{
XSDSchema schema = null;
Object component = null;
XSDElementDeclaration rootElement = null;
// XSDParticleContent particleContent = null;
try
{
// LoadSchema loadSchema = new LoadSchema();
// schema = loadSchema.loadSchemaUsingResourceSet(schemaURL, null);
schema = loadSchemaUsingResourceSet(schemaURL);
}
catch (Exception e)
{
e.printStackTrace();
}
//Browsing the schema content and searching for Element Declarations
Iterator iter = schema.getContents().iterator();
while (iter.hasNext())
{
component = iter.next();
if (component instanceof XSDElementDeclaration)
{
//Found root element decalation
rootElement = (XSDElementDeclaration) component;
break;
}
}
return rootElement;
}

/*
* This method parse an XSD Schema in a Form.
*/
public Form createForm(String filename)
{
XSDElementDeclaration rootElement = null;
rootElement = rootElementDeclarationFinder(filename);
return createTheRootElement(rootElement);
}


public static XSDElementDeclaration
getElementByReference(XSDElementDeclaration
elementDeclaration)
{
XSDElementDeclaration targetElementDeclaration = elementDeclaration;
if (elementDeclaration.isElementDeclarationReference())
{
targetElementDeclaration =
elementDeclaration.getResolvedElementDeclaration();
}
return targetElementDeclaration;
}


private XSDSchema loadSchemaUsingResourceSet(String schemaURL) throws
Exception
{
XSDSchema returnSchema = null;

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
new XSDResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
Boolean.TRUE);

URI uri;
File file = new File(schemaURL);
if (file.isFile())
{
uri = URI.createFileURI(file.getCanonicalFile().toString());
}
else
{
uri = URI.createURI(schemaURL);
}

XSDResourceImpl xsdSchemaResource = (XSDResourceImpl)
resourceSet.getResource(uri, true);
for (Iterator resources = resourceSet.getResources().iterator();
resources.hasNext(); /* no-op */)
{
Resource resource = (Resource) resources.next();
if (resource instanceof XSDResourceImpl)
{
XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
returnSchema = xsdResource.getSchema();
return returnSchema;
}
}
System.err.println("loadSchemaUsingResourceSet(" + schemaURL +
") did not contain any schemas!");
return null;
}
}


Thanks again !!
Re: my element is declared in schema A and its type in schema B, how to get its type [message #62002 is a reply to message #61978] Tue, 21 June 2005 18:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Elhadji,

Before I dive in too deeply, which version of EMF/XSD are you using?
I.e., could you be seeing the same problem as Robert in the XSD Schema
tree posting two notes up?

It looks like this code isn't quite right and should probably be using
elementRootRef:

String annotString =
annotation.createAnnotation(elementRoot.getType());


elhadji wrote:

> Hi Ed, you're right
>
> here is my schemas :
>
> the 1st and main schema :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="ns:Individu" xmlns:adr="ns:Adresse"
> targetNamespace="ns:Individu" elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:import namespace="ns:Adresse" schemaLocation="Adresse.xsd"/>
> <xs:element name="Individu" type="IndividuType">
> <xs:annotation>
> <xs:documentation>Un petit descriptif du schéma
> !</xs:documentation>
> </xs:annotation>
> </xs:element>
> <xs:complexType name="IndividuType">
> <xs:sequence>
> <xs:element name="Nom" type="xs:string"/>
> <xs:element name="Prenoms" type="xs:string"/>
> <xs:element name="Adresse" type="adr:LigneAdresseType"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
>
> the second schema:
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns="ns:Adresse"
> xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:lat="ns:LigneAdresse"
> targetNamespace="ns:Adresse" elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:import namespace="ns:LigneAdresse"
> schemaLocation="LigneAdresse.xsd"/>
> <xs:element name="Adresse" type="LigneAdresseType"/>
> <xs:complexType name="LigneAdresseType">
> <xs:simpleContent>
> <xs:restriction base="lat:LigneAdresseType">
> </xs:restriction>
> </xs:simpleContent>
> </xs:complexType>
> </xs:schema>
>
> the last schema:
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="ns:LigneAdresse" targetNamespace="ns:LigneAdresse"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xs:element name="LigneAdresse" type="LigneAdresseType"/>
> <xs:complexType name="LigneAdresseType">
> <xs:simpleContent>
> <xs:extension base="xs:string">
> <xs:attribute name="Numero" type="xs:string"/>
> <xs:attribute name="Rue" type="xs:string"
> use="optional"/>
> <xs:attribute name="CodePostal" type="xs:string"
> use="optional"/>
> <xs:attribute name="Ville" type="xs:string"/>
> <xs:attribute name="Pays" type="xs:string"/>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
> </xs:schema>
>
>
>
> My problem is when parsing the main schema and when i try to get the
> type of the element named "Adresse" i have null as value;
> what is wrong ?
>
>
> part of the code:
> i put here the most important class about the question but it can't
> run on standalone(it needs many other classes ), i think it may
> indicates you how to help me
>
> Thanks again for your help!
> /*
> * Copyright (C) 2003 by Genigraph
> * All rights reserved.
> *
> *All usage rights are governed by the applicable Genigraph agreement.
> */
>
> package com.ecitiz.xsd.parser;
>
> import java.io.File;
> import java.util.ArrayList;
> import java.util.Iterator;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.xsd.XSDComplexTypeDefinition;
> import org.eclipse.xsd.XSDElementDeclaration;
> import org.eclipse.xsd.XSDModelGroup;
> import org.eclipse.xsd.XSDParticle;
> import org.eclipse.xsd.XSDSchema;
> import org.eclipse.xsd.XSDSimpleTypeDefinition;
> import org.eclipse.xsd.XSDTerm;
> import org.eclipse.xsd.XSDTypeDefinition;
> import org.eclipse.xsd.util.XSDResourceFactoryImpl;
> import org.eclipse.xsd.util.XSDResourceImpl;
>
> import com.ecitiz.form.generator.model.Cardinality;
> import com.ecitiz.form.generator.model.FieldAttribute;
> import com.ecitiz.form.generator.model.Form;
> import com.ecitiz.form.generator.model.Section;
>
> /**
> * This Action logs an authenticated user off and redirect user to welcome
> * screen
> * * @author A. AUDEVART
> */
> public class XSDFormParser
> {
> /*
> * This method process the root element
> */
> static ArrayList listSection = new ArrayList();
> static ArrayList listFieldAttribute = new ArrayList();
> public Form createTheRootElement(XSDElementDeclaration elementRoot)
> {
> // Begin of what i have added
> XSDElementDeclaration elementRootRef =
> getElementByReference(elementRoot);
> //End of what i have added
> //Extract the annotation which describes the form.
> Annotation annotation = new Annotation();
> String help = annotation.createRootAnnotation(elementRootRef);
> //Extract the appInfo
> AppInfo appInfo = new AppInfo();
> String appInfoString = appInfo.createRootAppInfo(elementRootRef);
>
> Cardinality cardinality = new Cardinality(1, 1);
> TypeXSD xsdType = new TypeXSD();
>
> ModifyName modifName = new ModifyName(elementRootRef.getName(),
> appInfoString);
> // String nameXSD = modifName.getXSDName();
> String nameForm = modifName.getFormName();
> Form form = new Form(nameForm, help);
>
> XSDTypeDefinition elementType = elementRootRef.getTypeDefinition();
>
> if (elementType instanceof XSDComplexTypeDefinition)
> {
> XSDComplexTypeDefinition aComplexType =
> (XSDComplexTypeDefinition) elementType;
> //Extract the annotation which describes the first root section.
> String annotString = annotation.createAnnotation(elementType);
> //Extract the appInfo
> String appInfoString2 = appInfo.createAppInfo(elementType);
> ModifyName modifNameSection = new
> ModifyName(elementType.getName(), appInfoString2);
> String sectionNameXSD = modifNameSection.getXSDName();
> String sectionName = modifNameSection.getFormName();
> Section section = new Section(sectionName, annotString);
> section.setCardinality(cardinality);
> section.setXSDText(sectionNameXSD);
> section = VerifyRepeat.isRepeatSectionType(section);
> form.add(section);
>
> ComplexType complex = new ComplexType();
> complex.createAttribute(aComplexType, section, cardinality);
>
> XSDParticle particle = aComplexType.getComplexType();
> XSDTerm term = particle.getTerm();
> XSDModelGroup xsdModelGroup = (XSDModelGroup) term;
> EList particleList = xsdModelGroup.getParticles();
> for (Iterator iter = particleList.iterator(); iter.hasNext();)
> {
> XSDParticle aParticle = (XSDParticle) iter.next();
> Cardinality cardinality2 =
> CardinalityType.processParticle(aParticle);
> XSDTerm aTerm = aParticle.getTerm();
> XSDElementDeclaration element = (XSDElementDeclaration) aTerm;
> XSDElementDeclaration elementRef =
> getElementByReference(element);
> String help3 = annotation.createAnnotationElemDec(elementRef);
> //Extract the appInfo
> String appInfoString3 = appInfo.createRootAppInfo(elementRef);
> ModifyName modifName2 = new
> ModifyName(elementRef.getName(), appInfoString3);
> String sectionNameXSD2 = modifName2.getXSDName();
> String elementName = modifName2.getFormName();
> XSDTypeDefinition elementTypeRef =
> elementRef.getTypeDefinition();
> xsdType.processingAnElement(section, elementTypeRef,
> elementName,
> sectionNameXSD2 , cardinality2, help3);
> }
> }
> else
> {
> String annotString =
> annotation.createAnnotation(elementRoot.getType());
> SimpleType simpleType = new SimpleType();
> XSDSimpleTypeDefinition aSimpleType =
> (XSDSimpleTypeDefinition) elementType;
> XSDParticle aParticle = (XSDParticle)
> aSimpleType.getComplexType();
> Cardinality cardinality3;
> if ( aParticle != null)
> {
> cardinality3 = CardinalityType.processParticle(aParticle);
> }
> else
> {
> cardinality3 = new Cardinality(1, 1);
> }
> FieldAttribute field =
> simpleType.createSimpleType(aSimpleType, nameForm, cardinality);
> if (annotString != null)
> {
> field.setHelp(annotString);
> }
> field = VerifyRepeat.isRepeatFieldAttributeType(field);
> form.add(field);
> }
> return form;
> }
> // Begin of my methods
> public XSDElementDeclaration rootElementDeclarationFinder(String
> schemaURL)
> {
> XSDSchema schema = null;
> Object component = null;
> XSDElementDeclaration rootElement = null;
> // XSDParticleContent particleContent = null;
> try
> {
> // LoadSchema loadSchema = new LoadSchema();
> // schema = loadSchema.loadSchemaUsingResourceSet(schemaURL,
> null);
> schema = loadSchemaUsingResourceSet(schemaURL);
> } catch (Exception e) {
> e.printStackTrace();
> }
> //Browsing the schema content and searching for Element Declarations
> Iterator iter = schema.getContents().iterator();
> while (iter.hasNext())
> {
> component = iter.next();
> if (component instanceof XSDElementDeclaration)
> {
> //Found root element decalation
> rootElement = (XSDElementDeclaration) component;
> break;
> }
> }
> return rootElement;
> }
> /*
> * This method parse an XSD Schema in a Form.
> */
> public Form createForm(String filename)
> {
> XSDElementDeclaration rootElement = null;
> rootElement = rootElementDeclarationFinder(filename);
> return createTheRootElement(rootElement);
> }
> public static XSDElementDeclaration
> getElementByReference(XSDElementDeclaration elementDeclaration) {
> XSDElementDeclaration targetElementDeclaration = elementDeclaration;
> if (elementDeclaration.isElementDeclarationReference()) {
> targetElementDeclaration =
> elementDeclaration.getResolvedElementDeclaration();
> }
> return targetElementDeclaration;
> }
>
> private XSDSchema loadSchemaUsingResourceSet(String schemaURL)
> throws Exception
> {
> XSDSchema returnSchema = null;
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
> new XSDResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
> Boolean.TRUE);
> URI uri;
> File file = new File(schemaURL);
> if (file.isFile())
> {
> uri = URI.createFileURI(file.getCanonicalFile().toString());
> }
> else
> {
> uri = URI.createURI(schemaURL);
> }
> XSDResourceImpl xsdSchemaResource = (XSDResourceImpl)
> resourceSet.getResource(uri, true);
> for (Iterator resources = resourceSet.getResources().iterator();
> resources.hasNext(); /* no-op */)
> {
> Resource resource = (Resource) resources.next();
> if (resource instanceof XSDResourceImpl)
> {
> XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
> returnSchema = xsdResource.getSchema();
> return returnSchema;
> }
> }
> System.err.println("loadSchemaUsingResourceSet(" + schemaURL +
> ") did not contain any schemas!");
> return null;
> }
> }
>
>
> Thanks again !!
>
>
>
Re: my element is declared in schema A and its type in schema B, how to get its type [message #62025 is a reply to message #62002] Wed, 22 June 2005 08:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi Ed,
I'm using EMF/XSD 2.1.0, here is what i have download two months ago:
xsd-SDK-I200504070700.zip
Perhaps it was not stable when i was download it.

and Eclipse 3.0.1

About this instruction :
String annotString = annotation.createAnnotation(elementRoot.getType());

elementRoot is the root XSDElementDeclaration of the 1st schema

We have another model where we define many others classes we use in the
parser; that's why i have posted the main classe of the parser, it would
be very huge to post all classes.

i can get element defined as ref like this:
<xsd:element ref="cbc:Postbox" minOccurs="0" maxOccurs="1">
where "Postbox" is defined in another schema

but i can't get the type of elemnt defined like this :
<xsd:element name="ID" type="udt:IdentifierType" minOccurs="0"
maxOccurs="1">
where "IdentifierType" is defined in another schema.
The value of the type in this case is null!

What is wrong!
I hope my question is more understandable.

Thank you a lot for your help!
Re: my element is declared in schema A and its type in schema B, how to get its type [message #62048 is a reply to message #62025] Wed, 22 June 2005 13:57 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------060300000101020803080501
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Elhadji,

If I try the schemas you've provided with XSDMainExample (renamed from
XSDMainTest in older drivers) it seems to work fine right now. I.e., I
add this code within the loadAndPrint method:

XSDSchema xsdSchema = xsdResource.getSchema();

XSDComplexTypeDefinition indivduType =
xsdSchema.resolveComplexTypeDefinition("IndividuType");
if (indivduType.getContainer() != null)
{
XSDElementDeclaration xsdElementDeclaration =
(XSDElementDeclaration)((XSDParticle)((XSDModelGroup)indivdu Type.getComplexType().getContent()).getContents().get(2)).ge tContent();
System.err.println("#1#" +
xsdElementDeclaration.getTypeDefinition());
}

XSDElementDeclaration adresseElement =
xsdSchema.resolveElementDeclaration("Adresse");
if (adresseElement.getContainer() != null)
{
System.err.println("#2#" + adresseElement.getTypeDefinition());
}

And that produces this result:

#1#org.eclipse.xsd.impl.XSDComplexTypeDefinitionImpl@3f9ff1e3
(element: [xs:complexType: null]) (name: LigneAdresseType,
targetNamespace: ns:Adresse) (derivationMethod: restriction, final:
[], abstract: <unset>, contentTypeCategory: simple,
prohibitedSubstitutions: [], lexicalFinal: null, block: null, mixed:
<unset>)
#2#org.eclipse.xsd.impl.XSDComplexTypeDefinitionImpl@3f9ff1e3
(element: [xs:complexType: null]) (name: LigneAdresseType,
targetNamespace: ns:Adresse) (derivationMethod: restriction, final:
[], abstract: <unset>, contentTypeCategory: simple,
prohibitedSubstitutions: [], lexicalFinal: null, block: null, mixed:
<unset>)

So both Adresse elements have a non-null type.

Without the ability to reproduce your problem, I'm at a loss what to
suggest. It's possible that 99227
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=99227> fixed the problem,
so trying the latest build might be good.


elhadji wrote:

> Hi Ed,
> I'm using EMF/XSD 2.1.0, here is what i have download two months ago:
> xsd-SDK-I200504070700.zip Perhaps it was not stable when i was
> download it.
>
> and Eclipse 3.0.1
>
> About this instruction :
> String annotString = annotation.createAnnotation(elementRoot.getType());
>
> elementRoot is the root XSDElementDeclaration of the 1st schema
>
> We have another model where we define many others classes we use in
> the parser; that's why i have posted the main classe of the parser, it
> would be very huge to post all classes.
>
> i can get element defined as ref like this:
> <xsd:element ref="cbc:Postbox" minOccurs="0" maxOccurs="1">
> where "Postbox" is defined in another schema
>
> but i can't get the type of elemnt defined like this :
> <xsd:element name="ID" type="udt:IdentifierType" minOccurs="0"
> maxOccurs="1">
> where "IdentifierType" is defined in another schema.
> The value of the type in this case is null!
>
> What is wrong!
> I hope my question is more understandable.
>
> Thank you a lot for your help!
>
>
>
>
>


--------------060300000101020803080501
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Elhadji,<br>
<br>
If I try the schemas you've provided with XSDMainExample (renamed from
XSDMainTest in older drivers) it seems to work fine right now.
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595734 is a reply to message #61754] Mon, 20 June 2005 15:49 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
Elhadji,

Doing
xsdElementDeclaration.getResolveElementDeclaration().getType Definition()
should return it. If that's null, you're most likely looking at an
unresolved element declaration reference.


elhadji wrote:

> Hi,
> i have an elemnt declared in schema A
> its type is defined in schema B
> when parsing the schema A, the value of the type is null!
> How can i do?
>
> here is part of the code :
> <xsd:element name="IdentificationCode"
> type="cnt:CountryIdentificationCodeType"/>
>
> i have included the namespace "cnt" of schema B in the schema A.
> when myElement is the XSDElementDeclaration with name :
> IdentificationCode
> and when i try to get the type : CountryIdentificationCodeType
> by doing: myElement.getTypedefinition() i have null as value of the type.
>
> What is wrong?
> Thanks for your help.
>
>
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595763 is a reply to message #61779] Tue, 21 June 2005 08:05 Go to previous message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi Ed,

it must be a basic question; but i don't know what is mean a unresolved
element declaration. What i'm sure is i have validate the schema using
stylus, i have tested what you say but it until returns null for the value
of the type.

What i'm missing?

Thanks for your help!
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595796 is a reply to message #61827] Tue, 21 June 2005 12:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
Elhadji,

You are providing effectively no information that I can use as a basis
for helping you. You've not shown your schemas, so although you are
certain they are valid, I have no such certainty. You've not even
shown me whether you are dealing with a global element declaration or a
local one within a complex type. As far as I know, the type definition
of an element declaration can't be null for a global element
declaration, which I why I'm starting to assume you are dealing with a
reference to an element declaration <xsd:element ref="..."/> and most
likely are hitting the case where the referenced element doesn't resolve
and hence a place holder with the right namespace and name (but no type
definition) is created. The inability to resolve names is most often
caused by failure to load the schema with an absolute URI against which
relative schemaLocations can be properly resolved.

If you need a detailed answer, please provide enough information as the
basis for that, i.e., a relatively complete example and the code you are
using to load and examine the instance.


elhadji wrote:

> Hi Ed,
>
> it must be a basic question; but i don't know what is mean a
> unresolved element declaration. What i'm sure is i have validate the
> schema using stylus, i have tested what you say but it until returns
> null for the value of the type.
>
> What i'm missing?
>
> Thanks for your help!
>
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595827 is a reply to message #61903] Tue, 21 June 2005 16:53 Go to previous message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi Ed, you're right

here is my schemas :

the 1st and main schema :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="ns:Individu"
xmlns:adr="ns:Adresse"
targetNamespace="ns:Individu"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="ns:Adresse" schemaLocation="Adresse.xsd"/>
<xs:element name="Individu" type="IndividuType">
<xs:annotation>
<xs:documentation>Un petit descriptif du schéma !</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="IndividuType">
<xs:sequence>
<xs:element name="Nom" type="xs:string"/>
<xs:element name="Prenoms" type="xs:string"/>
<xs:element name="Adresse" type="adr:LigneAdresseType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>


the second schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="ns:Adresse"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lat="ns:LigneAdresse"
targetNamespace="ns:Adresse"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="ns:LigneAdresse"
schemaLocation="LigneAdresse.xsd"/>
<xs:element name="Adresse" type="LigneAdresseType"/>
<xs:complexType name="LigneAdresseType">
<xs:simpleContent>
<xs:restriction base="lat:LigneAdresseType">
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

the last schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="ns:LigneAdresse"
targetNamespace="ns:LigneAdresse"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="LigneAdresse" type="LigneAdresseType"/>
<xs:complexType name="LigneAdresseType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Numero" type="xs:string"/>
<xs:attribute name="Rue" type="xs:string" use="optional"/>
<xs:attribute name="CodePostal" type="xs:string" use="optional"/>
<xs:attribute name="Ville" type="xs:string"/>
<xs:attribute name="Pays" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>



My problem is when parsing the main schema and when i try to get the type
of the element named "Adresse" i have null as value;
what is wrong ?


part of the code:
i put here the most important class about the question but it can't run on
standalone(it needs many other classes ), i think it may indicates you how
to help me

Thanks again for your help!
/*
* Copyright (C) 2003 by Genigraph
* All rights reserved.
*
*All usage rights are governed by the applicable Genigraph agreement.
*/

package com.ecitiz.xsd.parser;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTerm;
import org.eclipse.xsd.XSDTypeDefinition;
import org.eclipse.xsd.util.XSDResourceFactoryImpl;
import org.eclipse.xsd.util.XSDResourceImpl;

import com.ecitiz.form.generator.model.Cardinality;
import com.ecitiz.form.generator.model.FieldAttribute;
import com.ecitiz.form.generator.model.Form;
import com.ecitiz.form.generator.model.Section;

/**
* This Action logs an authenticated user off and redirect user to welcome
* screen
*
* @author A. AUDEVART
*/
public class XSDFormParser
{
/*
* This method process the root element
*/

static ArrayList listSection = new ArrayList();
static ArrayList listFieldAttribute = new ArrayList();


public Form createTheRootElement(XSDElementDeclaration elementRoot)
{
// Begin of what i have added
XSDElementDeclaration elementRootRef =
getElementByReference(elementRoot);
//End of what i have added
//Extract the annotation which describes the form.
Annotation annotation = new Annotation();
String help = annotation.createRootAnnotation(elementRootRef);

//Extract the appInfo
AppInfo appInfo = new AppInfo();
String appInfoString = appInfo.createRootAppInfo(elementRootRef);

Cardinality cardinality = new Cardinality(1, 1);

TypeXSD xsdType = new TypeXSD();

ModifyName modifName = new ModifyName(elementRootRef.getName(),
appInfoString);
// String nameXSD = modifName.getXSDName();
String nameForm = modifName.getFormName();


Form form = new Form(nameForm, help);

XSDTypeDefinition elementType = elementRootRef.getTypeDefinition();

if (elementType instanceof XSDComplexTypeDefinition)
{
XSDComplexTypeDefinition aComplexType =
(XSDComplexTypeDefinition) elementType;
//Extract the annotation which describes the first root section.
String annotString = annotation.createAnnotation(elementType);
//Extract the appInfo
String appInfoString2 = appInfo.createAppInfo(elementType);
ModifyName modifNameSection = new
ModifyName(elementType.getName(), appInfoString2);
String sectionNameXSD = modifNameSection.getXSDName();
String sectionName = modifNameSection.getFormName();
Section section = new Section(sectionName, annotString);

section.setCardinality(cardinality);
section.setXSDText(sectionNameXSD);

section = VerifyRepeat.isRepeatSectionType(section);
form.add(section);

ComplexType complex = new ComplexType();
complex.createAttribute(aComplexType, section, cardinality);

XSDParticle particle = aComplexType.getComplexType();
XSDTerm term = particle.getTerm();
XSDModelGroup xsdModelGroup = (XSDModelGroup) term;
EList particleList = xsdModelGroup.getParticles();
for (Iterator iter = particleList.iterator(); iter.hasNext();)
{
XSDParticle aParticle = (XSDParticle) iter.next();
Cardinality cardinality2 =
CardinalityType.processParticle(aParticle);

XSDTerm aTerm = aParticle.getTerm();
XSDElementDeclaration element = (XSDElementDeclaration) aTerm;
XSDElementDeclaration elementRef =
getElementByReference(element);
String help3 = annotation.createAnnotationElemDec(elementRef);

//Extract the appInfo
String appInfoString3 = appInfo.createRootAppInfo(elementRef);

ModifyName modifName2 = new ModifyName(elementRef.getName(),
appInfoString3);
String sectionNameXSD2 = modifName2.getXSDName();
String elementName = modifName2.getFormName();

XSDTypeDefinition elementTypeRef =
elementRef.getTypeDefinition();
xsdType.processingAnElement(section, elementTypeRef,
elementName,
sectionNameXSD2 , cardinality2, help3);
}
}
else
{
String annotString =
annotation.createAnnotation(elementRoot.getType());
SimpleType simpleType = new SimpleType();
XSDSimpleTypeDefinition aSimpleType = (XSDSimpleTypeDefinition)
elementType;

XSDParticle aParticle = (XSDParticle)
aSimpleType.getComplexType();
Cardinality cardinality3;
if ( aParticle != null)
{
cardinality3 = CardinalityType.processParticle(aParticle);
}
else
{
cardinality3 = new Cardinality(1, 1);
}
FieldAttribute field = simpleType.createSimpleType(aSimpleType,
nameForm, cardinality);
if (annotString != null)
{
field.setHelp(annotString);
}
field = VerifyRepeat.isRepeatFieldAttributeType(field);
form.add(field);
}
return form;
}

// Begin of my methods
public XSDElementDeclaration rootElementDeclarationFinder(String
schemaURL)
{
XSDSchema schema = null;
Object component = null;
XSDElementDeclaration rootElement = null;
// XSDParticleContent particleContent = null;
try
{
// LoadSchema loadSchema = new LoadSchema();
// schema = loadSchema.loadSchemaUsingResourceSet(schemaURL, null);
schema = loadSchemaUsingResourceSet(schemaURL);
}
catch (Exception e)
{
e.printStackTrace();
}
//Browsing the schema content and searching for Element Declarations
Iterator iter = schema.getContents().iterator();
while (iter.hasNext())
{
component = iter.next();
if (component instanceof XSDElementDeclaration)
{
//Found root element decalation
rootElement = (XSDElementDeclaration) component;
break;
}
}
return rootElement;
}

/*
* This method parse an XSD Schema in a Form.
*/
public Form createForm(String filename)
{
XSDElementDeclaration rootElement = null;
rootElement = rootElementDeclarationFinder(filename);
return createTheRootElement(rootElement);
}


public static XSDElementDeclaration
getElementByReference(XSDElementDeclaration
elementDeclaration)
{
XSDElementDeclaration targetElementDeclaration = elementDeclaration;
if (elementDeclaration.isElementDeclarationReference())
{
targetElementDeclaration =
elementDeclaration.getResolvedElementDeclaration();
}
return targetElementDeclaration;
}


private XSDSchema loadSchemaUsingResourceSet(String schemaURL) throws
Exception
{
XSDSchema returnSchema = null;

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
new XSDResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
Boolean.TRUE);

URI uri;
File file = new File(schemaURL);
if (file.isFile())
{
uri = URI.createFileURI(file.getCanonicalFile().toString());
}
else
{
uri = URI.createURI(schemaURL);
}

XSDResourceImpl xsdSchemaResource = (XSDResourceImpl)
resourceSet.getResource(uri, true);
for (Iterator resources = resourceSet.getResources().iterator();
resources.hasNext(); /* no-op */)
{
Resource resource = (Resource) resources.next();
if (resource instanceof XSDResourceImpl)
{
XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
returnSchema = xsdResource.getSchema();
return returnSchema;
}
}
System.err.println("loadSchemaUsingResourceSet(" + schemaURL +
") did not contain any schemas!");
return null;
}
}


Thanks again !!
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595841 is a reply to message #61978] Tue, 21 June 2005 18:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
Elhadji,

Before I dive in too deeply, which version of EMF/XSD are you using?
I.e., could you be seeing the same problem as Robert in the XSD Schema
tree posting two notes up?

It looks like this code isn't quite right and should probably be using
elementRootRef:

String annotString =
annotation.createAnnotation(elementRoot.getType());


elhadji wrote:

> Hi Ed, you're right
>
> here is my schemas :
>
> the 1st and main schema :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="ns:Individu" xmlns:adr="ns:Adresse"
> targetNamespace="ns:Individu" elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:import namespace="ns:Adresse" schemaLocation="Adresse.xsd"/>
> <xs:element name="Individu" type="IndividuType">
> <xs:annotation>
> <xs:documentation>Un petit descriptif du schéma
> !</xs:documentation>
> </xs:annotation>
> </xs:element>
> <xs:complexType name="IndividuType">
> <xs:sequence>
> <xs:element name="Nom" type="xs:string"/>
> <xs:element name="Prenoms" type="xs:string"/>
> <xs:element name="Adresse" type="adr:LigneAdresseType"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
>
> the second schema:
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns="ns:Adresse"
> xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:lat="ns:LigneAdresse"
> targetNamespace="ns:Adresse" elementFormDefault="qualified"
> attributeFormDefault="unqualified">
> <xs:import namespace="ns:LigneAdresse"
> schemaLocation="LigneAdresse.xsd"/>
> <xs:element name="Adresse" type="LigneAdresseType"/>
> <xs:complexType name="LigneAdresseType">
> <xs:simpleContent>
> <xs:restriction base="lat:LigneAdresseType">
> </xs:restriction>
> </xs:simpleContent>
> </xs:complexType>
> </xs:schema>
>
> the last schema:
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="ns:LigneAdresse" targetNamespace="ns:LigneAdresse"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xs:element name="LigneAdresse" type="LigneAdresseType"/>
> <xs:complexType name="LigneAdresseType">
> <xs:simpleContent>
> <xs:extension base="xs:string">
> <xs:attribute name="Numero" type="xs:string"/>
> <xs:attribute name="Rue" type="xs:string"
> use="optional"/>
> <xs:attribute name="CodePostal" type="xs:string"
> use="optional"/>
> <xs:attribute name="Ville" type="xs:string"/>
> <xs:attribute name="Pays" type="xs:string"/>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
> </xs:schema>
>
>
>
> My problem is when parsing the main schema and when i try to get the
> type of the element named "Adresse" i have null as value;
> what is wrong ?
>
>
> part of the code:
> i put here the most important class about the question but it can't
> run on standalone(it needs many other classes ), i think it may
> indicates you how to help me
>
> Thanks again for your help!
> /*
> * Copyright (C) 2003 by Genigraph
> * All rights reserved.
> *
> *All usage rights are governed by the applicable Genigraph agreement.
> */
>
> package com.ecitiz.xsd.parser;
>
> import java.io.File;
> import java.util.ArrayList;
> import java.util.Iterator;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.xsd.XSDComplexTypeDefinition;
> import org.eclipse.xsd.XSDElementDeclaration;
> import org.eclipse.xsd.XSDModelGroup;
> import org.eclipse.xsd.XSDParticle;
> import org.eclipse.xsd.XSDSchema;
> import org.eclipse.xsd.XSDSimpleTypeDefinition;
> import org.eclipse.xsd.XSDTerm;
> import org.eclipse.xsd.XSDTypeDefinition;
> import org.eclipse.xsd.util.XSDResourceFactoryImpl;
> import org.eclipse.xsd.util.XSDResourceImpl;
>
> import com.ecitiz.form.generator.model.Cardinality;
> import com.ecitiz.form.generator.model.FieldAttribute;
> import com.ecitiz.form.generator.model.Form;
> import com.ecitiz.form.generator.model.Section;
>
> /**
> * This Action logs an authenticated user off and redirect user to welcome
> * screen
> * * @author A. AUDEVART
> */
> public class XSDFormParser
> {
> /*
> * This method process the root element
> */
> static ArrayList listSection = new ArrayList();
> static ArrayList listFieldAttribute = new ArrayList();
> public Form createTheRootElement(XSDElementDeclaration elementRoot)
> {
> // Begin of what i have added
> XSDElementDeclaration elementRootRef =
> getElementByReference(elementRoot);
> //End of what i have added
> //Extract the annotation which describes the form.
> Annotation annotation = new Annotation();
> String help = annotation.createRootAnnotation(elementRootRef);
> //Extract the appInfo
> AppInfo appInfo = new AppInfo();
> String appInfoString = appInfo.createRootAppInfo(elementRootRef);
>
> Cardinality cardinality = new Cardinality(1, 1);
> TypeXSD xsdType = new TypeXSD();
>
> ModifyName modifName = new ModifyName(elementRootRef.getName(),
> appInfoString);
> // String nameXSD = modifName.getXSDName();
> String nameForm = modifName.getFormName();
> Form form = new Form(nameForm, help);
>
> XSDTypeDefinition elementType = elementRootRef.getTypeDefinition();
>
> if (elementType instanceof XSDComplexTypeDefinition)
> {
> XSDComplexTypeDefinition aComplexType =
> (XSDComplexTypeDefinition) elementType;
> //Extract the annotation which describes the first root section.
> String annotString = annotation.createAnnotation(elementType);
> //Extract the appInfo
> String appInfoString2 = appInfo.createAppInfo(elementType);
> ModifyName modifNameSection = new
> ModifyName(elementType.getName(), appInfoString2);
> String sectionNameXSD = modifNameSection.getXSDName();
> String sectionName = modifNameSection.getFormName();
> Section section = new Section(sectionName, annotString);
> section.setCardinality(cardinality);
> section.setXSDText(sectionNameXSD);
> section = VerifyRepeat.isRepeatSectionType(section);
> form.add(section);
>
> ComplexType complex = new ComplexType();
> complex.createAttribute(aComplexType, section, cardinality);
>
> XSDParticle particle = aComplexType.getComplexType();
> XSDTerm term = particle.getTerm();
> XSDModelGroup xsdModelGroup = (XSDModelGroup) term;
> EList particleList = xsdModelGroup.getParticles();
> for (Iterator iter = particleList.iterator(); iter.hasNext();)
> {
> XSDParticle aParticle = (XSDParticle) iter.next();
> Cardinality cardinality2 =
> CardinalityType.processParticle(aParticle);
> XSDTerm aTerm = aParticle.getTerm();
> XSDElementDeclaration element = (XSDElementDeclaration) aTerm;
> XSDElementDeclaration elementRef =
> getElementByReference(element);
> String help3 = annotation.createAnnotationElemDec(elementRef);
> //Extract the appInfo
> String appInfoString3 = appInfo.createRootAppInfo(elementRef);
> ModifyName modifName2 = new
> ModifyName(elementRef.getName(), appInfoString3);
> String sectionNameXSD2 = modifName2.getXSDName();
> String elementName = modifName2.getFormName();
> XSDTypeDefinition elementTypeRef =
> elementRef.getTypeDefinition();
> xsdType.processingAnElement(section, elementTypeRef,
> elementName,
> sectionNameXSD2 , cardinality2, help3);
> }
> }
> else
> {
> String annotString =
> annotation.createAnnotation(elementRoot.getType());
> SimpleType simpleType = new SimpleType();
> XSDSimpleTypeDefinition aSimpleType =
> (XSDSimpleTypeDefinition) elementType;
> XSDParticle aParticle = (XSDParticle)
> aSimpleType.getComplexType();
> Cardinality cardinality3;
> if ( aParticle != null)
> {
> cardinality3 = CardinalityType.processParticle(aParticle);
> }
> else
> {
> cardinality3 = new Cardinality(1, 1);
> }
> FieldAttribute field =
> simpleType.createSimpleType(aSimpleType, nameForm, cardinality);
> if (annotString != null)
> {
> field.setHelp(annotString);
> }
> field = VerifyRepeat.isRepeatFieldAttributeType(field);
> form.add(field);
> }
> return form;
> }
> // Begin of my methods
> public XSDElementDeclaration rootElementDeclarationFinder(String
> schemaURL)
> {
> XSDSchema schema = null;
> Object component = null;
> XSDElementDeclaration rootElement = null;
> // XSDParticleContent particleContent = null;
> try
> {
> // LoadSchema loadSchema = new LoadSchema();
> // schema = loadSchema.loadSchemaUsingResourceSet(schemaURL,
> null);
> schema = loadSchemaUsingResourceSet(schemaURL);
> } catch (Exception e) {
> e.printStackTrace();
> }
> //Browsing the schema content and searching for Element Declarations
> Iterator iter = schema.getContents().iterator();
> while (iter.hasNext())
> {
> component = iter.next();
> if (component instanceof XSDElementDeclaration)
> {
> //Found root element decalation
> rootElement = (XSDElementDeclaration) component;
> break;
> }
> }
> return rootElement;
> }
> /*
> * This method parse an XSD Schema in a Form.
> */
> public Form createForm(String filename)
> {
> XSDElementDeclaration rootElement = null;
> rootElement = rootElementDeclarationFinder(filename);
> return createTheRootElement(rootElement);
> }
> public static XSDElementDeclaration
> getElementByReference(XSDElementDeclaration elementDeclaration) {
> XSDElementDeclaration targetElementDeclaration = elementDeclaration;
> if (elementDeclaration.isElementDeclarationReference()) {
> targetElementDeclaration =
> elementDeclaration.getResolvedElementDeclaration();
> }
> return targetElementDeclaration;
> }
>
> private XSDSchema loadSchemaUsingResourceSet(String schemaURL)
> throws Exception
> {
> XSDSchema returnSchema = null;
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",
> new XSDResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
> Boolean.TRUE);
> URI uri;
> File file = new File(schemaURL);
> if (file.isFile())
> {
> uri = URI.createFileURI(file.getCanonicalFile().toString());
> }
> else
> {
> uri = URI.createURI(schemaURL);
> }
> XSDResourceImpl xsdSchemaResource = (XSDResourceImpl)
> resourceSet.getResource(uri, true);
> for (Iterator resources = resourceSet.getResources().iterator();
> resources.hasNext(); /* no-op */)
> {
> Resource resource = (Resource) resources.next();
> if (resource instanceof XSDResourceImpl)
> {
> XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
> returnSchema = xsdResource.getSchema();
> return returnSchema;
> }
> }
> System.err.println("loadSchemaUsingResourceSet(" + schemaURL +
> ") did not contain any schemas!");
> return null;
> }
> }
>
>
> Thanks again !!
>
>
>
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595850 is a reply to message #62002] Wed, 22 June 2005 08:43 Go to previous message
Eclipse UserFriend
Originally posted by: ediouf.genigraph.fr

Hi Ed,
I'm using EMF/XSD 2.1.0, here is what i have download two months ago:
xsd-SDK-I200504070700.zip
Perhaps it was not stable when i was download it.

and Eclipse 3.0.1

About this instruction :
String annotString = annotation.createAnnotation(elementRoot.getType());

elementRoot is the root XSDElementDeclaration of the 1st schema

We have another model where we define many others classes we use in the
parser; that's why i have posted the main classe of the parser, it would
be very huge to post all classes.

i can get element defined as ref like this:
<xsd:element ref="cbc:Postbox" minOccurs="0" maxOccurs="1">
where "Postbox" is defined in another schema

but i can't get the type of elemnt defined like this :
<xsd:element name="ID" type="udt:IdentifierType" minOccurs="0"
maxOccurs="1">
where "IdentifierType" is defined in another schema.
The value of the type in this case is null!

What is wrong!
I hope my question is more understandable.

Thank you a lot for your help!
Re: my element is declared in schema A and its type in schema B, how to get its type [message #595856 is a reply to message #62025] Wed, 22 June 2005 13:57 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060300000101020803080501
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Elhadji,

If I try the schemas you've provided with XSDMainExample (renamed from
XSDMainTest in older drivers) it seems to work fine right now. I.e., I
add this code within the loadAndPrint method:

XSDSchema xsdSchema = xsdResource.getSchema();

XSDComplexTypeDefinition indivduType =
xsdSchema.resolveComplexTypeDefinition("IndividuType");
if (indivduType.getContainer() != null)
{
XSDElementDeclaration xsdElementDeclaration =
(XSDElementDeclaration)((XSDParticle)((XSDModelGroup)indivdu Type.getComplexType().getContent()).getContents().get(2)).ge tContent();
System.err.println("#1#" +
xsdElementDeclaration.getTypeDefinition());
}

XSDElementDeclaration adresseElement =
xsdSchema.resolveElementDeclaration("Adresse");
if (adresseElement.getContainer() != null)
{
System.err.println("#2#" + adresseElement.getTypeDefinition());
}

And that produces this result:

#1#org.eclipse.xsd.impl.XSDComplexTypeDefinitionImpl@3f9ff1e3
(element: [xs:complexType: null]) (name: LigneAdresseType,
targetNamespace: ns:Adresse) (derivationMethod: restriction, final:
[], abstract: <unset>, contentTypeCategory: simple,
prohibitedSubstitutions: [], lexicalFinal: null, block: null, mixed:
<unset>)
#2#org.eclipse.xsd.impl.XSDComplexTypeDefinitionImpl@3f9ff1e3
(element: [xs:complexType: null]) (name: LigneAdresseType,
targetNamespace: ns:Adresse) (derivationMethod: restriction, final:
[], abstract: <unset>, contentTypeCategory: simple,
prohibitedSubstitutions: [], lexicalFinal: null, block: null, mixed:
<unset>)

So both Adresse elements have a non-null type.

Without the ability to reproduce your problem, I'm at a loss what to
suggest. It's possible that 99227
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=99227> fixed the problem,
so trying the latest build might be good.


elhadji wrote:

> Hi Ed,
> I'm using EMF/XSD 2.1.0, here is what i have download two months ago:
> xsd-SDK-I200504070700.zip Perhaps it was not stable when i was
> download it.
>
> and Eclipse 3.0.1
>
> About this instruction :
> String annotString = annotation.createAnnotation(elementRoot.getType());
>
> elementRoot is the root XSDElementDeclaration of the 1st schema
>
> We have another model where we define many others classes we use in
> the parser; that's why i have posted the main classe of the parser, it
> would be very huge to post all classes.
>
> i can get element defined as ref like this:
> <xsd:element ref="cbc:Postbox" minOccurs="0" maxOccurs="1">
> where "Postbox" is defined in another schema
>
> but i can't get the type of elemnt defined like this :
> <xsd:element name="ID" type="udt:IdentifierType" minOccurs="0"
> maxOccurs="1">
> where "IdentifierType" is defined in another schema.
> The value of the type in this case is null!
>
> What is wrong!
> I hope my question is more understandable.
>
> Thank you a lot for your help!
>
>
>
>
>


--------------060300000101020803080501
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Elhadji,<br>
<br>
If I try the schemas you've provided with XSDMainExample (renamed from
XSDMainTest in older drivers) it seems to work fine right now.
Previous Topic:my element is declared in schema A and its type in schema B, how to get its type
Next Topic:ComplexType: Obtain elements of a sequence
Goto Forum:
  


Current Time: Wed Nov 26 19:12:59 GMT 2014

Powered by FUDForum. Page generated in 0.02623 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software