org.odpi.openmetadata.commonservices.generichandlers.OCFConnectionConverter Maven / Gradle / Ivy
The newest version!
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.commonservices.generichandlers;
import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
* OCFConnectionConverter transfers the relevant properties from some Open Metadata Repository Services (OMRS)
* EntityDetail and Relationship objects into a Connection bean (or a VirtualConnection bean).
*/
public class OCFConnectionConverter extends OMFConverter
{
/**
* Constructor
*
* @param repositoryHelper helper object to parse entity
* @param serviceName name of this component
* @param serverName local server name
*/
public OCFConnectionConverter(OMRSRepositoryHelper repositoryHelper,
String serviceName,
String serverName)
{
super(repositoryHelper, serviceName, serverName);
}
/**
* Using the supplied instances, return a new instance of the bean. It is used for beans such as
* a connection bean which made up of 3 entities (Connection, ConnectorType and Endpoint) plus the
* relationships between them. The relationships may be omitted if they do not have an properties.
*
* @param beanClass name of the class to create
* @param primaryEntity entity that is the root of the collection of entities that make up the
* content of the bean
* @param supplementaryEntities entities connected to the primary entity by the relationships
* @param relationships relationships linking the entities
* @param methodName calling method
* @return bean populated with properties from the instances supplied
* @throws PropertyServerException there is a problem instantiating the bean
*/
@Override
@SuppressWarnings(value = "unchecked")
public B getNewComplexBean(Class beanClass,
EntityDetail primaryEntity,
List supplementaryEntities,
List relationships,
String methodName) throws PropertyServerException
{
try
{
/*
* This is initial confirmation that the generic converter has been initialized with an appropriate bean class.
*/
B returnBean = beanClass.getDeclaredConstructor().newInstance();
if (returnBean instanceof Connection)
{
/*
* This cast should not fail due to the checking we have done above, but ClassCastException is caught just in case.
*/
return (B) getEmbeddedConnection(beanClass, primaryEntity, supplementaryEntities, relationships, methodName);
}
}
catch (IllegalAccessException | InstantiationException | ClassCastException | NoSuchMethodException | InvocationTargetException error)
{
super.handleInvalidBeanClass(beanClass.getName(), error, methodName);
}
return null;
}
}