import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
-import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.BindingCodec;
import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
ReferencedTypeImpl typeref = new ReferencedTypeImpl(type.getPackageName(), type.getName());
@SuppressWarnings("rawtypes")
WeakReference<Class> weakRef = typeToClass.get(typeref);
+ if(weakRef == null) {
+ LOG.error("Could not find loaded class for path: {} and type: {}",path,typeref.getFullyQualifiedName());
+ }
return weakRef.get();
}
@Override
@SuppressWarnings("rawtypes")
public void bindingClassEncountered(Class cls) {
+
ConcreteType typeRef = Types.typeForClass(cls);
+ if(typeToClass.containsKey(typeRef)) {
+ return;
+ }
+ LOG.info("Binding Class {} encountered.",cls);
WeakReference<Class> weakRef = new WeakReference<>(cls);
typeToClass.put(typeRef, weakRef);
+ if(DataObject.class.isAssignableFrom(cls)) {
+ @SuppressWarnings({"unchecked","unused"})
+ Object cdc = getCodecForDataObject((Class<? extends DataObject>) cls);
+ }
+ }
+
+ @Override
+ public void onClassProcessed(Class<?> cls) {
+ ConcreteType typeRef = Types.typeForClass(cls);
+ if(typeToClass.containsKey(typeRef)) {
+ return;
+ }
+ LOG.info("Binding Class {} encountered.",cls);
+ WeakReference<Class> weakRef = new WeakReference<>((Class) cls);
+ typeToClass.put(typeRef, weakRef);
}
private DataSchemaNode getSchemaNode(List<QName> path) {
ReferencedTypeImpl typeref = new ReferencedTypeImpl(caseNode.getValue().getPackageName(), caseNode
.getValue().getName());
ChoiceCaseNode node = (ChoiceCaseNode) SchemaContextUtil.findDataSchemaNode(module, caseNode.getKey());
+ if (node == null) {
+ LOG.error("YANGTools Bug: SchemaNode for {}, with path {} was not found in context.",
+ typeref.getFullyQualifiedName(), caseNode.getKey());
+ continue;
+ }
+
@SuppressWarnings("rawtypes")
ChoiceCaseCodecImpl value = new ChoiceCaseCodecImpl(node);
typeToCaseNodes.putIfAbsent(typeref, value);
BindingCodec<Map<QName, Object>, Object> delegate = newInstanceOf(choiceCodec);
ChoiceCodecImpl<?> newCodec = new ChoiceCodecImpl(delegate);
choiceCodecs.put(choiceClass, newCodec);
- CodecMapping.setClassToCaseMap(choiceCodec, (Map<Class, BindingCodec>) classToCaseRawCodec);
+ CodecMapping.setClassToCaseMap(choiceCodec, (Map<Class<?>, BindingCodec<?, ?>>) classToCaseRawCodec);
CodecMapping.setCompositeNodeToCaseMap(choiceCodec, newCodec.getCompositeToCase());
}
@Override
public void onValueCodecCreated(Class<?> valueClass, Class<?> valueCodec) {
- // TODO Auto-generated method stub
-
}
@Override
public void onCaseCodecCreated(Class<?> choiceClass,
Class<? extends BindingCodec<Map<QName, Object>, Object>> choiceCodec) {
- // TODO Auto-generated method stub
-
}
@Override
@Override
public boolean isAcceptable(Node<?> input) {
- if (false == (input instanceof CompositeNode)) {
+ if (!(input instanceof CompositeNode)) {
if (augmenting) {
return checkAugmenting((CompositeNode) input);
} else {
QName parent = input.getNodeType();
for (Node<?> childNode : input.getChildren()) {
QName child = childNode.getNodeType();
- if (false == Objects.equals(parent.getNamespace(), child.getNamespace())) {
- continue;
- }
- if (false == Objects.equals(parent.getRevision(), child.getRevision())) {
+ if (!Objects.equals(parent.getNamespace(), child.getNamespace()) || Objects.equals(parent.getRevision(), child.getRevision())) {
continue;
}
if (validNames.contains(child.getLocalName())) {
@Override
public Set<java.util.Map.Entry<Class, BindingCodec<Object, Object>>> entrySet() {
- return null;
+ return Collections.emptySet();
}
@Override
public BindingCodec get(Object key) {
if (key instanceof Class) {
Class cls = (Class) key;
- bindingClassEncountered(cls);
+ //bindingClassEncountered(cls);
ChoiceCaseCodecImpl caseCodec = getCaseCodecFor(cls);
return caseCodec.getDelegate();
}
this.choiceCases = choiceCases;
}
- @Override
- public Set<java.util.Map.Entry<CompositeNode, BindingCodec>> entrySet() {
- return null;
- }
-
@Override
public BindingCodec get(Object key) {
- if (false == (key instanceof CompositeNode)) {
+ if (!(key instanceof CompositeNode)) {
return null;
}
for (java.util.Map.Entry<Class, ChoiceCaseCodecImpl<?>> entry : choiceCases.entrySet()) {
}
return null;
}
+
+
}
/**
* Key type
*/
@SuppressWarnings("rawtypes")
- private static abstract class MapFacadeBase<T> implements Map<T, BindingCodec> {
+ private static abstract class MapFacadeBase<T> implements Map<T, BindingCodec<?, ?>> {
@Override
public boolean containsKey(Object key) {
}
@Override
- public Collection<BindingCodec> values() {
- return null;
+ public Collection<BindingCodec<?, ?>> values() {
+ return Collections.emptySet();
}
private UnsupportedOperationException notModifiable() {
}
@Override
- public BindingCodec<Map<QName, Object>, Object> put(T key, BindingCodec value) {
+ public BindingCodec<Map<QName, Object>, Object> put(T key, BindingCodec<?,?> value) {
throw notModifiable();
}
@Override
- public void putAll(Map<? extends T, ? extends BindingCodec> m) {
+ public void putAll(Map<? extends T, ? extends BindingCodec<?, ?>> m) {
throw notModifiable();
}
@Override
public boolean isEmpty() {
- return false;
+ return true;
}
@Override
public Set<T> keySet() {
- return null;
+ return Collections.emptySet();
}
@Override
- public Set<java.util.Map.Entry<T, BindingCodec>> entrySet() {
- return null;
+ public Set<java.util.Map.Entry<T, BindingCodec<?, ?>>> entrySet() {
+ return Collections.emptySet();
}
@Override
augmentationField.setAccessible(true);
Map<Class, Augmentation> augMap = (Map<Class, Augmentation>) augmentationField.get(input);
return augMap;
- } catch (NoSuchFieldException e) {
-
- } catch (SecurityException e) {
-
- } catch (IllegalArgumentException e) {
-
- } catch (IllegalAccessException e) {
-
- }
+ } catch (IllegalArgumentException | IllegalAccessException |NoSuchFieldException | SecurityException e) {
+ LOG.debug("Could not read augmentations for {}",input,e);
+ }
return Collections.emptyMap();
}
rawAugmentationCodecs.put(key, ret);
return ret;
} catch (InstantiationException e) {
-
+ LOG.error("Can not instantiate raw augmentation codec {}",key.getSimpleName(),e);
} catch (IllegalAccessException e) {
-
+ LOG.debug("BUG: Constructor for {} is not accessible.",key.getSimpleName(),e);
}
return null;
}