Search in sources :

Example 6 with ExtensionModule

use of com.centurylink.mdw.plugin.project.extensions.ExtensionModule in project mdw-designer by CenturyLinkCloud.

the class ProjectPersist method fromStream.

public WorkflowProject fromStream(InputStream inStream) {
    InputSource src = new InputSource(inStream);
    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
    try {
        // hold these until everything else is parsed
        final Map<String, Map<String, String>> extensionMods = new HashMap<String, Map<String, String>>();
        workflowProject.setDefaultFilesToIgnoreDuringUpdate();
        SAXParser parser = parserFactory.newSAXParser();
        parser.parse(src, new DefaultHandler() {

            // attributes for workflow project
            public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
                if (qName.equals("mdw-workflow")) {
                // outer element
                } else if (qName.equals("sourceProject")) {
                    workflowProject.setSourceProjectName(attrs.getValue("name"));
                    workflowProject.setAuthor(attrs.getValue("author"));
                    workflowProject.setProduction(Boolean.parseBoolean(attrs.getValue("production")));
                } else if (qName.equals("mdwFramework")) {
                    workflowProject.setMdwVersion(attrs.getValue("version"));
                } else if (qName.equals("webLogic")) {
                    workflowProject.getServerSettings().setHost(attrs.getValue("host"));
                    workflowProject.getServerSettings().setPort(Integer.parseInt(attrs.getValue("port")));
                } else if (qName.equals("server")) {
                    String container = attrs.getValue("container");
                    if (container != null)
                        workflowProject.getServerSettings().setContainerType(ContainerType.valueOf(container));
                    workflowProject.getServerSettings().setHost(attrs.getValue("host"));
                    workflowProject.getServerSettings().setPort(Integer.parseInt(attrs.getValue("port")));
                    workflowProject.setWebContextRoot(attrs.getValue("contextRoot"));
                } else if (qName.equals("database")) {
                    workflowProject.getMdwDataSource().setJdbcUrlWithCredentials(attrs.getValue("jdbcUrl"));
                    workflowProject.getMdwDataSource().setSchemaOwner(attrs.getValue("schemaOwner"));
                } else if (qName.equals("repository")) {
                    workflowProject.getMdwVcsRepository().setProvider(attrs.getValue("provider"));
                    String repoUrl = attrs.getValue("url");
                    if (repoUrl != null && repoUrl.trim().length() > 0)
                        workflowProject.getMdwVcsRepository().setRepositoryUrlWithCredentials(repoUrl);
                    String branch = attrs.getValue("branch");
                    if (branch != null && branch.trim().length() > 0)
                        workflowProject.getMdwVcsRepository().setBranch(branch);
                    String localPath = attrs.getValue("localPath");
                    if (localPath == null || localPath.trim().length() == 0)
                        // compatibility
                        localPath = attrs.getValue("localDir");
                    if (localPath != null && localPath.trim().length() > 0)
                        workflowProject.getMdwVcsRepository().setLocalPath(localPath);
                    String pkgPrefixes = attrs.getValue("pkgPrefixes");
                    if (pkgPrefixes != null && pkgPrefixes.trim().length() > 0)
                        workflowProject.getMdwVcsRepository().setPkgPrefixes(PluginUtil.arrayToList(pkgPrefixes.split("\\s*,\\s*")));
                } else if (qName.equals("filesToIgnore")) {
                    workflowProject.setFilesToIgnoreDuringUpdate(attrs.getValue("duringUpdate"));
                } else {
                    // extension modules (need fully parsed workflowProject,
                    // so save)
                    Map<String, String> attrMap = new HashMap<String, String>();
                    for (int i = 0; i < attrs.getLength(); i++) attrMap.put(attrs.getQName(i), attrs.getValue(i));
                    extensionMods.put(qName, attrMap);
                }
            }
        });
        inStream.close();
        // null
        workflowProject.setRemote(workflowProject.getMdwVersion() == null);
        // remote
        if ("Git".equals(workflowProject.getMdwVcsRepository().getProvider()))
            workflowProject.setPersistType(PersistType.Git);
        else if (workflowProject.getMdwDataSource().getJdbcUrl() != null)
            workflowProject.setPersistType(PersistType.Database);
        else
            workflowProject.setPersistType(PersistType.None);
        if (!workflowProject.isRemote()) {
            // process extensions
            for (ExtensionModule extension : WorkflowProjectManager.getInstance().getAvailableExtensions(workflowProject)) {
                for (String extensionName : extensionMods.keySet()) extension.readConfigElement(extensionName, extensionMods.get(extensionName), workflowProject);
            }
        } else {
            // undo defaults
            workflowProject.setFilesToIgnoreDuringUpdate(null);
        }
    } catch (Exception ex) {
        PluginMessages.log(ex);
        return null;
    }
    return workflowProject;
}
Also used : InputSource(org.xml.sax.InputSource) HashMap(java.util.HashMap) Attributes(org.xml.sax.Attributes) ExtensionModule(com.centurylink.mdw.plugin.project.extensions.ExtensionModule) CoreException(org.eclipse.core.runtime.CoreException) GeneralSecurityException(java.security.GeneralSecurityException) UnknownHostException(java.net.UnknownHostException) SAXException(org.xml.sax.SAXException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) SAXParser(javax.xml.parsers.SAXParser) HashMap(java.util.HashMap) Map(java.util.Map) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

ExtensionModule (com.centurylink.mdw.plugin.project.extensions.ExtensionModule)6 ExtensionModulesTable (com.centurylink.mdw.plugin.project.extensions.ExtensionModulesTable)2 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 Composite (org.eclipse.swt.widgets.Composite)2 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)1 DiscoveryException (com.centurylink.mdw.plugin.designer.DiscoveryException)1 ValueChangeListener (com.centurylink.mdw.plugin.designer.properties.editor.ValueChangeListener)1 ExtensionModulesUpdater (com.centurylink.mdw.plugin.project.assembly.ExtensionModulesUpdater)1 ServerSettings (com.centurylink.mdw.plugin.project.model.ServerSettings)1 VcsRepository (com.centurylink.mdw.plugin.project.model.VcsRepository)1 UnknownHostException (java.net.UnknownHostException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 XmlException (org.apache.xmlbeans.XmlException)1 ResourceException (org.eclipse.core.internal.resources.ResourceException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1