use of org.eclipse.xsd.XSDAnnotation in project webtools.sourceediting by eclipse.
the class AddExtensionElementCommand method undo.
public void undo() {
super.undo();
XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
xsdAnnotation.getElement().removeChild(appInfo);
List appInfos = xsdAnnotation.getApplicationInformation();
appInfos.remove(appInfo);
xsdAnnotation.updateElement();
}
use of org.eclipse.xsd.XSDAnnotation in project webtools.sourceediting by eclipse.
the class AddExtensionElementCommand method addAnnotationSet.
public void addAnnotationSet(XSDSchema xsdSchema, SpecificationForExtensionsSchema spec) {
XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, true);
addAnnotationSet(spec, xsdAnnotation);
}
use of org.eclipse.xsd.XSDAnnotation in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getUpdatedImage.
public static Image getUpdatedImage(XSDConcreteComponent input, Image baseImage, boolean isReadOnly) {
XSDAnnotation xsdAnnotation = getInputXSDAnnotation(input, false);
if (xsdAnnotation != null) {
if (xsdAnnotation.getApplicationInformation().size() > 0) {
// Will use the class name appended by the read only state as the name of the image.
// There is a disabled and an enabled version of each baseImage, so we can't simply
// use the component name as the name of the image
String imageName = input.getClass().getName() + isReadOnly;
Image newImage = XSDEditorPlugin.getDefault().getImageRegistry().get(imageName);
if (newImage == null) {
ImageOverlayDescriptor ovr = new ImageOverlayDescriptor(baseImage, isReadOnly);
newImage = ovr.getImage();
XSDEditorPlugin.getDefault().getImageRegistry().put(imageName, newImage);
}
return newImage;
}
}
return baseImage;
}
use of org.eclipse.xsd.XSDAnnotation in project webtools.sourceediting by eclipse.
the class XSDExtensionTreeContentProvider method getElements.
public Object[] getElements(Object inputElement) {
if (inputElement instanceof XSDConcreteComponent) {
XSDConcreteComponent component = (XSDConcreteComponent) inputElement;
List elementsAndAttributes = new ArrayList();
XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
if (xsdAnnotation != null) {
// Added this if statement
if (xsdAnnotation.getSchema() == component.getSchema()) {
List appInfoList = xsdAnnotation.getApplicationInformation();
Element appInfoElement = null;
if (appInfoList.size() > 0) {
appInfoElement = (Element) appInfoList.get(0);
}
if (appInfoElement != null) {
for (Iterator it = appInfoList.iterator(); it.hasNext(); ) {
Object obj = it.next();
if (obj instanceof Element) {
Element appInfo = (Element) obj;
NodeList nodeList = appInfo.getChildNodes();
int length = nodeList.getLength();
for (int i = 0; i < length; i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
elementsAndAttributes.add(node);
}
}
}
}
/**
* Construct attributes list
*/
NamedNodeMap attributes = appInfoElement.getAttributes();
if (attributes != null) {
// String defaultNamespace =
// (String)component.getSchema().getQNamePrefixToNamespaceMap().get("");
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
Node oneAttribute = attributes.item(i);
if (!isXmlnsAttribute(oneAttribute)) {
String namespace = oneAttribute.getNamespaceURI();
boolean isExtension = true;
if (namespace == null && oneAttribute.getPrefix() == null) {
isExtension = false;
} else if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(namespace)) {
isExtension = true;
}
if (isExtension) {
elementsAndAttributes.add(oneAttribute);
}
}
}
}
}
}
}
return elementsAndAttributes.toArray();
}
return Collections.EMPTY_LIST.toArray();
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-common by Talend.
the class MetadataRepository method visitElement.
@Override
public void visitElement(XSDElementDeclaration element) {
if (currentTypeStack.isEmpty()) {
// "top level" elements means new MDM entity type
String typeName = element.getName();
if (getComplexType(typeName) != null) {
// Don't process twice type
return;
}
// If entity's type is abstract
boolean isAbstract = false;
XSDTypeDefinition typeDefinition = element.getTypeDefinition();
if (typeDefinition != null && typeDefinition instanceof XSDComplexTypeDefinition) {
isAbstract = ((XSDComplexTypeDefinition) typeDefinition).isAbstract();
}
// Id fields
Map<String, XSDXPathDefinition> idFields = new LinkedHashMap<String, XSDXPathDefinition>();
EList<XSDIdentityConstraintDefinition> constraints = element.getIdentityConstraintDefinitions();
for (XSDIdentityConstraintDefinition constraint : constraints) {
EList<XSDXPathDefinition> fields = constraint.getFields();
for (XSDXPathDefinition field : fields) {
idFields.put(field.getValue(), field);
}
}
XmlSchemaAnnotationProcessorState state;
try {
XSDAnnotation annotation = element.getAnnotation();
state = new XmlSchemaAnnotationProcessorState();
for (XmlSchemaAnnotationProcessor processor : XML_ANNOTATIONS_PROCESSORS) {
processor.process(this, null, annotation, state);
}
} catch (Exception e) {
throw new RuntimeException("Annotation processing exception while parsing info for type '" + typeName + "'.", e);
}
// If write is not allowed for everyone, at least add "administration".
if (state.getAllowWrite().isEmpty()) {
state.getAllowWrite().add(ICoreConstants.ADMIN_PERMISSION);
}
ComplexTypeMetadata type = new ComplexTypeMetadataImpl(targetNamespace, typeName, state.getAllowWrite(), state.getDenyCreate(), state.getHide(), state.getDenyPhysicalDelete(), state.getDenyLogicalDelete(), state.getSchematron(), state.getPrimaryKeyInfo(), state.getLookupFields(), true, isAbstract, state.getWorkflowAccessRights());
// Register parsed localized labels
Map<Locale, String> localeToLabel = state.getLocaleToLabel();
for (Map.Entry<Locale, String> entry : localeToLabel.entrySet()) {
type.registerName(entry.getKey(), entry.getValue());
}
// Register parsed localized descriptions
Map<Locale, String> localeToDescription = state.getLocaleToDescription();
for (Map.Entry<Locale, String> entry : localeToDescription.entrySet()) {
type.registerDescription(entry.getKey(), entry.getValue());
}
// Keep line and column of definition
type.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
type.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
type.setData(XSD_ELEMENT, element);
type.setData(XSD_DOM_ELEMENT, element.getElement());
addTypeMetadata(type);
// Keep usage information
entityTypeUsage.get(element.getType()).add(type);
// Walk the fields
currentTypeStack.push(type);
{
XmlSchemaWalker.walk(element.getType(), this);
}
currentTypeStack.pop();
// Super types
XSDElementDeclaration substitutionGroup = element.getSubstitutionGroupAffiliation();
if (substitutionGroup != null && !XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(substitutionGroup.getTargetNamespace()) && !Types.ANY_TYPE.equals(substitutionGroup.getName())) {
if (!substitutionGroup.getResolvedElementDeclaration().equals(element)) {
SoftTypeRef superType = new SoftTypeRef(this, substitutionGroup.getTargetNamespace(), substitutionGroup.getName(), true);
type.addSuperType(superType);
}
}
// Register keys (TMDM-4470).
for (Map.Entry<String, XSDXPathDefinition> unresolvedId : idFields.entrySet()) {
SoftIdFieldRef keyField = new SoftIdFieldRef(this, type.getName(), unresolvedId.getKey());
// Keep line and column of definition
keyField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(unresolvedId.getValue().getElement()));
keyField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(unresolvedId.getValue().getElement()));
keyField.setData(XSD_DOM_ELEMENT, unresolvedId.getValue().getElement());
type.registerKey(keyField);
}
// entity.
if (type.getKeyFields().isEmpty() && type.getSuperTypes().isEmpty()) {
Map<String, TypeMetadata> userEntityTypes = entityTypes.get(getUserNamespace());
if (userEntityTypes != null) {
userEntityTypes.remove(type.getName());
}
}
} else {
// Non "top level" elements means fields for the MDM entity type being parsed
FieldMetadata fieldMetadata;
int minOccurs = ((XSDParticle) element.getContainer()).getMinOccurs();
int maxOccurs = ((XSDParticle) element.getContainer()).getMaxOccurs();
if (element.isElementDeclarationReference() && currentTypeStack.peek().getName().equals(element.getResolvedElementDeclaration().getName())) {
return;
}
if (element.getResolvedElementDeclaration() != null && element.getResolvedElementDeclaration().getTargetNamespace() == null) {
fieldMetadata = createFieldMetadata(element.getResolvedElementDeclaration(), currentTypeStack.peek(), minOccurs, maxOccurs);
} else {
fieldMetadata = createFieldMetadata(element, currentTypeStack.peek(), minOccurs, maxOccurs);
}
currentTypeStack.peek().addField(fieldMetadata);
}
}
Aggregations