import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
//YANG 1.1 allows notifications be tied to containers and lists
final Collection<DataSchemaNode> potentials = module.getChildNodes();
+ Set<NotificationDefinition> tiedNotifications = null;
for (final DataSchemaNode potential : potentials) {
if (potential instanceof NotificationNodeContainer) {
- final Set<NotificationDefinition> tiedNotifications = ((NotificationNodeContainer) potential)
+ tiedNotifications = ((NotificationNodeContainer) potential)
.getNotifications();
for (final NotificationDefinition tiedNotification: tiedNotifications) {
if (tiedNotification != null) {
resolveNotification(listenerInterface, potential.getQName().getLocalName(), basePackageName,
tiedNotification, module, schemaContext, verboseClassComments, genTypeBuilders,
typeProvider, genCtx);
- notifications.add(tiedNotification);
}
}
}
}
- listenerInterface.setDescription(createDescription(notifications, module, verboseClassComments));
+ if (tiedNotifications != null) {
+ listenerInterface.setDescription(createDescription(ImmutableSet.<NotificationDefinition>builder()
+ .addAll(notifications).addAll(tiedNotifications).build(), module, verboseClassComments));
+ } else {
+ listenerInterface.setDescription(createDescription(notifications, module, verboseClassComments));
+ }
genCtx.get(module).addTopLevelNodeType(listenerInterface);
import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.parameterizedTypeFor;
import static org.opendaylight.mdsal.binding.javav2.generator.util.Types.typeForClass;
-import javax.management.NotificationListener;
import org.opendaylight.mdsal.binding.javav2.model.api.ConcreteType;
import org.opendaylight.mdsal.binding.javav2.model.api.ParameterizedType;
import org.opendaylight.mdsal.binding.javav2.model.api.Type;
import org.opendaylight.mdsal.binding.javav2.spec.base.RpcCallback;
import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
import org.opendaylight.mdsal.binding.javav2.spec.base.TreeRoot;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.NotificationListener;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
import org.opendaylight.mdsal.binding.javav2.spec.structural.TreeChildNode;
@Override
protected String body() {
- String parentTypeForBuilderName;
+ final String parentTypeForBuilderName;
importedNames.put("genType", importedName(getType()));
importedNames.put("objects", importedName(Objects.class));
importedNames.put("object", importedName(Object.class));
if (getType().getParentType() != null) {
importedNames.put("parent", importedName(getType().getParentType()));
parentTypeForBuilderName = getType().getParentType().getName();
- } else {
+ } else if (getType().getParentTypeForBuilder() != null) {
importedNames.put("parentTypeForBuilder", importedName(getType().getParentTypeForBuilder()));
parentTypeForBuilderName = getType().getParentTypeForBuilder().getName();
+ } else {
+ parentTypeForBuilderName = null;
}
importedNames.put("augmentation", importedName(Augmentation.class));
importedNames.put("classInstMap", importedName(ClassToInstanceMap.class));
}
private static final class @{genType.getName}Impl implements @{genType.getName} {
-
+ @if(parentTypeForBuilderName != null) {
@implementedInterfaceGetter()
-
+ }
@generateFields(true)
@generateAugmentField(true)
}
@generateImplementedMethods() = {
+ @if(parentTypeForBuilderName != null) {
@@Override
public @{importedNames.get("item")}<@{parentTypeForBuilderName}> treeIdentifier() {
//TODO implement
return null;
}
-
+ }
@@Override
public @{importedNames.get("classInstMap")}<@{importedNames.get("augmentation")}<? super @{genType.getName}>>
augments() {
if (!(obj instanceof @{importedNames.get("treeNode")})) {
return false;
}
+ @if(parentTypeForBuilderName != null) {
if (!(obj instanceof @{importedNames.get("instantiable")})) {
return false;
}
.implementedInterface())) {
return false;
}
+ }
@{importedNames.get("genType")} other = (@{importedNames.get("genType")})obj;
@for(property <- properties) {
@if(property.getReturnType.getName.contains("[")) {
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.spec.runtime;
+
+import com.google.common.annotations.Beta;
+import java.util.EventListener;
+import org.opendaylight.mdsal.binding.javav2.spec.base.Notification;
+
+/**
+ * Marker interface for generated notification listener interfaces. This interface
+ * exists solely as support for generated code. Users should never implement this
+ * interface directly, but rather implement one of the sub-interfaces generated
+ * from a YANG model.
+ *
+ * <p>
+ * The subclasses of this interface have callbacks for events, which are derived
+ * from {@link Notification} class in form void
+ * on{NotificationType}(NotificationType notification).
+ *
+ * <p>
+ * E.g. if we have notification SessionUp the callback will have signature:
+ * <code>void onSessionUp(SessionUp notification)</code>
+ */
+@Beta
+public interface NotificationListener extends EventListener {
+}