use of com.twinsoft.convertigo.beans.core.Reference 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.core.Reference in project convertigo by convertigo.
the class ProjectExplorerView method loadDatabaseObject.
private void loadDatabaseObject(TreeParent parentTreeObject, DatabaseObject parentDatabaseObject, ProjectLoadingJob projectLoadingJob, final IProgressMonitor monitor) throws EngineException, IOException {
try {
new WalkHelper() {
// recursion parameters
TreeParent parentTreeObject;
ProjectLoadingJob projectLoadingJob;
// sibling parameters
ObjectsFolderTreeObject currentTreeFolder = null;
public void init(DatabaseObject databaseObject, TreeParent parentTreeObject, ProjectLoadingJob projectLoadingJob) throws Exception {
this.parentTreeObject = parentTreeObject;
this.projectLoadingJob = projectLoadingJob;
walkInheritance = true;
super.init(databaseObject);
}
protected ObjectsFolderTreeObject getFolder(TreeParent treeParent, int folderType) {
ObjectsFolderTreeObject ofto = null;
for (TreeObject to : treeParent.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
if (((ObjectsFolderTreeObject) to).folderType == folderType) {
ofto = (ObjectsFolderTreeObject) to;
break;
}
}
}
if (ofto == null) {
ofto = new ObjectsFolderTreeObject(viewer, folderType);
treeParent.addChild(ofto);
}
return ofto;
}
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
// retrieve recursion parameters
final TreeParent parentTreeObject = this.parentTreeObject;
final ProjectLoadingJob projectLoadingJob = this.projectLoadingJob;
// retrieve sibling parameters
ObjectsFolderTreeObject currentTreeFolder = this.currentTreeFolder;
String dboName = (databaseObject instanceof Step) ? ((Step) databaseObject).getStepNodeName() : databaseObject.getName();
monitor.subTask("Loading databaseObject '" + dboName + "'...");
DatabaseObjectTreeObject databaseObjectTreeObject = null;
// first call case, the tree object already exists and its content is just refreshed
if (parentTreeObject.getObject() == databaseObject) {
databaseObjectTreeObject = (DatabaseObjectTreeObject) parentTreeObject;
} else // recursive call case, the tree object doesn't exist and must be added to the parent tree object
{
int folderType = Integer.MIN_VALUE;
if (databaseObject instanceof Connector) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_CONNECTORS;
databaseObjectTreeObject = new ConnectorTreeObject(viewer, (Connector) databaseObject, false);
} else if (databaseObject instanceof Sequence) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SEQUENCES;
databaseObjectTreeObject = new SequenceTreeObject(viewer, (Sequence) databaseObject, false);
} else if (databaseObject instanceof MobileApplication) {
databaseObjectTreeObject = new MobileApplicationTreeObject(viewer, (MobileApplication) databaseObject, false);
} else if (databaseObject instanceof MobilePlatform) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_PLATFORMS;
databaseObjectTreeObject = new MobilePlatformTreeObject(viewer, (MobilePlatform) databaseObject, false);
} else /**
***********************************************************************************************
*/
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
databaseObjectTreeObject = new MobileApplicationComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_ROUTES;
databaseObjectTreeObject = new MobileRouteComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteEventComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
databaseObjectTreeObject = new MobileRouteEventComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.RouteActionComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_ACTIONS;
databaseObjectTreeObject = new MobileRouteActionComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_PAGES;
databaseObjectTreeObject = new MobilePageComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SHARED_ACTIONS;
databaseObjectTreeObject = new MobileUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SHARED_COMPONENTS;
databaseObjectTreeObject = new MobileUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_MENUS;
databaseObjectTreeObject = new MobileUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIAttribute) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_ATTRIBUTES;
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIControlAttr) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_CONTROLS;
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIStyle) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_STYLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIControlVariable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UICompVariable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIFormValidator) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VALIDATORS;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIAppEvent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIPageEvent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.UIEventSubscriber) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
}
databaseObjectTreeObject = new MobileUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
}
} else /**
***********************************************************************************************
*/
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
databaseObjectTreeObject = new NgxApplicationComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_PAGES;
databaseObjectTreeObject = new NgxPageComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SHARED_ACTIONS;
databaseObjectTreeObject = new NgxUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SHARED_COMPONENTS;
databaseObjectTreeObject = new NgxUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_MENUS;
databaseObjectTreeObject = new NgxUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIAttribute) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_ATTRIBUTES;
if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIControlAttr) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_CONTROLS;
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicAttr) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_ATTRIBUTES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIStyle) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_STYLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIControlVariable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UICompVariable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIAppEvent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIPageEvent) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.UIEventSubscriber) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EVENTS;
}
databaseObjectTreeObject = new NgxUIComponentTreeObject(viewer, GenericUtils.cast(databaseObject), false);
}
} else if (databaseObject instanceof UrlMapper) {
databaseObjectTreeObject = new UrlMapperTreeObject(viewer, (UrlMapper) databaseObject, false);
} else if (databaseObject instanceof UrlAuthentication) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_AUTHENTICATIONS;
databaseObjectTreeObject = new UrlAuthenticationTreeObject(viewer, (UrlAuthentication) databaseObject, false);
} else if (databaseObject instanceof UrlMapping) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_MAPPINGS;
databaseObjectTreeObject = new UrlMappingTreeObject(viewer, (UrlMapping) databaseObject, false);
} else if (databaseObject instanceof UrlMappingOperation) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_OPERATIONS;
databaseObjectTreeObject = new UrlMappingOperationTreeObject(viewer, (UrlMappingOperation) databaseObject, false);
} else if (databaseObject instanceof UrlMappingParameter) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_PARAMETERS;
databaseObjectTreeObject = new UrlMappingParameterTreeObject(viewer, (UrlMappingParameter) databaseObject, false);
} else if (databaseObject instanceof UrlMappingResponse) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_RESPONSES;
databaseObjectTreeObject = new UrlMappingResponseTreeObject(viewer, (UrlMappingResponse) databaseObject, false);
} else if (databaseObject instanceof Reference) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_REFERENCES;
databaseObjectTreeObject = new ReferenceTreeObject(viewer, (Reference) databaseObject, false);
} else if (databaseObject instanceof Pool) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_POOLS;
databaseObjectTreeObject = new DatabaseObjectTreeObject(viewer, databaseObject, false);
} else if (databaseObject instanceof Transaction) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_TRANSACTIONS;
databaseObjectTreeObject = new TransactionTreeObject(viewer, (Transaction) databaseObject, false);
} else if (databaseObject instanceof ScreenClass) {
if (databaseObject.getParent() instanceof IScreenClassContainer<?>) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SCREEN_CLASSES;
databaseObjectTreeObject = new ScreenClassTreeObject(viewer, (ScreenClass) databaseObject, false);
} else {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_INHERITED_SCREEN_CLASSES;
databaseObjectTreeObject = new ScreenClassTreeObject(viewer, (ScreenClass) databaseObject, false);
}
} else if (databaseObject instanceof Sheet) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_SHEETS;
databaseObjectTreeObject = new SheetTreeObject(viewer, (Sheet) databaseObject, parentTreeObject.getObject() != databaseObject.getParent());
} else if (databaseObject instanceof TestCase) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_TESTCASES;
databaseObjectTreeObject = new TestCaseTreeObject(viewer, (TestCase) databaseObject, false);
} else if (databaseObject instanceof Variable) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_VARIABLES;
databaseObjectTreeObject = new VariableTreeObject2(viewer, (Variable) databaseObject, false);
} else if (databaseObject instanceof Step) {
if (databaseObject.getParent() instanceof Sequence) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_STEPS;
}
databaseObjectTreeObject = new StepTreeObject(viewer, (Step) databaseObject, false);
} else if (databaseObject instanceof Statement) {
if (databaseObject.getParent() instanceof Transaction) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_FUNCTIONS;
}
databaseObjectTreeObject = new StatementTreeObject(viewer, (Statement) databaseObject, false);
} else if (databaseObject instanceof Criteria) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_CRITERIAS;
databaseObjectTreeObject = new CriteriaTreeObject(viewer, (Criteria) databaseObject, parentTreeObject.getObject() != databaseObject.getParent());
} else if (databaseObject instanceof ExtractionRule) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_EXTRACTION_RULES;
databaseObjectTreeObject = new ExtractionRuleTreeObject(viewer, (ExtractionRule) databaseObject, parentTreeObject.getObject() != databaseObject.getParent());
} else if (databaseObject instanceof BlockFactory) {
databaseObjectTreeObject = new DatabaseObjectTreeObject(viewer, databaseObject, parentTreeObject.getObject() != databaseObject.getParent());
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.core.Document) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_DOCUMENTS;
com.twinsoft.convertigo.beans.core.Document document = (com.twinsoft.convertigo.beans.core.Document) databaseObject;
String documentRenderer = document.getRenderer();
if (documentRenderer.equals("DesignDocumentTreeObject"))
databaseObjectTreeObject = new DesignDocumentTreeObject(viewer, document, false);
else
databaseObjectTreeObject = new DocumentTreeObject(viewer, document, false);
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.core.Listener) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_LISTENERS;
com.twinsoft.convertigo.beans.core.Listener listener = (com.twinsoft.convertigo.beans.core.Listener) databaseObject;
String listenerRenderer = listener.getRenderer();
if (listenerRenderer.equals("FullSyncListenerTreeObject")) {
databaseObjectTreeObject = new FullSyncListenerTreeObject(viewer, listener, false);
} else {
databaseObjectTreeObject = new ListenerTreeObject(viewer, listener, false);
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.core.Index) {
folderType = ObjectsFolderTreeObject.FOLDER_TYPE_INDEXES;
databaseObjectTreeObject = new DatabaseObjectTreeObject(viewer, databaseObject, false);
} else {
// unknow DBO case !!!
databaseObjectTreeObject = new DatabaseObjectTreeObject(viewer, databaseObject, false);
}
// no virtual folder
if (folderType == Integer.MIN_VALUE) {
parentTreeObject.addChild(databaseObjectTreeObject);
} else // virtual folder creation or reuse
{
/* fixed #5416 */
// if (currentTreeFolder == null || currentTreeFolder.folderType != folderType) {
// currentTreeFolder = new ObjectsFolderTreeObject(viewer, folderType);
// parentTreeObject.addChild(currentTreeFolder);
// }
currentTreeFolder = getFolder(parentTreeObject, folderType);
currentTreeFolder.addChild(databaseObjectTreeObject);
}
// case databaseObject has been changed through dbo::preconfigure, mark projectTreeObject as modified
if ((databaseObject.bNew) || (databaseObject.hasChanged && !databaseObject.bNew)) {
databaseObjectTreeObject.hasBeenModified(true);
}
// new value of recursion parameters
this.parentTreeObject = databaseObjectTreeObject;
}
// special databaseObject cases
if (databaseObject instanceof Project) {
Project project = (Project) databaseObject;
// Creates directories and files
createDirsAndFiles(project.getName());
// Creates or Refresh xsd and wsdl folders
IFolder xsdFolder, wsdlFolder = null;
IFolder xsdInternalFolder = null;
try {
wsdlFolder = ((ProjectTreeObject) parentTreeObject).getFolder("wsdl");
if (!wsdlFolder.exists())
wsdlFolder.create(true, true, null);
else
wsdlFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
xsdFolder = ((ProjectTreeObject) parentTreeObject).getFolder("xsd");
if (!xsdFolder.exists())
xsdFolder.create(true, true, null);
else {
xsdInternalFolder = xsdFolder.getFolder("internal");
if (!xsdInternalFolder.exists())
xsdInternalFolder.create(true, true, null);
xsdFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
} catch (Exception e) {
e.printStackTrace();
}
// Connectors
IFolder xsdConnectorInternalFolder = null;
Collection<Connector> connectors = project.getConnectorsList();
if (connectors.size() != 0) {
// Set default connector if none
if (project.getDefaultConnector() == null) {
// Report from 4.5: fix #401
ConvertigoPlugin.logWarning(null, "Project \"" + project.getName() + "\" has no default connector. Try to set a default one.");
Connector defaultConnector = connectors.iterator().next();
try {
project.setDefaultConnector(defaultConnector);
defaultConnector.hasChanged = true;
} catch (Exception e) {
ConvertigoPlugin.logWarning(e, "Unable to set a default connector for project \"" + project.getName() + "\"");
}
}
// Refresh Traces folder
IFolder ifolder = ((ProjectTreeObject) parentTreeObject).getFolder("Traces");
if (ifolder.exists()) {
try {
ifolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e) {
}
}
// Creates or Refresh internal xsd connector folders
for (Connector connector : connectors) {
try {
xsdConnectorInternalFolder = xsdInternalFolder.getFolder(connector.getName());
if (!xsdConnectorInternalFolder.exists())
xsdConnectorInternalFolder.create(true, true, null);
else
xsdConnectorInternalFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else if (databaseObject instanceof Connector) {
Connector connector = (Connector) databaseObject;
// Open connector editor
if (projectLoadingJob != null && connector.isDefault) {
projectLoadingJob.setDefaultConnectorTreeObject((ConnectorTreeObject) databaseObjectTreeObject);
}
// Traces
if (connector instanceof JavelinConnector) {
String projectName = databaseObject.getProject().getName();
if (projectLoadingJob == null) {
if (MigrationManager.isProjectMigrated(projectName)) {
UnloadedProjectTreeObject unloadedProjectTreeObject = new UnloadedProjectTreeObject(databaseObjectTreeObject.viewer, projectName);
this.projectLoadingJob = new ProjectLoadingJob(databaseObjectTreeObject.viewer, unloadedProjectTreeObject);
this.projectLoadingJob.loadTrace(databaseObjectTreeObject, new File(Engine.projectDir(projectName) + "/Traces/" + connector.getName()));
}
}
if (projectLoadingJob != null) {
projectLoadingJob.loadTrace(databaseObjectTreeObject, new File(Engine.projectDir(projectName) + "/Traces/" + connector.getName()));
}
}
} else if (databaseObject instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject;
// Functions
List<HandlersDeclarationTreeObject> treeObjects = new LinkedList<HandlersDeclarationTreeObject>();
String line, lineReaded;
int lineNumber = 0;
BufferedReader br = new BufferedReader(new StringReader(transaction.handlers));
line = br.readLine();
while (line != null) {
lineReaded = line.trim();
lineNumber++;
if (lineReaded.startsWith("function ")) {
try {
String functionName = lineReaded.substring(9, lineReaded.indexOf(')') + 1);
HandlersDeclarationTreeObject handlersDeclarationTreeObject = null;
if (functionName.endsWith(JavelinTransaction.EVENT_ENTRY_HANDLER + "()")) {
handlersDeclarationTreeObject = new HandlersDeclarationTreeObject(viewer, functionName, HandlersDeclarationTreeObject.TYPE_FUNCTION_SCREEN_CLASS_ENTRY, lineNumber);
} else if (functionName.endsWith(JavelinTransaction.EVENT_EXIT_HANDLER + "()")) {
handlersDeclarationTreeObject = new HandlersDeclarationTreeObject(viewer, functionName, HandlersDeclarationTreeObject.TYPE_FUNCTION_SCREEN_CLASS_EXIT, lineNumber);
} else {
handlersDeclarationTreeObject = new HandlersDeclarationTreeObject(viewer, functionName, HandlersDeclarationTreeObject.TYPE_OTHER, lineNumber);
}
if (handlersDeclarationTreeObject != null) {
treeObjects.add(handlersDeclarationTreeObject);
}
} catch (StringIndexOutOfBoundsException e) {
throw new EngineException("Exception in reading line of a transaction", e);
}
}
line = br.readLine();
}
if (treeObjects.size() != 0) {
ObjectsFolderTreeObject objectsFolderTreeObject = new ObjectsFolderTreeObject(viewer, ObjectsFolderTreeObject.FOLDER_TYPE_FUNCTIONS);
databaseObjectTreeObject.addChild(objectsFolderTreeObject);
for (HandlersDeclarationTreeObject handlersDeclarationTreeObject : treeObjects) {
objectsFolderTreeObject.addChild(handlersDeclarationTreeObject);
}
}
} else if (databaseObject instanceof Sheet) {
addTemplates((Sheet) databaseObject, databaseObjectTreeObject);
} else if (databaseObject instanceof ITablesProperty) {
ITablesProperty iTablesProperty = (ITablesProperty) databaseObject;
String[] tablePropertyNames = iTablesProperty.getTablePropertyNames();
for (int i = 0; i < tablePropertyNames.length; i++) {
String tablePropertyName = tablePropertyNames[i];
String tableRenderer = iTablesProperty.getTableRenderer(tablePropertyName);
XMLVector<XMLVector<Object>> xmlv = iTablesProperty.getTableData(tablePropertyName);
if (tableRenderer.equals("XMLTableDescriptionTreeObject")) {
XMLTableDescriptionTreeObject propertyXMLTableTreeObject = new XMLTableDescriptionTreeObject(viewer, tablePropertyName, xmlv, databaseObjectTreeObject);
databaseObjectTreeObject.addChild(propertyXMLTableTreeObject);
} else if (tableRenderer.equals("XMLRecordDescriptionTreeObject")) {
XMLRecordDescriptionTreeObject propertyXMLRecordTreeObject = new XMLRecordDescriptionTreeObject(viewer, tablePropertyName, xmlv, databaseObjectTreeObject);
databaseObjectTreeObject.addChild(propertyXMLRecordTreeObject);
}
}
}
monitor.worked(1);
// children cannot be added in the current virtual folder
this.currentTreeFolder = null;
super.walk(databaseObject);
// restore recursion parameters
this.parentTreeObject = parentTreeObject;
this.projectLoadingJob = projectLoadingJob;
// restore sibling parameters
this.currentTreeFolder = currentTreeFolder;
}
}.init(parentDatabaseObject, parentTreeObject, projectLoadingJob);
} catch (EngineException e) {
throw e;
} catch (Exception e) {
throw new EngineException("Exception in copyDatabaseObject", e);
}
}
use of com.twinsoft.convertigo.beans.core.Reference in project convertigo by convertigo.
the class CLI method generateMobileBuilder.
public void generateMobileBuilder(Project project, String mode) throws Exception {
MobileBuilder mb = project.getMobileBuilder();
MobileBuilderBuildMode bm = MobileBuilderBuildMode.production;
try {
bm = MobileBuilderBuildMode.valueOf(mode);
} catch (Exception e) {
}
mb.setAppBuildMode(bm);
List<Project> projects = new ArrayList<>();
projects.add(project);
int i = 0;
do {
for (Reference ref : projects.get(i).getReferenceList()) {
if (ref instanceof ProjectSchemaReference) {
ProjectSchemaReference pref = (ProjectSchemaReference) ref;
Project p = Engine.theApp.referencedProjectManager.importProject(pref.getParser());
if (p == null) {
Engine.logConvertigo.warn("Failed to import project reference: " + pref.getProjectName() + " (ignored)");
} else if (!projects.contains(p)) {
projects.add(p);
}
}
}
} while (++i < projects.size());
Collections.reverse(projects);
for (Project p : projects) {
MobileBuilder.initBuilder(p, true);
}
Collections.reverse(projects);
for (Project p : projects) {
MobileBuilder.releaseBuilder(p, true);
}
}
use of com.twinsoft.convertigo.beans.core.Reference in project convertigo by convertigo.
the class SchemaManager method getProjectReferences.
protected static void getProjectReferences(List<String> refs, String projectName) {
if (refs == null)
return;
try {
Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
if (p != null) {
if (!refs.contains(projectName)) {
refs.add(projectName);
for (Reference ref : p.getReferenceList()) {
if (ref instanceof ProjectSchemaReference) {
ProjectSchemaReference psr = (ProjectSchemaReference) ref;
getProjectReferences(refs, psr.getParser().getProjectName());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.twinsoft.convertigo.beans.core.Reference in project convertigo by convertigo.
the class XmlSchemaBuilder method midBuildSchema.
private void midBuildSchema(final int nb) throws EngineException {
// System.out.println("buildSchema for "+ getTargetNamespace());
boolean fullSchema = isFull;
try {
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject instanceof ISchemaGenerator) {
// generate itself and add to the caller list
if (databaseObject instanceof ISchemaImportGenerator) {
// Import case
if (databaseObject instanceof ProjectSchemaReference) {
ProjectSchemaReference ref = (ProjectSchemaReference) databaseObject;
String targetProjectName = ref.getParser().getProjectName();
String tns = Project.getProjectTargetNamespace(targetProjectName);
if (collection.schemaForNamespace(tns) == null) {
if (SchemaMeta.getXmlSchemaObject(schema, databaseObject) == null) {
XmlSchemaImport schemaImport = new XmlSchemaImport();
schemaImport.setNamespace(tns);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
XmlSchemaUtils.add(schema, schemaImport);
} else {
XmlSchemaBuilder builder = builderExecutor.getBuilderByTargetNamespace(tns);
if (builder != null) {
XmlSchemaUtils.remove(schema, SchemaMeta.getXmlSchemaObject(schema, databaseObject));
XmlSchema xmlSchema = collection.read(builder.schema.getSchemaDocument(), null);
XmlSchemaImport schemaImport = new XmlSchemaImport();
schemaImport.setNamespace(tns);
schemaImport.setSchema(xmlSchema);
SchemaMeta.setXmlSchemaObject(schema, databaseObject, schemaImport);
XmlSchemaUtils.add(schema, schemaImport);
}
}
}
}
}
} else {
// doesn't generate schema, just deep walk
super.walk(databaseObject);
}
}
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
// just walk references
return Reference.class.isAssignableFrom(dboClass);
}
}.init(project);
// add missing references import
if (nb == 1) {
if (this.equals(builderExecutor.getMainBuilder())) {
List<String> refs = new ArrayList<String>();
SchemaManager.getProjectReferences(refs, projectName);
List<String> missing = new ArrayList<String>();
missing.addAll(refs);
missing.remove(projectName);
for (String pname : refs) {
XmlSchemaObjectCollection col = schema.getIncludes();
for (int i = 0; i < col.getCount(); i++) {
XmlSchemaObject ob = col.getItem(i);
if (ob instanceof XmlSchemaImport) {
XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) ob;
String tns = Project.getProjectTargetNamespace(pname);
if (xmlSchemaImport.getNamespace().equals(tns)) {
missing.remove(pname);
}
}
}
}
for (String pname : missing) {
String tns = Project.getProjectTargetNamespace(pname);
XmlSchemaBuilder builder = builderExecutor.getBuilderByTargetNamespace(tns);
if (builder != null) {
XmlSchema xmlSchema = collection.read(builder.schema.getSchemaDocument(), null);
XmlSchemaImport schemaImport = new XmlSchemaImport();
schemaImport.setNamespace(tns);
schemaImport.setSchema(xmlSchema);
XmlSchemaUtils.add(schema, schemaImport);
}
}
}
}
new WalkHelper() {
List<XmlSchemaParticle> particleChildren;
List<XmlSchemaAttribute> attributeChildren;
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
// Transaction case
if (databaseObject instanceof Transaction) {
Transaction transaction = (Transaction) databaseObject;
String ns = schema.getTargetNamespace();
List<QName> partElementQNames = new ArrayList<QName>();
partElementQNames.add(new QName(ns, transaction.getXsdRequestElementName()));
partElementQNames.add(new QName(ns, transaction.getXsdResponseElementName()));
LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, true);
for (QName qname : partElementQNames) {
dw.walkByElementRef(schema, qname);
}
for (QName qname : map.keySet()) {
String nsURI = qname.getNamespaceURI();
if (nsURI.equals(ns))
continue;
if (nsURI.equals(Constants.URI_2001_SCHEMA_XSD))
continue;
SchemaManager.addXmlSchemaImport(collection, schema, nsURI);
}
map.clear();
// add the 'statistics' element
if (transaction.getAddStatistics()) {
XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) schema.getTypeByName(transaction.getXsdResponseTypeName());
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) xmlSchemaComplexType.getParticle();
XmlSchemaType statisticsType = schema.getTypeByName("ConvertigoStatsType");
XmlSchemaElement eStatistics = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
eStatistics.setName("statistics");
eStatistics.setMinOccurs(0);
eStatistics.setMaxOccurs(1);
eStatistics.setSchemaTypeName(statisticsType.getQName());
xmlSchemaGroupBase.getItems().add(eStatistics);
SchemaMeta.getReferencedDatabaseObjects(statisticsType).add(transaction);
}
} else // Sequence case
if (databaseObject instanceof Sequence) {
Sequence sequence = (Sequence) databaseObject;
// System.out.println("--sequence:"+ sequence.toString());
particleChildren = new LinkedList<XmlSchemaParticle>();
attributeChildren = new LinkedList<XmlSchemaAttribute>();
super.walk(databaseObject);
// check for an 'error' element if needed
boolean errorFound = false;
XmlSchemaType errorType = schema.getTypeByName("ConvertigoError");
if (errorType != null) {
Set<DatabaseObject> dbos = SchemaMeta.getReferencedDatabaseObjects(errorType);
for (DatabaseObject dbo : dbos) {
if (dbo instanceof Step) {
Step errorStep = (Step) dbo;
if (errorStep.getSequence().equals(sequence) && (errorStep instanceof XMLCopyStep || errorStep.getStepNodeName().equals("error"))) {
errorFound = true;
break;
}
}
}
}
// set particle : choice or sequence
XmlSchemaComplexType cType = (XmlSchemaComplexType) schema.getTypeByName(sequence.getComplexTypeAffectation().getLocalPart());
XmlSchemaSequence xmlSeq = new XmlSchemaSequence();
XmlSchemaChoice xmlChoice = new XmlSchemaChoice();
cType.setParticle(errorFound ? xmlSeq : xmlChoice);
if (!errorFound) {
XmlSchemaElement eError = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
eError.setName("error");
eError.setMinOccurs(0);
eError.setMaxOccurs(1);
eError.setSchemaTypeName(errorType.getQName());
SchemaMeta.getReferencedDatabaseObjects(errorType).add(sequence);
xmlChoice.getItems().add(xmlSeq);
xmlChoice.getItems().add(eError);
}
// add child particles
if (!particleChildren.isEmpty()) {
for (XmlSchemaParticle child : particleChildren) {
xmlSeq.getItems().add(child);
}
}
particleChildren.clear();
// add child attributes
for (XmlSchemaAttribute attribute : attributeChildren) {
cType.getAttributes().add(attribute);
}
attributeChildren.clear();
// add the 'statistics' element
if (sequence.getAddStatistics()) {
XmlSchemaType statisticsType = schema.getTypeByName("ConvertigoStatsType");
XmlSchemaElement eStatistics = XmlSchemaUtils.makeDynamicReadOnly(databaseObject, new XmlSchemaElement());
eStatistics.setName("statistics");
eStatistics.setMinOccurs(0);
eStatistics.setMaxOccurs(1);
eStatistics.setSchemaTypeName(statisticsType.getQName());
xmlSeq.getItems().add(eStatistics);
SchemaMeta.getReferencedDatabaseObjects(statisticsType).add(sequence);
}
// --------------------------- For Further Use -------------------------------------------------//
// Modify schema to avoid 'cosamb' (same tagname&type in different groupBase at same level)
// TODO : IfThenElse steps must be modified for xsd:sequence instead of xsd:choice
// TODO : Then/Else steps must be modified to add minOccurs=0 on xsd:sequence
// TODO : review/improve cosnoamb(XmlSchema, XmlSchemaGroupBase, XmlSchemaGroupBase) method
// ---------------------------------------------------------------------------------------------//
} else // Step case
if (databaseObject instanceof Step) {
Step step = (Step) databaseObject;
if (!step.isEnabled()) {
// stop walking for disabled steps
return;
}
List<XmlSchemaParticle> parentParticleChildren = particleChildren;
List<XmlSchemaAttribute> parentAttributeChildren = attributeChildren;
// System.out.println("step:"+ step.toString());
if (step instanceof TransactionStep) {
// System.out.println("SCHEMA TARGET STEP "+ step.toString() + "(" + step.hashCode() + ")");
}
if (step.isGenerateSchema() || (fullSchema && step.isXmlOrOutput())) {
// System.out.println("-> generate schema...");
List<XmlSchemaParticle> myParticleChildren = null;
List<XmlSchemaAttribute> myAttributeChildren = null;
// is base affected ?
@SuppressWarnings("unused") XmlSchemaType base = null;
QName baseQName = step instanceof ISimpleTypeAffectation ? ((ISimpleTypeAffectation) step).getSimpleTypeAffectation() : null;
if (baseQName != null && baseQName.getLocalPart().length() > 0) {
// base = baseQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(baseQName.getLocalPart()) : collection.getTypeByQName(baseQName);
base = XmlSchemaBuilder.this.resolveTypeByQName(baseQName);
}
// is type affected ?
XmlSchemaType type = null;
QName typeQName = step instanceof IComplexTypeAffectation ? ((IComplexTypeAffectation) step).getComplexTypeAffectation() : null;
if (typeQName != null && typeQName.getLocalPart().length() > 0) {
// type = typeQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(typeQName.getLocalPart()) : collection.getTypeByQName(typeQName);
type = XmlSchemaBuilder.this.resolveTypeByQName(typeQName);
}
// is element affected ?
XmlSchemaElement ref = null;
QName refQName = step instanceof IElementRefAffectation ? ((IElementRefAffectation) step).getElementRefAffectation() : null;
if (refQName != null && refQName.getLocalPart().length() > 0) {
// ref = refQName.getNamespaceURI().length() == 0 ? schema.getElementByName(refQName.getLocalPart()) : collection.getElementByQName(refQName);
ref = XmlSchemaBuilder.this.resolveElementByQName(refQName);
typeQName = new QName(schema.getTargetNamespace(), refQName.getLocalPart() + "Type");
if (ref == null && refQName.getNamespaceURI().equals(schema.getTargetNamespace())) {
ref = XmlSchemaUtils.makeDynamic(step, new XmlSchemaElement());
ref.setQName(refQName);
ref.setName(refQName.getLocalPart());
ref.setSchemaTypeName(baseQName);
XmlSchemaUtils.add(schema, ref);
} else if (ref != null) {
ref.setSchemaTypeName(baseQName);
// type = typeQName.getNamespaceURI().length() == 0 ? schema.getTypeByName(typeQName.getLocalPart()) : collection.getTypeByQName(typeQName);
type = XmlSchemaBuilder.this.resolveTypeByQName(typeQName);
}
}
if (type == null || !SchemaMeta.isReadOnly(type)) {
// prepare to receive children
if (step instanceof ISchemaParticleGenerator) {
myParticleChildren = particleChildren = new LinkedList<XmlSchemaParticle>();
if (fullSchema || ((ISchemaParticleGenerator) step).isGenerateElement()) {
myAttributeChildren = attributeChildren = new LinkedList<XmlSchemaAttribute>();
}
}
// deep walk
super.walk(step);
// generate itself and add to the caller list
if (step instanceof ISchemaAttributeGenerator) {
// Attribute case
XmlSchemaAttribute attribute = ((ISchemaAttributeGenerator) step).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, attribute);
parentAttributeChildren.add(attribute);
} else if (step instanceof ISchemaParticleGenerator) {
if (step instanceof RequestableStep) {
RequestableStep requestableStep = (RequestableStep) step;
String targetProjectName = requestableStep.getProjectName();
Project targetProject = requestableStep.getSequence().getLoadedProject(targetProjectName);
if (targetProject == null) {
Engine.logEngine.warn("(XmlSchemaBuilder) Not complete schema because: Missing required or not loaded project \"" + targetProjectName + "\"");
} else if (step instanceof SequenceStep) {
// SequenceStep case : walk target sequence first
try {
Sequence targetSequence = ((SequenceStep) step).getTargetSequence();
targetProjectName = targetSequence.getProject().getName();
String targetSequenceName = targetSequence.getName();
String stepSequenceName = step.getSequence().getName();
if (projectName.equals(targetProjectName)) {
boolean isAfter = targetSequenceName.compareToIgnoreCase(stepSequenceName) > 0;
if (isAfter) {
walk(targetSequence);
}
}
} catch (EngineException e) {
if (!e.getMessage().startsWith("There is no ")) {
throw e;
} else {
Engine.logEngine.warn("(XmlSchemaBuilder) Not complete schema because: " + e.getMessage());
}
}
}
}
// Particle case
XmlSchemaParticle particle = ((ISchemaParticleGenerator) step).getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, particle);
parentParticleChildren.add(particle);
// retrieve the xsd:element to add children
XmlSchemaElement element = SchemaMeta.getContainerXmlSchemaElement(ref == null ? particle : ref);
// retrieve the group to add children if any
XmlSchemaGroupBase group = SchemaMeta.getContainerXmlSchemaGroupBase(element != null ? element : particle);
// new complexType to enhance the element
XmlSchemaComplexType cType = element != null ? (XmlSchemaComplexType) element.getSchemaType() : null;
// do something only on case of child
if (!myParticleChildren.isEmpty() || (myAttributeChildren != null && !myAttributeChildren.isEmpty())) {
if (cType == null) {
cType = XmlSchemaUtils.makeDynamic(step, new XmlSchemaComplexType(schema));
}
// prepare element children in the group
if (!myParticleChildren.isEmpty()) {
if (group == null) {
group = XmlSchemaUtils.makeDynamic(step, new XmlSchemaSequence());
}
for (XmlSchemaParticle child : myParticleChildren) {
group.getItems().add(child);
}
}
if (element != null) {
XmlSchemaSimpleContentExtension sContentExt = SchemaManager.makeSimpleContentExtension(step, element, cType);
if (sContentExt != null) {
// add attributes
for (XmlSchemaAttribute attribute : myAttributeChildren) {
sContentExt.getAttributes().add(attribute);
}
} else {
// add attributes
for (XmlSchemaAttribute attribute : myAttributeChildren) {
cType.getAttributes().add(attribute);
}
// add elements
if (SchemaMeta.isDynamic(cType) && group != null) {
cType.setParticle(group);
}
}
}
}
if (element != null) {
// check if the type is named
if (typeQName != null && typeQName.getLocalPart().length() > 0) {
if (cType == null) {
cType = XmlSchemaUtils.makeDynamic(step, new XmlSchemaComplexType(schema));
SchemaManager.makeSimpleContentExtension(step, element, cType);
}
if (type == null) {
// the type doesn't exist, declare it
cType.setName(typeQName.getLocalPart());
schema.addType(cType);
schema.getItems().add(cType);
} else {
// the type already exists, merge it
XmlSchemaComplexType currentCType = (XmlSchemaComplexType) type;
SchemaManager.merge(schema, currentCType, cType);
cType = currentCType;
}
// reference the type in the current element
element.setSchemaTypeName(cType.getQName());
element.setSchemaType(null);
} else if (cType != null && SchemaMeta.isDynamic(cType) && element.getSchemaTypeName() == null) {
// the element contains an anonymous type
element.setSchemaType(cType);
}
}
} else {
XmlSchemaObject object;
XmlSchema xmlSchema = null;
if (step instanceof XMLCopyStep && !fullSchema) {
final XmlSchemaBuilder fullBuilder = builderExecutor.getBuilder(projectName, true);
if (fullBuilder != null) {
xmlSchema = fullBuilder.getXmlSchema();
XmlSchemaCollection xmlCollection = SchemaMeta.getCollection(xmlSchema);
object = step.getXmlSchemaObject(xmlCollection, xmlSchema);
} else {
xmlSchema = schema;
object = step.getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, object);
}
} else {
xmlSchema = schema;
object = step.getXmlSchemaObject(collection, schema);
SchemaMeta.setXmlSchemaObject(schema, step, object);
}
if (step instanceof XMLCopyStep) {
if (object instanceof XmlSchemaElement) {
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) object;
QName qname = xmlSchemaElement.getSchemaTypeName();
if (qname != null) {
XmlSchemaType xmlSchemaType = xmlSchema.getTypeByName(qname);
if (xmlSchemaType != null) {
SchemaMeta.getReferencedDatabaseObjects(xmlSchemaType).add(step);
}
}
}
}
if (object instanceof XmlSchemaParticle) {
particleChildren.add((XmlSchemaParticle) object);
} else if (object instanceof XmlSchemaAttribute) {
attributeChildren.add((XmlSchemaAttribute) object);
}
}
} else {
// re-use read only type
XmlSchemaElement elt = XmlSchemaUtils.makeDynamic(step, new XmlSchemaElement());
SchemaMeta.getReferencedDatabaseObjects(type).add(step);
SchemaMeta.setXmlSchemaObject(schema, step, elt);
elt.setName(step.getStepNodeName());
elt.setSchemaTypeName(typeQName);
particleChildren.add(elt);
}
} else // Other case
{
// doesn't generate schema, just deep walk
// System.out.println("-> do not generate schema (deep walk)");
super.walk(step);
}
// restore lists for siblings
particleChildren = parentParticleChildren;
attributeChildren = parentAttributeChildren;
} else {
// just deep walk
super.walk(databaseObject);
}
}
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
// just walk ISchemaGenerator DBO
return Step.class.isAssignableFrom(dboClass) || Sequence.class.isAssignableFrom(dboClass) || Transaction.class.isAssignableFrom(dboClass) || Connector.class.isAssignableFrom(dboClass);
}
}.init(project);
} catch (Exception e) {
throw new EngineException("midBuildSchema failed", e);
}
}
Aggregations