| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CompoundNamespaceContext | 
 | 
 | 4.0;4 | 
| 1 |  /** | |
| 2 |   * Copyright 2005-2011 The Kuali Foundation | |
| 3 |   * | |
| 4 |   * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 |   * you may not use this file except in compliance with the License. | |
| 6 |   * You may obtain a copy of the License at | |
| 7 |   * | |
| 8 |   * http://www.opensource.org/licenses/ecl2.php | |
| 9 |   * | |
| 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.kuali.rice.ken.util; | |
| 17 | ||
| 18 |  import java.util.ArrayList; | |
| 19 |  import java.util.Iterator; | |
| 20 |  import java.util.List; | |
| 21 | ||
| 22 |  import javax.xml.namespace.NamespaceContext; | |
| 23 | ||
| 24 |  /** | |
| 25 |   * XPath NamespaceContext implementation that delegates in sequence to a list of NamespaceContexts, | |
| 26 |   * returning the first match.  | |
| 27 |   * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 28 |   */ | |
| 29 | public class CompoundNamespaceContext implements NamespaceContext { | |
| 30 | private final List<NamespaceContext> contexts; | |
| 31 | ||
| 32 |      /** | |
| 33 |       * Constructs a CompoundNamespaceContext.java. | |
| 34 |       * @param first | |
| 35 |       * @param second | |
| 36 |       */ | |
| 37 | 0 |      public CompoundNamespaceContext(NamespaceContext first, NamespaceContext second) { | 
| 38 | 0 |          this.contexts = new ArrayList<NamespaceContext>(2); | 
| 39 | 0 |          this.contexts.add(first); | 
| 40 | 0 |          this.contexts.add(second); | 
| 41 | 0 |      } | 
| 42 | ||
| 43 |      /** | |
| 44 |       * Constructs a CompoundNamespaceContext.java. | |
| 45 |       * @param contexts | |
| 46 |       */ | |
| 47 | 0 |      public CompoundNamespaceContext(List<NamespaceContext> contexts) { | 
| 48 | 0 |          this.contexts = contexts; | 
| 49 | 0 |      } | 
| 50 | ||
| 51 |      /** | |
| 52 |       * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String) | |
| 53 |       */ | |
| 54 |      public String getNamespaceURI(String prefix) { | |
| 55 | 0 |          if (prefix == null) { | 
| 56 | 0 |              throw new IllegalArgumentException("The prefix cannot be null."); | 
| 57 | } | |
| 58 | 0 |          for (NamespaceContext nc: contexts) { | 
| 59 | 0 |              String uri = nc.getNamespaceURI(prefix); | 
| 60 | 0 |              if (uri != null) { | 
| 61 | 0 |                  return uri; | 
| 62 | } | |
| 63 | 0 |          } | 
| 64 | 0 |          return null; | 
| 65 | } | |
| 66 | ||
| 67 |      /** | |
| 68 |       * @see javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String) | |
| 69 |       */ | |
| 70 |      public String getPrefix(String namespaceURI) { | |
| 71 | 0 |          if (namespaceURI == null) { | 
| 72 | 0 |              throw new IllegalArgumentException("The namespace uri cannot be null."); | 
| 73 | } | |
| 74 | 0 |          for (NamespaceContext nc: contexts) { | 
| 75 | 0 |              String prefix = nc.getPrefix(namespaceURI); | 
| 76 | 0 |              if (prefix != null) { | 
| 77 | 0 |                  return prefix; | 
| 78 | } | |
| 79 | 0 |          } | 
| 80 | 0 |          return null; | 
| 81 | } | |
| 82 | ||
| 83 |      /** | |
| 84 |       * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) | |
| 85 |       */ | |
| 86 |      public Iterator getPrefixes(String namespaceURI) { | |
| 87 | 0 |          if (namespaceURI == null) { | 
| 88 | 0 |              throw new IllegalArgumentException("The namespace uri cannot be null."); | 
| 89 | } | |
| 90 | 0 |          for (NamespaceContext nc: contexts) { | 
| 91 | 0 |              Iterator prefixes = nc.getPrefixes(namespaceURI); | 
| 92 | 0 |              if (prefixes != null) { | 
| 93 | 0 |                  return prefixes; | 
| 94 | } | |
| 95 | 0 |          } | 
| 96 | 0 |          return null; | 
| 97 | } | |
| 98 | } |