Example usage for java.util Stack pop

List of usage examples for java.util Stack pop

Introduction

In this page you can find the example usage for java.util Stack pop.

Prototype

public synchronized E pop() 

Source Link

Document

Removes the object at the top of this stack and returns that object as the value of this function.

Usage

From source file:jp.terasoluna.fw.batch.util.BatchUtil.java

/**
 * ??//from ww  w.j  av a 2  s. co m
 * @param tranMap 
 * @param statMap 
 * @param log 
 */
public static void commitTransactions(Map<?, ?> tranMap, Map<String, TransactionStatus> statMap, Log log) {

    Set<Entry<String, TransactionStatus>> statSet = statMap.entrySet();

    if (statSet.isEmpty()) {
        return;
    }

    Stack<Entry<String, TransactionStatus>> stack = new Stack<Entry<String, TransactionStatus>>();
    for (Entry<String, TransactionStatus> stat : statSet) {
        stack.push(stat);
    }

    while (!stack.isEmpty()) {
        // ???
        Entry<String, TransactionStatus> statEntry = stack.pop();
        String key = statEntry.getKey();
        TransactionStatus trnStat = statEntry.getValue();
        if (trnStat == null) {
            continue;
        }

        // ???
        Object ptmObj = tranMap.get(key);
        if (ptmObj == null || !(ptmObj instanceof PlatformTransactionManager)) {
            continue;
        }
        PlatformTransactionManager ptm = (PlatformTransactionManager) ptmObj;

        if (log != null && log.isDebugEnabled()) {
            logDebug(log, LogId.DAL025038, trnStat);
        }
        // 
        ptm.commit(trnStat);
    }
}

From source file:maltcms.ui.fileHandles.properties.tools.SceneExporter.java

private void unlock(Stack<FileLock> s) {
    FileLock fl = s.pop();
    fl.releaseLock();
}

From source file:com.groupon.jenkins.buildtype.util.shell.ShellCommands.java

public ShellCommands addAll(final Stack<String> commands) {
    while (!commands.empty()) {
        this.commands.add(commands.pop());
    }//  w w  w.  j a v  a2s  . c om
    return this;
}

From source file:jp.terasoluna.fw.batch.util.BatchUtil.java

/**
 * ???//from   ww  w  .  j  a  v a2 s  .  c o m
 * @param tranMap PlatformTransactionManager
 * @param statMap TransactionStatus
 * @param log Log
 * @return ???PlatformTransactionManager?????????true??
 */
public static boolean endTransactions(Map<?, ?> tranMap, Map<String, TransactionStatus> statMap, Log log) {
    boolean isNormal = true;

    Set<Entry<String, TransactionStatus>> statSet = statMap.entrySet();

    if (statSet == null || statSet.isEmpty()) {
        return isNormal;
    }

    Stack<Entry<String, TransactionStatus>> stack = new Stack<Entry<String, TransactionStatus>>();
    for (Entry<String, TransactionStatus> stat : statSet) {
        stack.push(stat);
    }

    while (!stack.isEmpty()) {
        // ???
        Entry<String, TransactionStatus> statEntry = stack.pop();
        String key = statEntry.getKey();
        TransactionStatus trnStat = statEntry.getValue();

        if (trnStat == null) {
            continue;
        }

        // ???
        Object ptmObj = tranMap.get(key);
        if (ptmObj == null || !(ptmObj instanceof PlatformTransactionManager)) {
            continue;
        }
        PlatformTransactionManager ptm = (PlatformTransactionManager) ptmObj;

        // ??????
        if (trnStat.isCompleted()) {
            continue;
        }

        if (log != null && log.isDebugEnabled()) {
            logDebug(log, LogId.DAL025041, trnStat);
        }

        // ?
        try {
            ptm.rollback(trnStat);
        } catch (TransactionException e) {
            if (log != null && log.isErrorEnabled()) {
                logError(log, LogId.EAL025045, e, key);
            }
            isNormal = false;
            // ????????
        }

        if (log != null && log.isDebugEnabled()) {
            logDebug(log, LogId.DAL025041, trnStat);
        }
    }
    return isNormal;
}

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)(?:#.*$)",
            "");//  w ww .  j  a  v a  2 s.c  o  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:maltcms.ui.fileHandles.properties.tools.SceneExporter.java

private void unlockAll(Stack<FileLock> s) {
    while (!s.isEmpty()) {
        s.pop().releaseLock();
    }
}

From source file:Main.java

/**
 * Returns the XPath to retrieve targetElement from rootElement. rootElement may be null, in this case the XPath starts with and includes
 * the farthest non-null ancestor of targetElement. If rootElement == targetElement, an empty string
 * is returned. /*from w w  w .j  av a2 s.  c  o m*/
 * @param includeElementIndex Indicates if the element indices in the form elementName[n] should
 * be included in the XPath. 
 * @param namespacesMap Maps namespace ids to namespace URIs.
 */
public static String getXPath(Element rootElement, Element targetElement, boolean includeElementIndex,
        Map<String, String> namespacesMap) {
    Stack<Element> elementPath = new Stack<Element>();

    // since we need the mapping the other way round, we invert the map
    Map<String, String> namespaceUriToIdMap = new HashMap<String, String>();
    for (Entry<String, String> entry : namespacesMap.entrySet()) {
        namespaceUriToIdMap.put(entry.getValue(), entry.getKey());
    }

    // recursively find all ancestors of targetElement (up to, not including, rootElement) 
    {
        Element currentElement = targetElement;
        while (currentElement != null && currentElement != rootElement) {
            elementPath.push(currentElement);
            Node parent = currentElement.getParentNode();
            if (parent instanceof Element) {
                currentElement = (Element) currentElement.getParentNode();
            } else {
                currentElement = null;
            }
        }
    }

    // construct XPath
    StringBuilder builder = new StringBuilder();
    while (!elementPath.isEmpty()) {
        Element currentElement = elementPath.pop();
        if (builder.length() > 0) {
            // don't include "/" at the beginning
            builder.append("/");
        }

        if (namespacesMap != null) {
            String namespace = currentElement.getNamespaceURI();
            if (namespace != null) {
                namespace = namespaceUriToIdMap.get(namespace);
                builder.append(namespace);
                builder.append(":");
            }
        }
        builder.append(currentElement.getLocalName());
        if (includeElementIndex) {
            int index = getElementIndex(currentElement);
            builder.append("[");
            builder.append(index);
            builder.append("]");
        }
    }
    return builder.toString();
}

From source file:org.apache.synapse.FaultHandler.java

public void handleFault(MessageContext synCtx) {

    boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
    boolean traceOrDebugOn = traceOn || log.isDebugEnabled();

    if (traceOrDebugOn) {
        traceOrDebugWarn(traceOn, "FaultHandler executing impl: " + this.getClass().getName());
    }/*from   w ww . java2  s . c  om*/

    try {
        synCtx.getServiceLog().info("FaultHandler executing impl: " + this.getClass().getName());
        onFault(synCtx);

    } catch (SynapseException e) {

        Stack faultStack = synCtx.getFaultStack();
        if (faultStack != null && !faultStack.isEmpty()) {
            ((FaultHandler) faultStack.pop()).handleFault(synCtx);
        }
    }
}

From source file:org.apache.synapse.FaultHandler.java

/**
 * Extract and set ERROR_MESSAGE and ERROR_DETAIL to the message context from the Exception
 * @param synCtx the message context//  ww  w  .  j  a  v  a 2 s.c  o m
 * @param e the exception encountered
 */
public void handleFault(MessageContext synCtx, Exception e) {

    boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
    boolean traceOrDebugOn = traceOn || log.isDebugEnabled();

    if (e != null && synCtx.getProperty(SynapseConstants.ERROR_CODE) == null) {
        synCtx.setProperty(SynapseConstants.ERROR_CODE, SynapseConstants.DEFAULT_ERROR);
        // use only the first line as the message for multiline exception messages (Axis2 has these)
        synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, e.getMessage().split("\n")[0]);
        synCtx.setProperty(SynapseConstants.ERROR_DETAIL, getStackTrace(e));
        synCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, e);
    }

    if (traceOrDebugOn) {
        traceOrDebugWarn(traceOn, "ERROR_CODE : " + synCtx.getProperty(SynapseConstants.ERROR_CODE));
        traceOrDebugWarn(traceOn, "ERROR_MESSAGE : " + synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
        traceOrDebugWarn(traceOn, "ERROR_DETAIL : " + synCtx.getProperty(SynapseConstants.ERROR_DETAIL));
        traceOrDebugWarn(traceOn, "ERROR_EXCEPTION : " + synCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
    }

    synCtx.getServiceLog().warn("ERROR_CODE : " + synCtx.getProperty(SynapseConstants.ERROR_CODE)
            + " ERROR_MESSAGE : " + synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));

    try {
        if (traceOrDebugOn) {
            traceOrDebugWarn(traceOn, "FaultHandler : " + this);
        }
        onFault(synCtx);

    } catch (SynapseException se) {

        Stack faultStack = synCtx.getFaultStack();
        if (faultStack != null && !faultStack.isEmpty()) {
            ((FaultHandler) faultStack.pop()).handleFault(synCtx, se);
        } else {
            throw new RuntimeException(se);
        }
    }
}

From source file:com.amalto.core.history.UniqueIdTransformer.java

private void _addIds(org.w3c.dom.Document document, Element element, Stack<Integer> levels) {
    NamedNodeMap attributes = element.getAttributes();
    Attr id = document.createAttribute(ID_ATTRIBUTE_NAME);

    int thisElementId = levels.pop() + 1;
    StringBuilder builder;/*  ww  w  .j ava  2  s .  c om*/
    {
        builder = new StringBuilder();
        for (Integer level : levels) {
            builder.append(level);
        }
    }
    String prefix = builder.toString().isEmpty() ? StringUtils.EMPTY : builder.toString() + '-';
    id.setValue(prefix + element.getNodeName() + '-' + thisElementId);
    attributes.setNamedItem(id);

    levels.push(thisElementId);
    {
        levels.push(0);
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element child = (Element) children.item(i);
                _addIds(document, child, levels);
            }
        }
        levels.pop();
    }
}