private final TransactionProvider transactionProvider;
- public CandidateDatastoreQueryStrategy(TransactionProvider transactionProvider) {
+ public CandidateDatastoreQueryStrategy(final TransactionProvider transactionProvider) {
this.transactionProvider = transactionProvider;
}
@Override
- public Set<ObjectName> queryInstances(ConfigRegistryClient configRegistryClient) {
+ public Set<ObjectName> queryInstances(final ConfigRegistryClient configRegistryClient) {
ObjectName on = transactionProvider.getOrCreateTransaction();
ConfigTransactionClient proxy = configRegistryClient.getConfigTransactionClient(on);
return proxy.lookupConfigBeans();
private final Config configResolver;
private final XmlElement configElement;
- public ConfigExecution(Config configResolver, XmlElement configElement, TestOption testOption, EditStrategyType defaultStrategy) throws DocumentedException {
+ public ConfigExecution(final Config configResolver, final XmlElement configElement, final TestOption testOption, final EditStrategyType defaultStrategy) throws DocumentedException {
Config.checkUnrecognisedChildren(configElement);
this.configResolver = configResolver;
this.configElement = configElement;
return testOption == TestOption.set || testOption == TestOption.testThenSet;
}
- public Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
+ public Map<String, Multimap<String, ModuleElementResolved>> getResolvedXmlElements(
+ final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
return configResolver.fromXmlModulesResolved(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
}
- public ServiceRegistryWrapper getServiceRegistryWrapper(ServiceReferenceReadableRegistry serviceRegistry) {
+ public ServiceRegistryWrapper getServiceRegistryWrapper(final ServiceReferenceReadableRegistry serviceRegistry) {
// TODO cache service registry
return new ServiceRegistryWrapper(serviceRegistry);
}
- public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
+ public Map<String, Multimap<String,ModuleElementDefinition>> getModulesDefinition(
+ final ServiceReferenceReadableRegistry serviceRegistry) throws DocumentedException {
return configResolver.fromXmlModulesMap(configElement, defaultEditStrategyType, getServiceRegistryWrapper(serviceRegistry));
}
private final ConfigRegistryClient configRegistryClientNoNotifications;
private final RpcFacade rpcFacade;
- public ConfigSubsystemFacade(ConfigRegistryClient configRegistryClient, ConfigRegistryClient configRegistryClientNoNotifications, YangStoreService yangStoreService, String id) {
+ public ConfigSubsystemFacade(final ConfigRegistryClient configRegistryClient, final ConfigRegistryClient configRegistryClientNoNotifications, final YangStoreService yangStoreService, final String id) {
this.configRegistryClient = configRegistryClient;
this.configRegistryClientNoNotifications = configRegistryClientNoNotifications;
this.yangStoreService = yangStoreService;
rpcFacade = new RpcFacade(yangStoreService, configRegistryClient);
}
- public ConfigSubsystemFacade(ConfigRegistryClient configRegistryClient, ConfigRegistryClient configRegistryClientNoNotifications, YangStoreService yangStoreService, TransactionProvider txProvider) {
+ public ConfigSubsystemFacade(final ConfigRegistryClient configRegistryClient, final ConfigRegistryClient configRegistryClientNoNotifications, final YangStoreService yangStoreService, final TransactionProvider txProvider) {
this.configRegistryClient = configRegistryClient;
this.configRegistryClientNoNotifications = configRegistryClientNoNotifications;
this.yangStoreService = yangStoreService;
}
}
- public void executeConfigExecution(ConfigExecution configExecution) throws DocumentedException, ValidationException {
+ public void executeConfigExecution(final ConfigExecution configExecution) throws DocumentedException, ValidationException {
if (configExecution.shouldTest()) {
executeTests(configExecution);
}
return status;
}
- private void executeSet(ConfigExecution configExecution) throws DocumentedException {
+ private void executeSet(final ConfigExecution configExecution) throws DocumentedException {
set(configExecution);
LOG.debug("Set phase for {} operation successful, element: ", configExecution.getDefaultStrategy(), configExecution.getConfigElement());
}
- private void executeTests(ConfigExecution configExecution) throws DocumentedException, ValidationException {
+ private void executeTests(final ConfigExecution configExecution) throws DocumentedException, ValidationException {
test(configExecution, configExecution.getDefaultStrategy());
LOG.debug("Test phase for {} operation successful, element: ", configExecution.getDefaultStrategy(), configExecution.getConfigElement());
}
- private void test(ConfigExecution execution, EditStrategyType editStrategyType) throws ValidationException, DocumentedException {
+ private void test(final ConfigExecution execution, final EditStrategyType editStrategyType) throws ValidationException, DocumentedException {
ObjectName taON = transactionProvider.getTestTransaction();
try {
// default strategy = replace wipes config
}
}
- private void set(ConfigExecution ConfigExecution) throws DocumentedException {
+ private void set(final ConfigExecution ConfigExecution) throws DocumentedException {
ObjectName taON = transactionProvider.getOrCreateTransaction();
// default strategy = replace wipes config
setOnTransaction(ta, ConfigExecution);
}
- private void setServicesOnTransaction(ConfigTransactionClient ta, ConfigExecution execution) throws DocumentedException {
+ private void setServicesOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) throws DocumentedException {
Services services = execution.getServices();
LOG.debug("Saving service {} with on {} under name {} with service on {}", qnameOfService,
on, refNameToServiceEntry.getKey(), saved);
}
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new DocumentedException(String.format("Unable to edit ref name " + refNameToServiceEntry.getKey() + " for instance " + on, e),
ErrorType.APPLICATION,
ErrorTag.OPERATION_FAILED,
}
}
- private String getQname(ConfigTransactionClient ta, String namespace, String serviceName) {
+ private String getQname(final ConfigTransactionClient ta, final String namespace, final String serviceName) {
return ta.getServiceInterfaceName(namespace, serviceName);
}
- private void setOnTransaction(ConfigTransactionClient ta, ConfigExecution execution) throws DocumentedException {
+ private void setOnTransaction(final ConfigTransactionClient ta, final ConfigExecution execution) throws DocumentedException {
for (Multimap<String, ModuleElementResolved> modulesToResolved : execution.getResolvedXmlElements(ta).values()) {
}
}
- private void handleMisssingInstancesOnTransaction(ConfigTransactionClient ta,
- ConfigExecution execution) throws DocumentedException {
+ private void handleMisssingInstancesOnTransaction(final ConfigTransactionClient ta,
+ final ConfigExecution execution) throws DocumentedException {
for (Multimap<String, ModuleElementDefinition> modulesToResolved : execution.getModulesDefinition(ta).values()) {
for (Map.Entry<String, ModuleElementDefinition> moduleToResolved : modulesToResolved.entries()) {
return new Config(factories, identitiesMap, snapshot.getEnumResolver());
}
- private static Map<String, Map<Date, IdentityMapping>> transformIdentities(Set<Module> modules) {
+ private static Map<String, Map<Date, IdentityMapping>> transformIdentities(final Set<Module> modules) {
Map<String, Map<Date, IdentityMapping>> mappedIds = Maps.newHashMap();
for (Module module : modules) {
String namespace = module.getNamespace().toString();
public Map<String/* Namespace from yang file */,
Map<String /* Name of module entry from yang file */, ModuleConfig>> transformMbeToModuleConfigs(
- Map<String/* Namespace from yang file */,
+ final Map<String/* Namespace from yang file */,
Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> mBeanEntries) {
return transformMbeToModuleConfigs(configRegistryClient, mBeanEntries);
}
public Map<String/* Namespace from yang file */,
- Map<String /* Name of module entry from yang file */, ModuleConfig>> transformMbeToModuleConfigs(BeanReader reader,
- Map<String/* Namespace from yang file */,
+ Map<String /* Name of module entry from yang file */, ModuleConfig>> transformMbeToModuleConfigs(
+ final BeanReader reader,
+ final Map<String/* Namespace from yang file */,
Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> mBeanEntries) {
Map<String, Map<String, ModuleConfig>> namespaceToModuleNameToModuleConfig = Maps.newHashMap();
return new ConfigExecution(configMapping, XmlElement.fromDomElement(xmlToBePersisted), TestOption.testThenSet, EditStrategyType.getDefaultStrategy());
}
- private Map<String, Map<String, ModuleRuntime>> createModuleRuntimes(ConfigRegistryClient configRegistryClient,
- Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries) {
+ private Map<String, Map<String, ModuleRuntime>> createModuleRuntimes(final ConfigRegistryClient configRegistryClient,
+ final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries) {
Map<String, Map<String, ModuleRuntime>> retVal = Maps.newHashMap();
for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleEntry : mBeanEntries.entrySet()) {
return retVal;
}
- private InstanceRuntime createInstanceRuntime(RuntimeBeanEntry root, Map<RuntimeBeanEntry, InstanceConfig> cache) {
+ private InstanceRuntime createInstanceRuntime(final RuntimeBeanEntry root, final Map<RuntimeBeanEntry, InstanceConfig> cache) {
Map<String, InstanceRuntime> children = Maps.newHashMap();
for (RuntimeBeanEntry child : root.getChildren()) {
children.put(child.getJavaNamePrefix(), createInstanceRuntime(child, cache));
return new InstanceRuntime(cache.get(root), children, createJmxToYangMap(root.getChildren()));
}
- private Map<String, String> createJmxToYangMap(List<RuntimeBeanEntry> children) {
+ private Map<String, String> createJmxToYangMap(final List<RuntimeBeanEntry> children) {
Map<String, String> jmxToYangNamesForChildRbe = Maps.newHashMap();
for (RuntimeBeanEntry rbe : children) {
jmxToYangNamesForChildRbe.put(rbe.getJavaNamePrefix(), rbe.getYangName());
return jmxToYangNamesForChildRbe;
}
- public Element get(Document document) throws DocumentedException {
+ public Element get(final Document document) throws DocumentedException {
final ObjectName testTransaction = transactionProvider.getOrCreateReadTransaction();
final ConfigTransactionClient txClient = configRegistryClient.getConfigTransactionClient(testTransaction);
* @param transactionProvider
* @return
*/
- public static DatastoreQueryStrategy getInstanceQueryStrategy(Datastore source,
- TransactionProvider transactionProvider) {
+ public static DatastoreQueryStrategy getInstanceQueryStrategy(final Datastore source,
+ final TransactionProvider transactionProvider) {
switch (source) {
case running:
return new RunningDatastoreQueryStrategy(transactionProvider);
return configRegistryClient.invokeMethod(execution.on, execution.operationName, params, signature);
}
- public Element toXml(Document doc, Object result, OperationExecution execution) throws DocumentedException {
+ public Element toXml(final Document doc, final Object result, final OperationExecution execution) throws DocumentedException {
AttributeMappingStrategy<?, ? extends OpenType<?>> mappingStrategy = new ObjectMapper().prepareStrategy(execution.getReturnType());
Optional<?> mappedAttributeOpt = mappingStrategy.mapAttribute(result);
Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, execution.getReturnType().getOpenType());
private final TransactionProvider transactionProvider;
- public RunningDatastoreQueryStrategy(TransactionProvider transactionProvider) {
+ public RunningDatastoreQueryStrategy(final TransactionProvider transactionProvider) {
this.transactionProvider = transactionProvider;
}
@Override
- public Set<ObjectName> queryInstances(ConfigRegistryClient configRegistryClient) {
+ public Set<ObjectName> queryInstances(final ConfigRegistryClient configRegistryClient) {
ObjectName on = transactionProvider.getOrCreateReadTransaction();
ConfigTransactionClient proxy = configRegistryClient.getConfigTransactionClient(on);
return proxy.lookupConfigBeans();
public enum TestOption {
testOnly, set, testThenSet;
- public static TestOption getFromXmlName(String testOptionXmlName) {
+ public static TestOption getFromXmlName(final String testOptionXmlName) {
switch (testOptionXmlName) {
case "test-only":
return testOnly;
this.identityNameToSchemaNode = Maps.newHashMap();
}
- public void addIdSchemaNode(IdentitySchemaNode node) {
+ public void addIdSchemaNode(final IdentitySchemaNode node) {
String name = node.getQName().getLocalName();
Preconditions.checkState(!identityNameToSchemaNode.containsKey(name));
identityNameToSchemaNode.put(name, node);
}
- public boolean containsIdName(String idName) {
+ public boolean containsIdName(final String idName) {
return identityNameToSchemaNode.containsKey(idName);
}
private AttributeIfc lastAttribute;
- public T switchAttribute(AttributeIfc attributeIfc) {
+ public T switchAttribute(final AttributeIfc attributeIfc) {
this.lastAttribute = attributeIfc;
} else {
return caseJavaAttribute(openType);
}
- } catch (UnknownOpenTypeException e) {
+ } catch (final UnknownOpenTypeException e) {
throw getIllegalArgumentException(attributeIfc);
}
return lastAttribute;
}
- protected T caseJavaIdentityRefAttribute(OpenType<?> openType) {
+ protected T caseJavaIdentityRefAttribute(final OpenType<?> openType) {
return caseJavaAttribute(openType);
}
- protected T caseJavaUnionAttribute(OpenType<?> openType) {
+ protected T caseJavaUnionAttribute(final OpenType<?> openType) {
return caseJavaAttribute(openType);
}
- protected T caseJavaEnumAttribute(OpenType<?> openType) {
+ protected T caseJavaEnumAttribute(final OpenType<?> openType) {
return caseJavaAttribute(openType);
}
- protected T caseJavaBinaryAttribute(OpenType<?> openType) {
+ protected T caseJavaBinaryAttribute(final OpenType<?> openType) {
return caseJavaAttribute(openType);
}
- private IllegalArgumentException getIllegalArgumentException(AttributeIfc attributeIfc) {
+ private IllegalArgumentException getIllegalArgumentException(final AttributeIfc attributeIfc) {
return new IllegalArgumentException("Unknown attribute type " + attributeIfc.getClass() + ", " + attributeIfc
+ " with open type:" + attributeIfc.getOpenType());
}
- public final T caseJavaAttribute(OpenType<?> openType) {
+ public final T caseJavaAttribute(final OpenType<?> openType) {
if (openType instanceof SimpleType<?>) {
return caseJavaSimpleAttribute((SimpleType<?>) openType);
} else if (openType instanceof ArrayType<?>) {
private static class UnknownOpenTypeException extends RuntimeException {
private static final long serialVersionUID = 1L;
- public UnknownOpenTypeException(String message) {
+ public UnknownOpenTypeException(final String message) {
super(message);
}
}
private final String nullableDefault;
- public AbstractAttributeReadingStrategy(String nullableDefault) {
+ public AbstractAttributeReadingStrategy(final String nullableDefault) {
this.nullableDefault = nullableDefault;
}
}
@Override
- public AttributeConfigElement readElement(List<XmlElement> configNodes) throws DocumentedException {
+ public AttributeConfigElement readElement(final List<XmlElement> configNodes) throws DocumentedException {
if (configNodes.size() == 0){
return AttributeConfigElement.createNullValue(postprocessNullableDefault(nullableDefault));
}
abstract AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException;
- protected Object postprocessNullableDefault(String nullableDefault) {
+ protected Object postprocessNullableDefault(final String nullableDefault) {
return nullableDefault;
}
}
private final AttributeReadingStrategy innerStrategy;
- public ArrayAttributeReadingStrategy(String nullableDefault, AttributeReadingStrategy innerStrategy) {
+ public ArrayAttributeReadingStrategy(final String nullableDefault, final AttributeReadingStrategy innerStrategy) {
super(nullableDefault);
this.innerStrategy = innerStrategy;
}
@Override
- AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException {
+ AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
List<Object> innerList = Lists.newArrayList();
EditStrategyType innerEditStrategy= null;
for (XmlElement configNode : configNodes) {
private Object resolvedDefaultValue;
private String jmxName;
- public AttributeConfigElement(Object defaultValue, Object value, final EditStrategyType editStrategyType) {
+ public AttributeConfigElement(final Object defaultValue, final Object value, final EditStrategyType editStrategyType) {
this.defaultValue = defaultValue;
this.value = value;
this.editStrategy = Optional.fromNullable(editStrategyType);
}
- public void setJmxName(String jmxName) {
+ public void setJmxName(final String jmxName) {
this.jmxName = jmxName;
}
return jmxName;
}
- public void resolveValue(AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
- String attrName) throws DocumentedException {
+ public void resolveValue(final AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
+ final String attrName) throws DocumentedException {
resolvedValue = attributeResolvingStrategy.parseAttribute(attrName, value);
Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, defaultValue);
resolvedDefaultValue = resolvedDefault.isPresent() ? resolvedDefault.get() : null;
return editStrategy;
}
- public static AttributeConfigElement create(Object nullableDefault, Object value) {
+ public static AttributeConfigElement create(final Object nullableDefault, final Object value) {
return new AttributeConfigElement(nullableDefault, value, null);
}
- public static AttributeConfigElement createNullValue(Object nullableDefault) {
+ public static AttributeConfigElement createNullValue(final Object nullableDefault) {
return new AttributeConfigElement(nullableDefault, null, null);
}
private final Map<String, AttributeReadingStrategy> innerStrategies;
- public CompositeAttributeReadingStrategy(String nullableDefault,
- Map<String, AttributeReadingStrategy> innerStrategies) {
+ public CompositeAttributeReadingStrategy(final String nullableDefault,
+ final Map<String, AttributeReadingStrategy> innerStrategies) {
super(nullableDefault);
this.innerStrategies = innerStrategies;
}
@Override
- AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException {
+ AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s", configNodes);
private static final Object PREFIX_SEPARATOR = ":";
- public ObjectNameAttributeReadingStrategy(String nullableDefault) {
+ public ObjectNameAttributeReadingStrategy(final String nullableDefault) {
super(nullableDefault);
}
@Override
- AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException {
+ AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
XmlElement firstChild = configNodes.get(0);
Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild
return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild));
}
- private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) throws DocumentedException{
+ private ObjectNameAttributeMappingStrategy.MappedDependency resolve(final XmlElement firstChild) throws DocumentedException{
XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY);
Map.Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
dependencyName);
}
- public static String checkPrefixAndExtractServiceName(XmlElement typeElement, Map.Entry<String, String> prefixNamespace) throws DocumentedException {
+ public static String checkPrefixAndExtractServiceName(final XmlElement typeElement, final Map.Entry<String, String> prefixNamespace) throws DocumentedException {
String serviceName = typeElement.getTextContent();
Preconditions.checkNotNull(prefixNamespace.getKey(), "Service %s value cannot be linked to namespace",
XmlMappingConstants.TYPE_KEY);
private String key;
private Map<String, Map<Date, IdentityMapping>> identityMap;
- public Map<String, AttributeReadingStrategy> prepareReading(Map<String, AttributeIfc> yangToAttrConfig, Map<String, Map<Date, IdentityMapping>> identityMap) {
+ public Map<String, AttributeReadingStrategy> prepareReading(final Map<String, AttributeIfc> yangToAttrConfig, final Map<String, Map<Date, IdentityMapping>> identityMap) {
Map<String, AttributeReadingStrategy> strategies = Maps.newHashMap();
this.identityMap = identityMap;
return strategies;
}
- private AttributeReadingStrategy prepareReadingStrategy(String key, AttributeIfc attributeIfc) {
+ private AttributeReadingStrategy prepareReadingStrategy(final String key, final AttributeIfc attributeIfc) {
this.key = key;
return switchAttribute(attributeIfc);
}
@Override
- protected AttributeReadingStrategy caseJavaBinaryAttribute(OpenType<?> openType) {
+ protected AttributeReadingStrategy caseJavaBinaryAttribute(final OpenType<?> openType) {
return new SimpleBinaryAttributeReadingStrategy(getLastAttribute().getNullableDefault());
}
@Override
- protected AttributeReadingStrategy caseJavaUnionAttribute(OpenType<?> openType) {
+ protected AttributeReadingStrategy caseJavaUnionAttribute(final OpenType<?> openType) {
String mappingKey = JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION;
return new SimpleUnionAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey);
}
@Override
- public AttributeReadingStrategy caseJavaSimpleAttribute(SimpleType<?> openType) {
+ public AttributeReadingStrategy caseJavaSimpleAttribute(final SimpleType<?> openType) {
return new SimpleAttributeReadingStrategy(getLastAttribute().getNullableDefault());
}
@Override
- public AttributeReadingStrategy caseJavaArrayAttribute(ArrayType<?> openType) {
+ public AttributeReadingStrategy caseJavaArrayAttribute(final ArrayType<?> openType) {
SimpleAttributeReadingStrategy innerStrategy = new SimpleAttributeReadingStrategy(getLastAttribute().getNullableDefault());
return new ArrayAttributeReadingStrategy(getLastAttribute().getNullableDefault(), innerStrategy);
}
@Override
- public AttributeReadingStrategy caseJavaCompositeAttribute(CompositeType openType) {
+ public AttributeReadingStrategy caseJavaCompositeAttribute(final CompositeType openType) {
Preconditions.checkState(openType.keySet().size() == 1, "Unexpected number of elements for open type %s, should be 1", openType);
String mappingKey = openType.keySet().iterator().next();
return new SimpleCompositeAttributeReadingStrategy(getLastAttribute().getNullableDefault(), mappingKey);
}
@Override
- protected AttributeReadingStrategy caseJavaIdentityRefAttribute(OpenType<?> openType) {
+ protected AttributeReadingStrategy caseJavaIdentityRefAttribute(final OpenType<?> openType) {
Preconditions.checkState(openType instanceof CompositeType);
Set<String> keys = ((CompositeType) openType).keySet();
Preconditions.checkState(keys.size() == 1, "Unexpected number of elements for open type %s, should be 1", openType);
}
@Override
- protected AttributeReadingStrategy caseDependencyAttribute(SimpleType<?> openType) {
+ protected AttributeReadingStrategy caseDependencyAttribute(final SimpleType<?> openType) {
return new ObjectNameAttributeReadingStrategy(getLastAttribute().getNullableDefault());
}
@Override
- protected AttributeReadingStrategy caseTOAttribute(CompositeType openType) {
+ protected AttributeReadingStrategy caseTOAttribute(final CompositeType openType) {
AttributeIfc lastAttribute = getLastAttribute();
Preconditions.checkState(lastAttribute instanceof TOAttribute);
Map<String, AttributeIfc> inner = ((TOAttribute)lastAttribute).getYangPropertiesToTypesMap();
}
@Override
- protected AttributeReadingStrategy caseListAttribute(ArrayType<?> openType) {
+ protected AttributeReadingStrategy caseListAttribute(final ArrayType<?> openType) {
AttributeIfc lastAttribute = getLastAttribute();
Preconditions.checkState(lastAttribute instanceof ListAttribute);
AttributeReadingStrategy innerStrategy = prepareReadingStrategy(key, ((ListAttribute) lastAttribute).getInnerAttribute());
}
@Override
- protected AttributeReadingStrategy caseListDependeciesAttribute(ArrayType<?> openType) {
+ protected AttributeReadingStrategy caseListDependeciesAttribute(final ArrayType<?> openType) {
AttributeIfc lastAttribute = getLastAttribute();
Preconditions.checkState(lastAttribute instanceof ListDependenciesAttribute);
AttributeReadingStrategy innerStrategy = caseDependencyAttribute(SimpleType.OBJECTNAME);
import org.opendaylight.controller.config.util.xml.XmlElement;
public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
- public SimpleAttributeReadingStrategy(String nullableDefault) {
+ public SimpleAttributeReadingStrategy(final String nullableDefault) {
super(nullableDefault);
}
@Override
- AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException {
+ AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
XmlElement xmlElement = configNodes.get(0);
Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
+ " but was " + configNodes.size());
postprocessParsedValue(textContent));
}
- protected String readElementContent(XmlElement xmlElement) throws DocumentedException {
+ protected String readElementContent(final XmlElement xmlElement) throws DocumentedException {
return xmlElement.getTextContent();
}
@Override
- protected Object postprocessNullableDefault(String nullableDefault) {
+ protected Object postprocessNullableDefault(final String nullableDefault) {
return nullableDefault;
}
- protected Object postprocessParsedValue(String textContent) {
+ protected Object postprocessParsedValue(final String textContent) {
return textContent;
}
public class SimpleBinaryAttributeReadingStrategy extends SimpleAttributeReadingStrategy {
- public SimpleBinaryAttributeReadingStrategy(String nullableDefault) {
+ public SimpleBinaryAttributeReadingStrategy(final String nullableDefault) {
super(nullableDefault);
}
@Override
- protected Object postprocessParsedValue(String textContent) {
+ protected Object postprocessParsedValue(final String textContent) {
BaseEncoding en = BaseEncoding.base64();
byte[] decode = en.decode(textContent);
List<String> parsed = Lists.newArrayListWithCapacity(decode.length);
}
@Override
- protected Object postprocessNullableDefault(String nullableDefault) {
+ protected Object postprocessNullableDefault(final String nullableDefault) {
return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
}
}
private final String key;
- public SimpleCompositeAttributeReadingStrategy(String nullableDefault, String key) {
+ public SimpleCompositeAttributeReadingStrategy(final String nullableDefault, final String key) {
super(nullableDefault);
this.key = key;
}
@Override
- protected Object postprocessParsedValue(String textContent) {
+ protected Object postprocessParsedValue(final String textContent) {
HashMap<String,String> map = Maps.newHashMap();
map.put(key, textContent);
return map;
}
@Override
- protected Object postprocessNullableDefault(String nullableDefault) {
+ protected Object postprocessNullableDefault(final String nullableDefault) {
return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
}
}
private final String key;
private final Map<String, Map<Date, IdentityMapping>> identityMap;
- public SimpleIdentityRefAttributeReadingStrategy(String nullableDefault, String key, Map<String, Map<Date, IdentityMapping>> identityMap) {
+ public SimpleIdentityRefAttributeReadingStrategy(final String nullableDefault, final String key, final Map<String, Map<Date, IdentityMapping>> identityMap) {
super(nullableDefault);
this.key = key;
this.identityMap = identityMap;
}
@Override
- protected String readElementContent(XmlElement xmlElement) throws DocumentedException {
+ protected String readElementContent(final XmlElement xmlElement) throws DocumentedException {
Map.Entry<String, String> namespaceOfTextContent = xmlElement.findNamespaceOfTextContent();
String content = xmlElement.getTextContent();
}
@Override
- protected Object postprocessParsedValue(String textContent) {
+ protected Object postprocessParsedValue(final String textContent) {
HashMap<String,String> map = Maps.newHashMap();
map.put(key, textContent);
return map;
}
@Override
- protected Object postprocessNullableDefault(String nullableDefault) {
+ protected Object postprocessNullableDefault(final String nullableDefault) {
return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
}
}
private final String key;
- public SimpleUnionAttributeReadingStrategy(String nullableDefault, String key) {
+ public SimpleUnionAttributeReadingStrategy(final String nullableDefault, final String key) {
super(nullableDefault);
this.key = key;
}
@Override
- protected Object postprocessParsedValue(String textContent) {
+ protected Object postprocessParsedValue(final String textContent) {
char[] charArray = textContent.toCharArray();
List<String> chars = Lists.newArrayListWithCapacity(charArray.length);
}
@Override
- protected Object postprocessNullableDefault(String nullableDefault) {
+ protected Object postprocessNullableDefault(final String nullableDefault) {
return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
}
}
private final O attrOpenType;
- public AbstractAttributeMappingStrategy(O attributeIfc) {
+ public AbstractAttributeMappingStrategy(final O attributeIfc) {
this.attrOpenType = attributeIfc;
}
private final AttributeMappingStrategy<?, ? extends OpenType<?>> innerElementStrategy;
- public ArrayAttributeMappingStrategy(ArrayType<?> arrayType,
- AttributeMappingStrategy<?, ? extends OpenType<?>> innerElementStrategy) {
+ public ArrayAttributeMappingStrategy(final ArrayType<?> arrayType,
+ final AttributeMappingStrategy<?, ? extends OpenType<?>> innerElementStrategy) {
super(arrayType);
this.innerElementStrategy = innerElementStrategy;
}
@Override
- public Optional<List<Object>> mapAttribute(Object value) {
+ public Optional<List<Object>> mapAttribute(final Object value) {
if (value == null){
return Optional.absent();
}
private final Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies;
private final Map<String, String> jmxToJavaNameMapping;
- public CompositeAttributeMappingStrategy(CompositeType compositeType,
- Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies,
- Map<String, String> jmxToJavaNameMapping) {
+ public CompositeAttributeMappingStrategy(final CompositeType compositeType,
+ final Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies,
+ final Map<String, String> jmxToJavaNameMapping) {
super(compositeType);
this.innerStrategies = innerStrategies;
this.jmxToJavaNameMapping = jmxToJavaNameMapping;
}
@Override
- public Optional<Map<String, Object>> mapAttribute(Object value) {
+ public Optional<Map<String, Object>> mapAttribute(final Object value) {
if (value == null){
return Optional.absent();
}
return Optional.of(retVal);
}
- protected Optional<?> mapInnerAttribute(CompositeDataSupport compositeData, String jmxName, String description) {
+ protected Optional<?> mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName, final String description) {
Object innerValue = compositeData.get(jmxName);
AttributeMappingStrategy<?, ? extends OpenType<?>> attributeMappingStrategy = innerStrategies
private final EnumResolver enumResolver;
- public EnumAttributeMappingStrategy(CompositeType openType, final EnumResolver enumResolver) {
+ public EnumAttributeMappingStrategy(final CompositeType openType, final EnumResolver enumResolver) {
super(openType);
this.enumResolver = enumResolver;
}
@Override
- public Optional<String> mapAttribute(Object value) {
+ public Optional<String> mapAttribute(final Object value) {
if (value == null){
return Optional.absent();
}
private EnumResolver enumResolver;
public Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> prepareMapping(
- Map<String, AttributeIfc> configDefinition, EnumResolver enumResolver) {
+ final Map<String, AttributeIfc> configDefinition, final EnumResolver enumResolver) {
this.enumResolver = Preconditions.checkNotNull(enumResolver);
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> strategies = Maps.newHashMap();
return strategies;
}
- public AttributeMappingStrategy<?, ? extends OpenType<?>> prepareStrategy(AttributeIfc attributeIfc) {
+ public AttributeMappingStrategy<?, ? extends OpenType<?>> prepareStrategy(final AttributeIfc attributeIfc) {
if(attributeIfc instanceof DependencyAttribute) {
namespaceOfDepAttr = ((DependencyAttribute)attributeIfc).getDependency().getSie().getQName().getNamespace().toString();
return switchAttribute(attributeIfc);
}
- private Map<String, String> createJmxToYangMapping(TOAttribute attributeIfc) {
+ private Map<String, String> createJmxToYangMapping(final TOAttribute attributeIfc) {
Map<String, String> retVal = Maps.newHashMap();
for (Entry<String, AttributeIfc> entry : attributeIfc.getJmxPropertiesToTypesMap().entrySet()) {
retVal.put(entry.getKey(), (entry.getValue()).getAttributeYangName());
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaSimpleAttribute(SimpleType<?> openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaSimpleAttribute(final SimpleType<?> openType) {
return new SimpleAttributeMappingStrategy(openType);
}
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(ArrayType<?> openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(final ArrayType<?> openType) {
AttributeMappingStrategy<?, ? extends OpenType<?>> innerStrategy = new SimpleAttributeMappingStrategy(
(SimpleType<?>) openType.getElementOpenType());
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaCompositeAttribute(CompositeType openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaCompositeAttribute(final CompositeType openType) {
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
Map<String, String> attributeMapping = Maps.newHashMap();
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaUnionAttribute(OpenType<?> openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaUnionAttribute(final OpenType<?> openType) {
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
Map<String, String> attributeMapping = Maps.newHashMap();
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
- SimpleType<?> openType) {
+ final SimpleType<?> openType) {
return new ObjectNameAttributeMappingStrategy(openType, namespaceOfDepAttr);
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseTOAttribute(CompositeType openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseTOAttribute(final CompositeType openType) {
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
Preconditions.checkState(getLastAttribute() instanceof TOAttribute);
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListAttribute(ArrayType<?> openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
return new ArrayAttributeMappingStrategy(openType,
prepareStrategy(((ListAttribute) getLastAttribute()).getInnerAttribute()));
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListDependeciesAttribute(ArrayType<?> openType) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListDependeciesAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute);
return new ArrayAttributeMappingStrategy(openType, caseDependencyAttribute(SimpleType.OBJECTNAME));
}
private final String namespace;
- public ObjectNameAttributeMappingStrategy(SimpleType<?> openType, String namespace) {
+ public ObjectNameAttributeMappingStrategy(final SimpleType<?> openType, final String namespace) {
super(openType);
this.namespace = namespace;
}
@Override
- public Optional<MappedDependency> mapAttribute(Object value) {
+ public Optional<MappedDependency> mapAttribute(final Object value) {
if (value == null){
return Optional.absent();
}
public static class MappedDependency {
private final String namespace, serviceName, refName;
- public MappedDependency(String namespace, String serviceName, String refName) {
+ public MappedDependency(final String namespace, final String serviceName, final String refName) {
this.serviceName = serviceName;
this.refName = refName;
this.namespace = namespace;
public class SimpleAttributeMappingStrategy extends AbstractAttributeMappingStrategy<String, SimpleType<?>> {
- public SimpleAttributeMappingStrategy(SimpleType<?> openType) {
+ public SimpleAttributeMappingStrategy(final SimpleType<?> openType) {
super(openType);
}
@Override
- public Optional<String> mapAttribute(Object value) {
+ public Optional<String> mapAttribute(final Object value) {
if (value == null){
return Optional.absent();
}
static class DefaultWriterPlugin implements WriterPlugin {
@Override
- public String writeObject(Object value) {
+ public String writeObject(final Object value) {
return value.toString();
}
}
static class DatePlugin implements WriterPlugin {
@Override
- public String writeObject(Object value) {
+ public String writeObject(final Object value) {
Preconditions.checkArgument(value instanceof Date, "Attribute must be Date");
return Util.writeDate((Date) value);
}
CompositeAttributeMappingStrategy {
- public UnionCompositeAttributeMappingStrategy(CompositeType compositeType, Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies, Map<String, String> jmxToJavaNameMapping) {
+ public UnionCompositeAttributeMappingStrategy(final CompositeType compositeType, final Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies, final Map<String, String> jmxToJavaNameMapping) {
super(compositeType, innerStrategies, jmxToJavaNameMapping);
}
@Override
- protected Optional<?> mapInnerAttribute(CompositeDataSupport compositeData, String jmxName, String description) {
+ protected Optional<?> mapInnerAttribute(final CompositeDataSupport compositeData, final String jmxName, final String description) {
if(!description.equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)){
return Optional.absent();
}
abstract class AbstractAttributeResolvingStrategy<T, O extends OpenType<?>> implements AttributeResolvingStrategy<T, O> {
private O openType;
- public AbstractAttributeResolvingStrategy(O openType) {
+ public AbstractAttributeResolvingStrategy(final O openType) {
this.openType = openType;
}
private static final Logger LOG = LoggerFactory.getLogger(ArrayAttributeResolvingStrategy.class);
- public ArrayAttributeResolvingStrategy(AttributeResolvingStrategy<?, ? extends OpenType<?>> innerTypeResolved,
- ArrayType<?> openType) {
+ public ArrayAttributeResolvingStrategy(final AttributeResolvingStrategy<?, ? extends OpenType<?>> innerTypeResolved,
+ final ArrayType<?> openType) {
super(openType);
this.innerTypeResolvingStrategy = innerTypeResolved;
}
@Override
- public Optional<Object> parseAttribute(String attrName, Object value) throws DocumentedException {
+ public Optional<Object> parseAttribute(final String attrName, final Object value) throws DocumentedException {
if (value == null) {
return Optional.absent();
}
} else {
try {
innerTypeClass = Class.forName(getOpenType().getElementOpenType().getClassName());
- } catch (ClassNotFoundException e) {
+ } catch (final ClassNotFoundException e) {
throw new IllegalStateException("Unable to locate class for "
+ getOpenType().getElementOpenType().getClassName(), e);
}
final ArrayType<?> openType =
new ArrayType<>(getOpenType().getDimension(), innerTypeResolvingStrategy.getOpenType());
setOpenType(openType);
- } catch (OpenDataException e) {
+ } catch (final OpenDataException e) {
throw new IllegalStateException("An error occurred during restoration of array type " + this
+ " for attribute " + attrName + " from value " + value, e);
}
return Optional.of(parsedArray);
}
- private static String toStringArray(Object array) {
+ private static String toStringArray(final Object array) {
StringBuilder build = new StringBuilder(array.toString());
build.append(" [");
for (int i = 0; i < Array.getLength(array); i++) {
return build.toString();
}
- private static Class<?> getPrimitiveType(Class<?> innerTypeClass) {
+ private static Class<?> getPrimitiveType(final Class<?> innerTypeClass) {
try {
return (Class<?>) innerTypeClass.getField("TYPE").get(null);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException("Unable to determine primitive type to " + innerTypeClass);
}
}
private static final Logger LOG = LoggerFactory.getLogger(CompositeAttributeResolvingStrategy.class);
- CompositeAttributeResolvingStrategy(Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
- CompositeType openType, Map<String, String> yangToJavaAttrMapping) {
+ CompositeAttributeResolvingStrategy(final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
+ final CompositeType openType, final Map<String, String> yangToJavaAttrMapping) {
super(openType);
this.innerTypes = innerTypes;
this.yangToJavaAttrMapping = yangToJavaAttrMapping;
}
@Override
- public Optional<CompositeDataSupport> parseAttribute(String attrName, Object value) throws DocumentedException {
+ public Optional<CompositeDataSupport> parseAttribute(final String attrName, final Object value) throws DocumentedException {
if (value == null) {
return Optional.absent();
setOpenType(new CompositeType(getOpenType().getTypeName(), getOpenType().getDescription(), names, descriptions, itemTypes));
LOG.debug("Attribute {}. Open type reconstructed to {}", attrName, getOpenType(), getOpenType());
parsedValue = new CompositeDataSupport(getOpenType(), items);
- } catch (OpenDataException e) {
+ } catch (final OpenDataException e) {
throw new IllegalStateException("An error occurred during restoration of composite type " + this
+ " for attribute " + attrName + " from value " + value, e);
}
}
- protected Map<?, ?> preprocessValueMap(Map<?, ?> valueMap) {
+ protected Map<?, ?> preprocessValueMap(final Map<?, ?> valueMap) {
return valueMap;
}
private static final Logger LOG = LoggerFactory.getLogger(EnumAttributeResolvingStrategy.class);
private final EnumResolver enumResolver;
- EnumAttributeResolvingStrategy(CompositeType simpleType, final EnumResolver enumResolver) {
+ EnumAttributeResolvingStrategy(final CompositeType simpleType, final EnumResolver enumResolver) {
super(simpleType);
this.enumResolver = enumResolver;
}
}
@Override
- public Optional<Object> parseAttribute(String attrName, Object value) throws DocumentedException {
+ public Optional<Object> parseAttribute(final String attrName, final Object value) throws DocumentedException {
if (value == null) {
return Optional.absent();
}
private final ServiceRegistryWrapper serviceTracker;
private static final Logger LOG = LoggerFactory.getLogger(ObjectNameAttributeResolvingStrategy.class);
- ObjectNameAttributeResolvingStrategy(ServiceRegistryWrapper serviceTracker) {
+ ObjectNameAttributeResolvingStrategy(final ServiceRegistryWrapper serviceTracker) {
super(SimpleType.OBJECTNAME);
this.serviceTracker = serviceTracker;
}
@Override
- public Optional<ObjectName> parseAttribute(String attrName, Object value) {
+ public Optional<ObjectName> parseAttribute(final String attrName, final Object value) {
if (value == null) {
return Optional.absent();
}
private final ServiceRegistryWrapper serviceTracker;
private EnumResolver enumResolver;
- public ObjectResolver(ServiceRegistryWrapper serviceTracker) {
+ public ObjectResolver(final ServiceRegistryWrapper serviceTracker) {
this.serviceTracker = serviceTracker;
}
public Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> prepareResolving(
- Map<String, AttributeIfc> configDefinition, final EnumResolver enumResolver) {
+ final Map<String, AttributeIfc> configDefinition, final EnumResolver enumResolver) {
this.enumResolver = enumResolver;
Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> strategies = Maps.newHashMap();
return strategies;
}
- private AttributeResolvingStrategy<?, ? extends OpenType<?>> prepareStrategy(AttributeIfc attributeIfc) {
+ private AttributeResolvingStrategy<?, ? extends OpenType<?>> prepareStrategy(final AttributeIfc attributeIfc) {
return switchAttribute(attributeIfc);
}
- private Map<String, String> createYangToJmxMapping(TOAttribute attributeIfc) {
+ private Map<String, String> createYangToJmxMapping(final TOAttribute attributeIfc) {
Map<String, String> retVal = Maps.newHashMap();
for (Entry<String, AttributeIfc> entry : attributeIfc.getYangPropertiesToTypesMap().entrySet()) {
retVal.put(entry.getKey(), (entry.getValue()).getLowerCaseCammelCase());
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaSimpleAttribute(SimpleType<?> openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaSimpleAttribute(final SimpleType<?> openType) {
return new SimpleAttributeResolvingStrategy(openType);
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(ArrayType<?> openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(final ArrayType<?> openType) {
SimpleType<?> innerType = (SimpleType<?>) openType.getElementOpenType();
AttributeResolvingStrategy<?, ? extends OpenType<?>> strat = new SimpleAttributeResolvingStrategy(innerType);
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaCompositeAttribute(CompositeType openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaCompositeAttribute(final CompositeType openType) {
Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerMap = Maps.newHashMap();
Map<String, String> yangToJmxMapping = Maps.newHashMap();
return new CompositeAttributeResolvingStrategy(innerMap, openType, yangToJmxMapping);
}
- private void fillMappingForComposite(CompositeType openType, Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerMap, Map<String, String> yangToJmxMapping) {
+ private void fillMappingForComposite(final CompositeType openType, final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerMap, final Map<String, String> yangToJmxMapping) {
for (String innerAttributeKey : openType.keySet()) {
innerMap.put(innerAttributeKey, caseJavaAttribute(openType.getType(innerAttributeKey)));
yangToJmxMapping.put(innerAttributeKey, innerAttributeKey);
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaUnionAttribute(OpenType<?> openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseJavaUnionAttribute(final OpenType<?> openType) {
Preconditions.checkState(openType instanceof CompositeType, "Unexpected open type, expected %s but was %s");
CompositeType compositeType = (CompositeType) openType;
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
- SimpleType<?> openType) {
+ final SimpleType<?> openType) {
return new ObjectNameAttributeResolvingStrategy(serviceTracker);
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseTOAttribute(CompositeType openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseTOAttribute(final CompositeType openType) {
Preconditions.checkState(getLastAttribute() instanceof TOAttribute);
TOAttribute toAttribute = (TOAttribute) getLastAttribute();
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListAttribute(ArrayType<?> openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
return new ArrayAttributeResolvingStrategy(prepareStrategy(innerAttribute), openType);
}
@Override
- protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListDependeciesAttribute(ArrayType<?> openType) {
+ protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListDependeciesAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute);
return new ArrayAttributeResolvingStrategy(caseDependencyAttribute(SimpleType.OBJECTNAME), openType);
}
private static final Logger LOG = LoggerFactory.getLogger(SimpleAttributeResolvingStrategy.class);
- SimpleAttributeResolvingStrategy(SimpleType<?> simpleType) {
+ SimpleAttributeResolvingStrategy(final SimpleType<?> simpleType) {
super(simpleType);
}
}
@Override
- public Optional<Object> parseAttribute(String attrName, Object value) throws DocumentedException {
+ public Optional<Object> parseAttribute(final String attrName, final Object value) throws DocumentedException {
if (value == null) {
return Optional.absent();
}
Class<?> cls;
try {
cls = Class.forName(getOpenType().getClassName());
- } catch (ClassNotFoundException e) {
+ } catch (final ClassNotFoundException e) {
throw new RuntimeException("Unable to locate class for " + getOpenType().getClassName(), e);
}
static class DefaultResolver implements Resolver {
@Override
- public Object resolveObject(Class<?> type, String attrName, String value) throws DocumentedException {
+ public Object resolveObject(final Class<?> type, final String attrName, final String value) throws DocumentedException {
try {
return parseObject(type, value);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new DocumentedException("Unable to resolve attribute " + attrName + " from " + value,
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
}
}
- protected Object parseObject(Class<?> type, String value) throws DocumentedException {
+ protected Object parseObject(final Class<?> type, final String value) throws DocumentedException {
Method method = null;
try {
method = type.getMethod("valueOf", String.class);
static class StringResolver extends DefaultResolver {
@Override
- protected Object parseObject(Class<?> type, String value) {
+ protected Object parseObject(final Class<?> type, final String value) {
return value;
}
}
static class BigIntegerResolver extends DefaultResolver {
@Override
- protected Object parseObject(Class<?> type, String value) {
+ protected Object parseObject(final Class<?> type, final String value) {
return new BigInteger(value);
}
}
static class BigDecimalResolver extends DefaultResolver {
@Override
- protected Object parseObject(Class<?> type, String value) {
+ protected Object parseObject(final Class<?> type, final String value) {
return new BigDecimal(value);
}
}
static class CharResolver extends DefaultResolver {
@Override
- protected Object parseObject(Class<?> type, String value) {
+ protected Object parseObject(final Class<?> type, final String value) {
return value.charAt(0);
}
}
static class DateResolver extends DefaultResolver {
@Override
- protected Object parseObject(Class<?> type, String value) throws DocumentedException {
+ protected Object parseObject(final Class<?> type, final String value) throws DocumentedException {
try {
return Util.readDate(value);
- } catch (ParseException e) {
+ } catch (final ParseException e) {
LOG.trace("Unable parse value {} due to ",value, e);
throw new DocumentedException("Unable to parse value "+value+" as date.",
DocumentedException.ErrorType.APPLICATION,
final class UnionCompositeAttributeResolvingStrategy extends CompositeAttributeResolvingStrategy {
- UnionCompositeAttributeResolvingStrategy(Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
- CompositeType openType, Map<String, String> yangToJavaAttrMapping) {
+ UnionCompositeAttributeResolvingStrategy(final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
+ final CompositeType openType, final Map<String, String> yangToJavaAttrMapping) {
super(innerTypes, openType, yangToJavaAttrMapping);
}
- protected Map<String, Object> preprocessValueMap(Map<?, ?> valueMap) {
+ protected Map<String, Object> preprocessValueMap(final Map<?, ?> valueMap) {
CompositeType openType = getOpenType();
Preconditions.checkArgument(
private final AttributeWritingStrategy innnerStrategy;
- public ArrayAttributeWritingStrategy(AttributeWritingStrategy innerStrategy) {
+ public ArrayAttributeWritingStrategy(final AttributeWritingStrategy innerStrategy) {
this.innnerStrategy = innerStrategy;
}
@Override
- public void writeElement(Element parentElement, String namespace, Object value) {
+ public void writeElement(final Element parentElement, final String namespace, final Object value) {
Util.checkType(value, List.class);
for (Object innerObject : ((List<?>) value)) {
private final Document document;
private final Map<String, AttributeWritingStrategy> innerStrats;
- public CompositeAttributeWritingStrategy(Document document, String key,
- Map<String, AttributeWritingStrategy> innerStrats) {
+ public CompositeAttributeWritingStrategy(final Document document, final String key,
+ final Map<String, AttributeWritingStrategy> innerStrats) {
this.document = document;
this.key = key;
this.innerStrats = innerStrats;
}
@Override
- public void writeElement(Element parentElement, String namespace, Object value) {
+ public void writeElement(final Element parentElement, final String namespace, final Object value) {
Util.checkType(value, Map.class);
Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
* @param document
* @param key
*/
- public ObjectNameAttributeWritingStrategy(Document document, String key) {
+ public ObjectNameAttributeWritingStrategy(final Document document, final String key) {
this.document = document;
this.key = key;
}
@Override
- public void writeElement(Element parentElement, String namespace, Object value) {
+ public void writeElement(final Element parentElement, final String namespace, final Object value) {
Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
private Document document;
private String key;
- public Map<String, AttributeWritingStrategy> prepareWriting(Map<String, AttributeIfc> yangToAttrConfig,
- Document document) {
+ public Map<String, AttributeWritingStrategy> prepareWriting(final Map<String, AttributeIfc> yangToAttrConfig,
+ final Document document) {
Map<String, AttributeWritingStrategy> preparedWriting = Maps.newHashMap();
return preparedWriting;
}
- public AttributeWritingStrategy prepareWritingStrategy(String key, AttributeIfc expectedAttr, Document document) {
+ public AttributeWritingStrategy prepareWritingStrategy(final String key, final AttributeIfc expectedAttr, final Document document) {
Preconditions.checkNotNull(expectedAttr, "Mbean attributes mismatch, unable to find expected attribute for %s",
key);
this.document = document;
}
@Override
- protected AttributeWritingStrategy caseJavaBinaryAttribute(OpenType<?> openType) {
+ protected AttributeWritingStrategy caseJavaBinaryAttribute(final OpenType<?> openType) {
return new SimpleBinaryAttributeWritingStrategy(document, key);
}
}
@Override
- protected AttributeWritingStrategy caseJavaSimpleAttribute(SimpleType<?> openType) {
+ protected AttributeWritingStrategy caseJavaSimpleAttribute(final SimpleType<?> openType) {
return new SimpleAttributeWritingStrategy(document, key);
}
@Override
- protected AttributeWritingStrategy caseJavaArrayAttribute(ArrayType<?> openType) {
+ protected AttributeWritingStrategy caseJavaArrayAttribute(final ArrayType<?> openType) {
AttributeWritingStrategy innerStrategy = new SimpleAttributeWritingStrategy(document, key);
return new ArrayAttributeWritingStrategy(innerStrategy);
}
@Override
- protected AttributeWritingStrategy caseJavaIdentityRefAttribute(OpenType<?> openType) {
+ protected AttributeWritingStrategy caseJavaIdentityRefAttribute(final OpenType<?> openType) {
return new SimpleIdentityRefAttributeWritingStrategy(document, key);
}
@Override
- protected AttributeWritingStrategy caseJavaCompositeAttribute(CompositeType openType) {
+ protected AttributeWritingStrategy caseJavaCompositeAttribute(final CompositeType openType) {
return new SimpleCompositeAttributeWritingStrategy(document, key);
}
@Override
- protected AttributeWritingStrategy caseJavaUnionAttribute(OpenType<?> openType) {
+ protected AttributeWritingStrategy caseJavaUnionAttribute(final OpenType<?> openType) {
return new SimpleUnionAttributeWritingStrategy(document, key);
}
@Override
- protected AttributeWritingStrategy caseDependencyAttribute(SimpleType<?> openType) {
+ protected AttributeWritingStrategy caseDependencyAttribute(final SimpleType<?> openType) {
return new ObjectNameAttributeWritingStrategy(document, key);
}
@Override
- protected AttributeWritingStrategy caseTOAttribute(CompositeType openType) {
+ protected AttributeWritingStrategy caseTOAttribute(final CompositeType openType) {
Preconditions.checkState(getLastAttribute() instanceof TOAttribute);
Map<String, AttributeWritingStrategy> innerStrats = Maps.newHashMap();
}
@Override
- protected AttributeWritingStrategy caseListAttribute(ArrayType<?> openType) {
+ protected AttributeWritingStrategy caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
}
@Override
- protected AttributeWritingStrategy caseListDependeciesAttribute(ArrayType<?> openType) {
+ protected AttributeWritingStrategy caseListDependeciesAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute);
AttributeWritingStrategy innerStrategy = caseDependencyAttribute(SimpleType.OBJECTNAME);
return new ArrayAttributeWritingStrategy(innerStrategy);
public class RuntimeBeanEntryWritingStrategy extends CompositeAttributeWritingStrategy {
- public RuntimeBeanEntryWritingStrategy(Document document, String key,
- Map<String, AttributeWritingStrategy> innerStrats) {
+ public RuntimeBeanEntryWritingStrategy(final Document document, final String key,
+ final Map<String, AttributeWritingStrategy> innerStrats) {
super(document, key, innerStrats);
}
@Override
- public void writeElement(Element parentElement, String namespace, Object value) {
+ public void writeElement(final Element parentElement, final String namespace, final Object value) {
Util.checkType(value, Map.class);
Element innerNode = XmlUtil.createElement(getDocument(), getKey(), Optional.<String>absent());
* @param document
* @param key
*/
- public SimpleAttributeWritingStrategy(Document document, String key) {
+ public SimpleAttributeWritingStrategy(final Document document, final String key) {
this.document = document;
this.key = key;
}
@Override
- public void writeElement(Element parentElement, String namespace, Object value) {
+ public void writeElement(final Element parentElement, final String namespace, Object value) {
value = preprocess(value);
Util.checkType(value, String.class);
Element innerNode = createElement(document, key, (String) value, Optional.of(namespace));
parentElement.appendChild(innerNode);
}
- protected Element createElement(Document document, String key, String value, Optional<String> namespace) {
+ protected Element createElement(final Document document, final String key, final String value, final Optional<String> namespace) {
Element typeElement = XmlUtil.createElement(document, key, namespace);
typeElement.appendChild(document.createTextNode(value));
return typeElement;
}
- protected Object preprocess(Object value) {
+ protected Object preprocess(final Object value) {
return value;
}
* @param document
* @param key
*/
- public SimpleBinaryAttributeWritingStrategy(Document document, String key) {
+ public SimpleBinaryAttributeWritingStrategy(final Document document, final String key) {
super(document, key);
}
@Override
- protected Object preprocess(Object value) {
+ protected Object preprocess(final Object value) {
Util.checkType(value, List.class);
BaseEncoding en = BaseEncoding.base64();
* @param document
* @param key
*/
- public SimpleCompositeAttributeWritingStrategy(Document document, String key) {
+ public SimpleCompositeAttributeWritingStrategy(final Document document, final String key) {
super(document, key);
}
- protected Object preprocess(Object value) {
+ protected Object preprocess(final Object value) {
Util.checkType(value, Map.class);
Preconditions.checkArgument(((Map<?, ?>)value).size() == 1, "Unexpected number of values in %s, expected 1", value);
return ((Map<?, ?>)value).values().iterator().next();
* @param document
* @param key
*/
- public SimpleIdentityRefAttributeWritingStrategy(Document document, String key) {
+ public SimpleIdentityRefAttributeWritingStrategy(final Document document, final String key) {
super(document, key);
}
- protected Object preprocess(Object value) {
+ protected Object preprocess(final Object value) {
Util.checkType(value, Map.class);
Preconditions.checkArgument(((Map<?, ?>)value).size() == 1, "Unexpected number of values in %s, expected 1", value);
Object stringValue = ((Map<?, ?>) value).values().iterator().next();
}
@Override
- protected Element createElement(Document doc, String key, String value, Optional<String> namespace) {
+ protected Element createElement(final Document doc, final String key, final String value, final Optional<String> namespace) {
QName qName = QName.create(value);
String identityValue = qName.getLocalName();
String identityNamespace = qName.getNamespace().toString();
* @param document
* @param key
*/
- public SimpleUnionAttributeWritingStrategy(Document document, String key) {
+ public SimpleUnionAttributeWritingStrategy(final Document document, final String key) {
super(document, key);
}
- protected Object preprocess(Object value) {
+ protected Object preprocess(final Object value) {
Util.checkType(value, Map.class);
Preconditions.checkArgument(((Map<?, ?>)value).size() == 1, "Unexpected number of values in %s, expected 1", value);
Object listOfStrings = ((Map<?, ?>) value).values().iterator().next();
private final EnumResolver enumResolver;
- public Config(Map<String, Map<String, ModuleConfig>> moduleConfigs, final EnumResolver enumResolver) {
+ public Config(final Map<String, Map<String, ModuleConfig>> moduleConfigs, final EnumResolver enumResolver) {
this(moduleConfigs, Collections.<String, Map<Date, IdentityMapping>>emptyMap(), enumResolver);
}
- public Config(Map<String, Map<String, ModuleConfig>> moduleConfigs, Map<String, Map<Date, IdentityMapping>> identityMap, final EnumResolver enumResolver) {
+ public Config(final Map<String, Map<String, ModuleConfig>> moduleConfigs, final Map<String, Map<Date, IdentityMapping>> identityMap, final EnumResolver enumResolver) {
this.moduleConfigs = moduleConfigs;
this.identityMap = identityMap;
this.enumResolver = enumResolver;
}
- public static Map<String, Map<String, Collection<ObjectName>>> getMappedInstances(Set<ObjectName> instancesToMap,
- Map<String, Map<String, ModuleConfig>> configs) {
+ public static Map<String, Map<String, Collection<ObjectName>>> getMappedInstances(final Set<ObjectName> instancesToMap,
+ final Map<String, Map<String, ModuleConfig>> configs) {
Multimap<String, ObjectName> moduleToInstances = mapInstancesToModules(instancesToMap);
Map<String, Map<String, Collection<ObjectName>>> retVal = Maps.newLinkedHashMap();
return retVal;
}
- private static Multimap<String, ObjectName> mapInstancesToModules(Set<ObjectName> instancesToMap) {
+ private static Multimap<String, ObjectName> mapInstancesToModules(final Set<ObjectName> instancesToMap) {
Multimap<String, ObjectName> retVal = HashMultimap.create();
for (ObjectName objectName : instancesToMap) {
return retVal;
}
- public Element toXml(Set<ObjectName> instancesToMap, Optional<String> maybeNamespace, Document document,
- Element dataElement, ServiceRegistryWrapper serviceTracker) {
+ public Element toXml(final Set<ObjectName> instancesToMap, final Optional<String> maybeNamespace, final Document document,
+ final Element dataElement, final ServiceRegistryWrapper serviceTracker) {
Map<String, Map<String, Collection<ObjectName>>> moduleToInstances = getMappedInstances(instancesToMap,
moduleConfigs);
return dataElement;
}
- public Element moduleToXml(String moduleNamespace, String factoryName, String instanceName,
- ObjectName instanceON, Document document) {
+ public Element moduleToXml(final String moduleNamespace, final String factoryName, final String instanceName,
+ final ObjectName instanceON, final Document document) {
ModuleConfig moduleConfig = getModuleMapping(moduleNamespace, instanceName, factoryName);
return moduleConfig.toXml(instanceON, document, moduleNamespace, enumResolver);
}
// TODO refactor, replace Map->Multimap with e.g. ConfigElementResolved
// class
- public Map<String, Multimap<String, ModuleElementResolved>> fromXmlModulesResolved(XmlElement xml, EditStrategyType defaultEditStrategyType, ServiceRegistryWrapper serviceTracker) throws DocumentedException {
+ public Map<String, Multimap<String, ModuleElementResolved>> fromXmlModulesResolved(final XmlElement xml, final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException {
Optional<XmlElement> modulesElement = getModulesElement(xml);
List<XmlElement> moduleElements = getModulesElementList(modulesElement);
for (XmlElement moduleElement : moduleElements) {
ResolvingStrategy<ModuleElementResolved> resolvingStrategy = new ResolvingStrategy<ModuleElementResolved>() {
@Override
- public ModuleElementResolved resolveElement(ModuleConfig moduleMapping, XmlElement moduleElement, ServiceRegistryWrapper serviceTracker, String instanceName, String moduleNamespace, EditStrategyType defaultStrategy) throws DocumentedException {
+ public ModuleElementResolved resolveElement(final ModuleConfig moduleMapping, final XmlElement moduleElement, final ServiceRegistryWrapper serviceTracker, final String instanceName, final String moduleNamespace, final EditStrategyType defaultStrategy) throws DocumentedException {
return moduleMapping.fromXml(moduleElement, serviceTracker,
instanceName, moduleNamespace, defaultStrategy, identityMap, enumResolver);
}
/**
* return a map containing namespace -> moduleName -> instanceName map. Attribute parsing is omitted.
*/
- public Map<String, Multimap<String, ModuleElementDefinition>> fromXmlModulesMap(XmlElement xml,
- EditStrategyType defaultEditStrategyType, ServiceRegistryWrapper serviceTracker) throws DocumentedException {
+ public Map<String, Multimap<String, ModuleElementDefinition>> fromXmlModulesMap(final XmlElement xml,
+ final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException {
Optional<XmlElement> modulesElement = getModulesElement(xml);
List<XmlElement> moduleElements = getModulesElementList(modulesElement);
for (XmlElement moduleElement : moduleElements) {
ResolvingStrategy<ModuleElementDefinition> resolvingStrategy = new ResolvingStrategy<ModuleElementDefinition>() {
@Override
- public ModuleElementDefinition resolveElement(ModuleConfig moduleMapping, XmlElement moduleElement,
- ServiceRegistryWrapper serviceTracker, String instanceName, String moduleNamespace,
- EditStrategyType defaultStrategy) {
+ public ModuleElementDefinition resolveElement(final ModuleConfig moduleMapping, final XmlElement moduleElement,
+ final ServiceRegistryWrapper serviceTracker, final String instanceName, final String moduleNamespace,
+ final EditStrategyType defaultStrategy) {
// TODO: add check for conflicts between global and local
// edit strategy
String perInstanceEditStrategy = moduleElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY,
return retVal;
}
- private static Optional<XmlElement> getModulesElement(XmlElement xml) {
+ private static Optional<XmlElement> getModulesElement(final XmlElement xml) {
return xml.getOnlyChildElementOptionally(XmlMappingConstants.MODULES_KEY,
XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
}
- private List<XmlElement> getModulesElementList(Optional<XmlElement> modulesElement) throws DocumentedException {
+ private List<XmlElement> getModulesElementList(final Optional<XmlElement> modulesElement) throws DocumentedException {
List<XmlElement> moduleElements;
if (modulesElement.isPresent()) {
return moduleElements;
}
- private <T> void resolveModule(Map<String, Multimap<String, T>> retVal, ServiceRegistryWrapper serviceTracker,
- XmlElement moduleElement, EditStrategyType defaultStrategy, ResolvingStrategy<T> resolvingStrategy) throws DocumentedException {
+ private <T> void resolveModule(final Map<String, Multimap<String, T>> retVal, final ServiceRegistryWrapper serviceTracker,
+ final XmlElement moduleElement, final EditStrategyType defaultStrategy, final ResolvingStrategy<T> resolvingStrategy) throws DocumentedException {
XmlElement typeElement = null;
typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY);
Entry<String, String> prefixToNamespace = typeElement.findNamespaceOfTextContent();
innerMap.put(factoryName, resolvedElement);
}
- public Services fromXmlServices(XmlElement xml) throws DocumentedException {
+ public Services fromXmlServices(final XmlElement xml) throws DocumentedException {
Optional<XmlElement> servicesElement = getServicesElement(xml);
Services services;
return services;
}
- private static Optional<XmlElement> getServicesElement(XmlElement xml) {
+ private static Optional<XmlElement> getServicesElement(final XmlElement xml) {
return xml.getOnlyChildElementOptionally(XmlMappingConstants.SERVICES_KEY,
XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
}
- public static void checkUnrecognisedChildren(XmlElement parent) throws DocumentedException {
+ public static void checkUnrecognisedChildren(final XmlElement parent) throws DocumentedException {
Optional<XmlElement> servicesOpt = getServicesElement(parent);
Optional<XmlElement> modulesOpt = getModulesElement(parent);
parent.checkUnrecognisedElements(recognised);
}
- private String getFactoryName(String factoryNameWithPrefix, String prefixOrEmptyString) {
+ private String getFactoryName(final String factoryNameWithPrefix, final String prefixOrEmptyString) {
checkState(
factoryNameWithPrefix.startsWith(prefixOrEmptyString),
String.format("Internal error: text " + "content '%s' of type node does not start with prefix '%s'",
return factoryNameWithPrefix.substring(factoryNameAfterPrefixIndex);
}
- private ModuleConfig getModuleMapping(String moduleNamespace, String instanceName, String factoryName) {
+ private ModuleConfig getModuleMapping(final String moduleNamespace, final String instanceName, final String factoryName) {
Map<String, ModuleConfig> mappingsFromNamespace = moduleConfigs.get(moduleNamespace);
Preconditions.checkNotNull(mappingsFromNamespace,
private final Map<String, AttributeIfc> jmxToAttrConfig;
private final BeanReader configRegistryClient;
- public InstanceConfig(BeanReader configRegistryClient, Map<String, AttributeIfc> yangNamesToAttributes,
- String nullableDummyContainerName) {
+ public InstanceConfig(final BeanReader configRegistryClient, final Map<String, AttributeIfc> yangNamesToAttributes,
+ final String nullableDummyContainerName) {
this.yangToAttrConfig = yangNamesToAttributes;
this.nullableDummyContainerName = nullableDummyContainerName;
this.configRegistryClient = configRegistryClient;
}
- private Map<String, Object> getMappedConfiguration(ObjectName on, final EnumResolver enumResolver) {
+ 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()
continue;
}
toXml.put(configDefEntry.getValue().getAttributeYangName(), a.get());
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException("Unable to map value " + value + " to attribute "
+ configDefEntry.getKey(), e);
}
return toXml;
}
- public Element toXml(ObjectName on, String namespace, Document document, Element rootElement, final EnumResolver enumResolver) {
+ public Element toXml(final ObjectName on, final String namespace, final Document document, final Element rootElement, final EnumResolver enumResolver) {
Map<String, AttributeWritingStrategy> strats = new ObjectXmlWriter().prepareWriting(yangToAttrConfig, document);
Map<String, Object> mappedConfig = getMappedConfiguration(on, enumResolver);
Element parentElement;
for (Entry<String, ?> mappingEntry : mappedConfig.entrySet()) {
try {
strats.get(mappingEntry.getKey()).writeElement(parentElement, namespace, mappingEntry.getValue());
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException("Unable to write value " + mappingEntry.getValue() + " for attribute "
+ mappingEntry.getValue(), e);
}
return rootElement;
}
- private void resolveConfiguration(InstanceConfigElementResolved mappedConfig, ServiceRegistryWrapper depTracker, final EnumResolver enumResolver) {
+ private void resolveConfiguration(final InstanceConfigElementResolved mappedConfig, final ServiceRegistryWrapper depTracker, final EnumResolver enumResolver) {
// TODO make field, resolvingStrategies can be instantiated only once
Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> resolvingStrategies = new ObjectResolver(
value.resolveValue(attributeResolvingStrategy, attributeName);
value.setJmxName(
yangToAttrConfig.get(attributeName).getUpperCaseCammelCase());
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException("Unable to resolve value " + value
+ " to attribute " + attributeName, e);
}
}
}
- public InstanceConfigElementResolved fromXml(XmlElement moduleElement, ServiceRegistryWrapper services, String moduleNamespace,
- EditStrategyType defaultStrategy,
- Map<String, Map<Date, IdentityMapping>> identityMap, final EnumResolver enumResolver) throws DocumentedException {
+ public InstanceConfigElementResolved fromXml(XmlElement moduleElement, final ServiceRegistryWrapper services, final String moduleNamespace,
+ final EditStrategyType defaultStrategy,
+ final Map<String, Map<Date, IdentityMapping>> identityMap, final EnumResolver enumResolver) throws DocumentedException {
Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap);
if (size == expectedChildNodes) {
try {
moduleElement = moduleElement.getOnlyChildElement(nullableDummyContainerName, moduleNamespace);
- } catch (DocumentedException e) {
+ } catch (final DocumentedException e) {
throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " +
nameElement.getTextContent() + " - Expected child node with name " + nullableDummyContainerName +
"." + e.getMessage());
recognisedChildren.addAll(typeAndNameElements);
try {
moduleElement.checkUnrecognisedElements(recognisedChildren);
- } catch (DocumentedException e) {
+ } catch (final DocumentedException e) {
throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " +
nameElement.getTextContent() + " - " +
e.getMessage(), e.getErrorType(), e.getErrorTag(),e.getErrorSeverity(),e.getErrorInfo());
return instanceConfigElementResolved;
}
- private List<XmlElement> getConfigNodes(XmlElement moduleElement, String moduleNamespace, String name,
- List<XmlElement> recognisedChildren, List<XmlElement> typeAndName) throws DocumentedException {
+ private List<XmlElement> getConfigNodes(final XmlElement moduleElement, final String moduleNamespace, final String name,
+ final List<XmlElement> recognisedChildren, final List<XmlElement> typeAndName) throws DocumentedException {
List<XmlElement> foundConfigNodes = moduleElement.getChildElementsWithinNamespace(name, moduleNamespace);
if (foundConfigNodes.isEmpty()) {
LOG.debug("No config nodes {}:{} found in {}", moduleNamespace, name, moduleElement);
return foundConfigNodes;
}
- private static Map<String, AttributeIfc> reverseMap(Map<String, AttributeIfc> yangNameToAttr) {
+ private static Map<String, AttributeIfc> reverseMap(final Map<String, AttributeIfc> yangNameToAttr) {
Map<String, AttributeIfc> reversednameToAtr = Maps.newHashMap();
for (Entry<String, AttributeIfc> entry : yangNameToAttr.entrySet()) {
private final EditStrategyType editStrategy;
private final Map<String, AttributeConfigElement> configuration;
- public InstanceConfigElementResolved(String currentStrategy, Map<String, AttributeConfigElement> configuration,
- EditStrategyType defaultStrategy)
+ public InstanceConfigElementResolved(final String currentStrategy, final Map<String, AttributeConfigElement> configuration,
+ final EditStrategyType defaultStrategy)
throws DocumentedException {
this.editStrategy = parseStrategy(currentStrategy, defaultStrategy);
this.configuration = configuration;
}
- public InstanceConfigElementResolved(Map<String, AttributeConfigElement> configuration, EditStrategyType defaultStrategy) {
+ public InstanceConfigElementResolved(final Map<String, AttributeConfigElement> configuration, final EditStrategyType defaultStrategy) {
editStrategy = defaultStrategy;
this.configuration = configuration;
}
- static EditStrategyType parseStrategy(String currentStrategy, EditStrategyType defaultStrategy) throws OperationNotPermittedException {
+ static EditStrategyType parseStrategy(final String currentStrategy, final EditStrategyType defaultStrategy) throws OperationNotPermittedException {
EditStrategyType parsedStrategy = EditStrategyType.valueOf(currentStrategy);
EditStrategyType.compareParsedStrategyToDefaultEnforcing(parsedStrategy,defaultStrategy);
return parsedStrategy;
private final String moduleName;
private final InstanceConfig instanceConfig;
- public ModuleConfig(String moduleName, InstanceConfig mbeanMapping) {
+ public ModuleConfig(final String moduleName, final InstanceConfig mbeanMapping) {
this.moduleName = moduleName;
this.instanceConfig = mbeanMapping;
}
- public Element toXml(ObjectName instanceON, Document document, String namespace, final EnumResolver enumResolver) {
+ public Element toXml(final ObjectName instanceON, final Document document, final String namespace, final EnumResolver enumResolver) {
final Optional<String> configNs =
Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
Element root = XmlUtil.createElement(document, XmlMappingConstants.MODULE_KEY, configNs);
return root;
}
- public ModuleElementResolved fromXml(XmlElement moduleElement, ServiceRegistryWrapper depTracker, String instanceName,
- String moduleNamespace, EditStrategyType defaultStrategy, Map<String, Map<Date, IdentityMapping>> identityMap, final EnumResolver enumResolver) throws DocumentedException {
+ public ModuleElementResolved fromXml(final XmlElement moduleElement, final ServiceRegistryWrapper depTracker, final String instanceName,
+ final String moduleNamespace, final EditStrategyType defaultStrategy, final Map<String, Map<Date, IdentityMapping>> identityMap, final EnumResolver enumResolver) throws DocumentedException {
InstanceConfigElementResolved ice = instanceConfig.fromXml(moduleElement, depTracker, moduleNamespace, defaultStrategy, identityMap, enumResolver);
return new ModuleElementResolved(instanceName, ice);
private final EditStrategyType editStrategy;
private static final Logger LOG = LoggerFactory.getLogger(ModuleElementDefinition.class);
- public ModuleElementDefinition(String instanceName, String currentStrategy, EditStrategyType defaultStrategy) {
+ public ModuleElementDefinition(final String instanceName, final String currentStrategy, final EditStrategyType defaultStrategy) {
this.instanceName = instanceName;
if (currentStrategy == null || currentStrategy.isEmpty()) {
this.editStrategy = defaultStrategy;
EditStrategyType _edStrategy = null;
try {
_edStrategy = InstanceConfigElementResolved.parseStrategy(currentStrategy, defaultStrategy);
- } catch (OperationNotPermittedException e) {
+ } catch (final OperationNotPermittedException e) {
_edStrategy = defaultStrategy;
LOG.warn("Operation not permitted on current strategy {} while default strategy is {}. Element definition strategy set to default.",
currentStrategy,
private final String instanceName;
private final InstanceConfigElementResolved instanceConfigElementResolved;
- public ModuleElementResolved(String instanceName, InstanceConfigElementResolved instanceConfigElementResolved) {
+ public ModuleElementResolved(final String instanceName, final InstanceConfigElementResolved instanceConfigElementResolved) {
this.instanceName = instanceName;
this.instanceConfigElementResolved = instanceConfigElementResolved;
}
private final ServiceReferenceReadableRegistry configServiceRefRegistry;
- public ServiceRegistryWrapper(ServiceReferenceReadableRegistry configServiceRefRegistry) {
+ public ServiceRegistryWrapper(final ServiceReferenceReadableRegistry configServiceRefRegistry) {
this.configServiceRefRegistry = configServiceRefRegistry;
}
- public ObjectName getByServiceAndRefName(String namespace, String serviceType, String refName) {
+ public ObjectName getByServiceAndRefName(final String namespace, final String serviceType, final String refName) {
Map<String, Map<String, Map<String, String>>> mappedServices = getMappedServices();
Map<String, Map<String, String>> serviceNameToRefNameToInstance = mappedServices.get(namespace);
*/
return ObjectNameUtil.withoutTransactionName(
configServiceRefRegistry.getServiceReference(qNameOfService, refName));
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new IllegalArgumentException("No serviceInstance mapped to " + refName
+ " under service name " + serviceType + " , " + refNameToInstance.keySet(), e);
return namespaceToServiceNameToRefNameToInstance;
}
- private static Services resolveServices(Map<String, Map<String, Map<String, String>>> mappedServices) {
+ private static Services resolveServices(final Map<String, Map<String, Map<String, String>>> mappedServices) {
Services tracker = new Services();
for (Entry<String, Map<String, Map<String, String>>> namespaceEntry : mappedServices.entrySet()) {
// TODO support edit strategies on services
- public static Services fromXml(XmlElement xml) throws DocumentedException {
+ public static Services fromXml(final XmlElement xml) throws DocumentedException {
Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
return resolveServices(retVal);
}
- public static Element toXml(ServiceRegistryWrapper serviceRegistryWrapper, Document document) {
+ public static Element toXml(final ServiceRegistryWrapper serviceRegistryWrapper, final Document document) {
final Optional<String> configNs = Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
Element root = XmlUtil.createElement(document, XmlMappingConstants.SERVICES_KEY, configNs);
public static final class ServiceInstance {
public static final ServiceInstance EMPTY_SERVICE_INSTANCE = new ServiceInstance("", "");
- public ServiceInstance(String moduleName, String instanceName) {
+ public ServiceInstance(final String moduleName, final String instanceName) {
this.moduleName = moduleName;
this.instanceName = instanceName;
}
return serviceName;
}
- public void setServiceName(String serviceName) {
+ public void setServiceName(final String serviceName) {
this.serviceName = serviceName;
}
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj){
return true;
}
return true;
}
- public ObjectName getObjectName(String transactionName) {
+ public ObjectName getObjectName(final String transactionName) {
return ObjectNameUtil.createTransactionModuleON(transactionName, moduleName, instanceName);
}
- public static ServiceInstance fromObjectName(ObjectName on) {
+ public static ServiceInstance fromObjectName(final ObjectName on) {
return new ServiceInstance(ObjectNameUtil.getFactoryName(on), ObjectNameUtil.getInstanceName(on));
}
}
private final Rpc rpc;
private final EnumResolver enumResolver;
- public InstanceRuntimeRpc(Rpc rpc, final EnumResolver enumResolver) {
+ public InstanceRuntimeRpc(final Rpc rpc, final EnumResolver enumResolver) {
this.enumResolver = enumResolver;
this.yangToAttrConfig = map(rpc.getParameters());
this.rpc = rpc;
}
- private Map<String, AttributeIfc> map(List<JavaAttribute> parameters) {
+ private Map<String, AttributeIfc> map(final List<JavaAttribute> parameters) {
Map<String, AttributeIfc> mapped = Maps.newHashMap();
for (JavaAttribute javaAttribute : parameters) {
mapped.put(javaAttribute.getAttributeYangName(), javaAttribute);
return mapped;
}
- private void resolveConfiguration(Map<String, AttributeConfigElement> mappedConfig) {
+ private void resolveConfiguration(final Map<String, AttributeConfigElement> mappedConfig) {
// TODO make field, resolvingStrategies can be instantiated only once
Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> resolvingStrategies = new ObjectResolver(null)
configDefEntry.getValue().resolveValue(attributeResolvingStrategy, configDefEntry.getKey());
configDefEntry.getValue().setJmxName(
yangToAttrConfig.get(configDefEntry.getKey()).getUpperCaseCammelCase());
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException("Unable to resolve value " + configDefEntry.getValue()
+ " to attribute " + configDefEntry.getKey(), e);
}
}
}
- public Map<String, AttributeConfigElement> fromXml(XmlElement configRootNode) throws DocumentedException {
+ public Map<String, AttributeConfigElement> fromXml(final XmlElement configRootNode) throws DocumentedException {
Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
// FIXME add identity map to runtime data
private final List<ObjectName> allOpenedTransactions = new ArrayList<>();
private static final String NO_TRANSACTION_FOUND_FOR_SESSION = "No transaction found for session ";
- public TransactionProvider(ConfigRegistryClient configRegistryClient, String sessionIdForReporting) {
+ public TransactionProvider(final ConfigRegistryClient configRegistryClient, final String sessionIdForReporting) {
this.configRegistryClient = configRegistryClient;
this.sessionIdForReporting = sessionIdForReporting;
}
if (isStillOpenTransaction(tx)) {
configRegistryClient.getConfigTransactionClient(tx).abortConfig();
}
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.debug("Ignoring exception while closing transaction {}", tx, e);
}
}
return Optional.of(readTx);
}
- private boolean isStillOpenTransaction(ObjectName transaction) {
+ private boolean isStillOpenTransaction(final ObjectName transaction) {
return configRegistryClient.getOpenConfigs().contains(transaction);
}
allOpenedTransactions.remove(candidateTx);
candidateTx = null;
return status;
- } catch (ValidationException validationException) {
+ } catch (final ValidationException validationException) {
// no clean up: user can reconfigure and recover this transaction
LOG.warn("Transaction {} failed on {}", taON, validationException.toString());
throw validationException;
- } catch (ConflictingVersionException e) {
+ } catch (final ConflictingVersionException e) {
LOG.debug("Exception while commit of {}, aborting transaction", taON, e);
// clean up
abortTransaction();
readTx = null;
}
- public synchronized void abortTestTransaction(ObjectName testTx) {
+ public synchronized void abortTestTransaction(final ObjectName testTx) {
LOG.debug("Aborting transaction {}", testTx);
ConfigTransactionClient transactionClient = configRegistryClient.getConfigTransactionClient(testTx);
allOpenedTransactions.remove(testTx);
transactionClient.validateConfig();
}
- public void validateTestTransaction(ObjectName taON) throws ValidationException {
+ public void validateTestTransaction(final ObjectName taON) throws ValidationException {
ConfigTransactionClient transactionClient = configRegistryClient.getConfigTransactionClient(taON);
transactionClient.validateConfig();
}
- public void wipeTestTransaction(ObjectName taON) {
+ public void wipeTestTransaction(final ObjectName taON) {
wipeInternal(taON, true);
}
/**
* Wiping means removing all module instances keeping the transaction open + service references.
*/
- synchronized void wipeInternal(ObjectName taON, boolean isTest) {
+ synchronized void wipeInternal(final ObjectName taON, final boolean isTest) {
ConfigTransactionClient transactionClient = configRegistryClient.getConfigTransactionClient(taON);
Set<ObjectName> lookupConfigBeans = transactionClient.lookupConfigBeans();
for (ObjectName instance : lookupConfigBeans) {
try {
transactionClient.destroyModule(instance);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
if (isTest){
LOG.debug("Unable to clean configuration in transactiom {}", taON, e);
} else {