1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community 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
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
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.
15 */
16 package org.kuali.rice.krad.service.impl;
17
18 import org.kuali.rice.krad.document.Document;
19 import org.kuali.rice.krad.service.DocumentSerializerService;
20 import org.kuali.rice.krad.service.XmlObjectSerializerService;
21 import org.kuali.rice.krad.util.documentserializer.AlwaysTruePropertySerializibilityEvaluator;
22 import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluator;
23 import org.kuali.rice.krad.util.documentserializer.SerializationState;
24
25 /**
26 * Default implementation of the {@link DocumentSerializerService}. If no <workflowProperties> have been defined in the
27 * data dictionary for a document type (i.e. {@link Document#getDocumentPropertySerizabilityEvaluator()} returns an instance of
28 * {@link AlwaysTruePropertySerializibilityEvaluator}), then this service will revert to using the {@link XmlObjectSerializerService}
29 * bean, which was the old way of serializing a document for routing. If workflowProperties are defined, then this implementation
30 * will selectively serialize items.
31 */
32 public class DocumentSerializerServiceImpl extends SerializerServiceBase implements DocumentSerializerService {
33
34 /**
35 * Serializes a document for routing
36 *
37 * @see org.kuali.rice.krad.service.DocumentSerializerService#serializeDocumentToXmlForRouting(org.kuali.rice.krad.document.Document)
38 */
39 public String serializeDocumentToXmlForRouting(Document document) {
40 PropertySerializabilityEvaluator propertySerizabilityEvaluator = document.getDocumentPropertySerizabilityEvaluator();
41 evaluators.set(propertySerizabilityEvaluator);
42 SerializationState state = createNewDocumentSerializationState(document);
43 serializationStates.set(state);
44
45 Object xmlWrapper = wrapDocumentWithMetadata(document);
46 String xml;
47 if (propertySerizabilityEvaluator instanceof AlwaysTruePropertySerializibilityEvaluator) {
48 xml = getXmlObjectSerializerService().toXml(xmlWrapper);
49 }
50 else {
51 xml = xstream.toXML(xmlWrapper);
52 }
53
54 evaluators.set(null);
55 serializationStates.set(null);
56 return xml;
57 }
58
59 /**
60 * Wraps the document before it is routed. This implementation defers to {@link Document#wrapDocumentWithMetadataForXmlSerialization()}.
61 *
62 * @param document
63 * @return may return the document, or may return another object that wraps around the document to provide additional metadata
64 */
65 protected Object wrapDocumentWithMetadata(Document document) {
66 return document.wrapDocumentWithMetadataForXmlSerialization();
67 }
68
69 @Override
70 protected PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(Object dataObject) {
71 return null;
72 }
73 }