use of org.eclipse.xsd.XSDComplexTypeContent in project webtools.sourceediting by eclipse.
the class SetBaseTypeCommand method execute.
public void execute() {
try {
beginRecording(concreteComponent.getElement());
if (concreteComponent instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) concreteComponent;
XSDComplexTypeContent contentType = (baseType instanceof XSDComplexTypeDefinition) ? ((XSDComplexTypeDefinition) baseType).getContentType() : null;
// Complex type simple content
if (baseType instanceof XSDSimpleTypeDefinition || (contentType != null && contentType instanceof XSDSimpleTypeDefinition)) {
if (!(complexType.getContent() instanceof XSDSimpleTypeDefinition)) {
XSDSimpleTypeDefinition simpleContent = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
complexType.setContent(simpleContent);
}
} else // Complex type complex content
if (baseType instanceof XSDComplexTypeDefinition) {
if (!(complexType.getContent() instanceof XSDComplexTypeDefinition)) {
XSDComplexTypeDefinition complexContent = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
complexType.setContent(complexContent.getContent());
}
}
complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
complexType.setBaseTypeDefinition(baseType);
// vb This call should not be needed. The XSD Infoset model should reconcile itself properly.
complexType.updateElement(true);
formatChild(complexType.getElement());
} else if (concreteComponent instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) concreteComponent;
if (baseType instanceof XSDSimpleTypeDefinition) {
XSDVariety variety = simpleType.getVariety();
if (variety.getValue() == XSDVariety.ATOMIC) {
simpleType.setBaseTypeDefinition((XSDSimpleTypeDefinition) baseType);
} else if (variety.getValue() == XSDVariety.UNION) {
simpleType.getMemberTypeDefinitions().add(baseType);
} else if (variety.getValue() == XSDVariety.LIST) {
simpleType.setItemTypeDefinition((XSDSimpleTypeDefinition) baseType);
}
}
}
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDComplexTypeContent in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getModelGroup.
public static XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) {
XSDParticle particle = cType.getComplexType();
if (particle == null || particle.eContainer() != cType)
return null;
Object particleContent = particle.getContent();
XSDModelGroup group = null;
if (particleContent instanceof XSDModelGroupDefinition)
group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup();
else if (particleContent instanceof XSDModelGroup)
group = (XSDModelGroup) particleContent;
if (group == null)
return null;
if (group.getContents().isEmpty() || group.eResource() != cType.eResource()) {
XSDComplexTypeContent content = cType.getContent();
if (content instanceof XSDParticle)
group = (XSDModelGroup) ((XSDParticle) content).getContent();
}
return group;
}
use of org.eclipse.xsd.XSDComplexTypeContent in project tmdm-common by Talend.
the class MetadataRepository method visitComplexType.
@Override
public void visitComplexType(XSDComplexTypeDefinition type) {
String typeName = type.getName();
boolean isNonInstantiableType = currentTypeStack.isEmpty();
if (isNonInstantiableType) {
if (nonInstantiableTypes.get(getUserNamespace()) != null) {
if (nonInstantiableTypes.get(getUserNamespace()).containsKey(typeName)) {
// Ignore another definition of type (already processed).
return;
}
}
// There's no current 'entity' type being parsed, this is a complex type not to be used for entity but
// might be referenced by others entities (for fields, inheritance...).
ComplexTypeMetadata nonInstantiableType = new ComplexTypeMetadataImpl(targetNamespace, typeName, false, type.isAbstract());
// Keep line and column of definition
nonInstantiableType.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(type.getElement()));
nonInstantiableType.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(type.getElement()));
nonInstantiableType.setData(XSD_DOM_ELEMENT, type.getElement());
addTypeMetadata(nonInstantiableType);
currentTypeStack.push(nonInstantiableType);
// If type is used, declare usage
List<ComplexTypeMetadata> usages = entityTypeUsage.get(type);
for (ComplexTypeMetadata usage : usages) {
nonInstantiableType.declareUsage(usage);
}
} else {
// Keep track of the complex type used for entity type (especially for inheritance).
if (typeName != null) {
currentTypeStack.peek().setData(MetadataRepository.COMPLEX_TYPE_NAME, typeName);
}
}
XSDComplexTypeContent particle = type.getContent();
if (particle instanceof XSDParticle) {
XSDParticle currentParticle = (XSDParticle) particle;
if (currentParticle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) currentParticle.getTerm();
EList<XSDParticle> particles = group.getContents();
for (XSDParticle p : particles) {
XSDParticleContent particleContent = p.getContent();
XmlSchemaWalker.walk(particleContent, this);
}
}
} else if (particle != null) {
throw new IllegalArgumentException("Not supported XML Schema particle: " + particle.getClass().getName());
}
// Adds the type information about super types.
XSDTypeDefinition contentModel = type.getBaseTypeDefinition();
if (contentModel != null) {
if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(contentModel.getTargetNamespace()) && !Types.ANY_TYPE.equals(contentModel.getName())) {
SoftTypeRef superType = new SoftTypeRef(this, contentModel.getTargetNamespace(), contentModel.getName(), false);
if (currentTypeStack.peek() instanceof ContainedComplexTypeMetadata) {
superType.declareUsage(currentTypeStack.peek());
}
currentTypeStack.peek().addSuperType(superType);
particle = type.getContent();
if (particle instanceof XSDParticle) {
XSDParticle currentParticle = (XSDParticle) particle;
if (currentParticle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) currentParticle.getTerm();
EList<XSDParticle> particles = group.getContents();
for (XSDParticle p : particles) {
XSDParticleContent particleContent = p.getContent();
XmlSchemaWalker.walk(particleContent, this);
}
}
} else if (particle != null) {
throw new IllegalArgumentException("Not supported XML Schema particle: " + particle.getClass().getName());
}
}
}
if (isNonInstantiableType) {
currentTypeStack.pop();
}
}
use of org.eclipse.xsd.XSDComplexTypeContent in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method addAnnotationForComplexType.
public void addAnnotationForComplexType(XSDComplexTypeDefinition fromType, XSDComplexTypeDefinition toType) {
XSDComplexTypeContent tocomplexType = toType.getContent();
XSDComplexTypeContent fromcomplexType = fromType.getContent();
if (fromcomplexType instanceof XSDParticle) {
XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
EList<XSDParticle> fromlist = frommodelGroup.getContents();
EList<XSDParticle> tolist = tomodelGroup.getContents();
Iterator<XSDParticle> toIt = tolist.iterator();
for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
XSDParticle toel = toIt.next();
XSDTerm totm = toel.getTerm();
XSDTerm fromtm = fromel.getTerm();
if (fromtm instanceof XSDElementDeclaration) {
XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
if (fromannotation != null) {
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
addAnnotion(struc, fromannotation);
if (this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
}
addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
}
}
}
}
}
}
use of org.eclipse.xsd.XSDComplexTypeContent in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method copyElements.
// edit by ymli; fix the bug:0011523: pasty partcles to the element
public void copyElements() {
ArrayList<XSDParticle> particles = WorkbenchClipboard.getWorkbenchClipboard().getParticles();
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDComplexTypeContent content = null;
XSDElementDeclaration element = null;
if (selection.getFirstElement() instanceof XSDElementDeclaration) {
element = (XSDElementDeclaration) selection.getFirstElement();
content = ((XSDComplexTypeDefinition) element.getTypeDefinition()).getContent();
} else if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
content = ((XSDComplexTypeDefinition) selection.getFirstElement()).getContent();
} else if (selection.getFirstElement() instanceof XSDModelGroup) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) ((XSDModelGroup) selection.getFirstElement()).getContainer().getContainer();
content = complexType.getContent();
} else {
if (selection.getFirstElement() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) selection.getFirstElement();
XSDElementDeclaration declar = (XSDElementDeclaration) particle.getTerm();
if (declar.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition typeDefinition = (XSDComplexTypeDefinition) declar.getTypeDefinition();
content = typeDefinition.getContent();
}
}
}
if (content instanceof XSDParticle) {
XSDParticle partile = (XSDParticle) content;
if (partile.getTerm() instanceof XSDModelGroup) {
XSDModelGroup toGroup = ((XSDModelGroup) partile.getTerm());
for (XSDParticle particle : particles) {
// if the is particle with the same name, donot copy it.
if (isExist(toGroup, particle)) {
boolean ifOverwrite = MessageDialog.openConfirm(this.page.getSite().getShell(), Messages.XSDPasteConceptAction_Confirm, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg3, ((XSDElementDeclaration) particle.getTerm()).getName()));
if (ifOverwrite) {
reomveElement(toGroup, particle);
} else {
continue;
}
}
XSDParticle newParticle = (XSDParticle) particle.cloneConcreteComponent(true, false);
if (newParticle.getContent() instanceof XSDElementDeclaration && Util.changeElementTypeToSequence(element, newParticle.getMaxOccurs()) == Status.CANCEL_STATUS) {
break;
}
toGroup.getContents().add(newParticle);
toGroup.updateElement();
if (newParticle.getContent() instanceof XSDElementDeclaration) {
if (((XSDElementDeclaration) newParticle.getContent()).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
addAnnotationForComplexType((XSDComplexTypeDefinition) ((XSDElementDeclaration) particle.getContent()).getTypeDefinition(), (XSDComplexTypeDefinition) ((XSDElementDeclaration) newParticle.getContent()).getTypeDefinition());
}
XSDAnnotationsStructure struc1 = new XSDAnnotationsStructure(newParticle.getTerm());
addAnnotion(struc1, ((XSDElementDeclaration) particle.getTerm()).getAnnotation());
Util.changeElementTypeToSequence((XSDElementDeclaration) newParticle.getContent(), newParticle.getMaxOccurs());
}
}
}
}
}
Aggregations