I'd like to unmarshal the following xml to a MultiKeyMap:
<map>
<entry key1="foo" key2="foo">
<value property="val"/>
</entry>
<entry key1="bar" key2="bar">
<value property="val"/>
</entry>
</map>
I took a look through the Castor API and saw that there's a CollectionFieldHandler class, but I can't find any documentation on where I would need to register a custom collection handler.
First of all, collection isn't a map.
You can implement and register your own handler.
See http://www.castor.org/xml-fieldhandlers.html
Related
I have a problem a little problem related to the namespaces in the XML marshalled by Jaxb2 . When I print out the xml file, I get this "extra" annotations on the xml tags. Is there any way to get rid of the extra namespace annotations ?
Here is an example:
<?xml version="1.0" encoding="UTF-8" standalone="yes">
<root xmlns:ns2="http://www.something.com/something">
<ns2:food>steak</ns2:food>
<ns2:beverage>water</ns2:beverage>
</root>
I want to get rid of the ns2: namespace.
I tried with :
<bean id="glsJaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="${gls.jaxb2.contextpath}"/>
<property name="marshallerProperties">
<map>
<entry key="com.sun.xml.bind.namespacePrefixMapper">
<bean class="es.fs.fswarehousing.gls.ws.EmptyNamespacePrefixMapper"/>
</entry>
</map>
</property>
</bean>
But im getting :
ERROR [TaskExecutor-master-555-ProcessTask [8796749431734]]
[ActionNode] Error executing
org.springframework.oxm.UncategorizedMappingException: Unknown JAXB
exception; nested exception is javax.xml.bind.PropertyException: name:
com.sun.xml.bind.namespacePrefixMapper value:
es.fs.fswarehousing.gls.ws.EmptyNamespacePrefixMapper#17f6a8fe
Can someone give me any hint :) ?
Ive found this configuration on a applicationContext xml and I still dont understand it (even if I found info about it, is not clear) could someone give me an idea of how java chooses the right bean for its property? I did not find this bean in other file of the project context, seems like is "magic"
<bean id="mailCreator" class="com.project.ConfigurableXferEmailCreator">
<property name="mailCreatorMap">
<util:map id="mailCreatorMap" key-type="java.lang.String"
value-type="com.project.BaseMailCreator">
<entry>
<key>
<util:constant static-field="com.project.creatorType.TYPE1"/>
</key>
<bean class="com.project.creator1" parent="baseCreator">
<property name="service" ref="someService1" />
</bean>
</entry>
<entry>
<key>
<util:constant static-field="com.project.creatorType.TYPE2"/>
</key>
<bean class="com.project.creator1" parent="baseCreator">
<property name="service" ref="someService2" />
</bean>
</entry>
.... and so on
I really have no idea how java recognizes which one will use, I just know it uses the right service but I dont see where is being specifically set, could someone give me a hand?
I checked couple of sites like this but still no idea , does it call all services??
http://www.java2s.com/Tutorials/Java/Spring/0140__Spring_Map_Properties.htm
Your question:
"how java chooses the right bean for its property"
I assume you mean for example this line:
<property name="service" ref="someService1" />
if you do not see another XML bean element that defines "someService1"
fr example:
<bean id="someService1" class="com.project.SomeService1Impl">
Then it exists in the Java Code
try to find an annotation like below
#Service("someService1")
public class SomeService1Impl {
...
How?:
Spring loads "someService1" in the Spring Context on initialization , so the XML can reference it.
I need to provide a timeStamp and two signature action with different features,
when we put two signature it understand only first
how we could handle it in cxf?
we should provide custom action
http://cxf.apache.org/docs/ws-security.html
<constructor-arg>
<map>
<entry key="action" value="Timestamp Signature 12345"/>
<entry key="wss4j.action.map">
<map key-type="java.lang.Integer" value-type="java.lang.Object">
<entry key="12345" value-ref="customSignature"/>
</map>
</entry>
and we should create a class
CustomSignatureAction extends SignatureAction {
and override features which different with fist signature
I have an xml string in the following format
<map>
<entry>
<string>key</string>
<string>value</string>
</entry>
<entry>
<string>key2</string>
<string>value2</string>
</entry>
....
</map>
Is there an easy library/tool that I can use to read this type of xml directly into a Hashmap. I am not very familiar with working with xml, so I would really appreciate some help here.
Thanks.
I have several maps defined in my context file. Is there a way to combine those maps into one map that contains all of their entries, without writing Java code (and without using nested maps)? I'm looking for the equivalent of Map m = new HashMap(); m.putAll(carMap); m.putAll(bikeMap);
Seems like there should be a way to do this in Spring context file, but the Spring 3.0 reference doc section on util:map doesn't cover this use case.
<!-- I want to create a map with id "vehicles" that contains all entries of the other maps -->
<util:map id="cars">
<entry key="groceryGetter" value-ref="impreza"/>
</util:map>
<util:map id="bicycles">
<entry key="commuterBike" value-ref="schwinn"/>
</util:map>
Using collection merging concept in Spring, multiple beans like these can be merged incrementally. I used this in my project to merge lists , but can be extended to merge maps as well.
E.g.
<bean id="commonMap"
class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="1" value="one"/>
<entry key="2" value="two"/>
</map>
</property>
</bean>
<bean id="firstMap"
parent="commonMap"
class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map merge="true">
<entry key="3" value="three"/>
<entry key="4" value="four"/>
</map>
</property>
</bean>
The association of the second map definition with the first one is done through the parent attribute on the <bean> node and the entries in the first map are merged with those in the second using the merge attribute on the <map> node.
I bet there is no direct support for this feature in Spring.
However, writing a factory bean to use in Spring is not that difficult (haven't tried to compile that)
public class MapMerger <K,V> implements FactoryBean {
private Map<K,V> result = new HashMap<K,V>();
#Override
public Object getObject() {
return result;
}
#Override
public boolean isSingleton(){
return true;
}
#Override
public Class getObjectType(){
return Map.class;
}
public void setSourceMaps(List<Map<K,V>> maps) {
for (Map<K,V> m : maps) {
this.result.putAll(m);
}
}
}
In spring config, just do something like:
<bean id="yourResultMap" class="foo.MapMerger">
<property name="sourceMaps">
<util:list>
<ref bean="carMap" />
<ref bean="bikeMap" />
<ref bean="motorBikeMap" />
</util:list>
</property>
</bean>