001: /*
002: * Copyright 2005 Ralf Joachim
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.castor.mapping;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.exolab.castor.mapping.Mapping;
021: import org.exolab.castor.mapping.xml.Include;
022: import org.exolab.castor.util.DTDResolver;
023: import org.exolab.castor.xml.UnmarshalListener;
024:
025: /**
026: * An UnmarshalListener to handle mapping includes.
027: *
028: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
029: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
030: */
031: public final class MappingUnmarshallListener implements
032: UnmarshalListener {
033:
034: private static final Log LOG = LogFactory
035: .getLog(MappingUnmarshallListener.class);
036: private final MappingUnmarshaller _unmarshaller;
037:
038: private final Mapping _mapping;
039:
040: /** The entity resolver to use. May be null. */
041: private final DTDResolver _resolver;
042:
043: public MappingUnmarshallListener(
044: final MappingUnmarshaller unmarshaller,
045: final Mapping mapping, final DTDResolver resolver) {
046: _unmarshaller = unmarshaller;
047: _mapping = mapping;
048: _resolver = resolver;
049: }
050:
051: /**
052: * Not used for includes processing.
053: *
054: * @see org.exolab.castor.xml.UnmarshalListener#initialized(java.lang.Object)
055: * {@inheritDoc}
056: */
057: public void initialized(final Object object) {
058: }
059:
060: /**
061: * Not used for includes processing.
062: *
063: * @see org.exolab.castor.xml.UnmarshalListener#attributesProcessed(java.lang.Object)
064: * {@inheritDoc}
065: */
066: public void attributesProcessed(final Object object) {
067: }
068:
069: /**
070: * Not used for includes processing.
071: *
072: * @see org.exolab.castor.xml.UnmarshalListener#fieldAdded(java.lang.String,
073: * java.lang.Object, java.lang.Object)
074: * {@inheritDoc}
075: */
076: public void fieldAdded(final String fieldName, final Object parent,
077: final Object child) {
078: }
079:
080: /**
081: * This method is called after an object has been completely unmarshalled, including
082: * all of its children (if any).
083: *
084: * @param object the Object that was unmarshalled.
085: * @see org.exolab.castor.xml.UnmarshalListener#unmarshalled(java.lang.Object)
086: * {@inheritDoc}
087: */
088: public void unmarshalled(final Object object) {
089: if (object instanceof Include) {
090: Include include = (Include) object;
091: try {
092: _unmarshaller.loadMappingInternal(_mapping, _resolver,
093: include.getHref());
094: } catch (Exception ex) {
095: LOG.warn("Problem", ex);
096: //-- ignore error, it'll get reported
097: //-- later when we re-process the
098: //-- includes of the parent Mapping in
099: //-- loadMappingInternal
100: }
101: }
102: }
103: }
|