Source Code Cross Referenced for DefaultResolver.java in  » Web-Server » JicarillaHTTP » org » jicarilla » container » 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 Server » JicarillaHTTP » org.jicarilla.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:        The Jicarilla Software License
003:
004:        Copyright (c) 2003 Leo Simons.
005:        All rights reserved.
006:
007:        Permission is hereby granted, free of charge, to any person obtaining
008:        a copy of this software and associated documentation files (the
009:        "Software"), to deal in the Software without restriction, including
010:        without limitation the rights to use, copy, modify, merge, publish,
011:        distribute, sublicense, and/or sell copies of the Software, and to
012:        permit persons to whom the Software is furnished to do so, subject to
013:        the following conditions:
014:
015:        The above copyright notice and this permission notice shall be
016:        included in all copies or substantial portions of the Software.
017:
018:        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019:        EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020:        MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021:        IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022:        CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023:        TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024:        SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025:        ==================================================================== */
026:        package org.jicarilla.container;
027:
028:        import org.jicarilla.lang.Assert;
029:        import org.jicarilla.lang.Selector;
030:        import org.jicarilla.lang.Switch;
031:
032:        import java.util.ArrayList;
033:        import java.util.Iterator;
034:        import java.util.List;
035:
036:        /**
037:         * <p>A Straightforward implementation of the {@link Resolver} interface that
038:         * is backed by a {@link ResolverCallback} instance. This implementation is not
039:         * thread safe.</p>
040:         *
041:         * <p>You will normally not want to create instances of this class directly.
042:         * Rather, let the associated {@link DefaultContainer} worry about that.</p>
043:         *
044:         * @author <a href="mail at leosimons dot com">Leo Simons</a>
045:         * @version $Id: DefaultResolver.java,v 1.7 2004/03/23 13:37:51 lsimons Exp $
046:         */
047:        public class DefaultResolver implements  Resolver {
048:            // ----------------------------------------------------------------------
049:            //  Properties
050:            // ----------------------------------------------------------------------
051:            /** The callback to the container. */
052:            protected ResolverCallback m_callback;
053:
054:            // ----------------------------------------------------------------------
055:            //  Constructors
056:            // ----------------------------------------------------------------------
057:            /**
058:             * Create a new instance using the provided callback.
059:             *
060:             * @param callback value for {@link m_callback}.
061:             */
062:            public DefaultResolver(final ResolverCallback callback) {
063:                setCallback(callback);
064:            }
065:
066:            // ----------------------------------------------------------------------
067:            //  Getters and Setters
068:            // ----------------------------------------------------------------------
069:
070:            /**
071:             * Returns {@link m_callback}. Overriding is not recommended.
072:             *
073:             * @return {@link m_callback}
074:             */
075:            protected ResolverCallback getCallback() {
076:                return m_callback;
077:            }
078:
079:            /**
080:             * Sets {@link m_callback}. Direct usage is not recommended.
081:             *
082:             * @param callback the new {@link m_callback} value.
083:             */
084:            public void setCallback(final ResolverCallback callback) {
085:                Assert.assertNotNull("callback argument may not be null",
086:                        callback);
087:                m_callback = callback;
088:            }
089:
090:            // ----------------------------------------------------------------------
091:            //  Interface: Resolver
092:            // ----------------------------------------------------------------------
093:
094:            /**
095:             * @see {@link Resolver#get(Object)
096:             *
097:             * @param key
098:             * @return
099:             */
100:            public Object get(final Object key) {
101:                Assert.assertNotNull("key argument may not be null", key);
102:                if (!contains(key))
103:                    return null;
104:
105:                final Object adapter = getCallback().getSwitch().get(key);
106:
107:                return getInstanceFromAdapter(adapter, key);
108:            }
109:
110:            /**
111:             * @see {@link Resolver#getAll(Object)
112:             *
113:             * @param key
114:             * @return
115:             */
116:            public Object[] getAll(final Object key) {
117:                Assert.assertNotNull("key argument may not be null", key);
118:
119:                if (!contains(key))
120:                    return new Object[0];
121:
122:                final List instances = getInstanceListFromKey(key);
123:                return instances.toArray();
124:            }
125:
126:            /**
127:             * @see {@link Resolver#contains(Object)
128:             *
129:             * @param key
130:             * @return
131:             */
132:            public boolean contains(final Object key) {
133:                if (key == null)
134:                    return false;
135:
136:                if (getCallback().getSwitch().containsKey(key))
137:                    return true;
138:
139:                return false;
140:            }
141:
142:            /**
143:             * @see {@link Resolver#releaseInstance(Object)}
144:             *
145:             * @param component
146:             * @throws Exception
147:             */
148:            public void releaseInstance(final Object component)
149:                    throws Exception {
150:                getCallback().returnedInstance(component);
151:            }
152:
153:            // ----------------------------------------------------------------------
154:            //  Helper Methods
155:            // ----------------------------------------------------------------------
156:
157:            /**
158:             * Helper method that is called from {@link #get(Object)} to retrieve
159:             * an instance from an adapter and add that instance to the container
160:             * through {@link m_callback}.
161:             *
162:             * @param adapter
163:             * @param key
164:             * @return
165:             */
166:            protected Object getInstanceFromAdapter(final Object adapter,
167:                    final Object key) {
168:                if (adapter == null)
169:                    throw new JicarillaException(
170:                            "Internal error: the adapter associated with the key "
171:                                    + key + "could not be found!");
172:                if (!(adapter instanceof  Adapter))
173:                    throw new JicarillaException(
174:                            "Internal error: the adapter associated with the key "
175:                                    + key + "is not of type Adapter!");
176:
177:                final Object instance = ((Adapter) adapter).getInstance();
178:                getCallback().providedInstance(instance, adapter);
179:
180:                return instance;
181:            }
182:
183:            /**
184:             * Helper method that is called form {@link #getAll(Object)} to retrive
185:             * a list of instances from the switch provided by {@link m_callback}
186:             * and add those instances to to the container.
187:             *
188:             * @param key
189:             * @return
190:             */
191:            protected List getInstanceListFromKey(final Object key) {
192:
193:                final List instances = new ArrayList();
194:
195:                final Iterator it = getCallback().getSwitch().entryList()
196:                        .iterator();
197:                while (it.hasNext()) {
198:                    final Switch.Entry entry = (Switch.Entry) it.next();
199:                    final Selector selector = entry.getSelector();
200:                    if (selector.select(key)) {
201:                        // we catch and log the exception here because we will
202:                        // ignore it if we find some valid instances.
203:                        final Object adapter = entry.getValue();
204:                        final Object instance = getInstanceFromAdapter(adapter,
205:                                key);
206:                        instances.add(instance);
207:                    }
208:                }
209:
210:                //if( instances.size() == 0 ) // not good, since we're
211:                // supposed to contain it...
212:                // oh well.
213:                return instances;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.