Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsExtension element
https://www.eclipse.org/forums/index.php/mv/msg/187901/596117/#msg_596117
comeplete element defination of employee as subelement uses extension base.
Please help me to resolve extension base elements
My Requirement is to build schema tree. I am sending you sample schema and
code which I have used (modified for demo purpose).
/*
* Created on Mar 9, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.gxs.ai.ngwb.xsdparser;
/**
* @author tatinip
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class XSDParserNEW {
private boolean validateAndProcess(String xsdFile) throws Exception
{
/*
* This let's us test whether the string exists as a file.
* It not, we try as a URI.
*/
m_error_List = new ArrayList();
m_warning_List = new ArrayList();
URI uri;
if (xsdFile==null ){
//DMParseError parserError = new DMParseError(4,"","Schema file not
specified",0,0);
//m_error_List.add(parserError);
m_warning_List.add("Schema file not specified in Model file " +
m_modelName);
//this.rootNode = null;
return true;
}
File file = new File(xsdFile);
if (!file.exists()){
//DMParseError parserError = new DMParseError(4,"","File Not
Found",0,0);
//m_error_List.add(parserError);
m_warning_List.add("Schema file not Found " + xsdFile);
//this.rootNode = null;
return true;
}
if (file.isFile())
{
uri = URI.createFileURI(file.getCanonicalFile().toString());
}
else
{
uri = URI.createURI(xsdFile);
}
// Create a resource set, create a schema resource, and load the main
schema file into it.
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
Boolean.TRUE);
XSDResourceImpl xsdMainResource =
(XSDResourceImpl)resourceSet.createResource(uri);
xsdMainResource.setURI(uri);
xsdMainResource.load(resourceSet.getLoadOptions());
// Get the first resource, i.e., the main resource and those that have
been included or imported.
Object resource = resourceSet.getResources().get(0);
if (resource instanceof XSDResourceImpl)
{
XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
XSDSchema xsdSchema = xsdResource.getSchema();
xsdSchema.validate();
/*
* Schema file is valid if Diagnostics is empty
*/
if (!xsdSchema.getDiagnostics().isEmpty())
{
for (Iterator i = xsdSchema.getDiagnostics().iterator();
i.hasNext(); )
{
XSDDiagnostic xsdDiagnostic = (XSDDiagnostic)i.next();
String localizedSeverity =
XSDPlugin.INSTANCE.getString("_UI_XSDDiagnosticSeverity_" +
xsdDiagnostic.getSeverity());
//Handle Error
// DMParseError parserError = new
DMParseError(4,"" ,xsdDiagnostic.getMessage(),xsdDiagnostic.getLine(),xsdDiagn ostic.getColumn());
//m_error_List.add(parserError);
}
//this.rootNode = null;
xsdResource.unload();
return false;
}
// If the user not selected root element
set first element as root element
if (m_rootElementName == null ||
m_rootElementName.equalsIgnoreCase("")){
Iterator i = xsdSchema.getContents().iterator();
while(i.hasNext()){
XSDSchemaContent e = (XSDSchemaContent)i.next(); // probable root element
if (e instanceof XSDElementDeclaration){
m_rootElementName = e.getElement().getAttribute("name");
break;
}
}
}
int min = m_minOccurrence;
int max = m_maxOccurrence;
if(elem.getName() != null)
{
xPath = xPath+"/"+elem.getName();
printTree(xPath);
}
m_isRoot = false; // Need to do this after writing the root header,
//because the processing of child elements starts here
// Get the type definition of the Element
XSDTypeDefinition elemTypeDef= elem.getTypeDefinition();
if(elemTypeDef==null && elem.getResolvedElementDeclaration().getValue() ==
null)
{
// For a reference
dumpContentItem(elem.getResolvedElementDeclaration(), level, xPath);
}else if((elemTypeDef instanceof XSDSimpleTypeDefinition) &&
((XSDSimpleTypeDefinition)elem.getTypeDefinition()).getConte nts().isEmpty())
{
// Element doesn't have any children i.e simpleContent but might have
restrictions etc
}
else // The 'type' attribute is another element in the same XSD file
{
/* name of the Complex type must be ignored when an element refers to
* it with the 'type' attribute
*/
if(elemTypeDef instanceof XSDComplexTypeDefinition)
{
if(((XSDComplexTypeDefinition)elemTypeDef).getName()!=null )
m_ignoreCpexTypeDefnName = true;
}
dumpContentItem(elemTypeDef, level, xPath);
}
}
else if (item instanceof XSDComplexTypeDefinition)
{
XSDComplexTypeDefinitionImpl cplex = (XSDComplexTypeDefinitionImpl)item;
int min = m_minOccurrence;
int max = m_maxOccurrence;
if(!m_ignoreCpexTypeDefnName && cplex.getName()!=null)
{
xPath = xPath+"/"+cplex.getName();
}
// Process the attributes
for(Iterator i = cplex.getAttributeContents().iterator(); i.hasNext(); )
{
XSDAttributeGroupContent att_grp = (XSDAttributeGroupContent) i.next();
// For attribute group
if(att_grp instanceof XSDAttributeGroupDefinition)
{
dumpContentItem(((XSDAttributeGroupDefinition)att_grp), level, xPath);
/*for(Iterator j =
((XSDAttributeGroupDefinition)att_grp).getAttributeUses().it erator();
j.hasNext(); )
{
j.next(); // need to take care
//dumpContentItem(((XSDAttributeUse)j.next()).getAttributeDe claration(),level);
}
*/
}else if(att_grp instanceof XSDAttributeUse)
{
setAttributeOccurrences(((XSDAttributeUse)att_grp).getUse()) ;
dumpContentItem(((XSDAttributeUse)att_grp).getAttributeDecla ration(),level,
xPath);
}
else
{
System.out.println("2. UNHANDLED");
}
}
// Process the element content if it is not equal to null
if(cplex.getContent() != null)
{
if(cplex.getContent() instanceof XSDParticle)
{
dumpParticle((XSDParticle)cplex.getContent(), level, xPath);
}
else if(cplex.getContent() instanceof XSDSimpleTypeDefinition)
{
dumpContentItem((XSDSimpleTypeDefinition)cplex.getContent(), level, xPath);
}
else
{
System.out.println("1. UNHANDLED"+ cplex.getContent().toString());
}
}
}
else if (item instanceof XSDSimpleTypeDefinition)
{
XSDSimpleTypeDefinition simple = (XSDSimpleTypeDefinition)item;
int min = m_minOccurrence;
int max = m_maxOccurrence;