}
}
- private static final Map<SchemaPath, InstanceIdentifier<?>> pathToBindingIdentifier = new ConcurrentHashMap<>();
-
protected final InstanceIdentifier<?> getBindingIdentifierByPath(final SchemaPath path) {
- return pathToBindingIdentifier.get(path);
+ return PATH_TO_BINDING_IDENTIFIER.get(path);
}
protected final void putPathToBindingIdentifier(final SchemaPath path, final InstanceIdentifier<?> bindingIdentifier) {
- pathToBindingIdentifier.put(path, bindingIdentifier);
+ PATH_TO_BINDING_IDENTIFIER.put(path, bindingIdentifier);
}
protected final InstanceIdentifier<?> putPathToBindingIdentifier(final SchemaPath path,
final InstanceIdentifier<?> bindingIdentifier, final Class<?> childClass) {
@SuppressWarnings({ "unchecked", "rawtypes" })
InstanceIdentifier<?> newId = bindingIdentifier.builder().child((Class) childClass).build();
- pathToBindingIdentifier.put(path, newId);
+ PATH_TO_BINDING_IDENTIFIER.put(path, newId);
return newId;
}
+ protected abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> augmentationTransformerForImpl(Class<?> inputType);
+ protected abstract Class<? extends BindingCodec<Object, Object>> caseCodecForImpl(Class<?> inputType, ChoiceCaseNode node);
+ protected abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifiableImpl(Class<?> parentType);
+ protected abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifierImpl(Class<?> inputType);
+ protected abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> transformerForImpl(Class<?> inputType);
+
// Called from LazyGeneratedCodecRegistry
- abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> augmentationTransformerFor(Class<?> inputType);
- abstract Class<? extends BindingCodec<Object, Object>> caseCodecFor(Class<?> inputType, ChoiceCaseNode node);
- abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifiable(Class<?> parentType);
- abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifier(Class<?> inputType);
- abstract Class<? extends BindingCodec<Map<QName, Object>, Object>> transformerFor(Class<?> inputType);
+ final Class<? extends BindingCodec<Map<QName, Object>, Object>> augmentationTransformerFor(final Class<?> inputType) throws TransformerGeneratorException {
+ try {
+ return augmentationTransformerForImpl(inputType);
+ } catch (Exception e) {
+ throw TransformerGeneratorException.wrap(inputType, e);
+ }
+ }
+
+ final Class<? extends BindingCodec<Object, Object>> caseCodecFor(final Class<?> inputType, final ChoiceCaseNode node) throws TransformerGeneratorException {
+ try {
+ return caseCodecForImpl(inputType, node);
+ } catch (Exception e) {
+ throw TransformerGeneratorException.wrap(inputType, e);
+ }
+ }
+
+ final Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifiable(final Class<?> parentType) throws TransformerGeneratorException {
+ try {
+ return keyTransformerForIdentifiableImpl(parentType);
+ } catch (Exception e) {
+ throw TransformerGeneratorException.wrap(parentType, e);
+ }
+ }
+
+ final Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifier(final Class<?> inputType) throws TransformerGeneratorException {
+ try {
+ return keyTransformerForIdentifierImpl(inputType);
+ } catch (Exception e) {
+ throw TransformerGeneratorException.wrap(inputType, e);
+ }
+ }
+
+ final Class<? extends BindingCodec<Map<QName, Object>, Object>> transformerFor(final Class<?> inputType) throws TransformerGeneratorException {
+ try {
+ return transformerForImpl(inputType);
+ } catch (Exception e) {
+ throw TransformerGeneratorException.wrap(inputType, e);
+ }
+ }
}
if (potentialCodec != null) {
codec = potentialCodec;
} else {
- try {
- lock.waitForSchema(object);
- Class<? extends BindingCodec<Map<QName, Object>, Object>> augmentRawCodec = generator
- .augmentationTransformerFor(object);
- BindingCodec<Map<QName, Object>, Object> rawCodec = augmentRawCodec.newInstance();
-
- codec = new AugmentationCodecWrapper<T>(rawCodec, null, object);
- augmentationCodecs.put(object, codec);
- } catch (InstantiationException e) {
- LOG.error("Can not instantiate raw augmentation codec {}", object.getSimpleName(), e);
- } catch (IllegalAccessException e) {
- LOG.debug(
- "Run-time consistency issue: constructor {} is not available. This indicates either a code generation bug or a misconfiguration of JVM.",
- object.getSimpleName(), e);
- }
+ lock.waitForSchema(object);
+ Class<? extends BindingCodec<Map<QName, Object>, Object>> augmentRawCodec = generator
+ .augmentationTransformerFor(object);
+
+ BindingCodec<Map<QName, Object>, Object> rawCodec = newInstanceOf(augmentRawCodec);
+ codec = new AugmentationCodecWrapper<T>(rawCodec, null, object);
+ augmentationCodecs.put(object, codec);
}
Class<? extends Augmentable<?>> objectSupertype = getAugmentableArgumentFrom(object);
if (objectSupertype != null) {
return null;
}
- private <T> T newInstanceOf(final Class<?> newType) {
+ private static <T> T newInstanceOf(final Class<?> cls) {
try {
@SuppressWarnings("unchecked")
- T ret = (T) newType.newInstance();
+ T ret = (T) cls.newInstance();
return ret;
} catch (InstantiationException e) {
- throw new IllegalStateException(e);
+ LOG.error("Failed to instantiate codec {}", cls.getSimpleName(), e);
+ throw new IllegalStateException(String.format("Failed to instantiate codec %s", cls), e);
} catch (IllegalAccessException e) {
- throw new IllegalStateException(e);
+ LOG.debug("Run-time consistency issue: constructor for {} is not available. This indicates either a code generation bug or a misconfiguration of JVM.",
+ cls.getSimpleName(), e);
+ throw new IllegalStateException(String.format("Cannot access contructor of %s", cls), e);
}
}
ctQName = QName.asCtClass
}
- override Class<? extends BindingCodec<Map<QName, Object>, Object>> transformerFor(Class inputType) {
+ override transformerForImpl(Class inputType) {
return runOnClassLoader(inputType.classLoader) [ |
val ret = getGeneratedClass(inputType)
if (ret !== null) {
]
}
- override Class<? extends BindingCodec<Map<QName, Object>, Object>> augmentationTransformerFor(Class inputType) {
+ override augmentationTransformerForImpl(Class inputType) {
return runOnClassLoader(inputType.classLoader) [ |
val ret = getGeneratedClass(inputType)
]
}
- override Class<? extends BindingCodec<Object, Object>> caseCodecFor(Class inputType, ChoiceCaseNode node) {
+ override caseCodecForImpl(Class inputType, ChoiceCaseNode node) {
return runOnClassLoader(inputType.classLoader) [ |
createMapping(inputType, node, null)
val ret = getGeneratedClass(inputType)
]
}
- override Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifiable(Class parentType) {
+ override keyTransformerForIdentifiableImpl(Class parentType) {
return runOnClassLoader(parentType.classLoader) [ |
val inputName = parentType.name + "Key";
val inputType = loadClass(inputName);
return keyMethod.returnType as GeneratedTransferObject
}
- override Class<? extends BindingCodec<Map<QName, Object>, Object>> keyTransformerForIdentifier(Class inputType) {
+ override keyTransformerForIdentifierImpl(Class inputType) {
return runOnClassLoader(inputType.classLoader) [ |
val ret = getGeneratedClass(inputType)
if (ret !== null) {
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.generator.impl;
+
+final class TransformerGeneratorException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public TransformerGeneratorException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ public static TransformerGeneratorException wrap(final Class<?> cls, final Throwable cause) throws TransformerGeneratorException {
+ return new TransformerGeneratorException(String.format("Failed to generate for type %s", cls), cause);
+ }
+}