use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.
the class TemplateFactory method getTOAndMXInterfaceFtlFiles.
/**
* Get map of file name as key, FtlFile instance representing runtime mx
* bean as value that should be persisted from this instance.
*/
public static Map<String, FtlTemplate> getTOAndMXInterfaceFtlFiles(final RuntimeBeanEntry entry) {
final Map<String, FtlTemplate> result = new HashMap<>();
{
// create GeneralInterfaceFtlFile for runtime MXBean. Attributes will
// be transformed to getter methods
final String mxBeanTypeName = entry.getJavaNameOfRuntimeMXBean();
final List<String> extendedInterfaces = Collections.singletonList(RuntimeBean.class.getCanonicalName());
final List<MethodDeclaration> methods = new ArrayList<>();
// convert attributes to getters
for (final AttributeIfc attributeIfc : entry.getAttributes()) {
String returnType;
returnType = getReturnType(attributeIfc);
final String getterName = "get" + attributeIfc.getUpperCaseCammelCase();
final MethodDeclaration getter = new MethodDeclaration(returnType, getterName, Collections.<Field>emptyList());
methods.add(getter);
}
// add rpc methods
for (final Rpc rpc : entry.getRpcs()) {
// convert JavaAttribute parameters into fields
final List<Field> fields = new ArrayList<>();
for (final JavaAttribute ja : rpc.getParameters()) {
final Field field = new Field(Collections.emptyList(), ja.getType().getFullyQualifiedName(), ja.getLowerCaseCammelCase(), ja.getNullableDefaultWrappedForCode());
fields.add(field);
}
final MethodDeclaration operation = new MethodDeclaration(getReturnType(rpc.getReturnType()), rpc.getName(), fields);
methods.add(operation);
}
// FIXME header
final GeneralInterfaceTemplate runtimeMxBeanIfc = new GeneralInterfaceTemplate(null, entry.getPackageName(), mxBeanTypeName, extendedInterfaces, methods);
result.put(runtimeMxBeanIfc.getTypeDeclaration().getName() + ".java", runtimeMxBeanIfc);
}
result.putAll(TemplateFactory.tOsFromRbe(entry));
return result;
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.
the class ObjectXmlWriter method caseListAttribute.
@Override
protected AttributeWritingStrategy caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
AttributeWritingStrategy innerStrategy = prepareWritingStrategy(key, innerAttribute, document);
return new ArrayAttributeWritingStrategy(innerStrategy);
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.
the class InstanceConfig method getMappedConfiguration.
@SuppressWarnings("IllegalCatch")
private Map<String, Object> getMappedConfiguration(final ObjectName on, final EnumResolver enumResolver) {
// TODO make field, mappingStrategies can be instantiated only once
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> mappingStrategies = new ObjectMapper().prepareMapping(jmxToAttrConfig, enumResolver);
Map<String, Object> toXml = Maps.newHashMap();
for (Entry<String, AttributeIfc> configDefEntry : jmxToAttrConfig.entrySet()) {
// Skip children runtime beans as they are mapped by InstanceRuntime
if (configDefEntry.getValue() instanceof RuntimeBeanEntry) {
continue;
}
Object value = configRegistryClient.getAttributeCurrentValue(on, configDefEntry.getKey());
try {
AttributeMappingStrategy<?, ? extends OpenType<?>> attributeMappingStrategy = mappingStrategies.get(configDefEntry.getKey());
Optional<?> attribute = attributeMappingStrategy.mapAttribute(value);
if (!attribute.isPresent()) {
continue;
}
toXml.put(configDefEntry.getValue().getAttributeYangName(), attribute.get());
} catch (final RuntimeException e) {
throw new IllegalStateException("Unable to map value " + value + " to attribute " + configDefEntry.getKey(), e);
}
}
return toXml;
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.
the class ObjectResolver method caseListAttribute.
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
return new ArrayAttributeResolvingStrategy(prepareStrategy(innerAttribute), openType);
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.
the class ObjectXmlReader method caseListAttribute.
@Override
protected AttributeReadingStrategy caseListAttribute(final ArrayType<?> openType) {
AttributeIfc lastAttribute = getLastAttribute();
Preconditions.checkState(lastAttribute instanceof ListAttribute);
AttributeReadingStrategy innerStrategy = prepareReadingStrategy(key, ((ListAttribute) lastAttribute).getInnerAttribute());
return new ArrayAttributeReadingStrategy(lastAttribute.getNullableDefault(), innerStrategy);
}
Aggregations