Source Code Cross Referenced for Restlet.java in  » Web-Services » restlet-1.0.8 » org » restlet » 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 Services » restlet 1.0.8 » org.restlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 Noelios Consulting.
003:         * 
004:         * The contents of this file are subject to the terms of the Common Development
005:         * and Distribution License (the "License"). You may not use this file except in
006:         * compliance with the License.
007:         * 
008:         * You can obtain a copy of the license at
009:         * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010:         * language governing permissions and limitations under the License.
011:         * 
012:         * When distributing Covered Code, include this CDDL HEADER in each file and
013:         * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014:         * applicable, add the following below this CDDL HEADER, with the fields
015:         * enclosed by brackets "[]" replaced with your own identifying information:
016:         * Portions Copyright [yyyy] [name of copyright owner]
017:         */
018:
019:        package org.restlet;
020:
021:        import java.util.logging.Level;
022:        import java.util.logging.Logger;
023:
024:        import org.restlet.data.Request;
025:        import org.restlet.data.Response;
026:        import org.restlet.data.Status;
027:
028:        /**
029:         * Uniform class that provides a context and life cycle support. It has many
030:         * subclasses that focus on specific ways to process calls. The context property
031:         * is typically provided by a parent Component as a way to encapsulate access to
032:         * shared features such as logging and client connectors.
033:         * 
034:         * @author Jerome Louvel (contact@noelios.com)
035:         */
036:        public class Restlet extends Uniform {
037:            /** Error message. */
038:            private static final String UNABLE_TO_START = "Unable to start the Restlet";
039:
040:            /** The context. */
041:            private Context context;
042:
043:            /** Indicates if the restlet was started. */
044:            private boolean started;
045:
046:            /**
047:             * Constructor. Note that usage of this constructor is not recommended as
048:             * the Restlet won't have a proper context set. In general you will prefer
049:             * to use the other constructor and pass it the parent application's context
050:             * or eventually the parent component's context if you don't use
051:             * applications.
052:             */
053:            public Restlet() {
054:                this (null);
055:            }
056:
057:            /**
058:             * Constructor.
059:             * 
060:             * @param context
061:             *                The context.
062:             */
063:            public Restlet(Context context) {
064:                this .context = context;
065:                this .started = false;
066:            }
067:
068:            /**
069:             * Returns the context.
070:             * 
071:             * @return The context.
072:             */
073:            public Context getContext() {
074:                if (this .context == null) {
075:                    String logName = getClass().getCanonicalName();
076:
077:                    if (logName == null) {
078:                        logName = Restlet.class.getCanonicalName();
079:                    }
080:
081:                    this .context = new Context(logName);
082:                }
083:
084:                return this .context;
085:            }
086:
087:            /**
088:             * Returns the context's logger.
089:             * 
090:             * @return The context's logger.
091:             */
092:            public Logger getLogger() {
093:                return (getContext() != null) ? getContext().getLogger()
094:                        : Logger.getLogger(getClass().getCanonicalName());
095:            }
096:
097:            /**
098:             * Handles a call.
099:             * 
100:             * @param request
101:             *                The request to handle.
102:             * @param response
103:             *                The response to update.
104:             */
105:            public void handle(Request request, Response response) {
106:                init(request, response);
107:            }
108:
109:            /**
110:             * Initialize the Restlet by attempting to start it, unless it was already
111:             * started. If an exception is thrown during the start action, then the
112:             * response status is set to {@link Status#SERVER_ERROR_INTERNAL}.
113:             * 
114:             * @param request
115:             *                The request to handle.
116:             * @param response
117:             *                The response to update.
118:             */
119:            protected synchronized void init(Request request, Response response) {
120:                // Check if the Restlet was started
121:                if (isStopped()) {
122:                    try {
123:                        start();
124:                    } catch (Exception e) {
125:                        // Occurred while starting the Restlet
126:                        getContext().getLogger().log(Level.WARNING,
127:                                UNABLE_TO_START, e);
128:                        response.setStatus(Status.SERVER_ERROR_INTERNAL);
129:                    }
130:
131:                    if (!isStarted()) {
132:                        // No exception raised but the Restlet somehow couldn't be
133:                        // started
134:                        getContext().getLogger().log(Level.WARNING,
135:                                UNABLE_TO_START);
136:                        response.setStatus(Status.SERVER_ERROR_INTERNAL);
137:                    }
138:                }
139:            }
140:
141:            /**
142:             * Indicates if the Restlet is started.
143:             * 
144:             * @return True if the Restlet is started.
145:             */
146:            public synchronized boolean isStarted() {
147:                return this .started;
148:            }
149:
150:            /**
151:             * Indicates if the Restlet is stopped.
152:             * 
153:             * @return True if the Restlet is stopped.
154:             */
155:            public synchronized boolean isStopped() {
156:                return !this .started;
157:            }
158:
159:            /**
160:             * Sets the context.
161:             * 
162:             * @param context
163:             *                The context.
164:             */
165:            public void setContext(Context context) {
166:                this .context = context;
167:            }
168:
169:            /** Starts the Restlet. */
170:            public synchronized void start() throws Exception {
171:                this .started = true;
172:            }
173:
174:            /** Stops the Restlet. */
175:            public synchronized void stop() throws Exception {
176:                this .started = false;
177:            }
178:
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.