Source Code Cross Referenced for RequestState.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » engine » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » com.uwyn.rife.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: RequestState.java 3813 2007-06-25 18:22:03Z gbevin $
007:         */
008:        package com.uwyn.rife.engine;
009:
010:        import java.util.*;
011:
012:        import com.uwyn.rife.config.RifeConfig;
013:        import com.uwyn.rife.continuations.CallState;
014:        import com.uwyn.rife.continuations.ContinuationContext;
015:        import com.uwyn.rife.continuations.exceptions.AnswerException;
016:        import com.uwyn.rife.engine.exceptions.CancelEmbeddingTriggeredException;
017:        import com.uwyn.rife.engine.exceptions.EmbedPropertiesErrorException;
018:        import com.uwyn.rife.engine.exceptions.EngineException;
019:        import java.io.IOException;
020:        import javax.servlet.http.Cookie;
021:
022:        class RequestState {
023:            private static ThreadLocal<RequestState> sActiveRequestStates = new ThreadLocal<RequestState>();
024:
025:            private InitConfig mInitConfig = null;
026:            private Site mSite = null;
027:            private Request mRequest = null;
028:            private Response mResponse = null;
029:            private String mGateUrl = null;
030:            private ElementInfo mTarget = null;
031:            private ElementInfo mSnapback = null;
032:            private String mActiveElementId = null;
033:            private EmbeddingContext mEmbeddingContext = null;
034:            private ElementInfo mPrecedenceTarget = null;
035:            private Map<String, Cookie> mStateCookies = null;
036:            private Map<String, String[]> mStateGlobalVars = null;
037:            private ResultStates mResultStatesRestored = null;
038:            private ResultStates mResultStatesObtained = null;
039:
040:            private ElementExecutionState mElementExecutionState = null;
041:
042:            private String mContinuationId = null;
043:            private ContinuationContext<ElementSupport> mContinuationContext = null;
044:
045:            static RequestState getActiveRequestState() {
046:                return sActiveRequestStates.get();
047:            }
048:
049:            static RequestState getInstance(InitConfig initConfig, Site site,
050:                    Request request, Response response, String gateUrl,
051:                    ResultStates resultStates, String pathInfo,
052:                    ElementInfo target) {
053:                RequestState state = new RequestState(initConfig, site,
054:                        request, response, gateUrl, resultStates,
055:                        new ResultStates(resultStates), pathInfo, null);
056:
057:                state.setTarget(target);
058:                state.setSnapback(target);
059:                state.setupContinuations();
060:
061:                return state;
062:            }
063:
064:            static RequestState getEmbeddedInstance(Response response,
065:                    EmbeddingContext embeddingContext,
066:                    Map<String, String[]> parameters,
067:                    ElementInfo embeddedElement) {
068:                RequestState embedding_state = embeddingContext
069:                        .getElementContext().getRequestState();
070:
071:                RequestState embedded_state = new RequestState(embedding_state
072:                        .getInitConfig(), embedding_state.getSite(),
073:                        embedding_state.getRequest(), response, embedding_state
074:                                .getGateUrl(), embedding_state
075:                                .getElementResultStatesRestored(),
076:                        embedding_state.getElementResultStatesObtained(), "",
077:                        embeddingContext);
078:
079:                embedded_state.setTarget(embeddedElement);
080:                embedded_state.setSnapback(embeddedElement);
081:                embedded_state.setupContinuations();
082:
083:                // preserve the request parameters, trigger inputs and request method, this
084:                // makes the embedded element behave correctly after exits and such
085:                embedded_state.getElementState().setMethod(
086:                        embedding_state.getElementState().getMethod());
087:                embedded_state.getElementState().setRequestParameters(
088:                        parameters);
089:                embedded_state.getElementState().setTriggerInputs(
090:                        embedding_state.getElementState().getTriggerInputs());
091:                embedded_state.setStateCookies(embedding_state
092:                        .getStateCookies());
093:
094:                return embedded_state;
095:            }
096:
097:            private RequestState(InitConfig initConfig, Site site,
098:                    Request request, Response response, String gateUrl,
099:                    ResultStates resultStatesRestored,
100:                    ResultStates resultStatesObtained, String pathInfo,
101:                    EmbeddingContext embeddingContext) throws EngineException {
102:                assert initConfig != null;
103:                assert request != null;
104:                assert gateUrl != null;
105:
106:                mInitConfig = initConfig;
107:                mGateUrl = gateUrl;
108:                mSite = site;
109:                mEmbeddingContext = embeddingContext;
110:                mResultStatesRestored = resultStatesRestored;
111:                mResultStatesObtained = resultStatesObtained;
112:
113:                mRequest = request;
114:                mResponse = response;
115:
116:                mElementExecutionState = new ElementExecutionState(this );
117:                mElementExecutionState.setPathInfo(pathInfo);
118:            }
119:
120:            void setupContinuations() {
121:                mContinuationId = null;
122:                mContinuationContext = null;
123:
124:                // try to obtain the continuation ID from the result states
125:                if (mResultStatesObtained != null) {
126:                    String context_id = buildContextId();
127:                    ElementResultState result_state = mResultStatesObtained
128:                            .get(context_id);
129:                    if (result_state != null) {
130:                        mContinuationId = result_state.getContinuationId();
131:                    }
132:                }
133:
134:                // get the explicit continuation ID if it exists
135:                if (null == mContinuationId) {
136:                    String[] continuation_id_values = mElementExecutionState
137:                            .getRequestParameters().get(
138:                                    ReservedParameters.CONTID);
139:                    if (continuation_id_values != null
140:                            && continuation_id_values.length > 0) {
141:                        mContinuationId = continuation_id_values[0];
142:                    }
143:                }
144:            }
145:
146:            String getContinuationId() {
147:                return mContinuationId;
148:            }
149:
150:            void setContinuationId(String id) {
151:                mContinuationId = id;
152:                mContinuationContext = null;
153:            }
154:
155:            ContinuationContext getContinuationContext(ElementInfo elementInfo) {
156:                if (mContinuationId != null && null == mContinuationContext) {
157:                    try {
158:                        mContinuationContext = mSite.getContinuationManager()
159:                                .resumeContext(mContinuationId);
160:                    } catch (CloneNotSupportedException e) {
161:                        throw new EngineException(e);
162:                    }
163:                }
164:
165:                if (mContinuationContext != null) {
166:                    ElementSupport continuable_element = mContinuationContext
167:                            .getContinuable();
168:                    ElementInfo continuable_element_info = continuable_element
169:                            ._getElementInfo();
170:                    // the element info can be null if this continuation context was obtained
171:                    // through Terracotta from another node, in that case the comparison below
172:                    // can't be done
173:                    if (null == continuable_element_info) {
174:                        return mContinuationContext;
175:                    }
176:
177:                    String continuable_absolute_element_id = Site
178:                            .getAbsoluteId(continuable_element_info.getId(),
179:                                    continuable_element_info);
180:                    if (null == elementInfo
181:                            || continuable_absolute_element_id
182:                                    .equals(elementInfo.getId())) {
183:                        return mContinuationContext;
184:                    }
185:                }
186:                return null;
187:            }
188:
189:            ResultStates getElementResultStatesRestored() {
190:                return mResultStatesRestored;
191:            }
192:
193:            ResultStates getElementResultStatesObtained() {
194:                return mResultStatesObtained;
195:            }
196:
197:            String buildContextId() {
198:                return buildContextId(new StringBuilder()).toString();
199:            }
200:
201:            private StringBuilder buildContextId(StringBuilder buffer) {
202:                boolean is_embedded_submission = isEmbedded()
203:                        && null == getTarget().getUrl();
204:                if (is_embedded_submission) {
205:                    buffer = getEmbeddingContext().getElementContext()
206:                            .getRequestState().buildContextId(buffer);
207:                    buffer.append("::");
208:                    buffer
209:                            .append(getEmbeddingContext().getTemplate()
210:                                    .getName());
211:                    buffer.append(":");
212:                }
213:
214:                // during precedence, target the submission context id to the actual target element
215:                if (isPreceeding()) {
216:                    buffer.append(getPrecedenceTarget().getId());
217:                }
218:                // during inheritance, target the submission context id to the actual target element
219:                else if (mElementExecutionState.inInheritanceStructure()) {
220:                    buffer.append(getTarget().getId());
221:                }
222:                // use the ID of the active element if it's available
223:                else if (mActiveElementId != null) {
224:                    buffer.append(mActiveElementId);
225:                }
226:                // use the id of the target element
227:                else {
228:                    buffer.append(getTarget().getId());
229:                }
230:
231:                if (is_embedded_submission) {
232:                    String differentiator = getEmbeddingContext()
233:                            .getDifferentiator();
234:                    if (differentiator != null) {
235:                        buffer.append(":");
236:                        buffer.append(differentiator);
237:                    }
238:                }
239:
240:                return buffer;
241:            }
242:
243:            ElementContext getElementContext(ElementInfo elementInfo,
244:                    Response response) throws EngineException {
245:                ElementSupport element = null;
246:
247:                ContinuationContext context = getContinuationContext(elementInfo);
248:                if (context != null) {
249:                    element = (ElementSupport) mContinuationContext
250:                            .getContinuable();
251:                    synchronized (element) {
252:                        // ensure that the element's element info is set to the element, mainly
253:                        // for use with Terracotta
254:                        element.setElementInfo(elementInfo);
255:                    }
256:                } else {
257:                    element = elementInfo.getElement();
258:                }
259:
260:                if (null == element) {
261:                    throw new EngineException(
262:                            "Error while instantiating the element '"
263:                                    + elementInfo.getDeclarationName()
264:                                    + "' at url.");
265:                }
266:
267:                ElementContext element_context = new ElementContext(element,
268:                        this , response);
269:                if (null == element_context) {
270:                    throw new EngineException(
271:                            "Error while constructing the context for the element '"
272:                                    + elementInfo.getDeclarationName() + "'.");
273:                }
274:
275:                return element_context;
276:            }
277:
278:            void handlePrecedence(Response response,
279:                    ElementInfo precedenceTarget) {
280:                // obtain the precedence stack and if it exists the top parent
281:                Stack<ElementInfo> precedence_stack = precedenceTarget
282:                        .getPrecedenceStack();
283:                if (precedence_stack != null && precedence_stack.size() > 0) {
284:                    // preserve the original state variables
285:                    ElementInfo original_target = getTarget();
286:                    Stack<ElementInfo> original_inheritance_stack = mElementExecutionState
287:                            .getInheritanceStack();
288:                    RequestMethod original_method = mElementExecutionState
289:                            .getMethod();
290:
291:                    // retain initiating precedence target element info to be able to
292:                    // check for a precedence structure later
293:                    if (null == getPrecedenceTarget()) {
294:                        setPrecedenceTarget(precedenceTarget);
295:                        mElementExecutionState
296:                                .setMethod(RequestMethod.PRECEDENCE);
297:                    }
298:
299:                    // process all precedence elements
300:                    ElementInfo active_element = null;
301:
302:                    for (int i = precedence_stack.size() - 1; i >= 0; i--) {
303:                        active_element = precedence_stack.get(i);
304:
305:                        if (active_element == precedenceTarget) {
306:                            break;
307:                        }
308:
309:                        // process the precedence element
310:                        setTarget(active_element);
311:                        service();
312:                    }
313:
314:                    // clear the preserved precedence target element info only if this
315:                    // was the element info that initiated it
316:                    if (precedenceTarget == getPrecedenceTarget()) {
317:                        setPrecedenceTarget(null);
318:                    }
319:
320:                    // restore original state variables
321:                    setTarget(original_target);
322:                    mElementExecutionState
323:                            .setInheritanceStack(original_inheritance_stack);
324:                    mElementExecutionState.setMethod(original_method);
325:                }
326:            }
327:
328:            void service() throws EngineException {
329:                // Get the currently active request state to be able to restore it
330:                // as the active one after this new one finished executing. This is
331:                // needed for embedded requests.
332:                RequestState previous = sActiveRequestStates.get();
333:
334:                // Set the actively running request state
335:                sActiveRequestStates.set(this );
336:                try {
337:                    // obtain the inheritance stack and if it exists the top parent
338:                    ElementInfo element_info = null;
339:                    if (mElementExecutionState.inInheritanceStructure()) {
340:                        element_info = mElementExecutionState
341:                                .getInheritanceStack().pop();
342:                    } else {
343:                        element_info = mTarget;
344:                    }
345:
346:                    // preserve the ongoing continuation context
347:                    ContinuationContext previous_context = ContinuationContext
348:                            .getActiveContext();
349:
350:                    Object call_answer = null;
351:                    ElementContext element_context = getElementContext(
352:                            element_info, mResponse);
353:                    while (true) {
354:                        try {
355:                            // successively process each element context until none is available anymore
356:                            ContinuationContext.setActiveContext(null);
357:                            ElementContext next_element_context = element_context
358:                                    .processContext();
359:                            while (next_element_context != null) {
360:                                element_context = next_element_context;
361:                                ContinuationContext.setActiveContext(null);
362:                                synchronized (this ) {
363:                                    mActiveElementId = element_context
364:                                            .getElementInfo().getId();
365:                                    try {
366:                                        next_element_context = element_context
367:                                                .processContext();
368:                                    } finally {
369:                                        mActiveElementId = null;
370:                                    }
371:                                }
372:                            }
373:
374:                            call_answer = null;
375:                            break;
376:                        } catch (AnswerException e) {
377:                            synchronized (this ) {
378:                                // obtain the context and the answer of the answering element
379:                                ContinuationContext context = e.getContext();
380:                                call_answer = e.getAnswer();
381:
382:                                // handle the call state of the last processed element context
383:                                if (context != null
384:                                        && context.getActiveCallState() != null) {
385:                                    CallState call_state = context
386:                                            .getActiveCallState();
387:                                    mContinuationContext = null;
388:                                    mContinuationId = call_state
389:                                            .getContinuationId();
390:                                    mElementExecutionState = (ElementExecutionState) call_state
391:                                            .getState();
392:                                    mElementExecutionState
393:                                            .setRequestState(this );
394:
395:                                    // try to obtain the continuation context
396:                                    ContinuationContext continuation_context = getContinuationContext(null);
397:                                    if (null == continuation_context) {
398:                                        break;
399:                                    }
400:                                    element_info = ((ElementSupport) continuation_context
401:                                            .getContinuable()).getElementInfo();
402:
403:                                    // set the call answer
404:                                    continuation_context
405:                                            .setCallAnswer(call_answer);
406:
407:                                    // set the request target to the actual element, cancelling
408:                                    // the previous exit target that was set during the call
409:                                    // continuation
410:                                    setTarget(element_info);
411:
412:                                    // create the new element context
413:                                    element_context = getElementContext(
414:                                            element_info, mResponse);
415:
416:                                    // propagate the outputs of the answer element to the call element
417:                                    ElementSupport answer_element = (ElementSupport) e
418:                                            .getContext().getContinuable();
419:                                    ElementContext element_context_answer = (ElementContext) answer_element
420:                                            ._getElementContext();
421:                                    OutputValues outputs = element_context
422:                                            .getOutputs();
423:                                    for (Map.Entry<String, String[]> output_entry : element_context_answer
424:                                            .getOutputs().aggregateValues()
425:                                            .entrySet()) {
426:                                        outputs.put(output_entry.getKey(),
427:                                                output_entry.getValue());
428:                                    }
429:                                }
430:                            }
431:                        } catch (CancelEmbeddingTriggeredException e) {
432:                            if (isEmbedded()) {
433:                                throw e;
434:                            }
435:
436:                            mResponse.print(e.getEmbeddingContent());
437:                            mResponse.flush();
438:                            break;
439:                        }
440:                    }
441:
442:                    // restore ongoing continuation context
443:                    ContinuationContext.setActiveContext(previous_context);
444:                } finally {
445:                    // restory the previously running request state
446:                    sActiveRequestStates.set(previous);
447:                }
448:            }
449:
450:            void setTarget(ElementInfo targetElement) {
451:                assert targetElement != null;
452:
453:                synchronized (mElementExecutionState) {
454:                    mTarget = targetElement;
455:                    mElementExecutionState.clearVirtualInputs();
456:
457:                    // create the initial inheritance stack
458:                    Stack<ElementInfo> target_inheritancestack = mTarget
459:                            .getInheritanceStack();
460:                    mElementExecutionState.setInheritanceStack(null);
461:                    if (target_inheritancestack != null) {
462:                        Stack<ElementInfo> inheritance_stack = new Stack<ElementInfo>();
463:                        inheritance_stack.addAll(target_inheritancestack);
464:                        mElementExecutionState
465:                                .setInheritanceStack(inheritance_stack);
466:                    }
467:
468:                    // process the possible trigger list
469:                    if (mElementExecutionState.inInheritanceStructure()) {
470:                        if (!mElementExecutionState.hasTriggerList()) {
471:                            if (isEmbedded()) // don't take the trigger list that the embedder created as the trigger list for the embedded element
472:                            {
473:                                mElementExecutionState
474:                                        .setTriggerList(new ArrayList<TriggerContext>());
475:                            } else {
476:                                // if no trigger list is present, decode it from the request
477:                                mElementExecutionState
478:                                        .setTriggerList(TriggerListEncoder
479:                                                .decode(mElementExecutionState
480:                                                        .getRequestParameterValues(ReservedParameters.TRIGGERLIST)));
481:                            }
482:                        }
483:                    }
484:                }
485:            }
486:
487:            void setSnapback(ElementInfo snapbackElement) {
488:                assert snapbackElement != null;
489:
490:                mSnapback = snapbackElement;
491:            }
492:
493:            InitConfig getInitConfig() {
494:                return mInitConfig;
495:            }
496:
497:            Site getSite() {
498:                return mSite;
499:            }
500:
501:            void clearRequest() {
502:                mRequest = null;
503:            }
504:
505:            Request getRequest() {
506:                return mRequest;
507:            }
508:
509:            Response getResponse() {
510:                return mResponse;
511:            }
512:
513:            ElementInfo getTarget() {
514:                return mTarget;
515:            }
516:
517:            ElementInfo getSnapback() {
518:                return mSnapback;
519:            }
520:
521:            EmbeddingContext getEmbeddingContext() {
522:                return mEmbeddingContext;
523:            }
524:
525:            boolean isEmbedded() {
526:                return mEmbeddingContext != null;
527:            }
528:
529:            String getEmbedDifferentiator() {
530:                if (null == mEmbeddingContext) {
531:                    return null;
532:                }
533:
534:                return mEmbeddingContext.getDifferentiator();
535:            }
536:
537:            String getEmbedValue() {
538:                if (null == mEmbeddingContext) {
539:                    return null;
540:                }
541:
542:                return mEmbeddingContext.getValue();
543:            }
544:
545:            Object getEmbedData() {
546:                if (null == mEmbeddingContext) {
547:                    return null;
548:                }
549:
550:                return mEmbeddingContext.getData();
551:            }
552:
553:            Properties getEmbedProperties()
554:                    throws EmbedPropertiesErrorException {
555:                if (null == mEmbeddingContext) {
556:                    return null;
557:                }
558:
559:                try {
560:                    return mEmbeddingContext.getEmbedProperties();
561:                } catch (IOException e) {
562:                    throw new EmbedPropertiesErrorException(mTarget
563:                            .getDeclarationName(),
564:                            mEmbeddingContext.getValue(), e);
565:                }
566:            }
567:
568:            void setPrecedenceTarget(ElementInfo elementInfo) {
569:                mPrecedenceTarget = elementInfo;
570:            }
571:
572:            ElementInfo getPrecedenceTarget() {
573:                return mPrecedenceTarget;
574:            }
575:
576:            boolean isPreceeding() {
577:                return mPrecedenceTarget != null;
578:            }
579:
580:            String getGateUrl() {
581:                return mGateUrl;
582:            }
583:
584:            ElementExecutionState getElementState() {
585:                return mElementExecutionState;
586:            }
587:
588:            String getServerRootUrl(int port) {
589:                return mRequest.getServerRootUrl(port);
590:            }
591:
592:            String getWebappRootUrl(int port) {
593:                if (RifeConfig.Engine.getProxyRootUrl() != null) {
594:                    return RifeConfig.Engine.getProxyRootUrl();
595:                }
596:
597:                StringBuilder webapp_root = new StringBuilder();
598:                webapp_root.append(getServerRootUrl(port));
599:                String gate_url = getGateUrl();
600:                if (!gate_url.startsWith("/")) {
601:                    webapp_root.append("/");
602:                }
603:                webapp_root.append(gate_url);
604:                if (gate_url.length() > 0 && !gate_url.endsWith("/")) {
605:                    webapp_root.append("/");
606:                }
607:
608:                return webapp_root.toString();
609:            }
610:
611:            // wrapped methods
612:            Object getRequestAttribute(String name) {
613:                return mRequest.getAttribute(name);
614:            }
615:
616:            boolean hasRequestAttribute(String name) {
617:                return mRequest.hasAttribute(name);
618:            }
619:
620:            Enumeration getRequestAttributeNames() {
621:                return mRequest.getAttributeNames();
622:            }
623:
624:            String getCharacterEncoding() {
625:                return mRequest.getCharacterEncoding();
626:            }
627:
628:            String getContentType() {
629:                return mRequest.getContentType();
630:            }
631:
632:            long getDateHeader(String name) {
633:                return mRequest.getDateHeader(name);
634:            }
635:
636:            String getHeader(String name) {
637:                return mRequest.getHeader(name);
638:            }
639:
640:            Enumeration getHeaderNames() {
641:                return mRequest.getHeaderNames();
642:            }
643:
644:            Enumeration getHeaders(String name) {
645:                return mRequest.getHeaders(name);
646:            }
647:
648:            int getIntHeader(String name) {
649:                return mRequest.getIntHeader(name);
650:            }
651:
652:            Locale getLocale() {
653:                return mRequest.getLocale();
654:            }
655:
656:            Enumeration getLocales() {
657:                return mRequest.getLocales();
658:            }
659:
660:            String getProtocol() {
661:                return mRequest.getProtocol();
662:            }
663:
664:            String getRemoteAddr() {
665:                return mRequest.getRemoteAddr();
666:            }
667:
668:            String getRemoteUser() {
669:                return mRequest.getRemoteUser();
670:            }
671:
672:            String getRemoteHost() {
673:                return mRequest.getRemoteHost();
674:            }
675:
676:            int getServerPort() {
677:                return mRequest.getServerPort();
678:            }
679:
680:            String getScheme() {
681:                return mRequest.getScheme();
682:            }
683:
684:            String getServerName() {
685:                return mRequest.getServerName();
686:            }
687:
688:            boolean isSecure() {
689:                return mRequest.isSecure();
690:            }
691:
692:            void removeRequestAttribute(String name) {
693:                mRequest.removeAttribute(name);
694:            }
695:
696:            void setRequestAttribute(String name, Object object) {
697:                mRequest.setAttribute(name, object);
698:            }
699:
700:            // shielded methods
701:            boolean hasUploadedFile(String name) {
702:                return mRequest.hasFile(name);
703:            }
704:
705:            UploadedFile getUploadedFile(String name) {
706:                return mRequest.getFile(name);
707:            }
708:
709:            UploadedFile[] getUploadedFiles(String name) {
710:                return mRequest.getFiles(name);
711:            }
712:
713:            Collection<String> getUploadedFileNames() {
714:                return mRequest.getFiles().keySet();
715:            }
716:
717:            void setStateCookies(Map<String, Cookie> stateCookies) {
718:                mStateCookies = stateCookies;
719:            }
720:
721:            Map<String, Cookie> getStateCookies() {
722:                return mStateCookies;
723:            }
724:
725:            void setStateCookie(Cookie cookie) {
726:                assert cookie != null;
727:                assert cookie.getName() != null;
728:
729:                if (null == mStateCookies) {
730:                    mStateCookies = new HashMap<String, Cookie>();
731:                }
732:
733:                mStateCookies.put(cookie.getName(), cookie);
734:            }
735:
736:            boolean hasCookie(String name) {
737:                assert name != null;
738:
739:                if (mStateCookies != null && mStateCookies.containsKey(name)) {
740:                    return true;
741:                }
742:
743:                return mRequest.hasCookie(name);
744:            }
745:
746:            Cookie getCookie(String name) {
747:                assert name != null;
748:
749:                if (mStateCookies != null && mStateCookies.containsKey(name)) {
750:                    return mStateCookies.get(name);
751:                }
752:
753:                return mRequest.getCookie(name);
754:            }
755:
756:            HashMap<String, Cookie> getCookies() {
757:                HashMap<String, Cookie> cookies = new HashMap<String, Cookie>();
758:
759:                Cookie[] request_cookies = mRequest.getCookies();
760:                if (request_cookies != null) {
761:                    for (Cookie cookie : request_cookies) {
762:                        cookies.put(cookie.getName(), cookie);
763:                    }
764:                }
765:
766:                if (mStateCookies != null) {
767:                    cookies.putAll(mStateCookies);
768:                }
769:
770:                return cookies;
771:            }
772:
773:            Map<String, String[]> getStateGlobalVars() {
774:                return mStateGlobalVars;
775:            }
776:
777:            void setStateGlobalVar(String name, String[] values) {
778:                assert name != null;
779:
780:                if (null == mStateGlobalVars) {
781:                    mStateGlobalVars = new HashMap<String, String[]>();
782:                }
783:
784:                mStateGlobalVars.put(name, values);
785:            }
786:
787:            void clearStateGlobalVar(String name) {
788:                assert name != null;
789:
790:                if (null == mStateGlobalVars) {
791:                    return;
792:                }
793:
794:                mStateGlobalVars.remove(name);
795:            }
796:
797:            EmbeddingListener getEmbeddingListener() {
798:                return new EmbeddingListener(this );
799:            }
800:
801:            PrecedenceListener getPrecedenceListener() {
802:                return new PrecedenceListener(this );
803:            }
804:
805:            static class EmbeddingListener implements  OutputListener,
806:                    OutcookieListener {
807:
808:                private RequestState mState = null;
809:
810:                private EmbeddingListener(RequestState state) {
811:                    assert state != null;
812:
813:                    mState = state;
814:                }
815:
816:                public void outputValueSet(String name, String[] values) {
817:                    if (!mState.isEmbedded()) {
818:                        return;
819:                    }
820:
821:                    if (!mState.getEmbeddingContext().getElementContext()
822:                            .getElementInfo().containsGlobalVar(name)) {
823:                        return;
824:                    }
825:
826:                    mState.getEmbeddingContext().getElementContext()
827:                            .setOutputValues(name, values);
828:                    mState.getEmbeddingContext().getElementContext()
829:                            .getRequestState().setStateGlobalVar(name, values);
830:                }
831:
832:                public void outputValueCleared(String name) {
833:                    if (!mState.isEmbedded()) {
834:                        return;
835:                    }
836:
837:                    if (!mState.getEmbeddingContext().getElementContext()
838:                            .getElementInfo().containsGlobalVar(name)) {
839:                        return;
840:                    }
841:
842:                    mState.getEmbeddingContext().getElementContext()
843:                            .clearOutputValue(name);
844:                    mState.getEmbeddingContext().getElementContext()
845:                            .getRequestState().clearStateGlobalVar(name);
846:                }
847:
848:                public void automatedOutputValueSet(String name, String[] values) {
849:                    if (!mState.isEmbedded()) {
850:                        return;
851:                    }
852:
853:                    if (!mState.getEmbeddingContext().getElementContext()
854:                            .getElementInfo().containsGlobalVar(name)) {
855:                        return;
856:                    }
857:
858:                    mState.getEmbeddingContext().getElementContext()
859:                            .setAutomatedOutputValues(name, values);
860:                    mState.getEmbeddingContext().getElementContext()
861:                            .getRequestState().setStateGlobalVar(name, values);
862:                }
863:
864:                public void automatedOutputValueCleared(String name) {
865:                    if (!mState.isEmbedded()) {
866:                        return;
867:                    }
868:
869:                    if (!mState.getEmbeddingContext().getElementContext()
870:                            .getElementInfo().containsGlobalVar(name)) {
871:                        return;
872:                    }
873:
874:                    mState.getEmbeddingContext().getElementContext()
875:                            .clearAutomatedOutputValue(name);
876:                    mState.getEmbeddingContext().getElementContext()
877:                            .getRequestState().clearStateGlobalVar(name);
878:                }
879:
880:                public void outcookieSet(Cookie cookie) {
881:                    if (!mState.isEmbedded()) {
882:                        return;
883:                    }
884:
885:                    if (!mState.getEmbeddingContext().getElementContext()
886:                            .getElementInfo()
887:                            .containsIncookie(cookie.getName())
888:                            && !mState.getEmbeddingContext()
889:                                    .getElementContext().getElementInfo()
890:                                    .containsGlobalCookie(cookie.getName())) {
891:                        return;
892:                    }
893:
894:                    mState.getEmbeddingContext().getElementContext().setCookie(
895:                            cookie);
896:                    mState.getEmbeddingContext().getElementContext()
897:                            .getRequestState().setStateCookie(cookie);
898:                }
899:            }
900:
901:            static class PrecedenceListener implements  OutputListener,
902:                    OutcookieListener {
903:                private RequestState mState = null;
904:
905:                private PrecedenceListener(RequestState state) {
906:                    assert state != null;
907:
908:                    mState = state;
909:                }
910:
911:                public void outputValueSet(String name, String[] values) {
912:                    if (!mState.isPreceeding()) {
913:                        return;
914:                    }
915:
916:                    if (!mState.getPrecedenceTarget().containsGlobalVar(name)) {
917:                        return;
918:                    }
919:
920:                    mState.getElementState().getRequestParameters().put(name,
921:                            values);
922:                }
923:
924:                public void outputValueCleared(String name) {
925:                    if (!mState.isPreceeding()) {
926:                        return;
927:                    }
928:
929:                    if (!mState.getPrecedenceTarget().containsGlobalVar(name)) {
930:                        return;
931:                    }
932:
933:                    mState.getElementState().getRequestParameters()
934:                            .remove(name);
935:                }
936:
937:                public void automatedOutputValueSet(String name, String[] values) {
938:                    outputValueSet(name, values);
939:                }
940:
941:                public void automatedOutputValueCleared(String name) {
942:                    outputValueCleared(name);
943:                }
944:
945:                public void outcookieSet(Cookie cookie) {
946:                    if (!mState.isPreceeding()) {
947:                        return;
948:                    }
949:
950:                    if (!mState.getPrecedenceTarget().containsIncookie(
951:                            cookie.getName())
952:                            && !mState.getPrecedenceTarget()
953:                                    .containsGlobalCookie(cookie.getName())) {
954:                        return;
955:                    }
956:
957:                    mState.setStateCookie(cookie);
958:                }
959:            }
960:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.