01: /*
02: * Copyright 2005 Ralf Joachim
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.castor.mapping;
17:
18: import org.exolab.castor.mapping.xml.ClassMapping;
19: import org.exolab.castor.mapping.xml.MappingRoot;
20: import org.exolab.castor.xml.IDResolver;
21:
22: /**
23: * An IDResolver to allow us to resolve ClassMappings from included Mapping files.
24: *
25: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
26: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
27: */
28: public final class MappingUnmarshallIDResolver implements IDResolver {
29: private MappingRoot _mapping = null;
30:
31: public MappingUnmarshallIDResolver() {
32: super ();
33: }
34:
35: public void setMapping(final MappingRoot mapping) {
36: _mapping = mapping;
37: }
38:
39: /**
40: * Returns the Object whose id matches the given IDREF, or null if no Object was
41: * found.
42: *
43: * @param idref the IDREF to resolve.
44: * @return the Object whose id matches the given IDREF.
45: * @see org.exolab.castor.xml.IDResolver#resolve(java.lang.String)
46: */
47: public Object resolve(final String idref) {
48: if (_mapping == null) {
49: return null;
50: }
51: for (int i = 0; i < _mapping.getClassMappingCount(); i++) {
52: ClassMapping clsMap = _mapping.getClassMapping(i);
53: if (idref.equals(clsMap.getName())) {
54: return clsMap;
55: }
56: }
57: return null;
58: }
59: }
|