01: /*
02: * Copyright 2007 Bastian Schenke Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
05: * Unless required by applicable law or agreed to in writing, software distributed under the
06: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
07: * either express or implied. See the License for the specific language governing permissions
08: * and limitations under the License.
09: */
10: package nz.org.take.r2ml;
11:
12: import java.util.HashMap;
13: import java.util.Map;
14:
15: import javax.xml.bind.JAXBElement;
16: import de.tu_cottbus.r2ml.Documentation;
17:
18: /**
19: * @author Bastian Schenke (bastian.schenke@googlemail.com)
20: *
21: */
22: class DocumentationHandler implements XmlTypeHandler {
23:
24: /**
25: * Map a Documentation object to a Map<String, String> of annotations (key,
26: * value)
27: *
28: * @param obj
29: * a Documentation object
30: *
31: * @return a Map<String, String> containg all Annotations extracted from the Documentation object
32: *
33: * @see nz.org.take.r2ml.XmlTypeHandler#importObject(java.lang.Object,
34: * nz.org.take.r2ml.R2MLDriver)
35: */
36: @SuppressWarnings("unchecked")
37: public Object importObject(Object obj) throws R2MLException {
38: Documentation documentation = (Documentation) obj;
39: Map<String, String> docAnnotations = new HashMap<String, String>();
40: for (JAXBElement<?> docElem : documentation
41: .getRuleTextOrSourceCodeOrSubject()) {
42: XmlTypeHandler handler = R2MLDriver.get()
43: .getHandlerByXmlType(docElem.getDeclaredType());
44: Map<String, String> newAnnotations = (Map<String, String>) handler
45: .importObject(docElem.getValue());
46: docAnnotations.putAll(newAnnotations);
47: }
48:
49: return docAnnotations;
50: }
51:
52: }
|