List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:cc.warlock.rcp.stormfront.StormFrontGameViewConfiguration.java
License:Open Source License
public void parseElement(Element element) { profileViewMappings.put(element.attributeValue("viewId"), element.attributeValue("profileId")); }
From source file:ch.epfl.codimsd.qep.QEPFactory.java
License:Open Source License
/** * Build a hashtable containing operator opNode structures, according to what is defined * in the query execution plan./* ww w . jav a2s. c o m*/ * * @param document dom4j document of the QEP. * @return the opnode hashtable. * * @throws QEPInitializationException */ private static Hashtable<String, OpNode> buildOpNodeTable(Document document) throws QEPInitializationException { Hashtable<String, OpNode> operatorList = new Hashtable<String, OpNode>(); /*List listMod = document.selectNodes( "//qep:Module" ); Element modElement = (Element)listMod; String[] stringType = modElement.attributeValue("type").split(","); int numberOfIterations = Integer.parseInt(modElement.attributeValue("numberOfIterations")); */ List list = document.selectNodes("//op:Operator"); Iterator itt = list.iterator(); while (itt.hasNext()) { Element opElement = (Element) itt.next(); // Get operator ID from xml QEP int opID = Integer.parseInt(opElement.attributeValue("id")); // Build producers from xml QEP String[] stringProducers = opElement.attributeValue("prod").split(","); int[] producers = new int[stringProducers.length]; for (int i = 0; i < stringProducers.length; i++) producers[i] = Integer.parseInt(stringProducers[i]); // Get operator type String type = opElement.attributeValue("type"); // Get parallelizable information String parallelAtt = opElement.attributeValue("parallelizable"); boolean parallelizable = false; if (parallelAtt != null) { if (parallelAtt.equalsIgnoreCase("true")) parallelizable = true; } // Get operator name from xml QEP Iterator opItt = opElement.elementIterator(); Node xmlOpNode = (Node) opItt.next(); String opName = xmlOpNode.getText(); // Build operator parameters int i = 0; String paramString = ""; String[] params = null; if (opItt.hasNext()) { Element parameterList = (Element) opItt.next(); Iterator paramItt = parameterList.elementIterator(); while (paramItt.hasNext()) { Node parameter = (Node) paramItt.next(); paramString = paramString + parameter.getText() + ";"; i++; } params = new String[i]; params = paramString.split(";"); } // Build operator timeStamp long idTimeStamp = System.currentTimeMillis(); // Build OpNode object for this operator OpNode opNode = new OpNode(opID, opName, producers, params, idTimeStamp + "", type, parallelizable); // Build DataSources if necessary if (opNode.getType() != null) { if (opNode.getType().equalsIgnoreCase("Scan")) { // Write the number of tuples in the BlackBoard as specified in the QEP // This operation is not done in remote nodes as G2N has already been called String numberOfTuples = opElement.attributeValue(Constants.QEP_SCAN_NUMBER_TUPLES); // In remote QEP this parameter is null, so we dont write again the field numberOfTuples // used in the DiscoveryOptimizer when it calls G2N if (numberOfTuples != null) { if (!numberOfTuples.equalsIgnoreCase("?")) { BlackBoard bl = BlackBoard.getBlackBoard(); bl.put(Constants.QEP_SCAN_NUMBER_TUPLES, numberOfTuples); } } try { DataSourceManager dsManager = DataSourceManager.getDataSourceManager(); dsManager.createDataSources(opNode); } catch (Exception ex) { throw new QEPInitializationException( "Error creating the " + "datasource : " + ex.getMessage()); } } } // Put OpNode in the QEP operatorList.put(opID + "", opNode); } return operatorList; }
From source file:ch.javasoft.metabolic.compress.config.MetabolicCompressionConfig.java
License:BSD License
/** * Returns the preprocess-duplicate-genes flag, or false if no such flag * is configured//from w w w.j a v a 2 s . c o m * * @return the preprocess-duplicate-genes flag */ public boolean getPreprocessDuplicateGenes() { Element el = mRoot.element(XmlElement.preprocess_duplicate_genes.getXmlName()); return el == null ? false : Boolean.parseBoolean(el.attributeValue(XmlAttribute.value.getXmlName())); }
From source file:ch.javasoft.metabolic.compress.config.MetabolicCompressionConfig.java
License:BSD License
/** * Returns the compression methods derived from the xml configuration, or * {@link CompressionMethod#NONE} if no methods are specified. * /*from w w w . jav a 2 s.c om*/ * @return the compression methods * @throws XmlConfigException if a method cannot be parsed */ public CompressionMethod[] getCompressionMethods() throws XmlConfigException { Element elMethods = mRoot.element(XmlElement.compression_methods.getXmlName()); if (elMethods == null) return CompressionMethod.NONE; Iterator it = elMethods.elementIterator(XmlElement.method.getXmlName()); List<CompressionMethod> cmpMethods = new ArrayList<CompressionMethod>(); while (it.hasNext()) { Element elMethod = (Element) it.next(); String methodName = elMethod.attributeValue(XmlAttribute.name.getXmlName()); String strOn = elMethod.attributeValue(XmlAttribute.value.getXmlName()); boolean on = strOn == null ? true : Boolean.parseBoolean(strOn); if (on) { try { cmpMethods.add(CompressionMethod.valueOf(methodName)); } catch (Exception ex) { throw new XmlConfigException("invalid compression method: " + methodName, elMethod); } } } CompressionMethod[] res = new CompressionMethod[cmpMethods.size()]; return cmpMethods.toArray(res); }
From source file:ch.javasoft.metabolic.efm.config.DistributedConfig.java
License:BSD License
/** * Constructor for <code>DistributedConfig</code> with xml configuration. * The configuration element looks like this: * <pre>/*from w ww. jav a 2 s .com*/ <distribute partition="65536"><!--use power of 4--> <nodes vmargs = "-Xmx2500M" level="OFF"> <node name="node01.cluster.lan" vmargs="-Xmx1G" level="INFO"/> <node name="node02.cluster.lan"/> <node name="node03.cluster.lan"/> <node name="node04.cluster.lan"/> </nodes> <command value="/usr/bin/rsh [nodename] cd [workdir] ; /usr/bin/java [vmargs] -cp [classpath] [class] [args]"/> </distribute> * </pre> * @param elDistribute the <tt>distribute</tt> xml element * @throws XmlConfigException if an xml configuration exception occurs, * for instance due to invalid xml structure */ public DistributedConfig(Element elDistribute) throws XmlConfigException { final Element elNodes = XmlUtil.getRequiredSingleChildElement(elDistribute, XmlElement.nodes); final Element elCommand = XmlUtil.getRequiredSingleChildElement(elDistribute, XmlElement.command); final String sPartition = XmlUtil.getRequiredAttributeValue(elDistribute, XmlAttribute.partition); final String sThreshold = XmlUtil.getOptionalAttributeValue(elDistribute, XmlAttribute.candidate_threshold, "0"); final List<String> nodeNames = new ArrayList<String>(); final List<String> vmArgs = new ArrayList<String>(); final List<String> logLevels = new ArrayList<String>(); @SuppressWarnings("unchecked") final Iterator<Element> nodeIt = elNodes.elementIterator(XmlElement.node.getXmlName()); while (nodeIt.hasNext()) { final Element elNode = nodeIt.next(); nodeNames.add(XmlUtil.getRequiredAttributeValue(elNode, XmlAttribute.name)); //vmargs String vmargs = elNode.attributeValue(XmlAttribute.vmargs.getXmlName()); if (vmargs == null) vmargs = elNodes.attributeValue(XmlAttribute.vmargs.getXmlName()); vmArgs.add(vmargs); //log level String logLevel = elNode.attributeValue(XmlAttribute.level.getXmlName()); if (logLevel == null) logLevel = elNodes.attributeValue(XmlAttribute.level.getXmlName()); if (logLevel == null) logLevel = Level.INFO.getName(); logLevels.add(logLevel); } this.nodeNames = Collections.unmodifiableList(nodeNames); this.vmArgs = Collections.unmodifiableList(vmArgs); this.logLevels = Collections.unmodifiableList(logLevels); this.command = XmlUtil.getRequiredAttributeValue(elCommand, XmlAttribute.value); try { this.partition = Integer.parseInt(sPartition); } catch (Exception e) { throw new XmlConfigException( "cannot parse distribute attribute 'partitions': " + sPartition + ", e=" + e, elDistribute, e); } try { this.candidateThreashold = Long.parseLong(sThreshold); } catch (Exception e) { throw new XmlConfigException( "cannot parse distribute attribute 'candidate-threshold': " + sThreshold + ", e=" + e, elDistribute, e); } //check partition, must be power of 4 int cur = 1; while (partition / cur > 1) { cur <<= 2;// *= 4 } if (partition != cur) { throw new IllegalArgumentException("distributed partition must be a power of 4, but is " + partition); } }
From source file:ch.javasoft.metabolic.generate.ConfiguredGenerator.java
License:BSD License
public static void generate(Element metabolicParseElement, MetabolicNetwork net) throws XmlConfigException, IOException { XmlUtil.checkExpectedElementName(metabolicParseElement, XmlElements.metabolic_generate); Element parseElement = XmlUtil.getRequiredSingleChildElement(metabolicParseElement, XmlElements.generate); String type = parseElement.attributeValue(XmlAttributes.type.getXmlName()); GenerateType gType = GenerateType.find(type); if (gType == null) { throw new XmlConfigException("unknown generate type '" + type + "'", parseElement); }//from w w w .j ava 2s. co m switch (gType) { case sbml: generateSbml(parseElement, net); return; case matlab: generateMatlab(parseElement, net); return; default: //should not happen throw new XmlConfigException("internal error: unknown parse type " + gType, parseElement); } }
From source file:ch.javasoft.metabolic.parse.ConfiguredParser.java
License:BSD License
public static MetabolicNetwork parse(Element metabolicParseElement) throws XmlConfigException, IOException { XmlUtil.checkExpectedElementName(metabolicParseElement, XmlElements.metabolic_parse); Element parseElement = XmlUtil.getRequiredSingleChildElement(metabolicParseElement, XmlElements.parse); String type = parseElement.attributeValue(XmlAttributes.type.getXmlName()); ParseType pType = ParseType.find(type); if (pType == null) { throw new XmlConfigException("unknown parse type '" + type + "'", parseElement); }// w w w.j a va2s .c om switch (pType) { case flux_analyzer: return parseFluxAnalyzer(parseElement); case reaction_list: return parseReactionList(parseElement); case reaction_excel: return parseReactionExcel(parseElement); case stoichiometry: return parseStoichiometry(parseElement); case sbml: return parseSbml(parseElement); case junit: return parseJUnit(parseElement); default: //should not happen throw new XmlConfigException("internal error: unknown parse type " + pType, parseElement); } }
From source file:ch.javasoft.metabolic.parse.ConfiguredParser.java
License:BSD License
/** * Parses://from w w w .j ava 2s . c o m * * <pre> <external pattern="xt.*"/> * </pre> */ private static Pattern parseExternalPattern(Element parseElement) throws XmlConfigException { Element external = parseElement.element(XmlElements.external.getXmlName()); Pattern externalPat = null; if (external != null) { String patString = external.attributeValue(XmlAttributes.pattern.getXmlName()); try { externalPat = Pattern.compile(patString); } catch (Exception ex) { throw new XmlConfigException("cannot parse external pattern '" + patString + "', e=" + ex, external, ex); } } return externalPat; }
From source file:ch.javasoft.metabolic.parse.SbmlParser.java
License:BSD License
private Map<String, CompartmentMetabolite> parseMetabolites(Element elMetas, Map<Annotateable, Map<String, String>> annotations) throws DocumentException { Map<String, CompartmentMetabolite> metas = new LinkedHashMap<String, CompartmentMetabolite>(); Iterator it = elMetas.elementIterator(ELEMENT_METABOLITE); while (it.hasNext()) { Element el = (Element) it.next(); String metaId = el.attributeValue(ATTRIBUTE_ID); String metaName = el.attributeValue(ATTRIBUTE_NAME); String compartment = el.attributeValue(ATTRIBUTE_COMPARTMENT); CompartmentMetabolite meta = metaName == null ? new CompartmentMetabolite(metaId, compartment) : new CompartmentMetabolite(metaId, metaName, compartment); if (metas.put(metaId, meta) != null) { throw new DocumentException("duplicate metabolite: " + metaId); }//ww w . ja va 2 s . c o m parseAnnotations(el, meta, annotations); } return metas; }
From source file:ch.javasoft.metabolic.parse.SbmlParser.java
License:BSD License
private static Set<CompartmentReaction> parseReactions(Element elReacts, Map<String, CompartmentMetabolite> metas, Map<Annotateable, Map<String, String>> annotations) throws DocumentException { final Set<CompartmentReaction> reacts = new LinkedHashSet<CompartmentReaction>(); final Iterator<Element> it = elementIterator(elReacts, ELEMENT_REACTION); while (it.hasNext()) { boolean any = false; final Element el = it.next(); String reactId = el.attributeValue(ATTRIBUTE_ID); String reactName = el.attributeValue(ATTRIBUTE_NAME); boolean reversible = !Boolean.FALSE.toString() .equalsIgnoreCase(el.attributeValue(ATTRIBUTE_REVERSIBLE));//default is true final List<CompartmentMetaboliteRatio> ratios = new ArrayList<CompartmentMetaboliteRatio>(); final Iterator<Element> eduIt = elementIterator(el.element(ELEMENT_EDUCTS), ELEMENT_EDUCT); any |= eduIt.hasNext();/*from w ww .j a v a 2 s . c o m*/ while (eduIt.hasNext()) { Element edu = (Element) eduIt.next(); CompartmentMetaboliteRatio ratio = parseMetaboliteRatio(el, edu, metas, true /*educt*/); ratios.add(ratio); } final Iterator<Element> proIt = elementIterator(el.element(ELEMENT_PRODUCTS), ELEMENT_PRODUCT); any |= proIt.hasNext(); while (proIt.hasNext()) { final Element pro = proIt.next(); CompartmentMetaboliteRatio ratio = parseMetaboliteRatio(el, pro, metas, false /*educt*/); ratios.add(ratio); } if (!any) { throw new DocumentException( "reaction has neither educts nor products: " + reactId + "/" + reactName); } final CompartmentReaction reac = new CompartmentReaction(reactId, reactName, ratios, reversible); if (!reacts.add(reac)) { throw new DocumentException("duplicate reaction: " + reactId); } parseAnnotations(el, reac, annotations); } return reacts; }