1 /*
2 * Copyright 2005 Ralf Joachim
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14 package org.castor.mapping;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.castor.xml.UnmarshalListener;
19 import org.exolab.castor.mapping.Mapping;
20 import org.exolab.castor.mapping.xml.Include;
21 import org.exolab.castor.util.DTDResolver;
22
23 /**
24 * An UnmarshalListener to handle mapping includes.
25 *
26 * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
27 * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
28 */
29 public final class MappingUnmarshallListener implements UnmarshalListener {
30
31 private static final Log LOG = LogFactory.getLog(MappingUnmarshallListener.class);
32 private final MappingUnmarshaller _unmarshaller;
33
34 private final Mapping _mapping;
35
36 /** The entity resolver to use. May be null. */
37 private final DTDResolver _resolver;
38
39
40 public MappingUnmarshallListener(final MappingUnmarshaller unmarshaller, final Mapping mapping,
41 final DTDResolver resolver) {
42 _unmarshaller = unmarshaller;
43 _mapping = mapping;
44 _resolver = resolver;
45 }
46
47 /**
48 * Not used for includes processing.
49 *
50 * @see org.castor.xml.UnmarshalListener#initialized(java.lang.Object) {@inheritDoc}
51 */
52 public void initialized(final Object target, final Object parent) {}
53
54 /**
55 * Not used for includes processing.
56 *
57 * @see org.castor.xml.UnmarshalListener#attributesProcessed(java.lang.Object) {@inheritDoc}
58 */
59 public void attributesProcessed(final Object target, final Object parent) {}
60
61 /**
62 * Not used for includes processing.
63 *
64 * @see org.castor.xml.UnmarshalListener#fieldAdded(java.lang.String, java.lang.Object,
65 * java.lang.Object) {@inheritDoc}
66 */
67 public void fieldAdded(final String fieldName, final Object parent, final Object child) {}
68
69 /**
70 * This method is called after an object has been completely unmarshalled, including all of its
71 * children (if any).
72 *
73 * @param object the Object that was unmarshalled.
74 * @see org.castor.xml.UnmarshalListener#unmarshalled(java.lang.Object) {@inheritDoc}
75 */
76 public void unmarshalled(final Object target, final Object parent) {
77 if (target instanceof Include) {
78 Include include = (Include) target;
79 try {
80 _unmarshaller.loadMappingInternal(_mapping, _resolver, include.getHref());
81 } catch (Exception ex) {
82 LOG.warn("Problem", ex);
83 // -- ignore error, it'll get reported
84 // -- later when we re-process the
85 // -- includes of the parent Mapping in
86 // -- loadMappingInternal
87 }
88 }
89 }
90 }