use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGlobalCommand method run.
public void run() {
XSDConcreteComponent model = getModelObject();
XSDConcreteComponent parent = model.getContainer();
XSDTypeDefinition globalTypeDef = null;
if (model instanceof XSDComplexTypeDefinition) {
if (parent instanceof XSDElementDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDComplexTypeDefinition) model.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
}
} else if (model instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) model;
if (parent instanceof XSDElementDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
formatChild(globalTypeDef.getElement());
} else if (parent instanceof XSDAttributeDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDAttributeDeclaration) parent).setTypeDefinition((XSDSimpleTypeDefinition) globalTypeDef);
}
}
formatChild(globalTypeDef.getElement());
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypsGlobalEnablementTester method canEnable.
protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
if (selectedObject == null) {
return false;
}
XSDSchema selectedComponentSchema = null;
boolean enable = false;
selectedComponentSchema = selectedObject.getSchema();
if (selectedComponentSchema != null && selectedComponentSchema == schema) {
enable = true;
}
if (enable && selectedObject instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) selectedObject;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
return true;
}
} else if (enable && selectedObject instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) selectedObject;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
return true;
} else if (parent instanceof XSDAttributeDeclaration) {
return true;
}
}
return false;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGobalHandler method doExecute.
public Object doExecute(ISelection selection, XSDSchema schema) {
if (selection != null) {
Object selectedObject = ((StructuredSelection) selection).getFirstElement();
if (selectedObject instanceof XSDBaseAdapter) {
selectedObject = ((XSDBaseAdapter) selectedObject).getTarget();
}
XSDConcreteComponent concreteComp = null;
if (selectedObject instanceof Node) {
Node node = (Node) selectedObject;
concreteComp = schema.getCorrespondingComponent(node);
} else if (selectedObject instanceof XSDConcreteComponent) {
concreteComp = ((XSDConcreteComponent) selectedObject);
}
if (concreteComp != null) {
if (concreteComp instanceof XSDComplexTypeDefinition) {
isComplexType = true;
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) concreteComp;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
parentName = ((XSDElementDeclaration) parent).getName();
run(selection, schema, typeDef);
} else if (concreteComp instanceof XSDSimpleTypeDefinition) {
isComplexType = false;
XSDSimpleTypeDefinition simpleTypeDef = (XSDSimpleTypeDefinition) concreteComp;
XSDConcreteComponent parentComp = simpleTypeDef.getContainer();
if (parentComp instanceof XSDElementDeclaration) {
parentName = ((XSDElementDeclaration) parent).getName();
} else if (parent instanceof XSDAttributeDeclaration) {
parentName = ((XSDAttributeDeclaration) parent).getName();
}
run(selection, schema, simpleTypeDef);
}
}
}
}
return null;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-common by Talend.
the class MetadataRepository method createFieldMetadata.
// TODO Refactor!
private FieldMetadata createFieldMetadata(XSDElementDeclaration element, ComplexTypeMetadata containingType, int minOccurs, int maxOccurs) {
String fieldName = element.getName();
if (maxOccurs > 0 && minOccurs > maxOccurs) {
// Eclipse XSD does not check this
throw new IllegalArgumentException("Can not parse information on field '" + element.getQName() + "' of type '" + containingType + "' (maxOccurs > minOccurs)");
}
boolean isMany = maxOccurs == -1 || maxOccurs > 1;
XmlSchemaAnnotationProcessorState state = new XmlSchemaAnnotationProcessorState();
try {
XSDAnnotation annotation = element.getAnnotation();
for (XmlSchemaAnnotationProcessor processor : XML_ANNOTATIONS_PROCESSORS) {
processor.process(this, containingType, annotation, state);
}
} catch (Exception e) {
throw new RuntimeException("Annotation processing exception while parsing info for field '" + fieldName + "' in type '" + containingType.getName() + "'", e);
}
boolean isMandatory = minOccurs > 0;
boolean isContained = false;
boolean isReference = state.isReference();
boolean fkIntegrity = state.isFkIntegrity();
boolean fkIntegrityOverride = state.isFkIntegrityOverride();
List<FieldMetadata> foreignKeyInfo = state.getForeignKeyInfo();
String foreignKeyInfoFormat = state.getForeignKeyInfoFormat();
TypeMetadata fieldType = state.getFieldType();
FieldMetadata referencedField = state.getReferencedField();
TypeMetadata referencedType = state.getReferencedType();
List<String> hideUsers = state.getHide();
List<String> allowWriteUsers = state.getAllowWrite();
List<String> workflowAccessRights = state.getWorkflowAccessRights();
String visibilityRule = state.getVisibilityRule();
XSDTypeDefinition schemaType = element.getType();
if (schemaType instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleSchemaType = (XSDSimpleTypeDefinition) schemaType;
XSDSimpleTypeDefinition content = simpleSchemaType.getBaseTypeDefinition();
if (schemaType.getQName() != null) {
fieldType = new SoftTypeRef(this, schemaType.getTargetNamespace(), schemaType.getName(), false);
} else {
// Null QNames may happen for anonymous types extending other types.
fieldType = new SimpleTypeMetadata(targetNamespace, ANONYMOUS_PREFIX + String.valueOf(anonymousCounter++));
if (content != null) {
fieldType.addSuperType(new SoftTypeRef(this, content.getTargetNamespace(), content.getName(), false));
}
}
setFieldData(simpleSchemaType, fieldType);
fieldType.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
fieldType.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
fieldType.setData(XSD_DOM_ELEMENT, element.getElement());
fieldType.setData(MIN_OCCURS, minOccurs);
fieldType.setData(MAX_OCCURS, maxOccurs);
if (isReference) {
ReferenceFieldMetadata referenceField = new ReferenceFieldMetadata(containingType, false, isMany, isMandatory, fieldName, (ComplexTypeMetadata) referencedType, referencedField, foreignKeyInfo, foreignKeyInfoFormat, fkIntegrity, fkIntegrityOverride, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, state.getForeignKeyFilter(), visibilityRule);
referenceField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
referenceField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
referenceField.setData(XSD_ELEMENT, element);
referenceField.setData(XSD_DOM_ELEMENT, element.getElement());
referenceField.setData(MIN_OCCURS, minOccurs);
referenceField.setData(MAX_OCCURS, maxOccurs);
setLocalizedNames(referenceField, state.getLocaleToLabel());
setLocalizedDescriptions(referenceField, state.getLocaleToDescription());
setDefaultValueRule(referenceField, state.getDefaultValueRule());
setFieldData(simpleSchemaType, referenceField);
return referenceField;
}
if (content != null) {
if (content.getFacets().size() > 0) {
boolean isEnumeration = false;
for (int i = 0; i < content.getFacets().size(); i++) {
XSDConstrainingFacet item = content.getFacets().get(i);
if (item instanceof XSDEnumerationFacet) {
isEnumeration = true;
}
}
if (isEnumeration) {
EnumerationFieldMetadata enumField = new EnumerationFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
enumField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
enumField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
enumField.setData(XSD_ELEMENT, element);
enumField.setData(XSD_DOM_ELEMENT, element.getElement());
enumField.setData(MIN_OCCURS, minOccurs);
enumField.setData(MAX_OCCURS, maxOccurs);
setLocalizedNames(enumField, state.getLocaleToLabel());
setLocalizedDescriptions(enumField, state.getLocaleToDescription());
setDefaultValueRule(enumField, state.getDefaultValueRule());
setFieldData(simpleSchemaType, enumField);
return enumField;
} else {
FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
field.setData(XSD_ELEMENT, element);
field.setData(XSD_DOM_ELEMENT, element.getElement());
field.setData(MIN_OCCURS, minOccurs);
field.setData(MAX_OCCURS, maxOccurs);
setLocalizedNames(field, state.getLocaleToLabel());
setLocalizedDescriptions(field, state.getLocaleToDescription());
setDefaultValueRule(field, state.getDefaultValueRule());
setFieldData(simpleSchemaType, field);
return field;
}
} else {
FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
field.setData(XSD_ELEMENT, element);
field.setData(XSD_DOM_ELEMENT, element.getElement());
field.setData(MIN_OCCURS, minOccurs);
field.setData(MAX_OCCURS, maxOccurs);
setLocalizedNames(field, state.getLocaleToLabel());
setLocalizedDescriptions(field, state.getLocaleToDescription());
setDefaultValueRule(field, state.getDefaultValueRule());
setFieldData(simpleSchemaType, field);
return field;
}
}
}
if (fieldType == null) {
String qName = element.getType() == null ? null : element.getType().getQName();
if (qName != null) {
TypeMetadata metadata = getType(element.getType().getTargetNamespace(), element.getType().getName());
if (metadata != null) {
fieldType = new SoftTypeRef(this, targetNamespace, schemaType.getName(), false);
isContained = true;
} else {
if (schemaType instanceof XSDComplexTypeDefinition) {
fieldType = new SoftTypeRef(this, schemaType.getTargetNamespace(), schemaType.getName(), false);
isContained = true;
} else {
throw new NotImplementedException("Support for '" + schemaType.getClass() + "'.");
}
}
} else {
// Ref & anonymous complex type
isContained = true;
XSDElementDeclaration refName = element.getResolvedElementDeclaration();
if (schemaType != null) {
fieldType = new ComplexTypeMetadataImpl(targetNamespace, ANONYMOUS_PREFIX + String.valueOf(anonymousCounter++), false);
isContained = true;
} else if (refName != null) {
// Reference being an element, consider references as references to entity type.
fieldType = new SoftTypeRef(this, refName.getTargetNamespace(), refName.getName(), true);
} else {
throw new NotImplementedException();
}
}
}
if (isContained) {
ContainedTypeFieldMetadata containedField = new ContainedTypeFieldMetadata(containingType, isMany, isMandatory, fieldName, (ComplexTypeMetadata) fieldType, isReference, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
containedField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
containedField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
containedField.setData(XSD_ELEMENT, element);
containedField.setData(XSD_DOM_ELEMENT, element.getElement());
containedField.setData(MIN_OCCURS, minOccurs);
containedField.setData(MAX_OCCURS, maxOccurs);
if (fieldType.getName().startsWith(ANONYMOUS_PREFIX)) {
currentTypeStack.push((ComplexTypeMetadata) containedField.getType());
{
XmlSchemaWalker.walk(schemaType, this);
}
currentTypeStack.pop();
}
setLocalizedNames(containedField, state.getLocaleToLabel());
setLocalizedDescriptions(containedField, state.getLocaleToDescription());
return containedField;
} else {
FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
field.setData(XSD_ELEMENT, element);
field.setData(XSD_DOM_ELEMENT, element.getElement());
field.setData(MIN_OCCURS, minOccurs);
field.setData(MAX_OCCURS, maxOccurs);
setLocalizedNames(field, state.getLocaleToLabel());
setLocalizedDescriptions(field, state.getLocaleToDescription());
return field;
}
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class ComplexTypeConfigComposite method fillCandidatsInComboExtends.
private void fillCandidatsInComboExtends() {
ISelection oldSection = comboExtends.getSelection();
List<Object> allExtends = new ArrayList<Object>();
for (XSDComplexTypeDefinition eachComplexType : Util.getComplexTypes(complexType.getSchema())) {
if (eachComplexType.equals(complexType) || Util.isAllComplexType(eachComplexType))
continue;
if (Util.getParentTypes(eachComplexType).contains(complexType))
continue;
if (Util.isSequenceComplexType(eachComplexType) && !radGroupSequence.getSelection())
continue;
if (Util.isChoiceComplexType(eachComplexType) && !radGroupChoice.getSelection())
continue;
allExtends.add(eachComplexType);
}
// $NON-NLS-1$
allExtends.add(0, "");
comboExtends.setInput(allExtends);
comboExtends.setSelection(oldSection);
}
Aggregations