2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.lib
.detached
;
18 import javax
.xml
.transform
.Result
;
19 import javax
.xml
.transform
.Source
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.argeo
.slc
.detached
.DetachedAnswer
;
23 import org
.argeo
.slc
.detached
.DetachedCommunication
;
24 import org
.argeo
.slc
.detached
.DetachedException
;
25 import org
.argeo
.slc
.detached
.DetachedRequest
;
26 import org
.argeo
.slc
.detached
.DetachedXmlConverter
;
27 import org
.springframework
.oxm
.Marshaller
;
28 import org
.springframework
.oxm
.Unmarshaller
;
30 public class DetachedXmlConverterSpring
implements DetachedXmlConverter
{
31 private Marshaller marshaller
;
32 private Unmarshaller unmarshaller
;
34 public void marshallCommunication(DetachedCommunication detCom
,
36 if (detCom
instanceof DetachedRequest
) {
37 marshallRequest((DetachedRequest
) detCom
, result
);
38 } else if (detCom
instanceof DetachedAnswer
) {
39 marshallAnswer((DetachedAnswer
) detCom
, result
);
41 throw new DetachedException("Unkown communication type "
46 public DetachedCommunication
unmarshallCommunication(Source source
) {
48 return (DetachedCommunication
) unmarshaller
.unmarshal(source
);
49 } catch (Exception e
) {
50 throw new SlcException("Could not unmarshall", e
);
54 public void marshallRequest(DetachedRequest request
, Result result
) {
56 marshaller
.marshal(request
, result
);
57 } catch (Exception e
) {
58 throw new SlcException("Could not marshall", e
);
62 public void marshallAnswer(DetachedAnswer answer
, Result result
) {
64 marshaller
.marshal(answer
, result
);
65 } catch (Exception e
) {
66 throw new SlcException("Could not marshall", e
);
70 public void setMarshaller(Marshaller marshaller
) {
71 this.marshaller
= marshaller
;
74 public void setUnmarshaller(Unmarshaller unmarshaller
) {
75 this.unmarshaller
= unmarshaller
;