concept context in category java

This is an excerpt from Manning's book Functional Programming in Java: How functional techniques improve your Java programs.
Ultimately you should abstract the removal of empty elements into a separate method in the List class. But for the rest of this book, we’ll continue considering Empty as a Failure in the context of the sequence method.
The List class you studied in chapters 5 and 8 is a computational context, but rather than dealing with errors, it allows the use of functions that work on single elements in the context of a collection of elements. It also deals with the absence of data represented by an empty list.
This function can be applied to an integer value, but when composed with other functions, the value will be the output of another function, so it will usually already be in context, and often the same type of context. Here’s an example:
Result<Integer> ri = ... Result<Double> rd = ri.flatMap(inverse);It’s important to note that you don’t take the value in ri out of its context to apply the function. It works the other way around: you pass the function to the context (the Result type) so that it can be applied inside it, producing a new context, possibly wrapping the resulting value. Here, you pass the function to the ri context, producing the new rd result.

This is an excerpt from Manning's book Portlets in Action.
In the context of the Hello World portlet, you’ll learn how to perform the following activities:
In the context of the example User Registration portlet, chapter 2 introduced you to some of the classes and interfaces of the Portlet 2.0 specification. This chapter and the next will provide comprehensive coverage of the Portlet 2.0 API using an example Book Catalog portlet.
Table 3.6. Important PortletContext methods
Method
Description
getAttribute, setAttribute, removeAttribute Get, set, and remove context attributes. The context attributes that are available to portlets through PortletContext are also accessible to JSPs and servlets (that form part of the same portlet application) through ServletContext, and vice versa. getInitParameter Obtains the context initialization parameters. Context initialization parameters are different from portlet initialization parameters in the sense that they’re available to all portlets in the same portlet application. Context initialization parameters are specified in web.xml using the contextparam element. getContainerRuntimeOptions Returns an enumeration of portlet container-runtime options supported by the portlet container. The return type is Enumeration<String>. getNamedDispatcher Accepts the servlet name to which the returned RequestDispatcher refers. getMimeType Accepts a filename as an argument and returns its MIME type (such as text/html and application/pdf). A portlet application is also a web application, and like any web application it has a ServletContext. Like HttpSession and PortletSession, PortletContext and ServletContext mirror attributes stored in the context and they follow the same lifecycle. If you store an attribute in PortletContext, it’s available to ServletContext, and vice versa. If the ServletContext is destroyed by the servlet container, the PortletContext is also destroyed by the portlet container. Because PortletContext mirrors the ServletContext attributes and follows the same lifecycle, you can use the following ServletContext listeners for your PortletContext: ServletContextListener and ServletContextAttributeListener.

This is an excerpt from Manning's book AspectJ in Action, Second Edition.
AOP’s advice may superficially look like an event responder, but there are some important differences. First, you won’t see invocations such as notify<ChangeType>() in the subject class; thus, advice decouples the observer pattern logic from the subject. As a result, you can produce notifications that weren’t planned in advance, making your system extensible over what it was originally designed to be and bringing it new life in some situations. Second, the context collected by pointcuts (equivalent to information carried in an event object) is much more flexible and powerful in AOP. Point-cuts can collect just the right amount of context needed for advice logic. With a typical event model, you end up passing everything that you might possibly need.
Let’s write a pattern template that you can use to create your own implementation easily. First, you write a pointcut selecting the needed join points. You don’t need to collect any context in this pointcut (but you may collect context—it doesn’t matter from the pattern’s perspective). Next, you advise this pointcut with an around advice to create and use the worker object, as shown in the following snippet:
The basic idea behind the wormhole pattern, shown in figure 12.1, is to specify two pointcuts: one for the caller and the other for the callee, with the former collecting the context to be transported through the wormhole. Then, you specify the wormhole as the execution of the callee’s join points in the control flow of a caller’s join points.
Figure 12.1. The wormhole pattern. Each horizontal bar shows a level in the call stack. The wormhole makes the object in the caller plane available to the methods in the called plane without passing the object through the call stack.
![]()
Figure 12.1 depicts each level in the call stack as a plane in the space. To transport context from one plane to another, you’d normally have to pass it to the next plane until it reached the desired location. The wormhole pattern provides a path that cuts directly through the planes, which avoids having the context trickle through the levels from caller to callee.
public aspect WormholeAspect { pointcut callerSpace(<caller context>) : <caller pointcut>; pointcut calleeSpace(<callee context>) : <callee pointcut>; pointcut wormhole(<caller context>, <callee context>) : cflow(callerSpace(<caller context>)) && calleeSpace(<callee context>); // advice to wormhole before(<caller context>, <callee context>) : wormhole(<caller context>, <callee context>) { ... advice body } }In this template, you define a pointcut in the caller’s space that collects the associated context. Similarly, you define a pointcut in the callee’s space. The collected context in both cases could be an execution, a target, arguments to the callee join point, or any associated annotations. You then create a wormhole through these two spaces using a pointcut that selects the join points selected by the calleeSpace() pointcut in the control flow of the join points selected by the callerSpace() pointcut. Because you have the context available for both of these join points, you can write advice to the wormhole() pointcut using this information.
Pass the context as additional parameters to methods, which subsequently pass it on. This continues until the context reaches the place of its use. This causes API pollution—every method in the execution stack must have extra parameters to pass on the context collected. Use thread-local storage to set and access the context information. This requires the caller to create a ThreadLocal variable to store the context information. Although this approach avoids API pollution, it entails changes in both caller and callee implementation and requires an understanding of how the context is stored. You must also clear the context correctly. This is especially important in an environment that uses thread pools (practically, that includes every application and web server). If you forget to clear a thread local, you run the risk of exposing old information to the next user of that thread. Therefore, even if you don’t use the wormhole pattern, consider using an aspect to set and clear thread locals. (Hint: use a before advice to set the context and an after advice to clear it—much the same as the indentation aspects in chapter 10.) In either case, multiple modules are involved in the logic to manage the context.

This is an excerpt from Manning's book Struts 2 in Action.
While many Java developers today may have worked on web applications for most of their careers, it’s always beneficial to revisit the foundations of the domain in which one is working. A solid understanding of the context in which a framework such as Struts 2 is situated provides an intuitive understanding of the architectural decisions made by the framework. Also, establishing a common vocabulary for our discussions will make everything easier throughout the book.
In this chapter, we’ll start looking at the Struts 2 tag library in detail. We’ll provide a good reference to the tags and clear examples of their usage. We’ll also finish exploring the Object-Graph Navigation Language (OGNL). We’ve already seen how OGNL is used to bind form fields to Java properties, such as those exposed on our action, to guide the framework’s automatic data transfer mechanism. In chapter 5 we learned about the type conversion aspects of OGNL in the context of data entering the framework.
Now, we’ll focus on the OGNL expression language (EL) in the context of data exiting the framework through the Struts 2 tag API. While the previous chapter showed us how to map incoming request parameters to Java properties exposed on the ValueStack, this chapter will show you how to pull data off of those properties for the rendering of result pages. We’ll explore the syntax of the OGNL EL and study the locations from which it can pull data. In particular, we’ll look closely at the ValueStack and the ActionContext. These objects hold all of the data important to processing a given request, including your action object. While it may be possible to blissfully ignore their existence during much of your development, we think the benefits are too high not to spend a few minutes getting to know them.