Source Code Cross Referenced for SimplePropertyConfiguration.java in  » ESB » mule » org » mule » config » spring » parsers » assembly » configuration » 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.config.spring.parsers.assembly.configuration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: SimplePropertyConfiguration.java 10256 2008-01-08 15:20:25Z 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:
011:        package org.mule.config.spring.parsers.assembly.configuration;
012:
013:        import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
014:
015:        import java.util.ArrayList;
016:        import java.util.HashMap;
017:        import java.util.HashSet;
018:        import java.util.List;
019:        import java.util.Map;
020:        import java.util.Properties;
021:        import java.util.Set;
022:
023:        import org.springframework.core.Conventions;
024:        import org.springframework.util.StringUtils;
025:
026:        /**
027:         * A direct implementation of {@link PropertyConfiguration}
028:         */
029:        public class SimplePropertyConfiguration implements 
030:                PropertyConfiguration {
031:
032:            private List references = new ArrayList();
033:            private Properties nameMappings = new Properties();
034:            private Map valueMappings = new HashMap();
035:            private Set collections = new HashSet();
036:            private Map ignored = new HashMap();
037:            private boolean ignoreAll = false;
038:
039:            public void addReference(String propertyName) {
040:                references.add(dropRef(propertyName));
041:            }
042:
043:            public void addMapping(String propertyName, Map mappings) {
044:                valueMappings.put(propertyName, new NamedValueMap(propertyName,
045:                        mappings));
046:            }
047:
048:            public void addMapping(String propertyName, String mappings) {
049:                valueMappings.put(propertyName, new NamedValueMap(propertyName,
050:                        mappings));
051:            }
052:
053:            public void addMapping(String propertyName, ValueMap mappings) {
054:                valueMappings.put(propertyName, new NamedValueMap(propertyName,
055:                        mappings));
056:            }
057:
058:            public void addAlias(String alias, String propertyName) {
059:                nameMappings.put(alias, propertyName);
060:            }
061:
062:            public void addCollection(String propertyName) {
063:                collections.add(dropRef(propertyName));
064:            }
065:
066:            public void addIgnored(String propertyName) {
067:                ignored.put(dropRef(propertyName), Boolean.TRUE);
068:            }
069:
070:            public void removeIgnored(String propertyName) {
071:                ignored.put(dropRef(propertyName), Boolean.FALSE);
072:            }
073:
074:            public void setIgnoredDefault(boolean ignoreAll) {
075:                this .ignoreAll = ignoreAll;
076:            }
077:
078:            public String getAttributeMapping(String alias) {
079:                return getAttributeMapping(alias, alias);
080:            }
081:
082:            public String getAttributeMapping(String alias, String deflt) {
083:                return nameMappings.getProperty(alias, deflt);
084:            }
085:
086:            public boolean isCollection(String propertyName) {
087:                return collections.contains(dropRef(propertyName));
088:            }
089:
090:            public boolean isIgnored(String propertyName) {
091:                String name = dropRef(propertyName);
092:                if (ignored.containsKey(name)) {
093:                    return ((Boolean) ignored.get(name)).booleanValue();
094:                } else {
095:                    return ignoreAll;
096:                }
097:            }
098:
099:            /**
100:             * A property can be explicitly registered as a bean reference via registerBeanReference()
101:             * or it can simply use the "-ref" suffix.
102:             * @param attributeName true if the name appears to correspond to a reference
103:             */
104:            public boolean isReference(String attributeName) {
105:                return (references.contains(dropRef(attributeName))
106:                        || attributeName
107:                                .endsWith(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF_SUFFIX)
108:                        || attributeName
109:                                .endsWith(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REFS_SUFFIX) || attributeName
110:                        .equals(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF));
111:            }
112:
113:            public SingleProperty getSingleProperty(String name) {
114:                return new SinglePropertyWrapper(name, this );
115:            }
116:
117:            /**
118:             * Extract a JavaBean property name from the supplied attribute name.
119:             * <p>The default implementation uses the {@link org.springframework.core.Conventions#attributeNameToPropertyName(String)}
120:             * method to perform the extraction.
121:             * <p>The name returned must obey the standard JavaBean property name
122:             * conventions. For example for a class with a setter method
123:             * '<code>setBingoHallFavourite(String)</code>', the name returned had
124:             * better be '<code>bingoHallFavourite</code>' (with that exact casing).
125:             *
126:             * @param oldName the attribute name taken straight from the XML element being parsed; will never be <code>null</code>
127:             * @return the extracted JavaBean property name; must never be <code>null</code>
128:             */
129:            public String translateName(String oldName) {
130:                // Remove the bean reference suffix if any.
131:                String name = dropRef(oldName);
132:                // Map to the real property name if necessary.
133:                name = getAttributeMapping(name);
134:                // JavaBeans property convention.
135:                name = Conventions.attributeNameToPropertyName(name);
136:                if (!StringUtils.hasText(name)) {
137:                    throw new IllegalStateException(
138:                            "Illegal property name for " + oldName
139:                                    + ": cannot be null or empty.");
140:                }
141:                return name;
142:            }
143:
144:            protected String dropRef(String name) {
145:                return org.mule.util.StringUtils
146:                        .chomp(
147:                                org.mule.util.StringUtils
148:                                        .chomp(
149:                                                name,
150:                                                AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF_SUFFIX),
151:                                AbstractMuleBeanDefinitionParser.ATTRIBUTE_REFS_SUFFIX);
152:            }
153:
154:            public Object translateValue(String name, String value) {
155:                NamedValueMap vm = (NamedValueMap) valueMappings.get(name);
156:                if (vm != null) {
157:                    return vm.getValue(value);
158:                } else {
159:                    return value;
160:                }
161:            }
162:
163:            public static class NamedValueMap {
164:                private String propertyName;
165:                private ValueMap valueMap;
166:
167:                public NamedValueMap(String propertyName, String mappingsString) {
168:                    this .propertyName = propertyName;
169:                    valueMap = new MapValueMap(mappingsString);
170:                }
171:
172:                public NamedValueMap(String propertyName, Map valueMap) {
173:                    this .propertyName = propertyName;
174:                    this .valueMap = new MapValueMap(valueMap);
175:                }
176:
177:                public NamedValueMap(String propertyName, ValueMap valueMap) {
178:                    this .propertyName = propertyName;
179:                    this .valueMap = valueMap;
180:                }
181:
182:                public String getPropertyName() {
183:                    return propertyName;
184:                }
185:
186:                public Object getValue(String key) {
187:                    return valueMap.rewrite(key);
188:                }
189:            }
190:
191:            public static class MapValueMap implements  ValueMap {
192:
193:                private Map map;
194:
195:                public MapValueMap(Map map) {
196:                    this .map = map;
197:                }
198:
199:                public MapValueMap(String definition) {
200:                    map = new HashMap();
201:
202:                    String[] values = StringUtils.tokenizeToStringArray(
203:                            definition, ",");
204:                    for (int i = 0; i < values.length; i++) {
205:                        String value = values[i];
206:                        int x = value.indexOf("=");
207:                        if (x == -1) {
208:                            throw new IllegalArgumentException(
209:                                    "Mappings string not properly defined: "
210:                                            + definition);
211:                        }
212:                        map.put(value.substring(0, x), value.substring(x + 1));
213:                    }
214:
215:                }
216:
217:                public Object rewrite(String value) {
218:                    Object result = map.get(value);
219:                    if (null == result) {
220:                        return value;
221:                    } else {
222:                        return result.toString();
223:                    }
224:                }
225:
226:            }
227:
228:        }
w_w_w___.__j_av__a2s.co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.