public String getImplementedInterface(DataObject message) { return message.getImplementedInterface().getName(); }
@SuppressWarnings("unchecked") public static <T extends DataObject> Map<InstanceIdentifier<T>, T> collectTypeFromMap(Class<T> tClass, Map<InstanceIdentifier<?>, DataObject> map) { Map<InstanceIdentifier<T>, T> result = Maps.newHashMap(); for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : map.entrySet()) { if (tClass.isAssignableFrom(entry.getValue().getImplementedInterface())) { final InstanceIdentifier<T> tIID = (InstanceIdentifier<T>) entry.getKey(); final T tObj = (T) entry.getValue(); result.put(tIID, tObj); } } return result; }
/** * Find data hierarchy parent from concrete Data class * * This method is shorthand which gets DataObject class by invoking * {@link DataObject#getImplementedInterface()} and uses * {@link #findHierarchicalParent(Class)}. * * @param child * Child object for which the parent needs to be located. * @return Parent class, or null if a parent is not found. */ public static Class<?> findHierarchicalParent(final DataObject child) { if (child instanceof ChildOf) { return ClassLoaderUtils.findFirstGenericArgument(child.getImplementedInterface(), ChildOf.class); } return null; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!AggregatedTopology.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } AggregatedTopology other = (AggregatedTopology)obj; if (!Objects.equals(_originalTopology, other.getOriginalTopology())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!RpcLeafOnlyUsesAugment.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } RpcLeafOnlyUsesAugment other = (RpcLeafOnlyUsesAugment)obj; if (!Objects.equals(_leafFromGrouping, other.getLeafFromGrouping())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!NestedListSimpleAugment.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } NestedListSimpleAugment other = (NestedListSimpleAugment)obj; if (!Objects.equals(_type, other.getType())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!RpcSecondLeafOnlyAugment.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } RpcSecondLeafOnlyAugment other = (RpcSecondLeafOnlyAugment)obj; if (!Objects.equals(_secondSimpleValue, other.getSecondSimpleValue())) { return false; } return true; }
@Override public boolean equals(java.lang.Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.SupportedTunnelsParameters.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.SupportedTunnelsParameters other = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.SupportedTunnelsParameters)obj; if (!Objects.equals(_ipPortLocatorEntry, other.getIpPortLocatorEntry())) { return false; } return true; }
@Override public boolean equals(java.lang.Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping other = (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping)obj; if (!Objects.equals(_flowHashIdMap, other.getFlowHashIdMap())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!TreeLeafOnlyUsesAugment.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } TreeLeafOnlyUsesAugment other = (TreeLeafOnlyUsesAugment)obj; if (!Objects.equals(_leafFromGrouping, other.getLeafFromGrouping())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!IdentifiableNode.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } IdentifiableNode other = (IdentifiableNode)obj; if (!Objects.equals(_nodeIdentifier, other.getNodeIdentifier())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!InventoryNode.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } InventoryNode other = (InventoryNode)obj; if (!Objects.equals(_inventoryNodeRef, other.getInventoryNodeRef())) { return false; } return true; }
@Override public boolean equals(java.lang.Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.RpcLeafOnlyUsesAugment.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.RpcLeafOnlyUsesAugment other = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.RpcLeafOnlyUsesAugment)obj; if (!Objects.equals(_leafFromGrouping, other.getLeafFromGrouping())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!RpcLeafOnlyAugment.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } RpcLeafOnlyAugment other = (RpcLeafOnlyAugment)obj; if (!Objects.equals(_simpleValue, other.getSimpleValue())) { return false; } return true; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DataObject)) { return false; } if (!InventoryNodeConnector.class.equals(((DataObject)obj).getImplementedInterface())) { return false; } InventoryNodeConnector other = (InventoryNodeConnector)obj; if (!Objects.equals(_inventoryNodeConnectorRef, other.getInventoryNodeConnectorRef())) { return false; } return true; }
public static final <T extends DataObject> Optional<T> readData(final DataObject source, final Class<T> child) { checkArgument(source != null, "Object should not be null."); checkArgument(child != null, "Child type should not be null"); Class<? extends DataContainer> parentClass = source.getImplementedInterface(); @SuppressWarnings("unchecked") T potential = (T) resolveReadStrategy(parentClass, child).read(source, child); return Optional.fromNullable(potential); }
/** * {@inheritDoc} */ @Override public <T extends DataObject> void validate(@Nonnull final Class<T> tClass, @Nonnull final DataObject data, @Nonnull final Validator.Extent extent) throws ValidationException { if (!tClass.isAssignableFrom(data.getClass())) { throw new IllegalArgumentException( String.format("data must be the same type as tClass, got=%s : expected=%s", data.getImplementedInterface(), tClass)); } // We are checking the type of data above @SuppressWarnings("unchecked") T tData = (T) data; validatorFor(tClass).validate(tData, extent); }
/** * Transforms POJO message into ByteBuf * @param version version used for encoding received message * @param out ByteBuf for storing and sending transformed message * @param message POJO message */ public void messageToBuffer(short version, ByteBuf out, DataObject message) { OFSerializer<DataObject> serializer = registry.getSerializer( new MessageTypeKey<>(version, message.getImplementedInterface())); serializer.serialize(message, out); }
private <T extends DataContainer> ContainerNode serializeDataObject(final DataObject data, final BiFunction<Class<? extends T>, NormalizedNodeStreamWriter, BindingStreamEventWriter> newWriter) { final NormalizedNodeResult result = new NormalizedNodeResult(); // We create DOM stream writer which produces normalized nodes final NormalizedNodeStreamWriter domWriter = ImmutableNormalizedNodeStreamWriter.from(result); @SuppressWarnings("unchecked") final Class<? extends DataObject> type = (Class<? extends DataObject>) data.getImplementedInterface(); final BindingStreamEventWriter writer = newWriter.apply((Class<T>)type, domWriter); try { getSerializer(type).serialize(data, writer); } catch (final IOException e) { LOG.error("Unexpected failure while serializing data {}", data, e); throw new IllegalStateException("Failed to create normalized node", e); } return (ContainerNode) result.getResult(); }
@Override @SuppressWarnings("unchecked") public void serialize(final DataObjectSerializerRegistry reg, final DataObject obj, final BindingStreamEventWriter stream) throws IOException { @SuppressWarnings("rawtypes") Class cazeClass = obj.getImplementedInterface(); stream.startChoiceNode(choiceClass, BindingStreamEventWriter.UNKNOWN_SIZE); DataObjectSerializer caseSerializer = reg.getSerializer(cazeClass); if (caseSerializer != null) { caseSerializer.serialize(obj, stream); } else { LOG.warn("No serializer for case {} is available in registry {}", cazeClass, reg); } stream.endNode(); } }