List of usage examples for java.util Stack peek
public synchronized E peek()
From source file:org.restcomm.connect.interpreter.rcml.Parser.java
private void text(final Stack<Tag.Builder> builders, final XMLStreamReader stream) { if (!stream.isWhiteSpace()) { // Read the text. final Tag.Builder builder = builders.peek(); final String text = stream.getText().trim(); builder.setText(text);/*from ww w . j a va 2s . com*/ } }
From source file:org.sakaiproject.calendar.impl.ExclusionRecurrenceRule.java
/** * Serialize the resource into XML, adding an element to the doc under the top of the stack element. * @param doc The DOM doc to contain the XML (or null for a string return). * @param stack The DOM elements, the top of which is the containing element of the new "resource" element. * @return The newly added element.//ww w. jav a 2s .com */ public Element toXml(Document doc, Stack stack) { // add the "rule" element to the stack'ed element Element rule = doc.createElement("ex-rule"); ((Element) stack.peek()).appendChild(rule); // set the class name - old style for CHEF 1.2.10 compatibility rule.setAttribute("class", "org.chefproject.osid.calendar.ExclusionRecurrenceRule"); // set the rule class name w/o package, for modern usage rule.setAttribute("name", "ExclusionRecurrenceRule"); // set the ranges for (Iterator iRanges = m_ranges.iterator(); iRanges.hasNext();) { TimeRange range = (TimeRange) iRanges.next(); Element rangeElement = doc.createElement("range"); rule.appendChild(rangeElement); rangeElement.setAttribute("range", range.toString()); } return rule; }
From source file:com.glaf.batch.job.BatchJob.java
public void execute(JobExecution execution) { IJobService jobService = ContextFactory.getBean("jobService"); if (execution.getSteps() != null && !execution.getSteps().isEmpty()) { List<StepExecution> steps = execution.getSteps(); Collections.sort(steps);/* ww w . j av a 2 s . c o m*/ /** * ?? */ Stack<StepExecution> stack = new Stack<StepExecution>(); for (int i = steps.size() - 1; i >= 0; i--) { stack.push(steps.get(i)); } while (!stack.empty()) { StepExecution step = stack.peek(); if (!jobService.stepExecutionCompleted(step.getJobStepKey())) { boolean success = false; int retry = 0; while (retry < 3 && !success) { retry++; try { jobService.startStepExecution(step.getJobStepKey()); if (StringUtils.isNotEmpty(step.getJobClass())) { Object object = ClassUtils.instantiateObject(step.getJobClass()); if (object instanceof IStep) { IStep ix = (IStep) object; ix.execute(step); if (jobService.stepExecutionCompleted(step.getJobStepKey())) { /** * ???? */ stack.pop(); success = true; retry = Integer.MAX_VALUE; break; } } } } catch (Exception ex) { ex.printStackTrace(); } } if (!success) { throw new RuntimeException( step.getStepKey() + " " + step.getStepName() + " execute failed."); } } } } }
From source file:com.bluexml.xforms.generator.forms.renderable.common.association.selection.multiple.RenderableSMultipleActionsAddRemove.java
@Override public Rendered render(String path, Stack<Renderable> parents, Stack<Rendered> renderedParents, boolean isInIMultRepeater) { // FIXME root path ModelElementBindSimple bindActions = ((RenderableSMultiple) parents.peek()).getBindActions(); this.selectorBindId = selector.getBindId(); this.selectorBindLabel = selector.getBindLabel(); this.selectorBindType = selector.getBindType(); RenderedXMLElement rendered = new RenderedXMLElement(); if ((getFormGenerator().isInReadOnlyMode() == false) || bean.isDisabled()) { // #1238 String repeaterId = renderedParents.peek().getOptionalData(); Element xformsElement = XFormsGenerator.createElement("div", XFormsGenerator.NAMESPACE_XHTML); String rootPath = getRootPath(renderedParents); // #1218 xformsElement.addContent(getTriggerAdd(bindActions, path, rootPath)); xformsElement.addContent(XFormsGenerator.createElement("br", XFormsGenerator.NAMESPACE_XHTML)); xformsElement.addContent(getTriggerRemove(bindActions, repeaterId)); rendered.setXformsElement(xformsElement); }// ww w . j a v a 2 s. c om return rendered; }
From source file:com.ikanow.aleph2.harvest.logstash.utils.LogstashConfigUtils.java
@SuppressWarnings("deprecation") public static ObjectNode parseLogstashConfig(String configFile, StringBuffer error) { ObjectNode tree = _mapper.createObjectNode(); // Stage 0: remove escaped "s and 's (for the purpose of the validation): // (prevents tricksies with escaped "s and then #s) // (http://stackoverflow.com/questions/5082398/regex-to-replace-single-backslashes-excluding-those-followed-by-certain-chars) configFile = configFile.replaceAll("(?<!\\\\)(?:((\\\\\\\\)*)\\\\)[\"']", "X"); //TESTED (by hand - using last 2 fields of success_2_1) // Stage 1: remove #s, and anything in quotes (for the purpose of the validation) configFile = configFile.replaceAll("(?m)(?:([\"'])(?:(?!\\1).)*\\1)", "VALUE").replaceAll("(?m)(?:#.*$)", "");//from www . j av a 2s. co m //TESTED (2_1 - including with a # inside the ""s - Event_Date -> Event_#Date) //TESTED (2_2 - various combinations of "s nested inside 's) ... yes that is a negative lookahead up there - yikes! // Stage 2: get a nested list of objects int depth = 0; int ifdepth = -1; Stack<Integer> ifStack = new Stack<Integer>(); ObjectNode inputOrFilter = null; Matcher m = _navigateLogstash.matcher(configFile); // State: String currTopLevelBlockName = null; String currSecondLevelBlockName = null; ObjectNode currSecondLevelBlock = null; while (m.find()) { boolean simpleField = false; //DEBUG //System.out.println("--DEPTH="+depth + " GROUP=" + m.group() + " IFS" + Arrays.toString(ifStack.toArray())); //System.out.println("STATES: " + currTopLevelBlockName + " AND " + currSecondLevelBlockName); if (m.group().equals("}")) { if (ifdepth == depth) { // closing an if statement ifStack.pop(); if (ifStack.isEmpty()) { ifdepth = -1; } else { ifdepth = ifStack.peek(); } } //TESTED (1_1bc, 2_1) else { // closing a processing block depth--; if (depth < 0) { // {} Mismatch error.append("{} Mismatch (})"); return null; } //TESTED (1_1abc) } } else { // new attribute! String typeName = m.group(1); if (null == typeName) { // it's an if statement or a string value typeName = m.group(4); if (null != typeName) { simpleField = true; } } else if (typeName.equalsIgnoreCase("else")) { // It's an if statement.. typeName = null; } if (null == typeName) { // if statement after all // Just keep track of ifs so we can ignore them ifStack.push(depth); ifdepth = depth; // (don't increment depth) } //TESTED (1_1bc, 2_1) else { // processing block String subTypeName = m.group(3); if (null != subTypeName) { // eg codec.multiline typeName = typeName + "." + subTypeName; } //TESTED (2_1, 2_3) if (depth == 0) { // has to be one of input/output/filter) String topLevelType = typeName.toLowerCase(); if (topLevelType.equalsIgnoreCase("input") || topLevelType.equalsIgnoreCase("filter")) { if (tree.has(topLevelType)) { error.append("Multiple input or filter blocks: " + topLevelType); return null; } //TESTED (1_3ab) else { inputOrFilter = _mapper.createObjectNode(); tree.put(topLevelType, inputOrFilter); // Store state: currTopLevelBlockName = topLevelType; } //TESTED (*) } else { if (topLevelType.equalsIgnoreCase("output")) { error.append( "Not allowed output blocks - these are appended automatically by the logstash harvester"); } else { error.append("Unrecognized processing block: " + topLevelType); } return null; } //TESTED (1_4a) } else if ((depth == 1) && (null != inputOrFilter)) { // processing blocks String subElType = typeName.toLowerCase(); // Some validation: can't include a type called "filter" anywhere if ((null != currTopLevelBlockName) && currTopLevelBlockName.equals("input")) { if (subElType.equals("filter") || subElType.endsWith(".filter")) { error.append("Not allowed sub-elements of input called 'filter' (1)"); return null; } } //TESTED (1_5b) ArrayNode subElements = (ArrayNode) inputOrFilter.get(subElType); if (null == subElements) { subElements = _mapper.createArrayNode(); inputOrFilter.put(subElType, subElements); } ObjectNode newEl = _mapper.createObjectNode(); subElements.add(newEl); // Store state: currSecondLevelBlockName = subElType; currSecondLevelBlock = newEl; } //TESTED (*) else if (depth == 2) { // attributes of processing blocks // we'll just store the field names for these and do any simple validation that was too complicated for the regexes String subSubElType = typeName.toLowerCase(); // Validation: if (null != currTopLevelBlockName) { // 1] sincedb path if (currTopLevelBlockName.equals("input") && (null != currSecondLevelBlockName)) { // (don't care what the second level block name is - no sincedb allowed) if (subSubElType.equalsIgnoreCase("sincedb_path")) { error.append("Not allowed sincedb_path in input.* block"); return null; } //TESTED (1_5a) // 2] no sub-(-sub etc)-elements of input called filter if (subSubElType.equals("filter") || subSubElType.endsWith(".filter")) { error.append("Not allowed sub-elements of input called 'filter' (2)"); return null; } //TESTED (1_5c) } } // Store in map: if (null != currSecondLevelBlock) { currSecondLevelBlock.put(subSubElType, _mapper.createObjectNode()); } } // (won't go any deeper than this) if (!simpleField) { depth++; } } } } if (0 != depth) { error.append("{} Mismatch ({)"); return null; } //TESTED (1_2a) return tree; }
From source file:org.restcomm.connect.interpreter.rcml.Parser.java
private void end(final Stack<Tag.Builder> builders, final XMLStreamReader stream) { if (builders.size() > 1) { final Tag.Builder builder = builders.pop(); final Tag tag = builder.build(); builders.peek().addChild(tag); }//from w w w .j a va 2 s .c o m }
From source file:org.apache.hadoop.hive.ql.lib.LevelOrderWalker.java
/** * Enumerate numLevels of ancestors by putting them in the stack and dispatch * the current node./*from w ww . j a v a2 s.c o m*/ * * @param nd current operator in the ancestor tree * @param level how many level of ancestors included in the stack * @param stack operator stack * @throws SemanticException */ @SuppressWarnings("unchecked") private void walk(Node nd, int level, Stack<Node> stack) throws SemanticException { List<Operator<? extends OperatorDesc>> parents = ((Operator<? extends OperatorDesc>) nd) .getParentOperators(); if (level >= numLevels || CollectionUtils.isEmpty(parents)) { dispatch(stack.peek(), stack); return; } for (Node parent : parents) { stack.add(0, parent); walk(parent, level + 1, stack); stack.remove(0); } }
From source file:com.bluexml.xforms.generator.forms.renderable.common.association.selection.multiple.RenderableSMultipleActionsOrder.java
@Override public Rendered render(String path, Stack<Renderable> parents, Stack<Rendered> renderedParents, boolean isInIMultRepeater) { RenderedXMLElement rendered = new RenderedXMLElement(); if ((getFormGenerator().isInReadOnlyMode() == false) || bean.isDisabled()) { // #1238 repeaterId = renderedParents.peek().getOptionalData(); Element xformsElement = XFormsGenerator.createElement("div", XFormsGenerator.NAMESPACE_XHTML); ModelElementBindSimple bindActions = ((RenderableSMultiple) parents.peek()).getBindActions(); String rootPath = isInIMultRepeater ? getRootPath(renderedParents) : null; xformsElement.addContent(getTriggerUp(bindActions, rootPath)); xformsElement.addContent(XFormsGenerator.createElement("br", XFormsGenerator.NAMESPACE_XHTML)); xformsElement.addContent(getTriggerDown(bindActions, rootPath)); rendered.setXformsElement(xformsElement); }//from ww w. j a v a2s .com return rendered; }
From source file:org.cvasilak.jboss.mobile.app.activities.JBossServerRootActivity.java
@Override protected void onResume() { super.onResume(); // Select proper stack ActionBar.Tab tab = getSupportActionBar().getSelectedTab(); Stack<String> backStack = backStacks.get(tab.getTag()); if (!backStack.isEmpty()) { // Restore topmost fragment (e.g. after application switch) String tag = backStack.peek(); Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); if (fragment.isDetached()) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.attach(fragment);//from w ww . jav a2 s. co m ft.commit(); } } }
From source file:com.galenframework.parser.IndentationStructureParser.java
private void processLine(Stack<IndentationNode> stack, String line, int lineNumber, String source) { StructNode newStructNode = new StructNode(line.trim()); newStructNode.setFileLineNumber(lineNumber); newStructNode.setSource(source);/*w w w .j a v a 2 s .c o m*/ int calculatedIndentation = calculateIndentation(line, lineNumber); while (calculatedIndentation <= stack.peek().indentation && stack.peek().parent != null) { stack.pop(); } StructNode parent = stack.peek().structNode; if (parent.getChildNodes() != null && parent.getChildNodes().size() > 0 && calculatedIndentation != stack.peek().childIndentation) { throw new SyntaxException(new Line(line, lineNumber), "Inconsistent indentation"); } parent.addChildNode(newStructNode); stack.peek().childIndentation = calculatedIndentation; stack.push(new IndentationNode(calculatedIndentation, newStructNode, parent)); }