Search in sources :

Example 1 with Namespace

use of org.jdom2.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindPartialCode.

public void testFindPartialCode() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("c")).addContent(new Element("temp").setAttribute("lang", "kl_AA", xml).addContent("d"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "c", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 2 with Namespace

use of org.jdom2.Namespace in project JMRI by JMRI.

the class LocaleSelectorTest method testFindFullCode.

public void testFindFullCode() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl_KL", xml).addContent("c"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "c", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 3 with Namespace

use of org.jdom2.Namespace in project JMRI by JMRI.

the class ConnectionConfigManager method initialize.

@Override
public void initialize(Profile profile) throws InitializationException {
    if (!isInitialized(profile)) {
        log.debug("Initializing...");
        Element sharedConnections = null;
        Element perNodeConnections = null;
        try {
            sharedConnections = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(CONNECTIONS, NAMESPACE, true));
        } catch (NullPointerException ex) {
            // Normal if this is a new profile
            log.info("No connections configured.");
            log.debug("Null pointer thrown reading shared configuration.", ex);
        }
        if (sharedConnections != null) {
            try {
                perNodeConnections = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(CONNECTIONS, NAMESPACE, false));
            } catch (NullPointerException ex) {
                // Normal if the profile has not been used on this computer
                log.info("No local configuration found.");
                log.debug("Null pointer thrown reading local configuration.", ex);
            // TODO: notify user
            }
            for (Element shared : sharedConnections.getChildren(CONNECTION)) {
                Element perNode = shared;
                String className = shared.getAttributeValue(CLASS);
                // NOI18N
                String userName = shared.getAttributeValue(USER_NAME, "");
                // NOI18N
                String systemName = shared.getAttributeValue(SYSTEM_NAME, "");
                // NOI18N
                String manufacturer = shared.getAttributeValue(MANUFACTURER, "");
                log.debug("Read shared connection {}:{} ({}) class {}", userName, systemName, manufacturer, className);
                if (perNodeConnections != null) {
                    for (Element e : perNodeConnections.getChildren(CONNECTION)) {
                        if (systemName.equals(e.getAttributeValue(SYSTEM_NAME))) {
                            perNode = e;
                            className = perNode.getAttributeValue(CLASS);
                            // NOI18N
                            userName = perNode.getAttributeValue(USER_NAME, "");
                            // NOI18N
                            manufacturer = perNode.getAttributeValue(MANUFACTURER, "");
                            log.debug("Read perNode connection {}:{} ({}) class {}", userName, systemName, manufacturer, className);
                        }
                    }
                }
                try {
                    log.debug("Creating connection {}:{} ({}) class {}", userName, systemName, manufacturer, className);
                    XmlAdapter adapter = (XmlAdapter) Class.forName(className).newInstance();
                    ConnectionConfigManagerErrorHandler handler = new ConnectionConfigManagerErrorHandler();
                    adapter.setExceptionHandler(handler);
                    if (!adapter.load(shared, perNode)) {
                        log.error("Unable to create {} for {}, load returned false", className, shared);
                        // NOI18N
                        String english = Bundle.getMessage(Locale.ENGLISH, "ErrorSingleConnection", userName, systemName);
                        // NOI18N
                        String localized = Bundle.getMessage("ErrorSingleConnection", userName, systemName);
                        this.addInitializationException(profile, new InitializationException(english, localized));
                    }
                    handler.exceptions.forEach((exception) -> {
                        this.addInitializationException(profile, exception);
                    });
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
                    log.error("Unable to create {} for {}", className, shared, ex);
                    // NOI18N
                    String english = Bundle.getMessage(Locale.ENGLISH, "ErrorSingleConnection", userName, systemName);
                    // NOI18N
                    String localized = Bundle.getMessage("ErrorSingleConnection", userName, systemName);
                    this.addInitializationException(profile, new InitializationException(english, localized, ex));
                } catch (Exception ex) {
                    log.error("Unable to load {} into {}", shared, className, ex);
                    // NOI18N
                    String english = Bundle.getMessage(Locale.ENGLISH, "ErrorSingleConnection", userName, systemName);
                    // NOI18N
                    String localized = Bundle.getMessage("ErrorSingleConnection", userName, systemName);
                    this.addInitializationException(profile, new InitializationException(english, localized, ex));
                }
            }
        }
        setInitialized(profile, true);
        List<Exception> exceptions = this.getInitializationExceptions(profile);
        if (exceptions.size() == 1) {
            if (exceptions.get(0) instanceof InitializationException) {
                throw (InitializationException) exceptions.get(0);
            } else {
                throw new InitializationException(exceptions.get(0));
            }
        } else if (exceptions.size() > 1) {
            // NOI18N
            String english = Bundle.getMessage(Locale.ENGLISH, "ErrorMultipleConnections");
            // NOI18N
            String localized = Bundle.getMessage("ErrorMultipleConnections");
            throw new InitializationException(english, localized);
        }
        log.debug("Initialized...");
    }
}
Also used : Element(org.jdom2.Element) InitializationException(jmri.util.prefs.InitializationException) XmlAdapter(jmri.configurexml.XmlAdapter) InitializationException(jmri.util.prefs.InitializationException) JDOMException(org.jdom2.JDOMException)

Example 4 with Namespace

use of org.jdom2.Namespace in project JMRI by JMRI.

the class RevHistoryXml method revisionElement.

static Element revisionElement(Revision r) {
    Element rev = new Element("revision", NAMESPACE);
    Element revnumber = new Element("revnumber", NAMESPACE);
    revnumber.addContent("" + r.revnumber);
    rev.addContent(revnumber);
    Element date = new Element("date", NAMESPACE);
    date.addContent(r.date);
    rev.addContent(date);
    Element authorinitials = new Element("authorinitials", NAMESPACE);
    authorinitials.addContent(r.authorinitials);
    rev.addContent(authorinitials);
    Element revremark = new Element("revremark", NAMESPACE);
    revremark.addContent(r.revremark);
    rev.addContent(revremark);
    return rev;
}
Also used : Element(org.jdom2.Element)

Example 5 with Namespace

use of org.jdom2.Namespace in project JMRI by JMRI.

the class RevHistoryXml method loadRevision.

static void loadRevision(RevHistory r, Element e) {
    Element s;
    Namespace n = Namespace.getNamespace(NAMESPACE);
    int revnumber = 0;
    s = e.getChild("revnumber", n);
    if (s != null) {
        String c = s.getText();
        revnumber = Integer.parseInt(c);
    }
    String date = null;
    s = e.getChild("date", n);
    if (s != null) {
        date = s.getText();
    }
    String authorinitials = null;
    s = e.getChild("authorinitials", n);
    if (s != null) {
        authorinitials = s.getText();
    }
    String revremark = null;
    s = e.getChild("revremark", n);
    if (s != null) {
        revremark = s.getText();
    }
    r.addRevision(revnumber, date, authorinitials, revremark);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Element (org.jdom2.Element)31 Namespace (org.jdom2.Namespace)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)11 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)10 HashMap (java.util.HashMap)9 JDOMException (org.jdom2.JDOMException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 BranchingBehavior (de.hpi.bpt.scylla.model.configuration.BranchingBehavior)3 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)2 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)2 Resource (de.hpi.bpt.scylla.model.global.resource.Resource)2 CommonProcessElements (de.hpi.bpt.scylla.model.process.CommonProcessElements)2 Graph (de.hpi.bpt.scylla.model.process.graph.Graph)2 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 DataObjectType (de.hpi.bpt.scylla.model.process.node.DataObjectType)2