2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.util;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.Module;
20 public abstract class AbstractModuleStringIdentityrefCodec extends AbstractStringIdentityrefCodec {
22 * Resolve a string prefix into the corresponding module.
24 * @param prefix Prefix
25 * @return module mapped to prefix, or null if the module cannot be resolved
27 protected abstract @Nullable Module moduleForPrefix(@NonNull String prefix);
30 protected final QName createQName(final String prefix, final String localName) {
31 final Module module = moduleForPrefix(prefix);
32 checkArgument(module != null, "Failed to lookup prefix %s", prefix);
34 final QName qname = QName.create(module.getQNameModule(), localName);
35 for (IdentitySchemaNode identity : module.getIdentities()) {
36 if (qname.equals(identity.getQName())) {
37 return identity.getQName();
41 throw new IllegalArgumentException("Failed to find identity matching " + qname);