use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class MobileComponentImportVariablesAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
if (databaseObject != null) {
if (databaseObject instanceof UIDynamicAction) {
UIDynamicAction dynAction = (UIDynamicAction) databaseObject;
IonBean ionBean = ((UIDynamicAction) dynAction).getIonBean();
if (ionBean != null) {
// Case of CallSequenceAction
if (ionBean.getName().equals("CallSequenceAction")) {
Object value = ionBean.getProperty("requestable").getValue();
if (!value.equals(false)) {
String target = value.toString();
if (!target.isEmpty()) {
try {
String projectName = target.substring(0, target.indexOf('.'));
String sequenceName = target.substring(target.indexOf('.') + 1);
Project p = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
Sequence sequence = p.getSequenceByName(sequenceName);
int size = sequence.numberOfVariables();
for (int i = 0; i < size; i++) {
RequestableVariable variable = (RequestableVariable) sequence.getVariable(i);
if (variable != null) {
String variableName = variable.getName();
if (dynAction.getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
UIControlVariable uiVariable = new UIControlVariable();
uiVariable.setName(variableName);
uiVariable.setComment(variable.getDescription());
uiVariable.setVarSmartType(new MobileSmartSourceType(variable.getDefaultValue().toString()));
dynAction.addUIComponent(uiVariable);
uiVariable.bNew = true;
uiVariable.hasChanged = true;
dynAction.hasChanged = true;
}
}
}
} catch (Exception e) {
}
}
}
} else // Case of InvokeAction
if (ionBean.getName().equals("InvokeAction")) {
UIDynamicInvoke dynInvoke = (UIDynamicInvoke) databaseObject;
UIActionStack stack = dynInvoke.getTargetSharedAction();
if (stack != null) {
for (UIStackVariable variable : stack.getVariables()) {
String variableName = variable.getName();
if (dynAction.getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
UIControlVariable uiVariable = new UIControlVariable();
uiVariable.setName(variableName);
uiVariable.setComment(variable.getComment());
MobileSmartSourceType msst = new MobileSmartSourceType();
msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
msst.setSmartValue(variable.getVariableValue());
uiVariable.setVarSmartType(msst);
dynAction.addUIComponent(uiVariable);
uiVariable.bNew = true;
uiVariable.hasChanged = true;
dynAction.hasChanged = true;
}
}
}
}
if (dynAction.hasChanged) {
IScriptComponent main = dynAction.getMainScriptComponent();
if (main != null) {
if (main instanceof ApplicationComponent) {
((ApplicationComponent) main).markApplicationAsDirty();
}
if (main instanceof PageComponent) {
((PageComponent) main).markPageAsDirty();
}
}
explorerView.reloadTreeObject(treeObject);
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
}
}
} else if (databaseObject instanceof UIUseShared) {
UIUseShared useShared = (UIUseShared) databaseObject;
UISharedComponent sharedComp = useShared.getTargetSharedComponent();
if (sharedComp != null) {
for (UICompVariable variable : sharedComp.getVariables()) {
String variableName = variable.getName();
if (useShared.getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
UIControlVariable uiVariable = new UIControlVariable();
uiVariable.setName(variableName);
uiVariable.setComment(variable.getComment());
MobileSmartSourceType msst = new MobileSmartSourceType();
msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
msst.setSmartValue(variable.getVariableValue());
uiVariable.setVarSmartType(msst);
useShared.addUIComponent(uiVariable);
uiVariable.bNew = true;
uiVariable.hasChanged = true;
useShared.hasChanged = true;
}
}
if (useShared.hasChanged) {
IScriptComponent main = useShared.getMainScriptComponent();
if (main != null) {
if (main instanceof ApplicationComponent) {
((ApplicationComponent) main).markApplicationAsDirty();
}
if (main instanceof PageComponent) {
((PageComponent) main).markPageAsDirty();
}
}
explorerView.reloadTreeObject(treeObject);
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to add variables to action !");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SequenceExecuteSelectedAction method openEditors.
private void openEditors(ProjectExplorerView explorerView, List<Step> steps, Set<SequenceStep> alreadyOpened) {
for (Step step : steps) {
if (step.isEnabled()) {
if (step instanceof SequenceStep) {
SequenceStep sequenceStep = (SequenceStep) step;
String projectName = sequenceStep.getProjectName();
// load project if necessary
if (!step.getSequence().getProject().getName().equals(projectName))
loadProject(explorerView, projectName);
if (alreadyOpened.contains(sequenceStep)) {
// avoid sequence recursion
return;
}
alreadyOpened.add(sequenceStep);
try {
ProjectTreeObject projectTreeObject = (ProjectTreeObject) explorerView.getProjectRootObject(projectName);
Sequence subSequence = projectTreeObject.getObject().getSequenceByName(sequenceStep.getSequenceName());
SequenceTreeObject subSequenceTreeObject = (SequenceTreeObject) explorerView.findTreeObjectByUserObject(subSequence);
// recurse on sequence
openEditors(explorerView, subSequenceTreeObject, alreadyOpened);
} catch (EngineException e) {
e.printStackTrace();
}
} else if (step instanceof TransactionStep) {
TransactionStep transactionStep = (TransactionStep) step;
String projectName = transactionStep.getProjectName();
if (!step.getSequence().getProject().getName().equals(projectName))
// load project if necessary
loadProject(explorerView, projectName);
try {
ProjectTreeObject projectTreeObject = (ProjectTreeObject) explorerView.getProjectRootObject(projectName);
Connector connector = projectTreeObject.getObject().getConnectorByName(transactionStep.getConnectorName());
ConnectorTreeObject connectorTreeObject = (ConnectorTreeObject) explorerView.findTreeObjectByUserObject(connector);
// open connector editor
connectorTreeObject.openConnectorEditor();
} catch (EngineException e) {
e.printStackTrace();
}
} else if (step instanceof StepWithExpressions) {
openEditors(explorerView, ((StepWithExpressions) step).getSteps(), alreadyOpened);
}
}
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SequenceExecuteSelectedAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
openEditors(explorerView, sequenceTreeObject);
Sequence sequence = sequenceTreeObject.getObject();
ProjectTreeObject projectTreeObject = sequenceTreeObject.getProjectTreeObject();
SequenceEditor sequenceEditor = projectTreeObject.getSequenceEditor(sequence);
if (sequenceEditor != null) {
getActivePage().activate(sequenceEditor);
boolean fromStub = action.getId().contains("FromStub");
sequenceEditor.getSequenceEditorPart().getDocument(sequence.getName(), null, fromStub);
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SequenceImportFromXsdAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) ((databaseObject instanceof Sequence) ? databaseObjectTreeObject : databaseObjectTreeObject.getParentDatabaseObjectTreeObject());
Sequence sequence = (databaseObject instanceof Sequence) ? (Sequence) databaseObject : ((StepWithExpressions) databaseObject).getSequence();
FileDialog fileDialog = new FileDialog(shell, SWT.PRIMARY_MODAL | SWT.SAVE);
fileDialog.setText("Import schema file");
fileDialog.setFilterExtensions(new String[] { "*.xsd" });
fileDialog.setFilterNames(new String[] { "Schema files" });
fileDialog.setFilterPath(Engine.PROJECTS_PATH);
String filePath = fileDialog.open();
if (filePath != null) {
filePath = filePath.replaceAll("\\\\", "/");
XmlSchemaCollection collection = new XmlSchemaCollection();
collection.setBaseUri(filePath);
XmlSchema xmlSchema = SchemaUtils.loadSchema(new File(filePath), collection);
SchemaMeta.setCollection(xmlSchema, collection);
SchemaObjectsDialog dlg = new SchemaObjectsDialog(shell, sequence, xmlSchema);
if (dlg.open() == Window.OK) {
if (dlg.result instanceof Throwable) {
throw (Throwable) dlg.result;
} else {
Step step = (Step) dlg.result;
if (step != null) {
if (databaseObject instanceof Sequence) {
sequence.addStep(step);
sequence.hasChanged = true;
} else {
StepWithExpressions swe = (StepWithExpressions) databaseObject;
swe.addStep(step);
swe.hasChanged = true;
}
sequence.hasChanged = true;
// Reload sequence in tree without updating its schema for faster reload
ConvertigoPlugin.logDebug("Reload sequence: start");
explorerView.reloadTreeObject(sequenceTreeObject);
ConvertigoPlugin.logDebug("Reload sequence: end");
// Select target dbo in tree
explorerView.objectSelected(new CompositeEvent(databaseObject));
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import step from xsd!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SchemaManager method makeResponse.
public synchronized Document makeResponse(Document document) {
try {
Element documentElement = document.getDocumentElement();
if (documentElement != null) {
String project = documentElement.getAttribute("project");
String sequence = documentElement.getAttribute("sequence");
String connector = documentElement.getAttribute("connector");
String transaction = documentElement.getAttribute("transaction");
XmlSchema schema = getSchemaForProject(project);
XmlSchemaCollection collection = SchemaMeta.getCollection(schema);
String targetNamespace = schema.getTargetNamespace();
String prefix = collection.getNamespaceContext().getPrefix(targetNamespace);
String requestableName = sequence != null && sequence.length() > 0 ? sequence : connector + "__" + transaction;
String tagname = prefix + ":" + requestableName + "Response";
QName qname = new QName(targetNamespace, requestableName + "Response");
Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(project);
boolean isIncludeResponseElement = true;
if (!"".equals(sequence)) {
try {
Sequence seqObj = p.getSequenceByName(sequence);
isIncludeResponseElement = seqObj.isIncludeResponseElement();
} catch (Exception e) {
}
}
Document responseDoc = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element requestableResponse = responseDoc.createElementNS(targetNamespace, tagname);
if (isIncludeResponseElement) {
Node renamed = responseDoc.renameNode(responseDoc.importNode(documentElement, true), "", "response");
requestableResponse.appendChild(renamed);
} else {
NodeList children = documentElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
requestableResponse.appendChild(responseDoc.importNode(children.item(i), true));
}
}
final Map<XmlSchemaObject, List<List<XmlSchemaObject>>> map = new LinkedHashMap<XmlSchemaObject, List<List<XmlSchemaObject>>>();
new XmlSchemaWalker(true, true) {
List<XmlSchemaObject> elist = null;
List<XmlSchemaObject> alist = null;
Map<QName, XmlSchemaObject> mso = new HashMap<QName, XmlSchemaObject>();
Map<QName, XmlSchemaObject> mto = new HashMap<QName, XmlSchemaObject>();
public void init(XmlSchema xmlSchema, QName qname, Element element) {
XmlSchemaElement rxe = SchemaMeta.getCollection(xmlSchema).getElementByQName(qname);
if (rxe != null) {
List<List<XmlSchemaObject>> list = new ArrayList<List<XmlSchemaObject>>();
list.add(new ArrayList<XmlSchemaObject>());
list.add(new ArrayList<XmlSchemaObject>());
map.put(rxe, list);
mso.put(qname, rxe);
elist = list.get(0);
alist = list.get(1);
walkElement(xmlSchema, rxe);
/*for (XmlSchemaObject xso: map.keySet()) {
System.out.println(((XmlSchemaElement)xso).getName());
System.out.print("\t[");
for (XmlSchemaObject child: map.get(xso).get(1)) {
System.out.print(((XmlSchemaAttribute)child).getName()+",");
}
System.out.println("]");
for (XmlSchemaObject child: map.get(xso).get(0)) {
System.out.println("\t"+((XmlSchemaElement)child).getName());
}
}*/
makeCompliant(rxe, element);
}
}
protected boolean makeCompliant(XmlSchemaObject xso, Node node) {
String tns = node.getNamespaceURI();
String nodeName = node.getNodeName();
String localName = nodeName.substring(nodeName.indexOf(":") + 1);
String xsoName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getName() : ((XmlSchemaAttribute) xso).getName();
if (xsoName.equals(localName)) {
Document doc = node.getOwnerDocument();
QName xsoQName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getQName() : ((XmlSchemaAttribute) xso).getQName();
boolean elementQualified = SchemaMeta.getSchema(xso).getElementFormDefault().getValue().equals("qualified");
boolean attributeQualified = SchemaMeta.getSchema(xso).getAttributeFormDefault().getValue().equals("qualified");
boolean isQualified = (xsoQName != null && !xsoQName.getNamespaceURI().equals("")) || (xso instanceof XmlSchemaElement ? elementQualified : attributeQualified);
// String targetNamespace = SchemaMeta.getSchema(xso).getTargetNamespace();
// String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(targetNamespace);
String targetNamespace = xsoQName != null && !xsoQName.getNamespaceURI().equals("") ? xsoQName.getNamespaceURI() : SchemaMeta.getSchema(xso).getTargetNamespace();
String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(targetNamespace);
prefix = prefix == null ? (xsoQName != null && !xsoQName.getNamespaceURI().equals("") ? xsoQName.getPrefix() : "") : prefix;
if (isQualified)
node = doc.renameNode(node, targetNamespace, prefix + ":" + localName);
else
node = doc.renameNode(node, "", localName);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
if (element.hasAttributes()) {
NamedNodeMap attributes = element.getAttributes();
List<Node> list = new ArrayList<Node>();
for (int i = 0; i < attributes.getLength(); i++) {
Node attr = attributes.item(i);
String attrNodeName = attr.getNodeName();
boolean found = false;
for (XmlSchemaObject a : map.get(xso).get(1)) {
if (makeCompliant(a, attr)) {
found = true;
break;
}
}
if (!found) {
if (attrNodeName.equals("xsi:type") || attrNodeName.startsWith("xmlns:") || attrNodeName.endsWith(":encodingStyle")) {
list.add(attr);
}
} else {
if (attrNodeName.startsWith("xsi:")) {
attr = doc.renameNode(attr, Constants.URI_2001_SCHEMA_XSI, attrNodeName);
String attrNodeValue = attr.getNodeValue();
int index = attrNodeValue.indexOf(":");
if (index != -1) {
String pref = attrNodeValue.substring(0, index);
if (attributes.getNamedItem("xmlns:" + pref) == null) {
String ns = SchemaMeta.getCollection(xso).getNamespaceContext().getNamespaceURI(pref);
if ("".equals(ns) || ns == null)
ns = SchemaMeta.getSchema(xso).getTargetNamespace();
element.setAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + pref, ns);
}
}
}
if (attrNodeName.startsWith("xmlns:")) {
attr = doc.renameNode(attr, Constants.XMLNS_ATTRIBUTE_NS_URI, attrNodeName);
}
}
}
for (Node attr : list) {
element.removeAttributeNode((Attr) attr);
}
}
if (element.hasChildNodes()) {
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.TEXT_NODE)
continue;
// System.out.println("element: "+children.item(i).getNodeName());
for (XmlSchemaObject e : map.get(xso).get(0)) {
// System.out.println(" test "+((XmlSchemaElement)e).getName());
if (makeCompliant(e, children.item(i))) {
break;
}
}
}
}
}
return true;
} else {
// System.out.println(nodeName);
if ((tns != null) && !tns.equals("")) {
Document doc = node.getOwnerDocument();
String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(tns);
if ((prefix != null) && !prefix.equals("")) {
node = doc.renameNode(node, tns, prefix + ":" + localName);
}
}
}
return false;
}
@Override
public void walkByTypeName(XmlSchema xmlSchema, QName qname) {
XmlSchemaType obj = SchemaMeta.getCollection(xmlSchema).getTypeByQName(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByTypeName(xmlSchema, qname);
} else {
if (mto.containsKey(qname)) {
// System.out.println("\nWalk type "+ qname);
elist.addAll(map.get(mto.get(qname)).get(0));
}
}
}
}
@Override
public void walkByElementRef(XmlSchema xmlSchema, QName qname) {
XmlSchemaElement obj = SchemaMeta.getCollection(xmlSchema).getElementByQName(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByElementRef(xmlSchema, qname);
} else {
if (mto.containsKey(qname)) {
// System.out.println("\nWalk elem ref "+ qname);
elist.add(mto.get(qname));
}
}
}
}
@Override
public void walkByAttributeGroupRef(XmlSchema xmlSchema, QName qname) {
XmlSchema schema = SchemaMeta.getCollection(xmlSchema).schemaForNamespace(qname.getNamespaceURI());
XmlSchemaAttributeGroup obj = (XmlSchemaAttributeGroup) schema.getAttributeGroups().getItem(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByAttributeGroupRef(xmlSchema, qname);
}
}
}
@Override
public void walkByAttributeRef(XmlSchema xmlSchema, QName qname) {
XmlSchemaAttribute obj = SchemaMeta.getCollection(xmlSchema).getAttributeByQName(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByAttributeRef(xmlSchema, qname);
} else {
if (mto.containsKey(qname)) {
// System.out.println("\nWalk attr ref "+ qname);
alist.add(mto.get(qname));
}
}
}
}
@Override
public void walkByGroupRef(XmlSchema xmlSchema, QName qname) {
XmlSchema schema = SchemaMeta.getCollection(xmlSchema).schemaForNamespace(qname.getNamespaceURI());
XmlSchemaGroup obj = (XmlSchemaGroup) schema.getGroups().getItem(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByGroupRef(xmlSchema, qname);
}
}
}
@Override
protected void walkElement(XmlSchema xmlSchema, XmlSchemaElement obj) {
List<XmlSchemaObject> el = elist;
List<XmlSchemaObject> al = alist;
QName qname = obj.getQName();
QName refName = obj.getRefName();
QName typeName = obj.getSchemaTypeName();
if (refName == null) {
el.add(obj);
List<List<XmlSchemaObject>> list = new ArrayList<List<XmlSchemaObject>>();
list.add(new ArrayList<XmlSchemaObject>());
list.add(new ArrayList<XmlSchemaObject>());
map.put(obj, list);
// System.out.print("\nname="+obj.getName());
String ns = SchemaMeta.getSchema(obj).getTargetNamespace();
if (typeName != null) {
if (!mto.containsKey(typeName)) {
if (typeName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
typeName = new QName(ns, obj.getName());
}
mto.put(typeName, obj);
// System.out.print("; typeN="+typeName);
} else {
map.put(obj, map.get(mto.get(typeName)));
// type already done
return;
}
} else {
if (qname != null) {
if (qname.getNamespaceURI().equals("")) {
qname = new QName(ns, obj.getName());
}
} else
qname = new QName(ns, obj.getName());
if (!mto.containsKey(qname)) {
mto.put(qname, obj);
// System.out.print("; qname="+qname);
}
}
elist = list.get(0);
alist = list.get(1);
super.walkElement(xmlSchema, obj);
elist = el;
alist = al;
} else {
super.walkElement(xmlSchema, obj);
elist = el;
alist = al;
}
}
@Override
protected void walkAttribute(XmlSchema xmlSchema, XmlSchemaAttribute obj) {
if (obj.getRefName() == null) {
alist.add(obj);
}
super.walkAttribute(xmlSchema, obj);
}
}.init(schema, qname, requestableResponse);
responseDoc.appendChild(requestableResponse);
// System.out.println(XMLUtils.prettyPrintDOM(responseDoc));
return responseDoc;
}
} catch (Exception e) {
e.printStackTrace();
}
return document;
}
Aggregations