1
1
/*
2
- * Copyright 2011-2013 the original author or authors.
2
+ * Copyright 2011-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
25
25
import org .springframework .beans .factory .support .ManagedMap ;
26
26
import org .springframework .beans .factory .xml .BeanDefinitionParser ;
27
+ import org .springframework .data .mongodb .core .MongoClientOptionsFactoryBean ;
27
28
import org .springframework .data .mongodb .core .MongoOptionsFactoryBean ;
28
29
import org .springframework .util .xml .DomUtils ;
29
30
import org .w3c .dom .Element ;
34
35
* @author Mark Pollack
35
36
* @author Oliver Gierke
36
37
* @author Thomas Darimont
38
+ * @author Christoph Strobl
37
39
*/
38
40
abstract class MongoParsingUtils {
39
41
@@ -87,6 +89,47 @@ static boolean parseMongoOptions(Element element, BeanDefinitionBuilder mongoBui
87
89
return true ;
88
90
}
89
91
92
+ /**
93
+ * @param element
94
+ * @param mongoClientBuilder
95
+ * @return
96
+ * @since 1.7
97
+ */
98
+ public static boolean parseMongoClientOptions (Element element , BeanDefinitionBuilder mongoClientBuilder ) {
99
+
100
+ Element optionsElement = DomUtils .getChildElementByTagName (element , "client-options" );
101
+ if (optionsElement == null ) {
102
+ return false ;
103
+ }
104
+
105
+ BeanDefinitionBuilder clientOptionsDefBuilder = BeanDefinitionBuilder
106
+ .genericBeanDefinition (MongoClientOptionsFactoryBean .class );
107
+
108
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "description" , "description" );
109
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "min-connections-per-host" , "minConnectionsPerHost" );
110
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "connections-per-host" , "connectionsPerHost" );
111
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "threads-allowed-to-block-for-connection-multiplier" ,
112
+ "threadsAllowedToBlockForConnectionMultiplier" );
113
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "max-wait-time" , "maxWaitTime" );
114
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "max-connection-idle-time" , "maxConnectionIdleTime" );
115
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "max-connection-life-time" , "maxConnectionLifeTime" );
116
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "connect-timeout" , "connectTimeout" );
117
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "socket-timeout" , "socketTimeout" );
118
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "socket-keep-alive" , "socketKeepAlive" );
119
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "read-preference" , "readPreference" );
120
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "write-concern" , "writeConcern" );
121
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "heartbeat-frequency" , "heartbeatFrequency" );
122
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "min-heartbeat-frequency" , "minHeartbeatFrequency" );
123
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "heartbeat-connect-timeout" , "heartbeatConnectTimeout" );
124
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "heartbeat-socket-timeout" , "heartbeatSocketTimeout" );
125
+ setPropertyValue (clientOptionsDefBuilder , optionsElement , "ssl" , "ssl" );
126
+ setPropertyReference (clientOptionsDefBuilder , optionsElement , "ssl-socket-factory-ref" , "sslSocketFactory" );
127
+
128
+ mongoClientBuilder .addPropertyValue ("mongoClientOptions" , clientOptionsDefBuilder .getBeanDefinition ());
129
+
130
+ return true ;
131
+ }
132
+
90
133
/**
91
134
* Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
92
135
* {@link WriteConcernPropertyEditor}.
@@ -103,4 +146,38 @@ static BeanDefinitionBuilder getWriteConcernPropertyEditorBuilder() {
103
146
104
147
return builder ;
105
148
}
149
+
150
+ /**
151
+ * Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
152
+ * {@link ReadPreferencePropertyEditor}.
153
+ *
154
+ * @return
155
+ * @since 1.7
156
+ */
157
+ static BeanDefinitionBuilder getReadPreferencePropertyEditorBuilder () {
158
+
159
+ Map <String , Class <?>> customEditors = new ManagedMap <String , Class <?>>();
160
+ customEditors .put ("com.mongodb.ReadPreference" , ReadPreferencePropertyEditor .class );
161
+
162
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition (CustomEditorConfigurer .class );
163
+ builder .addPropertyValue ("customEditors" , customEditors );
164
+
165
+ return builder ;
166
+ }
167
+
168
+ /**
169
+ * One should only register one bean definition but want to have the convenience of using
170
+ * AbstractSingleBeanDefinitionParser but have the side effect of registering a 'default' property editor with the
171
+ * container.
172
+ */
173
+ static BeanDefinitionBuilder getServerAddressPropertyEditorBuilder () {
174
+
175
+ Map <String , String > customEditors = new ManagedMap <String , String >();
176
+ customEditors .put ("com.mongodb.ServerAddress[]" ,
177
+ "org.springframework.data.mongodb.config.ServerAddressPropertyEditor" );
178
+
179
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition (CustomEditorConfigurer .class );
180
+ builder .addPropertyValue ("customEditors" , customEditors );
181
+ return builder ;
182
+ }
106
183
}
0 commit comments