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);
}
}
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();
}
}
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;
}
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());
}
}
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();
}
}
}
Aggregations