1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.api.jaxb; |
17 | |
|
18 | |
import javax.xml.bind.MarshalException; |
19 | |
import javax.xml.bind.UnmarshalException; |
20 | |
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter; |
21 | |
import javax.xml.bind.annotation.adapters.XmlAdapter; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.kuali.rice.core.util.jaxb.NameAndNamespacePair; |
25 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
26 | |
import org.kuali.rice.kim.api.type.KimTypeContract; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class NameAndNamespacePairToKimTypeIdAdapter extends XmlAdapter<NameAndNamespacePair,String> { |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
@Override |
39 | |
public String unmarshal(NameAndNamespacePair v) throws Exception { |
40 | 0 | if (v != null) { |
41 | 0 | KimTypeContract kimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace( |
42 | |
v.getNamespaceCode(), new NormalizedStringAdapter().unmarshal(v.getName())); |
43 | 0 | if (kimType == null) { |
44 | 0 | throw new UnmarshalException("Cannot find KIM Type with namespace \"" + v.getNamespaceCode() + "\" and name \"" + v.getName() + "\""); |
45 | |
} |
46 | 0 | return kimType.getId(); |
47 | |
} |
48 | 0 | return null; |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@Override |
55 | |
public NameAndNamespacePair marshal(String v) throws Exception { |
56 | 0 | if (v != null) { |
57 | 0 | KimTypeContract kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(StringUtils.trim(v)); |
58 | 0 | if (kimType == null) { |
59 | 0 | throw new MarshalException("Cannot find KIM Type with ID \"" + v + "\""); |
60 | |
} |
61 | 0 | return new NameAndNamespacePair(kimType.getNamespaceCode(), kimType.getName()); |
62 | |
} |
63 | 0 | return null; |
64 | |
} |
65 | |
|
66 | |
} |