Source Code Cross Referenced for DefaultResourceLocator.java in  » Inversion-of-Control » DNA » org » codehaus » dna » impl » 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 » Inversion of Control » DNA » org.codehaus.dna.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The DNA Group. All rights reserved.
003:         *
004:         * This software is published under the terms of the DNA
005:         * Software License version 1.1, a copy of which has been included
006:         * with this distribution in the LICENSE.txt file.
007:         */
008:        package org.codehaus.dna.impl;
009:
010:        import java.util.HashMap;
011:        import java.util.Map;
012:
013:        import org.codehaus.dna.MissingResourceException;
014:        import org.codehaus.dna.ResourceLocator;
015:
016:        /**
017:         * ResourceLocator implementation backed by a Map and
018:         * optionally delegating to parent ResourceLocators.
019:         * The developer should create the DefaultResourceLocator,
020:         * associate resources with locator and then invoke
021:         * {@link #makeReadOnly()} before passing the Locator to
022:         * the client component.
023:         *
024:         * <p>The implementation will first check for resources
025:         * associated with itself and if unable to locate resource
026:         * locally it will delegate to parent ResourceLocator.</p>
027:         *
028:         * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
029:         */
030:        public class DefaultResourceLocator extends AbstractFreezable implements 
031:                ResourceLocator {
032:            /**
033:             * parent locator to look into if unable to
034:             * find resource in current locator.
035:             */
036:            private final ResourceLocator m_parent;
037:
038:            /**
039:             * Resources registered with locator.
040:             */
041:            private final Map m_resources = new HashMap();
042:
043:            /**
044:             * Create a ResourceLocator with no parent.
045:             */
046:            public DefaultResourceLocator() {
047:                this (null);
048:            }
049:
050:            /**
051:             * Create a ResourceLocator with specified parent.
052:             *
053:             * @param parent the parent ResourceLocator
054:             */
055:            public DefaultResourceLocator(final ResourceLocator parent) {
056:                m_parent = parent;
057:            }
058:
059:            /**
060:             * Return resource registered with specified key.
061:             *
062:             * @param key the key
063:             * @return the resource
064:             * @throws MissingResourceException if unable to locate
065:             *         resource with specified key
066:             */
067:            public Object lookup(final String key)
068:                    throws MissingResourceException {
069:                final Object resource = getResourceMap().get(key);
070:                if (null != resource) {
071:                    return resource;
072:                }
073:
074:                final ResourceLocator parent = getParent();
075:                if (null != parent) {
076:                    return parent.lookup(key);
077:                } else {
078:                    final String message = "Unable to locate resource " + key
079:                            + ".";
080:                    throw new MissingResourceException(message, key);
081:                }
082:            }
083:
084:            /**
085:             * Return true if a resource exists with specified key.
086:             *
087:             * @param key the key
088:             * @return true if a resource exists with specified key.
089:             */
090:            public boolean contains(final String key) {
091:                final Object resource = getResourceMap().get(key);
092:                if (null != resource) {
093:                    return true;
094:                }
095:
096:                final ResourceLocator parent = getParent();
097:                if (null != parent) {
098:                    return parent.contains(key);
099:                } else {
100:                    return false;
101:                }
102:            }
103:
104:            /**
105:             * Add a resource to resource locator.
106:             *
107:             * @param key the key used to store resource (Must not be null).
108:             * @param resource the resource (Must not be null).
109:             */
110:            public void put(final String key, final Object resource) {
111:                if (null == key) {
112:                    throw new NullPointerException("key");
113:                }
114:                if (null == resource) {
115:                    throw new NullPointerException("resource");
116:                }
117:                checkWriteable();
118:                getResourceMap().put(key, resource);
119:            }
120:
121:            /**
122:             * Return the parent ResourceLocator if any.
123:             *
124:             * @return the parent ResourceLocator if any.
125:             */
126:            protected final ResourceLocator getParent() {
127:                return m_parent;
128:            }
129:
130:            /**
131:             * Return the map used to store resources.
132:             *
133:             * @return the map used to store resources.
134:             */
135:            protected final Map getResourceMap() {
136:                return m_resources;
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.