Search in sources :

Example 46 with XSDAnnotation

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();
}
Also used : List(java.util.List) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 47 with XSDAnnotation

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);
}
Also used : XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 48 with 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;
}
Also used : ImageOverlayDescriptor(org.eclipse.wst.xsd.ui.internal.adt.design.ImageOverlayDescriptor) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) Image(org.eclipse.swt.graphics.Image)

Example 49 with XSDAnnotation

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();
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 50 with XSDAnnotation

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);
    }
}
Also used : Locale(java.util.Locale) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaAnnotationProcessorState(org.talend.mdm.commmon.metadata.annotation.XmlSchemaAnnotationProcessorState) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) NotImplementedException(org.apache.commons.lang.NotImplementedException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XmlSchemaAnnotationProcessor(org.talend.mdm.commmon.metadata.annotation.XmlSchemaAnnotationProcessor) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Aggregations

XSDAnnotation (org.eclipse.xsd.XSDAnnotation)55 Element (org.w3c.dom.Element)33 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)28 XSDParticle (org.eclipse.xsd.XSDParticle)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)20 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)17 ArrayList (java.util.ArrayList)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDTerm (org.eclipse.xsd.XSDTerm)16 TreePath (org.eclipse.jface.viewers.TreePath)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDComponent (org.eclipse.xsd.XSDComponent)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)10 EList (org.eclipse.emf.common.util.EList)9 XSDSchema (org.eclipse.xsd.XSDSchema)8 Iterator (java.util.Iterator)7