void copyStates( ESMoL::Stateflow inputStateflow, ESMoL::Stateflow outputStateflow ) {

	getConnectorRefList().clear();
	getTransConnectorMap().clear();

	StateVector stateVector = inputStateflow.State_kind_children();
	for( StateVector::iterator stvItr = stateVector.begin() ; stvItr != stateVector.end() ; ++stvItr ) {
		ESMoL::State inputState = *stvItr;
		ESMoL::State outputState = ESMoL::State::Create( outputStateflow );
		copyState( inputState, outputState );
	}
	for( ConnectorRefList::iterator crlItr = getConnectorRefList().begin() ; crlItr != getConnectorRefList().end() ; ++crlItr ) {
		ESMoL::ConnectorRef inputConnectorRef = *crlItr;
		ESMoL::TransConnector inputTransConnector = inputConnectorRef.ref();
		if ( inputTransConnector == Udm::null ) {
			std::cerr << "Warning:  ConnectorRef is a null reference!" << std::endl;
			continue;
		}

		TransConnectorMap::iterator tcmItr = getTransConnectorMap().find( inputConnectorRef );
		if ( tcmItr == getTransConnectorMap().end() ) {
			std::cerr << "Warning:  ConnectorRef has no copy in TransConnectorMap" << std::endl;
			continue;
		}
		ESMoL::TransConnector outputTransConnector = tcmItr->second;
		if ( outputTransConnector.type() != ESMoL::ConnectorRef::meta ) {
			std::cerr << "Warning:  TransConnector should be a ConnectorRef" << std::endl;
			continue;
		}
		ESMoL::ConnectorRef outputConnectorRef = ESMoL::ConnectorRef::Cast( outputTransConnector );

		tcmItr = getTransConnectorMap().find( inputTransConnector );
		if ( tcmItr == getTransConnectorMap().end() ) {
			std::cerr << "Warning:  TransConnector has no copy in TransConnectorMap" << std::endl;
			continue;
		}
		outputTransConnector = tcmItr->second;

		outputConnectorRef.ref() = outputTransConnector;
	}
}
void copyState( ESMoL::State inputState, ESMoL::State outputState ) {

	UdmEngine::copyState( inputState, outputState );

	TransStartVector transStartVector = inputState.TransStart_kind_children();
	for( TransStartVector::iterator tsvItr = transStartVector.begin() ; tsvItr != transStartVector.end() ; ++tsvItr ) {
		ESMoL::TransStart inputTransStart = *tsvItr;
		ESMoL::TransStart outputTransStart = ESMoL::TransStart::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputTransStart, outputTransStart )  );
	}

	DataVector dataVector = inputState.Data_kind_children();
	for( DataVector::iterator dtvItr = dataVector.begin() ; dtvItr != dataVector.end() ; ++dtvItr ) {
		copyData(  *dtvItr, ESMoL::Data::Create( outputState )  );
	}

	EventVector eventVector = inputState.Event_kind_children();
	for( EventVector::iterator envItr = eventVector.begin() ; envItr != eventVector.end() ; ++envItr ) {
		copyEvent(  *envItr, ESMoL::Event::Create( outputState )  );
	}

	JunctionVector junctionVector = inputState.Junction_kind_children();
	for( JunctionVector::iterator jnvItr = junctionVector.begin() ; jnvItr != junctionVector.end() ; ++jnvItr ) {
		ESMoL::Junction inputJunction = *jnvItr;
		ESMoL::Junction outputJunction = ESMoL::Junction::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputJunction, outputJunction )  );
	}

	StateVector stateVector = inputState.State_kind_children();
	for( StateVector::iterator stvItr = stateVector.begin() ; stvItr != stateVector.end() ; ++stvItr ) {
		ESMoL::State inputSubState = *stvItr;
		ESMoL::State outputSubState = ESMoL::State::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputSubState, outputSubState )  );
		copyState( inputSubState, outputSubState );
	}

	ConnectorRefVector connectorRefVector = inputState.ConnectorRef_kind_children();
	for( ConnectorRefVector::iterator jnvItr = connectorRefVector.begin() ; jnvItr != connectorRefVector.end() ; ++jnvItr ) {
		ESMoL::ConnectorRef inputConnectorRef = *jnvItr;
		ESMoL::ConnectorRef outputConnectorRef = ESMoL::ConnectorRef::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputConnectorRef, outputConnectorRef )  );
		getConnectorRefList().push_back( inputConnectorRef );
	}

	TransitionVector transitionVector = inputState.Transition_kind_children();
	for( TransitionVector::iterator trvItr = transitionVector.begin() ; trvItr != transitionVector.end() ; ++trvItr ) {
		ESMoL::Transition inputTransition = *trvItr;

		ESMoL::TransConnector inputSrcTransConnector = inputTransition.srcTransition_end();
		TransConnectorMap::iterator tcmItr = getTransConnectorMap().find( inputSrcTransConnector );
		if ( tcmItr == getTransConnectorMap().end() ) {
			std::cerr << "WARNING:  transconnector does not map to copy" << std::endl;
			continue;
		}
		ESMoL::TransConnector outputSrcTransConnector = tcmItr->second;

		ESMoL::TransConnector inputDstTransConnector = inputTransition.dstTransition_end();
		tcmItr = getTransConnectorMap().find( inputDstTransConnector );
		if ( tcmItr == getTransConnectorMap().end() ) {
			std::cerr << "WARNING:  transconnector does not map to copy" << std::endl;
			continue;
		}
		ESMoL::TransConnector outputDstTransConnector = tcmItr->second;

		ESMoL::Transition outputTransition = ESMoL::Transition::Create( outputState );
		UdmEngine::copyTransition( inputTransition, outputTransition );

		outputTransition.srcTransition_end() = outputSrcTransConnector;
		outputTransition.dstTransition_end() = outputDstTransConnector;
	}
}