Search in sources :

Example 46 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class DatabaseObjectsManager method clearCache.

public void clearCache(String projectName) {
    Object lock;
    synchronized (importLocks) {
        lock = importLocks.get(projectName);
        if (lock == null) {
            importLocks.put(projectName, lock = new Object());
        }
    }
    synchronized (lock) {
        Project project;
        synchronized (projects) {
            project = projects.remove(projectName);
        }
        RestApiManager.getInstance().removeUrlMapper(projectName);
        MobileBuilder.releaseBuilder(project);
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 47 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class DatabaseObjectsManager method symbolsProjectCheckUndefined.

public boolean symbolsProjectCheckUndefined(String projectName) throws Exception {
    final Project project = getOriginalProjectByName(projectName, false);
    if (project == null) {
        return false;
    }
    if (project.undefinedGlobalSymbols) {
        project.undefinedGlobalSymbols = false;
        new WalkHelper() {

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (databaseObject.isSymbolError()) {
                    project.undefinedGlobalSymbols = true;
                } else {
                    super.walk(databaseObject);
                }
            }
        }.init(project);
    }
    return project.undefinedGlobalSymbols;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 48 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class SchemaManager method getSchemaForProject.

public XmlSchema getSchemaForProject(final String projectName, Option... options) throws Exception {
    final boolean fullSchema = Option.fullSchema.is(options);
    final Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
    XmlSchemaCacheEntry cacheEntry = getCacheEntry(projectName);
    synchronized (cacheEntry) {
        boolean forceRebuild = needSchemaRebuild(projectName, cacheEntry.lastBuildTime);
        long lastChange = project.getLastChange();
        if (Option.noCache.not(options)) {
            if (cacheEntry != null && cacheEntry.lastChange == lastChange && !forceRebuild) {
                if (!fullSchema && cacheEntry.schema != null) {
                    // System.out.println("Schema for project \"" + projectName + "\" returned from cache");
                    return cacheEntry.schema;
                }
                if (fullSchema && cacheEntry.fullSchema != null) {
                    // System.out.println("Full schema for project \"" + projectName + "\" returned from cache");
                    return cacheEntry.fullSchema;
                }
            }
        }
        try {
            XmlSchema schema = new XmlSchemaBuilderExecutor().buildSchema(projectName, options);
            // always cache
            cacheEntry.lastChange = lastChange;
            cacheEntry.lastBuildTime = System.currentTimeMillis();
            if (fullSchema) {
                cacheEntry.fullSchema = schema;
            } else {
                cacheEntry.schema = schema;
            }
            return schema;
        } catch (Exception e) {
            System.out.println("Unabled to build schema for project \"" + projectName + "\" (see the complete error in logs)");
            Engine.logEngine.error("Unabled to build schema for project \"" + projectName + "\"", e);
            throw e;
        }
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) XmlSchema(org.apache.ws.commons.schema.XmlSchema) SAXException(org.xml.sax.SAXException)

Example 49 with Project

use of com.twinsoft.convertigo.beans.core.Project 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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaWalker(com.twinsoft.convertigo.engine.util.XmlSchemaWalker) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) NodeList(org.w3c.dom.NodeList) XmlSchemaAttributeGroup(org.apache.ws.commons.schema.XmlSchemaAttributeGroup) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) SAXException(org.xml.sax.SAXException) Project(com.twinsoft.convertigo.beans.core.Project) XmlSchemaGroup(org.apache.ws.commons.schema.XmlSchemaGroup) XmlSchema(org.apache.ws.commons.schema.XmlSchema)

Example 50 with Project

use of com.twinsoft.convertigo.beans.core.Project 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();
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) Reference(com.twinsoft.convertigo.beans.core.Reference) SAXException(org.xml.sax.SAXException)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)148 EngineException (com.twinsoft.convertigo.engine.EngineException)56 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 IOException (java.io.IOException)39 File (java.io.File)37 Sequence (com.twinsoft.convertigo.beans.core.Sequence)35 Connector (com.twinsoft.convertigo.beans.core.Connector)33 ArrayList (java.util.ArrayList)29 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)26 JSONException (org.codehaus.jettison.json.JSONException)26 Transaction (com.twinsoft.convertigo.beans.core.Transaction)24 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)22 SAXException (org.xml.sax.SAXException)21 CoreException (org.eclipse.core.runtime.CoreException)20 Step (com.twinsoft.convertigo.beans.core.Step)19 Element (org.w3c.dom.Element)19 Shell (org.eclipse.swt.widgets.Shell)18 JSONObject (org.codehaus.jettison.json.JSONObject)17 IProject (org.eclipse.core.resources.IProject)17 Cursor (org.eclipse.swt.graphics.Cursor)17