Search in sources :

Example 6 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project tmdm-studio-se by Talend.

the class UtilMockTest method testFindOutAllSonElements.

@Test
public void testFindOutAllSonElements() {
    XSDFactory factory = XSDFactory.eINSTANCE;
    Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String[] targetNameSpaces = { "http://www.w3.org/2001/XMLSchema", "", "" };
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String[] names = { "p1", "p2", "p3" };
    XSDTypeDefinition[] types = { factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
    XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
    xsdElementDeclaration.setName(names[0]);
    xsdElementDeclaration.setTargetNamespace(targetNameSpaces[0]);
    XSDComplexTypeDefinition xsdComplexTypeDef = factory.createXSDComplexTypeDefinition();
    xsdElementDeclaration.setAnonymousTypeDefinition(xsdComplexTypeDef);
    XSDParticle typeParticle = factory.createXSDParticle();
    xsdComplexTypeDef.setContent(typeParticle);
    XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
    for (int i = 0; i < names.length; i++) {
        XSDElementDeclaration xsdEleDec = factory.createXSDElementDeclaration();
        xsdEleDec.setName(names[i]);
        xsdEleDec.setTargetNamespace(targetNameSpaces[i]);
        if (i == 0) {
            xsdEleDec.setTypeDefinition(xsdComplexTypeDef);
        } else {
            xsdEleDec.setTypeDefinition(types[i]);
        }
        XSDParticle xsdParticle = factory.createXSDParticle();
        xsdParticle.setContent(xsdEleDec);
        xsdModelGroup.getContents().add(xsdParticle);
    }
    typeParticle.setContent(xsdModelGroup);
    PowerMockito.mockStatic(Util.class);
    try {
        // $NON-NLS-1$
        String methodToExecute = "findOutAllSonElements";
        PowerMockito.when(Util.class, methodToExecute, any(XSDElementDeclaration.class), anySet()).thenCallRealMethod();
        List<XSDElementDeclaration> allson = Whitebox.invokeMethod(Util.class, methodToExecute, xsdElementDeclaration, complexTypes);
        assertNotNull(allson);
        assertTrue(allson.size() == 2);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method openOnGlobalReference.

/**
 * Method openOnGlobalReference. The comp argument is a resolved xsd schema
 * object from another file. This is created and called from another schema
 * model to allow F3 navigation to open a new editor and choose the referenced
 * object within that editor context
 *
 * @param comp
 */
public void openOnGlobalReference(XSDConcreteComponent comp) {
    XSDConcreteComponent namedComponent = openOnSelectionHelper.openOnGlobalReference(comp);
    if (namedComponent == null) {
        namedComponent = getXSDSchema();
    }
    XSDBaseAdapter adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(namedComponent);
    getSelectionManager().setSelection(new StructuredSelection(adapter));
    IAction action = getActionRegistry().getAction(SetInputToGraphView.ID);
    if (action != null) {
        action.run();
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) IAction(org.eclipse.jface.action.IAction) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)

Example 8 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class XSDHyperlinkDetector method getTargetXSDComponent.

/**
 * Finds the XSD component for the given node.
 *
 * @param xsdSchema cannot be null
 * @param node cannot be null
 * @return XSDConcreteComponent
 */
private XSDConcreteComponent getTargetXSDComponent(XSDSchema xsdSchema, IDOMNode node) {
    XSDConcreteComponent xsdComponent = xsdSchema.getCorrespondingComponent(node);
    String attributeName = null;
    if (node instanceof Attr) {
        Attr attribute = (Attr) node;
        attributeName = attribute != null ? attribute.getName() : null;
    }
    XSDHyperlinkTargetLocator xsdHyperlinkTargetLocator = new XSDHyperlinkTargetLocator();
    XSDConcreteComponent component = xsdHyperlinkTargetLocator.locate(xsdComponent, attributeName);
    return component;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Attr(org.w3c.dom.Attr)

Example 9 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class XSDSubstitutionGroupEditManager method modifyComponentReference.

public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDElementDeclaration concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adapter = (Adapter) referencingObject;
        if (adapter.getTarget() instanceof XSDElementDeclaration) {
            concreteComponent = (XSDElementDeclaration) adapter.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDElementDeclaration) referencingObject;
    }
    if (concreteComponent != null) {
        if (component.isNew()) {
            XSDElementDeclaration elementDec = null;
            if (component.getMetaName() == IXSDSearchConstants.ELEMENT_META_NAME) {
                AddXSDElementCommand command = new AddXSDElementCommand(Messages._UI_ACTION_ADD_ELEMENT, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                elementDec = (XSDElementDeclaration) command.getAddedComponent();
            }
            if (elementDec != null) {
                Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, elementDec.getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
                command.execute();
            }
        } else {
            Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, ((XSDElementDeclaration) component.getObject()).getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
            command.execute();
        }
        XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
    }
}
Also used : AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) Command(org.eclipse.gef.commands.Command) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Adapter(org.eclipse.emf.common.notify.Adapter)

Example 10 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.

the class XSDTypeReferenceEditManager method modifyComponentReference.

public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDConcreteComponent concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adpater = (Adapter) referencingObject;
        if (adpater.getTarget() instanceof XSDConcreteComponent) {
            concreteComponent = (XSDConcreteComponent) adpater.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDConcreteComponent) referencingObject;
    }
    if (concreteComponent != null) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            if (// This means we set to anonymous type
            component.getName() == null && concreteComponent instanceof XSDElementDeclaration) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) concreteComponent;
                // with the proper undo descriptions
                if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                    XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
                    elementDeclaration.setAnonymousTypeDefinition(complexType);
                } else {
                    XSDSimpleTypeDefinition simpleType = factory.createXSDSimpleTypeDefinition();
                    simpleType.setBaseTypeDefinition(// $NON-NLS-1$
                    elementDeclaration.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
                    elementDeclaration.setAnonymousTypeDefinition(simpleType);
                }
                // TODO use external literal string
                elementDeclaration.getElement().removeAttribute("type");
            } else if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedComplexType();
            } else {
                AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedSimpleType();
            }
            if (td != null) {
                Command command = new UpdateTypeReferenceCommand(concreteComponent, td);
                command.setLabel(Messages._UI_ACTION_SET_TYPE);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new UpdateTypeReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.setLabel(Messages._UI_ACTION_SET_TYPE);
            command.execute();
        }
    }
}
Also used : AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) UpdateTypeReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand) XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateTypeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) UpdateTypeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand) UpdateTypeReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand) Command(org.eclipse.gef.commands.Command) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)88 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)30 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)18 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)17 Adapter (org.eclipse.emf.common.notify.Adapter)15 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDParticle (org.eclipse.xsd.XSDParticle)13 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)11 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)11 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)11 List (java.util.List)10 Element (org.w3c.dom.Element)10 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)9 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)9