Source Code Cross Referenced for MessagePropertiesContext.java in  » ESB » mule » org » mule » transport » 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 » ESB » mule » org.mule.transport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: MessagePropertiesContext.java 10489 2008-01-23 17:53:38Z dfeist $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:        package org.mule.transport;
011:
012:        import org.mule.api.transport.PropertyScope;
013:        import org.mule.util.MapUtils;
014:        import org.mule.util.ObjectUtils;
015:
016:        import java.io.Serializable;
017:        import java.util.Collections;
018:        import java.util.HashMap;
019:        import java.util.Iterator;
020:        import java.util.Map;
021:        import java.util.Set;
022:        import java.util.TreeMap;
023:        import java.util.TreeSet;
024:
025:        import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
026:
027:        /** TODO */
028:        public class MessagePropertiesContext implements  Serializable {
029:            protected Map scopedMap;
030:            protected Set keySet;
031:
032:            //TODO RM*: Map these to a RegistryMapView, currently in another branch :(
033:            //Treat Application properites as a special call
034:            Map applicationProperties = new ConcurrentHashMap(0);
035:
036:            private PropertyScope defaultScope = PropertyScope.OUTBOUND;
037:
038:            public MessagePropertiesContext() {
039:                keySet = new TreeSet();
040:                scopedMap = new TreeMap(new PropertyScope.ScopeComarator());
041:
042:                scopedMap.put(PropertyScope.INVOCATION, new HashMap(6));
043:                scopedMap.put(PropertyScope.INBOUND, new HashMap(6));
044:                scopedMap.put(PropertyScope.OUTBOUND, new HashMap(6));
045:                scopedMap.put(PropertyScope.SESSION, new HashMap(6));
046:
047:            }
048:
049:            public MessagePropertiesContext(PropertyScope defaultScope) {
050:                this ();
051:                //We can't set a read only scope as default
052:                checkScopeForWriteAccess(defaultScope);
053:                this .defaultScope = defaultScope;
054:            }
055:
056:            /**
057:             * if a property is not available in any ther scope, should we check the registry.
058:             * Note there will be performance implementations is this is enabled
059:             */
060:            private boolean fallbackToRegistry = false;
061:
062:            protected Map getScopedProperties(PropertyScope scope) {
063:                Map map = (Map) scopedMap.get(scope);
064:                if (map == null) {
065:                    throw new IllegalArgumentException("Scope not registered: "
066:                            + scope);
067:                }
068:                return map;
069:            }
070:
071:            void registerInvocationProperties(Map properties) {
072:                if (properties != null) {
073:                    getScopedProperties(PropertyScope.INVOCATION).putAll(
074:                            properties);
075:                    keySet.addAll(properties.keySet());
076:                }
077:            }
078:
079:            void addInboundProperties(Map properties) {
080:                if (properties != null) {
081:                    getScopedProperties(PropertyScope.INBOUND).putAll(
082:                            properties);
083:                    keySet.addAll(properties.keySet());
084:                }
085:            }
086:
087:            void registerSessionProperties(Map properties) {
088:                if (properties != null) {
089:                    getScopedProperties(PropertyScope.SESSION).putAll(
090:                            properties);
091:                    keySet.addAll(properties.keySet());
092:                }
093:            }
094:
095:            public Object getProperty(String key) {
096:                Object value = null;
097:                for (Iterator iterator = scopedMap.values().iterator(); iterator
098:                        .hasNext();) {
099:                    Map props = (Map) iterator.next();
100:                    value = props.get(key);
101:                    if (value != null) {
102:                        break;
103:                    }
104:                }
105:                if (value == null && fallbackToRegistry) {
106:                    value = applicationProperties.get(key);
107:                }
108:                return value;
109:            }
110:
111:            public Object getProperty(String key, PropertyScope scope) {
112:                if (PropertyScope.APPLICATION.equals(scope)) {
113:                    return applicationProperties.get(key);
114:                }
115:
116:                Map props = getScopedProperties(scope);
117:                return props.get(key);
118:            }
119:
120:            public void clearProperties() {
121:                Map props = getScopedProperties(PropertyScope.INVOCATION);
122:                keySet.removeAll(props.keySet());
123:                props.clear();
124:                props = getScopedProperties(PropertyScope.OUTBOUND);
125:                keySet.removeAll(props.keySet());
126:                props.clear();
127:                props = getScopedProperties(PropertyScope.SESSION);
128:                keySet.removeAll(props.keySet());
129:                props.clear();
130:                //inbound are read Only
131:            }
132:
133:            public void clearProperties(PropertyScope scope) {
134:                checkScopeForWriteAccess(scope);
135:                Map props = getScopedProperties(scope);
136:                keySet.removeAll(props.keySet());
137:                props.clear();
138:            }
139:
140:            /**
141:             * Removes a property on this message
142:             *
143:             * @param key the property key to remove
144:             * @return the removed property value or null if the property did not exist
145:             */
146:            public Object removeProperty(String key) {
147:                Object value = getScopedProperties(PropertyScope.INVOCATION)
148:                        .remove(key);
149:                if (value == null) {
150:                    value = getScopedProperties(PropertyScope.OUTBOUND).remove(
151:                            key);
152:                }
153:                if (value == null) {
154:                    value = getScopedProperties(PropertyScope.SESSION).remove(
155:                            key);
156:                }
157:                if (value != null) {
158:                    keySet.remove(key);
159:                }
160:                return value;
161:            }
162:
163:            /**
164:             * Set a property on the message
165:             *
166:             * @param key   the key on which to associate the value
167:             * @param value the property value
168:             */
169:            public void setProperty(String key, Object value) {
170:                getScopedProperties(defaultScope).put(key, value);
171:                keySet.add(key);
172:            }
173:
174:            /**
175:             * Set a property on the message
176:             *
177:             * @param key   the key on which to associate the value
178:             * @param value the property value
179:             * @param scope the scope to se the property on
180:             * @see org.mule.api.transport.PropertyScope
181:             */
182:            public void setProperty(String key, Object value,
183:                    PropertyScope scope) {
184:                checkScopeForWriteAccess(scope);
185:                getScopedProperties(scope).put(key, value);
186:                keySet.add(key);
187:            }
188:
189:            /** @return all property keys on this message */
190:            public Set getPropertyNames() {
191:                return Collections.unmodifiableSet(keySet);
192:            }
193:
194:            /** @return all property keys on this message for the given scope */
195:            public Set getPropertyNames(PropertyScope scope) {
196:                return Collections.unmodifiableSet(getScopedProperties(scope)
197:                        .keySet());
198:            }
199:
200:            protected void checkScopeForWriteAccess(PropertyScope scope) {
201:                if (scope == null || PropertyScope.INBOUND.equals(scope)
202:                        || PropertyScope.APPLICATION.equals(scope)) {
203:                    throw new IllegalArgumentException(
204:                            "Scope is invalid for writing properties: " + scope);
205:                }
206:            }
207:
208:            public Object getProperty(String key, Object defaultValue) {
209:                Object value = getProperty(key);
210:                if (value == null) {
211:                    value = defaultValue;
212:                }
213:                return value;
214:            }
215:
216:            public byte getByteProperty(String name, byte defaultValue) {
217:                return ObjectUtils.getByte(getProperty(name), defaultValue);
218:            }
219:
220:            public short getShortProperty(String name, short defaultValue) {
221:                return ObjectUtils.getShort(getProperty(name), defaultValue);
222:            }
223:
224:            public int getIntProperty(String name, int defaultValue) {
225:                return ObjectUtils.getInt(getProperty(name), defaultValue);
226:            }
227:
228:            public long getLongProperty(String name, long defaultValue) {
229:                return ObjectUtils.getLong(getProperty(name), defaultValue);
230:            }
231:
232:            public float getFloatProperty(String name, float defaultValue) {
233:                return ObjectUtils.getFloat(getProperty(name), defaultValue);
234:            }
235:
236:            public double getDoubleProperty(String name, double defaultValue) {
237:                return ObjectUtils.getDouble(getProperty(name), defaultValue);
238:            }
239:
240:            public boolean getBooleanProperty(String name, boolean defaultValue) {
241:                return ObjectUtils.getBoolean(getProperty(name), defaultValue);
242:            }
243:
244:            public String getStringProperty(String name, String defaultValue) {
245:                return ObjectUtils.getString(getProperty(name), defaultValue);
246:            }
247:
248:            public String toString() {
249:                StringBuffer buf = new StringBuffer(128);
250:                buf.append("Properites{");
251:                for (Iterator iterator = scopedMap.entrySet().iterator(); iterator
252:                        .hasNext();) {
253:                    Map.Entry entry = (Map.Entry) iterator.next();
254:                    buf.append(entry.getKey()).append(":");
255:                    buf
256:                            .append(MapUtils.toString((Map) entry.getValue(),
257:                                    false));
258:                    buf.append(", ");
259:                }
260:                buf.append("}");
261:                return buf.toString();
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.