Example usage for java.util Stack peek

List of usage examples for java.util Stack peek

Introduction

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

Prototype

public synchronized E peek() 

Source Link

Document

Looks at the object at the top of this stack without removing it from the stack.

Usage

From source file:com.datastax.hectorjpa.spring.ConsistencyLevelAspect.java

/**
 * Validates any method that has the valid annotation on it and is wired as
 * a spring service/*from   w ww. java2s  .c  o  m*/
 * 
 * @param jp
 * @throws Throwable
 */
@Around("@annotation(com.datastax.hectorjpa.spring.Consistency)")
public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable {

    logger.debug("Invoking before advice for @Consistency annotation.  Target object is {} on method {}",
            pjp.getTarget(), pjp.getSignature());

    MethodSignature sig = (MethodSignature) pjp.getSignature();

    Object[] args = pjp.getArgs();

    Method signatureMethod = sig.getMethod();

    Class<?>[] signatureTypes = signatureMethod.getParameterTypes();

    // we do this because we want to get the best match from the child
    // classes
    Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length];

    for (int i = 0; i < signatureTypes.length; i++) {

        if (args[i] != null) {
            runtimeArgs[i] = args[i].getClass();
        } else {
            runtimeArgs[i] = signatureTypes[i];
        }
    }

    Class<?> runtimeClass = pjp.getTarget().getClass();

    // check if this is annotated, if not proceed and execute it

    HConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs);

    if (level == null) {
        return pjp.proceed(args);
    }

    Stack<HConsistencyLevel> stack = threadStack.get();

    stack.push(level);
    JPAConsistency.set(level);

    Object result = null;

    try {
        result = pjp.proceed(args);
    } finally {
        stack.pop();

        if (stack.size() > 0) {
            JPAConsistency.set(stack.peek());
        } else {
            JPAConsistency.remove();
        }

    }

    return result;
}

From source file:mml.handler.get.MMLGetMMLHandler.java

/**
 * Are we in a section governed by a line format?
 * @param stack the tag stack// ww w . java2  s .c  o m
 * @return true if it is true
 */
boolean isLineFormat(Stack<EndTag> stack) {
    if (!stack.isEmpty()) {
        EndTag top = stack.peek();
        if (top != null) {
            String prop = (String) top.def.get("prop");
            return lineFormats.contains(prop);
        } else
            return false;
    } else
        return false;
}

From source file:org.apache.synapse.mediators.GetPropertyFunction.java

/**
 * Returns the string value of the property using arg one as key and arg two as scope
 *
 * @param scopeObject scope will decide from where property will be picked up from
 *        i.e. axis2, transport, default/synapse
 * @param keyObject the key of the property
 * @param navigator object model which can be used for navigation around
 * @param dateformat The dateformat that need to convert
 * @return The String value of property using arg one as key and arg two as scope
 *//*from   w  w  w  .  ja v  a2  s. c  om*/
public Object evaluate(Object scopeObject, Object keyObject, Object dateformat, Navigator navigator) {

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

    String scope = StringFunction.evaluate(scopeObject, navigator);
    String key = StringFunction.evaluate(keyObject, navigator);

    if (key == null || "".equals(key)) {
        if (traceOrDebugOn) {
            traceOrDebug(traceOn, "property-name should be provided when executing synapse:get-property"
                    + "(scope,prop-name) or synapse:get-property(prop-name) Xpath function");
        }
        return NULL_STRING;
    }

    //Irrespective of the scope ,if the dateformat has provided ,
    // should return the Date according to the provided format

    if (SynapseConstants.SYSTEM_DATE.equals(key)) {
        if (dateformat != null) {
            Format formatter = new SimpleDateFormat(dateformat.toString());
            return formatter.format(new java.util.Date());
        } else {
            Format formatter = new SimpleDateFormat();
            return formatter.format(new java.util.Date());
        }
    }

    //return the current system time as a string , don't care scope
    if (SynapseConstants.SYSTEM_TIME.equals(key)) {

        return Long.toString(System.currentTimeMillis());
    }

    if (XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {

        if (SynapseConstants.HEADER_TO.equals(key)) {
            EndpointReference toEPR = synCtx.getTo();
            if (toEPR != null) {
                return toEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_FROM.equals(key)) {
            EndpointReference fromEPR = synCtx.getFrom();
            if (fromEPR != null) {
                return fromEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_ACTION.equals(key)) {
            String wsaAction = synCtx.getWSAAction();
            if (wsaAction != null) {
                return wsaAction;
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_FAULT.equals(key)) {
            EndpointReference faultEPR = synCtx.getFaultTo();
            if (faultEPR != null) {
                return faultEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_REPLY_TO.equals(key)) {
            EndpointReference replyToEPR = synCtx.getReplyTo();
            if (replyToEPR != null) {
                return replyToEPR.getAddress();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_RELATES_TO.equals(key)) {
            RelatesTo relatesTo = synCtx.getRelatesTo();
            if (relatesTo != null) {
                return relatesTo.getValue();
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.HEADER_MESSAGE_ID.equals(key)) {
            String messageID = synCtx.getMessageID();
            if (messageID != null) {
                return messageID;
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.PROPERTY_FAULT.equals(key)) {
            if (synCtx.getEnvelope().hasFault()) {
                return SynapseConstants.TRUE;
            } else if (synCtx instanceof Axis2MessageContext) {
                org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
                        .getAxis2MessageContext();
                if (axis2MessageContext.getProperty(BaseConstants.FAULT_MESSAGE) != null
                        && SynapseConstants.TRUE
                                .equals(axis2MessageContext.getProperty(BaseConstants.FAULT_MESSAGE))) {
                    return SynapseConstants.TRUE;
                }
            } else {
                return NULL_STRING;
            }
        } else if (SynapseConstants.PROPERTY_MESSAGE_FORMAT.equals(key)) {
            if (synCtx.isDoingPOX())
                return SynapseConstants.FORMAT_POX;
            else if (synCtx.isDoingGET())
                return SynapseConstants.FORMAT_GET;
            else if (synCtx.isSOAP11())
                return SynapseConstants.FORMAT_SOAP11;
            else
                return SynapseConstants.FORMAT_SOAP12;
        } else if (SynapseConstants.PROPERTY_OPERATION_NAME.equals(key)
                || SynapseConstants.PROPERTY_OPERATION_NAMESPACE.equals(key)) {
            if (synCtx instanceof Axis2MessageContext) {
                AxisOperation axisOperation = ((Axis2MessageContext) synCtx).getAxis2MessageContext()
                        .getAxisOperation();
                if (axisOperation != null) {
                    if (SynapseConstants.PROPERTY_OPERATION_NAMESPACE.equals(key)) {
                        return axisOperation.getName().getNamespaceURI();
                    } else {
                        return axisOperation.getName().getLocalPart();
                    }
                }
            }
        } else {
            Object result = synCtx.getProperty(key);
            if (result != null) {
                return result;
            } else {
                return synCtx.getEntry(key);
            }
        }
    } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
                .getAxis2MessageContext();
        return axis2MessageContext.getProperty(key);

    } else if (XMLConfigConstants.SCOPE_FUNC.equals(scope)) {
        Stack<TemplateContext> functionStack = (Stack) synCtx
                .getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
        TemplateContext topCtxt = functionStack.peek();
        if (topCtxt != null) {
            return topCtxt.getParameterValue(key);
        }
    } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) {

        org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx)
                .getAxis2MessageContext();
        Object headers = axis2MessageContext
                .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

        if (headers != null && headers instanceof Map) {
            Map headersMap = (Map) headers;
            return headersMap.get(key);
        }

    } else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope) && synCtx instanceof Axis2MessageContext) {
        Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
        org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
        return axis2smc.getAxis2MessageContext().getOperationContext().getProperty(key);
    } else if (XMLConfigConstants.SCOPE_REGISTRY.equals(scope)) {
        String[] regParam = key.split("@");
        String regPath = null;
        String propName = null;
        if (regParam.length == 2) {
            regPath = regParam[0];
            propName = regParam[1];
        } else if (regParam.length == 1) {
            regPath = regParam[0];
        }

        Entry propEntry = synCtx.getConfiguration().getEntryDefinition(regPath);
        if (propEntry == null) {
            propEntry = new Entry();
            propEntry.setType(Entry.REMOTE_ENTRY);
            propEntry.setKey(key);
        }
        Registry registry = synCtx.getConfiguration().getRegistry();
        if (registry != null) {
            registry.getResource(propEntry, new Properties());
            if (propName != null) {
                Properties reqProperties = propEntry.getEntryProperties();
                if (reqProperties != null) {
                    if (reqProperties.get(propName) != null) {
                        return reqProperties.getProperty(propName);
                    }
                }
            } else if (propEntry.getValue() != null) {
                if (propEntry.getValue() instanceof OMText) {
                    return ((OMText) propEntry.getValue()).getText();
                }
                return propEntry.getValue().toString();
            }
        }
    } else if (XMLConfigConstants.SCOPE_SYSTEM.equals(scope)) {
        String propVal = System.getProperty(key);
        if (propVal != null) {
            return propVal;
        } else {
            if (traceOrDebugOn) {
                traceOrDebug(traceOn, "System property " + key + " not found");
            }
            return NULL_STRING;
        }

    } else {
        if (traceOrDebugOn) {
            traceOrDebug(traceOn, "Invalid scope : '" + scope + "' has been set for the "
                    + "synapse:get-property(scope,prop-name) XPath function");
        }
    }
    return NULL_STRING;
}

From source file:org.wso2.carbon.esb.car.deployment.test.CAppDeploymentOrderTest.java

private boolean checkUnDeployLogOrder(LogViewerClient logViewerClient)
        throws LogViewerLogViewerException, RemoteException {
    LogEvent[] systemLogs;/*from  www . ja  v a2s  .co m*/
    systemLogs = logViewerClient.getAllRemoteSystemLogs();
    //Create a stack to store the intended logs in order
    Stack<String> logStack = new Stack<>();
    logStack.push("Inbound Endpoint named 'inbound-endpoint' has been undeployed");
    logStack.push("Sequence named 'test-sequence' has been undeployed");

    //Check whether the logs are in the stack's order
    if (systemLogs != null) {
        for (LogEvent logEvent : systemLogs) {
            if (logEvent == null) {
                continue;
            }
            if (logStack.size() != 0 && logEvent.getMessage().contains(logStack.peek())) {
                logStack.pop();
            }
        }
    }
    return logStack.isEmpty();
}

From source file:org.wso2.carbon.esb.car.deployment.test.CAppDeploymentOrderTest.java

private boolean checkLogOrder(LogViewerClient logViewerClient)
        throws LogViewerLogViewerException, RemoteException {
    LogEvent[] systemLogs;//from  w w w.  ja  v  a 2s  .c o  m
    systemLogs = logViewerClient.getAllRemoteSystemLogs();
    //Create a stack to store the intended logs in order
    Stack<String> logStack = new Stack<>();
    logStack.push("Sequence named 'test-sequence' has been deployed from file");
    logStack.push("Inbound Endpoint named 'inbound-endpoint' has been deployed from file");

    //Check whether the logs are in the stack's order
    if (systemLogs != null) {
        for (LogEvent logEvent : systemLogs) {
            if (logEvent == null) {
                continue;
            }
            if (logStack.size() != 0 && logEvent.getMessage().contains(logStack.peek())) {
                logStack.pop();
            }
        }
    }

    return logStack.size() == 0;
}

From source file:com.tune.reporting.base.endpoints.EndpointBase.java

/**
 * Validate any parentheses within string are balanced.
 * @param str  Contents partitioned with parentheses.
 * @return Boolean If contents contains balanced parentheses returns true.
 *//* w  w  w . j a  v  a  2 s  .c  om*/
public static boolean isParenthesesBalanced(final String str) {
    if (str.isEmpty()) {
        return true;
    }

    Stack<Character> stack = new Stack<Character>();
    for (int i = 0; i < str.length(); i++) {
        char current = str.charAt(i);
        if (current == '{' || current == '(' || current == '[') {
            stack.push(current);
        }

        if (current == '}' || current == ')' || current == ']') {
            if (stack.isEmpty()) {
                return false;
            }

            char last = stack.peek();
            if (current == '}' && last == '{' || current == ')' && last == '('
                    || current == ']' && last == '[') {
                stack.pop();
            } else {
                return false;
            }
        }
    }

    return stack.isEmpty();
}

From source file:com.spidertracks.datanucleus.spring.ConsistencyLevelAspect.java

/**
 * Validates any method that has the valid annotation on it and is wired as
 * a spring service//  w w  w.  j  ava  2 s .  co  m
 * 
 * @param jp
 * @throws Throwable
 */
@Around("@annotation(com.spidertracks.datanucleus.spring.Consistency)")
public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable {

    logger.debug("Invoking before advice for @Consistency annotation.  Target object is {} on method {}",
            pjp.getTarget(), pjp.getSignature());

    MethodSignature sig = (MethodSignature) pjp.getSignature();

    Object[] args = pjp.getArgs();

    Method signatureMethod = sig.getMethod();

    Class<?>[] signatureTypes = signatureMethod.getParameterTypes();

    // we do this because we want to get the best match from the child
    // classes
    Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length];

    for (int i = 0; i < signatureTypes.length; i++) {

        if (args[i] != null) {
            runtimeArgs[i] = args[i].getClass();
        } else {
            runtimeArgs[i] = signatureTypes[i];
        }
    }

    Class<?> runtimeClass = pjp.getTarget().getClass();

    // check if this is annotated, if not proceed and execute it

    ConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs);

    if (level == null) {
        return pjp.proceed(args);
    }

    Stack<ConsistencyLevel> stack = threadStack.get();

    stack.push(level);
    com.spidertracks.datanucleus.client.Consistency.set(level);

    Object result = null;

    try {
        result = pjp.proceed(args);
    } finally {
        stack.pop();

        if (stack.size() > 0) {
            com.spidertracks.datanucleus.client.Consistency.set(stack.peek());
        } else {
            com.spidertracks.datanucleus.client.Consistency.remove();
        }

    }

    return result;
}

From source file:edu.kit.dama.mdm.dataorganization.impl.jpa.DataOrganizerImpl.java

/**
 * Build a tree for a digital object id from a list of DataOrganizationNode
 * obtained from a data source.//from   ww w  .java2  s .  c om
 *
 * @param nodes The list of nodes.
 * @param digitalObjectID The digital object id the tree is associated with.
 *
 * @return The tree.
 */
private FileTree buildTree(List<DataOrganizationNode> nodes, DigitalObjectId digitalObjectID) {

    FileTree tree = null;
    if (!nodes.isEmpty()) {
        Stack<DataOrganizationNode> stack = new Stack<>();
        DataOrganizationNode node = nodes.get(0);
        if (!(node instanceof CollectionNode)) {
            return null;
        }
        tree = new FileTree((CollectionNode) node);
        tree.setDigitalObjectId(digitalObjectID);
        node = tree;
        stack.push(node);
        DataOrganizationNode nextNode;
        for (int i = 1; i < nodes.size(); ++i) {
            nextNode = nodes.get(i);
            while (stack.peek().getStepNoLeaved() < nextNode.getStepNoLeaved()) {
                stack.pop();
            }
            node = stack.peek();
            ((CollectionNode) node).addChild(nextNode);
            stack.push(nextNode);
        }
    }
    return tree;
}

From source file:org.apache.tiles.impl.BasicTilesContainer.java

/**
 * Get attribute context from request./*from w  w w  .  j  a  v a2s.  c o  m*/
 *
 * @param tilesContext current Tiles application context.
 * @return BasicAttributeContext or null if context is not found.
 * @since 2.0.6
 */
protected AttributeContext getContext(TilesRequestContext tilesContext) {
    Stack<AttributeContext> contextStack = getContextStack(tilesContext);
    if (!contextStack.isEmpty()) {
        return contextStack.peek();
    } else {
        return null;
    }
}

From source file:org.apache.tiles.impl.BasicTilesContainer.java

/**
 * Starts an attribute context inside the container.
 *
 * @param tilesContext The request context to use.
 * @return The newly created attribute context.
 *///from  ww  w  . j a v a  2 s.co  m
private AttributeContext startContext(TilesRequestContext tilesContext) {
    AttributeContext context = new BasicAttributeContext();
    Stack<AttributeContext> stack = getContextStack(tilesContext);
    if (!stack.isEmpty()) {
        AttributeContext parent = stack.peek();
        context.inheritCascadedAttributes(parent);
    }
    stack.push(context);
    return context;
}