use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-common by Talend.
the class MetadataRepository method visitSimpleType.
@Override
public void visitSimpleType(XSDSimpleTypeDefinition type) {
String typeName = type.getName();
TypeMetadata typeMetadata = getNonInstantiableType(targetNamespace, typeName);
if (typeMetadata == null) {
typeMetadata = new SimpleTypeMetadata(targetNamespace, typeName);
}
List<TypeMetadata> superTypes = new LinkedList<TypeMetadata>();
if (typeName == null) {
// Anonymous simple type (expects this is a restriction of a simple type or fails).
XSDSimpleTypeDefinition baseTypeDefinition = type.getBaseTypeDefinition();
if (baseTypeDefinition != null) {
typeName = baseTypeDefinition.getName();
} else {
throw new NotImplementedException("Support for " + type);
}
} else {
// Simple type might inherit from other simple types (i.e. UUID from string).
XSDSimpleTypeDefinition baseType = type.getBaseTypeDefinition();
if (baseType != null && baseType.getName() != null) {
superTypes.add(new SoftTypeRef(this, baseType.getTargetNamespace(), baseType.getName(), false));
EList<XSDConstrainingFacet> facets = type.getFacetContents();
for (XSDConstrainingFacet currentFacet : facets) {
if (currentFacet instanceof XSDMaxLengthFacet) {
typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getValue()));
} else if (currentFacet instanceof XSDLengthFacet) {
typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
} else if (currentFacet instanceof XSDTotalDigitsFacet) {
// this is the totalDigits
typeMetadata.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getValue()));
} else if (currentFacet instanceof XSDFractionDigitsFacet) {
// this is the fractionDigits
typeMetadata.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getValue()));
} else if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Ignore simple type facet on type '" + typeName + "': " + currentFacet);
}
}
}
}
if (getNonInstantiableType(targetNamespace, typeName) == null) {
for (TypeMetadata superType : superTypes) {
typeMetadata.addSuperType(superType);
}
addTypeMetadata(typeMetadata);
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class CustomTypeSorter method getCurSelectedCustomBaseType.
private XSDSimpleTypeDefinition getCurSelectedCustomBaseType() {
IStructuredSelection selection = (IStructuredSelection) comboCustomTypes.getSelection();
if (selection == null || selection.isEmpty()) {
return null;
}
XSDSimpleTypeDefinition curSelectedCustomBaseType = xsdSimpleType.getSchema().resolveSimpleTypeDefinition(xsdSimpleType.getSchema().getSchemaForSchemaNamespace(), (String) selection.getFirstElement());
if (!xsdSimpleType.getSchema().getTypeDefinitions().contains(curSelectedCustomBaseType)) {
return xsdSimpleType.getSchema().resolveSimpleTypeDefinition(xsdSimpleType.getSchema().getSchemaForSchemaNamespace(), // $NON-NLS-1$
"string");
}
return curSelectedCustomBaseType;
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class ComplexTypeInputDialog method modifyText.
public void modifyText(ModifyEvent e) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
// $NON-NLS-1$
conceptPanel.setMessage("");
String type = conceptPanel.getText();
if (// $NON-NLS-1$
Pattern.compile("^\\s+\\w+\\s*").matcher(type).matches() || type.trim().replaceAll("\\s", "").length() != type.trim().length()) {
// $NON-NLS-1$//$NON-NLS-2$
conceptPanel.setMessage(Messages._NameWithEmptyCharacters);
getButton(IDialogConstants.OK_ID).setEnabled(false);
return;
}
type = type.trim();
if (!XSDUtil.isValidatedXSDName(type)) {
conceptPanel.setMessage(Messages.InvalidName_Message);
getButton(IDialogConstants.OK_ID).setEnabled(false);
return;
}
for (XSDTypeDefinition specType : xsdSchema.getTypeDefinitions()) {
String typeToCompare = specType.getName();
// $NON-NLS-1$
int delimiter = type.indexOf(" : ");
if (delimiter != -1) {
type = type.substring(0, delimiter);
}
if (typeToCompare.equals(type)) {
if (caller instanceof XSDNewComplexTypeDefinition) {
conceptPanel.setMessage(Messages._SameTypeNameExists);
getButton(IDialogConstants.OK_ID).setEnabled(false);
} else if (caller instanceof XSDChangeToComplexTypeAction && specType instanceof XSDSimpleTypeDefinition) {
conceptPanel.setMessage(Messages._SameTypeNameExists);
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
break;
}
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class MatchRuleSelectionFilter method check.
public FilterResult check(Object obj) {
if (obj instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) obj;
int maxOccurs = particle.getMaxOccurs();
if (maxOccurs > 1 || maxOccurs == -1) {
return FilterResult.DISABLE;
}
XSDTerm term = particle.getTerm();
if (term instanceof XSDElementDeclaration) {
XSDElementDeclaration element = ((XSDElementDeclaration) term);
XSDTypeDefinition type = element.getType();
if (type instanceof XSDSimpleTypeDefinition) {
return FilterResult.ENABLE;
}
}
}
return FilterResult.DISABLE;
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class TreeExpandHelper method getName.
private String getName(Object objA) {
if (objA instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) objA;
return decl.getName();
}
if (objA instanceof XSDModelGroup) {
XSDModelGroup goup = (XSDModelGroup) objA;
XSDParticle particle = (XSDParticle) goup.getContainer();
XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) particle.getContainer();
String name = complexTypeDefinition.getName();
return name;
}
if (objA instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition goupDef = (XSDModelGroupDefinition) objA;
return goupDef.getName();
}
if (objA instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) objA;
if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
return decl.getName();
}
}
if (objA instanceof XSDAnnotation) {
return null;
}
if (objA instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition constraint = (XSDIdentityConstraintDefinition) objA;
return constraint.getName();
}
if (objA instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleDefine = (XSDSimpleTypeDefinition) objA;
return simpleDefine.getName();
}
if (objA instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complexDefine = (XSDComplexTypeDefinition) objA;
return complexDefine.getName();
}
return null;
}
Aggregations