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.exolab.castor.mapping.xml.ClassMapping; 17 import org.exolab.castor.mapping.xml.MappingRoot; 18 import org.exolab.castor.xml.IDResolver; 19 20 /** 21 * An IDResolver to allow us to resolve ClassMappings from included Mapping files. 22 * 23 * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a> 24 * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $ 25 */ 26 public final class MappingUnmarshallIDResolver implements IDResolver { 27 private MappingRoot _mapping = null; 28 29 public MappingUnmarshallIDResolver() { 30 super(); 31 } 32 33 public void setMapping(final MappingRoot mapping) { 34 _mapping = mapping; 35 } 36 37 /** 38 * Returns the Object whose id matches the given IDREF, or null if no Object was found. 39 * 40 * @param idref the IDREF to resolve. 41 * @return the Object whose id matches the given IDREF. 42 * @see org.exolab.castor.xml.IDResolver#resolve(java.lang.String) 43 */ 44 public Object resolve(final String idref) { 45 if (_mapping == null) { 46 return null; 47 } 48 for (int i = 0; i < _mapping.getClassMappingCount(); i++) { 49 ClassMapping clsMap = _mapping.getClassMapping(i); 50 if (idref.equals(clsMap.getName())) { 51 return clsMap; 52 } 53 } 54 return null; 55 } 56 }