use of com.twinsoft.convertigo.beans.common.XmlQName in project convertigo by convertigo.
the class SessionGetObjectStep method getXmlSchemaObject.
@Override
public XmlSchemaElement getXmlSchemaObject(XmlSchemaCollection collection, XmlSchema schema) {
XmlSchemaElement element = XmlSchemaUtils.makeDynamic(this, new XmlSchemaElement());
element.setName(getStepNodeName());
if (!getXmlElementRefAffectation().isEmpty()) {
XmlSchemaComplexType eType = XmlSchemaUtils.makeDynamic(this, new XmlSchemaComplexType(schema));
element.setType(eType);
XmlSchemaSequence eSequence = XmlSchemaUtils.makeDynamic(this, new XmlSchemaSequence());
eType.setParticle(eSequence);
SchemaMeta.setContainerXmlSchemaGroupBase(element, eSequence);
XmlSchemaElement el = XmlSchemaUtils.makeDynamic(this, new XmlSchemaElement());
eSequence.getItems().add(el);
el.setRefName(getElementRefAffectation());
el.setMinOccurs(0);
el.setMaxOccurs(1);
} else {
XmlQName xmlQName = getXmlComplexTypeAffectation();
if (xmlQName.isEmpty()) {
xmlQName = getXmlSimpleTypeAffectation();
if (xmlQName.isEmpty()) {
xmlQName = new XmlQName(Constants.XSD_STRING);
}
}
element.setSchemaTypeName(xmlQName.getQName());
}
return element;
}
use of com.twinsoft.convertigo.beans.common.XmlQName in project convertigo by convertigo.
the class Migration7_0_0 method migrate.
public static void migrate(final String projectName) {
try {
Map<String, Reference> referenceMap = new HashMap<String, Reference>();
XmlSchema projectSchema = null;
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
// Copy all xsd files to project's xsd directory
File destDir = new File(project.getXsdDirPath());
copyXsdOfProject(projectName, destDir);
String projectWsdlFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".wsdl";
File wsdlFile = new File(projectWsdlFilePath);
String projectXsdFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".xsd";
File xsdFile = new File(projectXsdFilePath);
if (xsdFile.exists()) {
// Load project schema from old XSD file
XmlSchemaCollection collection = new XmlSchemaCollection();
collection.setSchemaResolver(new DefaultURIResolver() {
public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
// Case of a c8o project location
if (schemaLocation.startsWith("../") && schemaLocation.endsWith(".xsd")) {
try {
String targetProjectName = schemaLocation.substring(3, schemaLocation.indexOf("/", 3));
File pDir = new File(Engine.projectDir(targetProjectName));
if (pDir.exists()) {
File pFile = new File(Engine.PROJECTS_PATH + schemaLocation.substring(2));
// Case c8o project is already migrated
if (!pFile.exists()) {
Document doc = Engine.theApp.schemaManager.getSchemaForProject(targetProjectName).getSchemaDocument();
DOMSource source = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory.newInstance().newTransformer().transform(source, result);
StringReader reader = new StringReader(writer.toString());
return new InputSource(reader);
}
}
return null;
} catch (Exception e) {
Engine.logDatabaseObjectManager.warn("[Migration 7.0.0] Unable to find schema location \"" + schemaLocation + "\"", e);
return null;
}
} else if (schemaLocation.indexOf("://") == -1 && schemaLocation.endsWith(".xsd")) {
return super.resolveEntity(targetNamespace, schemaLocation, Engine.PROJECTS_PATH + "/" + projectName);
}
return super.resolveEntity(targetNamespace, schemaLocation, baseUri);
}
});
projectSchema = SchemaUtils.loadSchema(new File(projectXsdFilePath), collection);
ConvertigoError.updateXmlSchemaObjects(projectSchema);
SchemaMeta.setCollection(projectSchema, collection);
for (Connector connector : project.getConnectorsList()) {
for (Transaction transaction : connector.getTransactionsList()) {
try {
// Migrate transaction in case of a Web Service consumption project
if (transaction instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) transaction;
String reqn = xmlHttpTransaction.getResponseElementQName();
if (!reqn.equals("")) {
boolean useRef = reqn.indexOf(";") == -1;
// Doc/Literal case
if (useRef) {
try {
String[] qn = reqn.split(":");
QName refName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
} catch (Exception e) {
}
} else // RPC case
{
int index, index2;
try {
index = reqn.indexOf(";");
String opName = reqn.substring(0, index);
if ((index2 = reqn.indexOf(";", index + 1)) != -1) {
String eltName = reqn.substring(index + 1, index2);
String eltType = reqn.substring(index2 + 1);
String[] qn = eltType.split(":");
QName typeName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
String responseElementQName = opName + ";" + eltName + ";" + "{" + typeName.getNamespaceURI() + "}" + typeName.getLocalPart();
xmlHttpTransaction.setResponseElementQName(responseElementQName);
}
} catch (Exception e) {
}
}
}
}
// Retrieve required XmlSchemaObjects for transaction
QName requestQName = new QName(project.getTargetNamespace(), transaction.getXsdRequestElementName());
QName responseQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseElementName());
LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, false);
dw.walkByElementRef(projectSchema, requestQName);
dw.walkByElementRef(projectSchema, responseQName);
// Create transaction schema
String targetNamespace = projectSchema.getTargetNamespace();
String prefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
XmlSchema transactionSchema = SchemaUtils.createSchema(prefix, targetNamespace, XsdForm.unqualified.name(), XsdForm.unqualified.name());
// Add required prefix declarations
List<String> nsList = new LinkedList<String>();
for (QName qname : map.keySet()) {
String nsURI = qname.getNamespaceURI();
if (!nsURI.equals(Constants.URI_2001_SCHEMA_XSD)) {
if (!nsList.contains(nsURI)) {
nsList.add(nsURI);
}
}
String nsPrefix = qname.getPrefix();
if (!nsURI.equals(targetNamespace)) {
NamespaceMap nsMap = SchemaUtils.getNamespaceMap(transactionSchema);
if (nsMap.getNamespaceURI(nsPrefix) == null) {
nsMap.add(nsPrefix, nsURI);
transactionSchema.setNamespaceContext(nsMap);
}
}
}
// Add required imports
for (String namespaceURI : nsList) {
XmlSchemaObjectCollection includes = projectSchema.getIncludes();
for (int i = 0; i < includes.getCount(); i++) {
XmlSchemaObject xmlSchemaObject = includes.getItem(i);
if (xmlSchemaObject instanceof XmlSchemaImport) {
if (((XmlSchemaImport) xmlSchemaObject).getNamespace().equals(namespaceURI)) {
// do not allow import with same ns !
if (namespaceURI.equals(project.getTargetNamespace()))
continue;
String location = ((XmlSchemaImport) xmlSchemaObject).getSchemaLocation();
// This is a convertigo project reference
if (location.startsWith("../")) {
// Copy all xsd files to xsd directory
String targetProjectName = location.substring(3, location.indexOf("/", 3));
copyXsdOfProject(targetProjectName, destDir);
}
// Add reference
addReferenceToMap(referenceMap, namespaceURI, location);
// Add import
addImport(transactionSchema, namespaceURI, location);
}
}
}
}
QName responseTypeQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseTypeName());
// Add required schema objects
for (QName qname : map.keySet()) {
if (qname.getNamespaceURI().equals(targetNamespace)) {
XmlSchemaObject ob = map.get(qname);
if (qname.getLocalPart().startsWith("ConvertigoError"))
continue;
transactionSchema.getItems().add(ob);
// Add missing response error element and attributes
if (qname.equals(responseTypeQName)) {
Transaction.addSchemaResponseObjects(transactionSchema, (XmlSchemaComplexType) ob);
}
}
}
// Add missing ResponseType (with document)
if (map.containsKey(responseTypeQName)) {
Transaction.addSchemaResponseType(transactionSchema, transaction);
}
// Add everything
if (map.isEmpty()) {
Transaction.addSchemaObjects(transactionSchema, transaction);
}
// Add c8o error objects (for internal xsd edition only)
ConvertigoError.updateXmlSchemaObjects(transactionSchema);
// Save schema to file
String transactionXsdFilePath = transaction.getSchemaFilePath();
new File(transaction.getSchemaFileDirPath()).mkdirs();
SchemaUtils.saveSchema(transactionXsdFilePath, transactionSchema);
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating transaction \"" + transaction.getName() + "\"", e);
}
if (transaction instanceof TransactionWithVariables) {
TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
handleRequestableVariable(transactionVars.getVariablesList());
// Change SQLQuery variables : i.e. {id} --> {{id}}
if (transaction instanceof SqlTransaction) {
String sqlQuery = ((SqlTransaction) transaction).getSqlQuery();
sqlQuery = sqlQuery.replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{{$1}}");
((SqlTransaction) transaction).setSqlQuery(sqlQuery);
}
}
}
}
} else {
// Should only happen for projects which version <= 4.6.0
XmlSchemaCollection collection = new XmlSchemaCollection();
String prefix = project.getName() + "_ns";
projectSchema = SchemaUtils.createSchema(prefix, project.getNamespaceUri(), XsdForm.unqualified.name(), XsdForm.unqualified.name());
ConvertigoError.addXmlSchemaObjects(projectSchema);
SchemaMeta.setCollection(projectSchema, collection);
for (Connector connector : project.getConnectorsList()) {
for (Transaction transaction : connector.getTransactionsList()) {
if (transaction instanceof TransactionWithVariables) {
TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
handleRequestableVariable(transactionVars.getVariablesList());
}
}
}
}
// Handle sequence objects
for (Sequence sequence : project.getSequencesList()) {
handleSteps(projectSchema, referenceMap, sequence.getSteps());
handleRequestableVariable(sequence.getVariablesList());
}
// Add all references to project
if (!referenceMap.isEmpty()) {
for (Reference reference : referenceMap.values()) project.add(reference);
}
// Delete XSD file
if (xsdFile.exists())
xsdFile.delete();
// Delete WSDL file
if (wsdlFile.exists())
wsdlFile.delete();
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating project \"" + projectName + "\"", e);
}
}
use of com.twinsoft.convertigo.beans.common.XmlQName in project convertigo by convertigo.
the class Migration7_0_0 method handleSteps.
private static void handleSteps(XmlSchema projectSchema, Map<String, Reference> referenceMap, List<Step> stepList) {
for (Step step : stepList) {
if (step instanceof XMLActionStep) {
XMLVector<XMLVector<Object>> sourcesDefinition = ((XMLActionStep) step).getSourcesDefinition();
for (XMLVector<Object> row : sourcesDefinition) {
if (row.size() > 1) {
XMLVector<String> definition = GenericUtils.cast(row.get(1));
handleSourceDefinition(definition);
}
}
}
if (step instanceof TransactionStep) {
XMLVector<String> definition = ((TransactionStep) step).getConnectionStringDefinition();
handleSourceDefinition(definition);
}
if (step instanceof IStepSourceContainer) {
/**
* Case step's xpath has not been migrated when project has been deployed
** on a 5.0 server from a Studio with an older version *
*/
IStepSourceContainer stepSourceContainer = (IStepSourceContainer) step;
XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
handleSourceDefinition(definition);
}
if (step instanceof IVariableContainer) {
IVariableContainer variableContainer = (IVariableContainer) step;
for (Variable variable : variableContainer.getVariables()) {
if (variable instanceof IStepSourceContainer) {
IStepSourceContainer stepSourceContainer = (IStepSourceContainer) variable;
XMLVector<String> definition = stepSourceContainer.getSourceDefinition();
handleSourceDefinition(definition);
}
}
}
String targetProjectName = null;
String typeLocalName = null;
if (step instanceof TransactionStep) {
targetProjectName = ((TransactionStep) step).getProjectName();
typeLocalName = ((TransactionStep) step).getConnectorName() + "__" + ((TransactionStep) step).getTransactionName() + "ResponseType";
} else if (step instanceof SequenceStep) {
targetProjectName = ((SequenceStep) step).getProjectName();
typeLocalName = ((SequenceStep) step).getSequenceName() + "ResponseType";
}
String namespaceURI = null;
// Case of Requestable steps
if (targetProjectName != null) {
try {
namespaceURI = Project.CONVERTIGO_PROJECTS_NAMESPACEURI + targetProjectName;
if (!targetProjectName.equals(step.getProject().getName())) {
try {
namespaceURI = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(targetProjectName).getTargetNamespace();
} catch (Exception e) {
}
// Add reference
String location = "../" + targetProjectName + "/" + targetProjectName + ".xsd";
addReferenceToMap(referenceMap, namespaceURI, location);
}
// Set step's typeQName
step.setXmlComplexTypeAffectation(new XmlQName(new QName(namespaceURI, typeLocalName)));
} catch (Exception e) {
e.printStackTrace();
}
} else // Other steps
{
try {
String targetNamespace = projectSchema.getTargetNamespace();
String targetPrefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
String s = null;
try {
if (step instanceof XMLCopyStep) {
XmlSchemaCollection collection = SchemaMeta.getCollection(projectSchema);
XmlSchemaObject ob = step.getXmlSchemaObject(collection, projectSchema);
if (ob != null) {
if (ob instanceof XmlSchemaSequence) {
ob = ((XmlSchemaSequence) ob).getItems().getItem(0);
}
if (ob instanceof XmlSchemaElement || ob instanceof XmlSchemaAttribute) {
QName schemaTypeName = ob instanceof XmlSchemaElement ? ((XmlSchemaElement) ob).getSchemaTypeName() : ((XmlSchemaAttribute) ob).getSchemaTypeName();
String schemaTypePrefix = projectSchema.getNamespaceContext().getPrefix(schemaTypeName.getNamespaceURI());
String schemaTypeLocalName = schemaTypeName.getLocalPart();
s = schemaTypePrefix + ":" + schemaTypeLocalName;
}
}
} else {
String schemaType = step.getSchemaDataType();
s = schemaType.equals("") ? "xsd:string" : schemaType;
}
} catch (Exception e) {
s = "xsd:string";
}
if ((s != null) && (!s.equals("")) && (!s.startsWith("xsd:"))) {
String prefix = s.split(":")[0];
typeLocalName = s.split(":")[1];
if (prefix.equals(targetPrefix)) {
// ignore
} else {
// Retrieve namespace uri
namespaceURI = projectSchema.getNamespaceContext().getNamespaceURI(prefix);
// Set step's typeQName
QName qname = new QName(namespaceURI, typeLocalName);
XmlSchemaType schemaType = projectSchema.getTypeByName(qname);
if (schemaType instanceof XmlSchemaComplexType)
step.setXmlComplexTypeAffectation(new XmlQName(qname));
if (schemaType instanceof XmlSchemaSimpleType)
step.setXmlSimpleTypeAffectation(new XmlQName(qname));
}
}
} catch (Exception e) {
}
}
if (step instanceof ISimpleTypeAffectation) {
QName qName = XmlSchemaUtils.getSchemaDataTypeName(step.getSchemaDataType());
step.setXmlSimpleTypeAffectation(new XmlQName(qName));
}
if (step instanceof StepWithExpressions) {
handleSteps(projectSchema, referenceMap, ((StepWithExpressions) step).getSteps());
}
}
}
use of com.twinsoft.convertigo.beans.common.XmlQName in project convertigo by convertigo.
the class UpdateXSDTypesAction method run.
public void run() {
final 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();
ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
messageBox.setMessage(message);
if (messageBox.open() == SWT.YES) {
RequestableObject requestable = (RequestableObject) treeObject.getObject();
String requestableName = StringUtils.normalize(requestable.getName(), true);
Document document = null;
String result = null;
if (!(requestableName.equals(requestable.getName()))) {
throw new Exception("Requestable name should be normalized");
}
if (requestable instanceof Transaction) {
Connector connector = (Connector) requestable.getParent();
String connectorName = StringUtils.normalize(connector.getName(), true);
if (!(connectorName.equals(connector.getName()))) {
throw new Exception("Connector name should be normalized");
}
if (connector.getDefaultTransaction() == null) {
throw new Exception("Connector must have a default transaction");
}
if (requestable instanceof HtmlTransaction) {
if (extract) {
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor == null) {
ConvertigoPlugin.infoMessageBox("Please open connector first.");
return;
}
document = connectorEditor.getLastGeneratedDocument();
if (document == null) {
ConvertigoPlugin.infoMessageBox("You should first generate the XML document before trying to extract the XSD types.");
return;
}
result = requestable.generateXsdTypes(document, extract);
} else {
HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
throw new Exception("Default transaction name should be normalized");
}
String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
if (requestable.equals(defaultTransaction))
result = defaultXsdTypes;
else {
TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
if (dlg.open() == Window.OK) {
result = dlg.result;
result += defaultXsdTypes;
}
}
}
} else {
if (extract) {
ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
if (connectorEditor == null) {
ConvertigoPlugin.infoMessageBox("Please open connector first.");
return;
}
document = connectorEditor.getLastGeneratedDocument();
if (document == null) {
ConvertigoPlugin.infoMessageBox("You should first generate the XML document before trying to extract the XSD types.");
return;
}
String prefix = requestable.getXsdTypePrefix();
document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
}
if (requestable instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
String reqn = xmlHttpTransaction.getResponseElementQName();
if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
if (!xmlQName.isEmpty()) {
ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
return;
}
if (!reqn.equals("")) {
ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
return;
}
}
}
result = requestable.generateXsdTypes(document, extract);
}
}
if ((result != null) && (!result.equals(""))) {
String xsdTypes = result;
if (requestable instanceof Transaction) {
if (requestable instanceof XmlHttpTransaction) {
XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
String reqn = xmlHttpTransaction.getResponseElementQName();
if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
// ignore
;
} else
((Transaction) requestable).writeSchemaToFile(xsdTypes);
} else
((Transaction) requestable).writeSchemaToFile(xsdTypes);
}
requestable.hasChanged = true;
Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
explorerView.refreshFirstSelectedTreeObject();
explorerView.objectSelected(new CompositeEvent(requestable));
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to update schema!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.common.XmlQName in project convertigo by convertigo.
the class XmlQNameEditorComposite method getValue.
@Override
public XmlQName getValue() {
String namespace = tNamespace.getText();
String localName = tLocalName.getText();
if (localName.length() == 0) {
return new XmlQName();
} else {
return new XmlQName(new QName(namespace, localName));
}
}
Aggregations